This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Inline assembler + register values
- From: Konstantin Vladimirov <konstantin dot vladimirov at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 24 Jan 2012 15:35:59 +0400
- Subject: Inline assembler + register values
Hi,
This problem is backend independent, so I build reproduction in x86
backend. Consider code:
int func(int x);
int test(int x, int *data)
{
int retval;
register int *buffer asm ("eax");
buffer = data;
retval = func(x);
__asm__ __volatile__ (".internal_label _t." "4096"
".%0.%1.%2:;nop"::"ri" (buffer), "ri" (4137), "ri" (4));
return retval;
}
here nop will be replaced for something, that essentially uses %eax,
but it is not actually required for minimal reproduction.
being compiled with gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch
revision 160292]
with following options:
gcc -m32 -O2 -S -fomit-frame-pointer reprox86.c
yields assembler:
.type test, @function
test:
subl $28, %esp
movl 32(%esp), %eax
movl %eax, (%esp)
call func // <--- here eax is clobbered
.internal_label _t.4096.%eax.$4137.$4:;nop 0
addl $28, %esp
ret
That looks quite odd. I have a question -- why compiler doesn't save &
restore buffer (i.e. %eax) value around function call, when we
specifically pointed to %eax usage in the inline assembler
instruction?
Thanks for responses in advance.
---
With best regards, Konstantin