This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Stack frame question on x86 code generation
- From: Gang-Ryung Uh <uh18104 at yahoo dot com>
- To: James E Wilson <wilson at specifixinc dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 25 Apr 2005 18:22:48 -0700 (PDT)
- Subject: Re: Stack frame question on x86 code generation
Thanks for your response. Please find the subsequent
question.
Best regards,
--- James E Wilson <wilson@specifixinc.com> 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
/usr/lib/gcc-lib/i386-redhat-linux/3.3.2/specs
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
> 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.
>
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
> MMX/SSE
> 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,
> http://www.SpecifixInc.com
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com