noreturn function attribute and ret asm instruction

Kristis Makris kristis.makris@asu.edu
Tue Aug 19 13:59:00 GMT 2003



Hello, 

$ 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. Conceptually
I should be able to just define the function in C. Shouldn't this
noreturn behaviour be fixed ?

Thanks, 
Kristis





More information about the Gcc-help mailing list