This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Adding assembly after end of functions in GCC-3.4
- From: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 12 Feb 2004 15:21:21 +0100 (CET)
- Subject: Adding assembly after end of functions in GCC-3.4
Hello,
I was wondering, now that the functions are completely
re-ordered with GCC-3.4, and so you can no more put asm ("") in
between functions, if it would (undocumentely) work to put an
asm("") in between the last return of a function and the closing
brace of the function. I could use it to place some assembler
instructions or directives after the last "ret" assembly instruction.
The two uses I can see is to know the size in bytes of a function
and to simulate the still uninplemented longcall/long_call/far
function attribute for ia32 (i.e. terminating the function
by "lret"/"lretw" - in Intel terms a "far return" poping %ip and %cs)
Other people may find other uses to put assembly there (switching
section with the assembly " .previous " operation).
Well, it does not work (the volatile assembly is not inserted)
and it does not generate any warning neither...
Etienne.
[etienne@localhost gujin]$ cat asm.c
void do_something (void);
extern char sizeof_fct[];
// extern void sizeof_fct[]; // would be more meaningfull?
void fct (void)
{
do_something();
return;
asm volatile (" sizeof_fct = fct - . \n");
}
void another (void)
{ asm (".macro ret \n lretw \n .endm \n"); {
do_something();
return;
} asm volatile (".purgem ret \n"); }
[etienne@localhost gujin]$ ../toolchain-3.4/bin/gcc -Wall -w -O -S asm.c -o
asm.s
[etienne@localhost gujin]$ cat asm.s
.file "asm.c"
.text
.globl fct
.type fct, @function
fct:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
call do_something
leave
ret
.size fct, .-fct
.globl another
.type another, @function
another:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
#APP
.macro ret
lretw
.endm
#NO_APP
call do_something
leave
ret
.size another, .-another
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.0 20040121 (prerelease)"
------------ the macro ret is still defined here,
------------ the (possibly) following function will have
------------ problems.
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/