public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* noreturn function attribute and ret asm instruction
@ 2003-08-23 16:33 Kristis Makris
  2003-08-25 20:30 ` Jim Wilson
  0 siblings, 1 reply; 22+ messages in thread
From: Kristis Makris @ 2003-08-23 16:33 UTC (permalink / raw)
  To: gcc-bugs

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



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2003-10-01 17:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-23 16:33 noreturn function attribute and ret asm instruction Kristis Makris
2003-08-25 20:30 ` Jim Wilson
2003-08-26  6:51   ` Kristis Makris
2003-08-26  7:05     ` Zack Weinberg
2003-08-30  0:09       ` Kristis Makris
2003-09-02 21:17         ` Jim Wilson
2003-09-02 21:57           ` Zack Weinberg
2003-09-02 22:02             ` Joseph S. Myers
2003-09-03  2:19             ` Kristis Makris
2003-09-12  1:29             ` Kristis Makris
2003-09-12  7:10               ` Jim Wilson
2003-09-12 18:16                 ` Kristis Makris
2003-09-13  3:41                   ` Jim Wilson
2003-09-14 17:31                     ` Kristis Makris
2003-09-14 20:22                       ` Jim Wilson
2003-09-15 18:21                         ` Kristis Makris
2003-09-15 20:15                           ` Jim Wilson
2003-10-01  5:59           ` Hans-Peter Nilsson
2003-10-01  7:00             ` Zack Weinberg
2003-10-01  7:26               ` Hans-Peter Nilsson
2003-10-01 16:21               ` Richard Henderson
2003-10-01 17:57                 ` Zack Weinberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).