Re: Stack frame question on x86 code generation

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

 



Gang-Ryung Uh wrote:
Could anyone help me understand what is the gcc strategy to prepare the stack frame?

You didn't mention the gcc version, or the gcc target. Different gcc versions and targets will give different answers. Even different x86 targets work differently.


printf("0x%x=return address, *ret);

You are missing a quote here.

question1: Why the stack frame size is 56?

A bug. It is 40 in current gcc development sources, or rather, I should say that it is 40 that gets subtracted from the stack pointer. The actual frame size also includes stuff that is being pushed.


This is probably the same issue as discussed in the thead here
    http://gcc.gnu.org/ml/gcc/2005-04/msg01191.html

Then, why they adding 16 bytes padding?

Probably the same bug. I get "leal -9(%ebp), %eax" which makes sense for a 5 byte array, with 4 bytes of data allocated ahead of it.


question2: Why gcc makes the stack frame bigger before
           the function call printf?

This is probably to maintain 16-byte stack alignment when we reach printf. We maintain 16-byte stack alignment so that MMX/SSE instructions will work.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

[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