www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/05/17:41:06

To: djgpp AT delorie DOT com
Subject: Re: inline asm & jmp
References: <37084934 DOT 6866274 AT news3 DOT ibm DOT net>
From: Michael Bukin <M DOT A DOT Bukin AT inp DOT nsk DOT su>
Date: 05 Apr 1999 13:02:44 +0700
In-Reply-To: snowball3@usa.net's message of "Mon, 05 Apr 1999 05:35:00 GMT"
Message-ID: <204smvli4b.fsf@Sky.inp.nsk.su>
Lines: 39
X-Mailer: Gnus v5.5/Emacs 19.34
Reply-To: djgpp AT delorie DOT com

snowball3 AT usa DOT net (Mark E.) writes:

> I'm experimenting with inline assembly by trying to create an alias to a
> libc function, but so far I've been unsuccessful.
> ...
> All I wanted was the 'jmp' instruction, not extra stack code. I've read the
> extended assembly portion of the gcc manual and I've tried out some of the
> constraints, but nothing gets rid of the extra code. Is there a way to tell
> asm() to output just the 'jmp' or am I out of luck?

asm does not output extra code for this function.  Your jmp
instruction is output verbatim.  Even if you can find a way to get rid
of extra code for setting standard stack frame generated by compiler
(try -fomit-frame-pointer, for example), you should not rely on it.
Instead, you can use the following

__asm__ __volatile__
  ("	.globl _memchr_alias\n"
   "_memchr_alias:\n"
   "	jmp _memchr");

And prototype it correctly before calling your alias function:

void *memchr_alias (const void *string, int ch, size_t num);

Also, you can read about alias attribute, supported by gcc

info gcc "c ext" "function attr"

And read about `--wrap' option of ld

info ld invocation options

Or make your memchr_alias as inline function which calls memchr and
gcc will generate optimized code (but why don't you call memchr
directly?).

-- 
Michael Bukin

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019