This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
noreturn function attribute and ret asm instruction
- From: Kristis Makris <kristis dot makris at asu dot edu>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Aug 2003 08:53:52 -0700
- Subject: noreturn function attribute and ret asm instruction
Hello,
I have also send this to gcc-help but got no response.
$ gcc --version
gcc (GCC) 3.3 (Debian)
I am trying to create a C function that does not return and I have
implemented it like this:
void __attribute__((always_inline)) __attribute__((noreturn))
dynreplace_branch(void *address)
{
__asm__ __volatile__ ( "jmp *%0"
: /* output */
: "m" (address) /* input */
);
}
This produces the following asm code:
$ objdump -d -z -r arch/i386/kernel/dynreplace.o
arch/i386/kernel/dynreplace.o: file format elf32-i386
Disassembly of section .text:
00000000 <dynreplace_branch>:
0: ff 64 24 04 jmp *0x4(%esp,1)
4: c3 ret
The problem I have with this is the ret instruction that gets generated,
while I'm trying to do just a jmp.
Is a #defined version of the function or simply writing this in assembly
instead of C the only way I can produce only the jmp without the ret ? I
would assume noreturn would imply that no ret instruction would be
emmitted but that does not seem to be the case. I was able to get the
just the jump when I #define the function as:
#define dynreplace_branch(address) \
__asm__ __volatile__ ( "jmp *%0" \
: /* output */ \
: "m" (address) /* input */ \
);
But then I lose the type checking feature if I use a macro, plus I am
stuck havind to add "\"s at the end of each line so I can't write too
much code in a legible way, plus I can't really memcpy during runtime
the code produced by this macro, the way I would if this was a function.
Conceptually I should be able to just define the function in C. Is this
noreturn behaviour expected ? Shouldn't the "ret" be missing from the
code produced here (is this a bug)? Is there another attribute that
won't produce that "ret" instruction ?
Thanks,
Kristis