Re: gcc return struct code generation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Thank you for your time, sir. I think the better option is to rearrange my code and forget this issue.

For curiosity, today i test this code with the intel compiler (12.0.5.220). It generates this code for fn:

icc -O2 -fomit-frame-pointer -c z.c


0000000000000000 <fn>:
   0:56                   push   %rsi
   1:e8 00 00 00 00       callq  6 <fn+0x6>
   6:48 03 c2             add    %rdx,%rax
   9:59                   pop    %rcx
   a:c3                   retq   

Yo can see the code changes the values of registers RSI and RCX with apparently no reason ! (appart of computing correctly the c code of fn).
Also this code uses stack with apparently no reason, or i can not see it.

Regards.

Jose.



----- Mensaje original -----
De: Ian Lance Taylor <iant@xxxxxxxxxx>
Para: jose gomez valcarcel <jcgv33@xxxxxxxx>
CC: "gcc-help@xxxxxxxxxxx" <gcc-help@xxxxxxxxxxx>
Enviado: martes 30 de agosto de 2011 15:12
Asunto: Re: gcc return struct code generation

jose gomez valcarcel <jcgv33@xxxxxxxx> writes:

> I also think is a bug, but i'm not sure. My toy kernel has no assembly (.S) files, but of course it has c functions with
> inline assembly. My context switch function it's a c funtion (yes i know there are better ways of doing this) with some
> inline assembly code first to save context, some c code, and then some assembly code to restore context and do 'iret'.
> It works only if the C code doesn't touch the rsp, because I 'intercept' the end of the function.
>
> I known that is 'questionable' code, but the real question is that i expect that this simple C code not to touch RSP with optimizations
> enabled in x86_64. I got surprised. Note that you point of stack aligned on 16 byte boundary is irrelevant, because it has to be aligned
> on 'fn' entry call.

I see.  The stack alignment is not irrelevant if your function callls
any other functions, because the function will have to adjust for the 8
byte return address pushed on the stack by its caller.  If that is an
issue you can use the -mpreferred-stack-boundary option to compensate.
Of course you need to make sure that the stack pointer is correctly
aligned before returning to any regular C code.

Ian




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux