This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Stack frame question on x86 code generation
- From: Gang-Ryung Uh <uh18104 at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Sat, 23 Apr 2005 11:09:44 -0700 (PDT)
- Subject: Stack frame question on x86 code generation
Could anyone help me understand what is the gcc
strategy to prepare the stack frame?
For the following function,
void function(int a, int b, int c)
{
char buffer1[5];
char buffer2[10];
int *ret;
ret = &buffer1[0]+28;
printf("0x%x=return address, *ret);
}
I compiled with gcc -O0 -S option and the compiler
produces the code that I cannot quite follow the
stack frame layout strategy in gcc.
function:
pushl %ebp
movl %esp, %ebp
subl $56, %esp // question 1
leal -24(%ebp), %eax
addl $28, %eax
movl %eax, -44(%ebp)
subl $8, %esp // question 2
movl -44(%ebp), %eax
pushl (%eax)
pushl $.LC0
call printf
Here are my questions:
question1: Why the stack frame size is 56?
observation: (1) compiler add 16 bytes
padding before allocating storage
for array buffer1 (2) buffer1 need
5 bytes. However, due to alignment
issue, they seem to add 3 extra bytes.
Thus, -24(%ebp) should point to buffer1[0].
Then, why they adding 16 bytes padding?
question2: Why gcc makes the stack frame bigger before
the function call printf?
subl $8, %esp
Does it related to printf? If it does, then
could you explain why?
Thanks in advance.
Best regards,
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com