This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Stack frame question on x86 code generation

Thanks for your response. Please find the subsequent

Best regards,

--- James E Wilson <> wrote:

> 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.
% gcc -v
Reading specs from
Configured with: ../configure --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix
--disable-checking --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)

> >   printf("0x%x=return address, *ret);
> You are missing a quote here.

You are absolutely right.

> > 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.

Well, that answers. 

> This is probably the same issue as discussed in the
> thead here
> >            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.

That answers, too!

> > 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
> instructions will work.

I am not quite following this. It sounds like the
stack frame
of the current development gcc version is not aligned
with 16 bytes with -40. How you can make it 16 bytes
aligned with -8? 

> -- 
> Jim Wilson, GNU Tools Support,

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]