Re: Why gcc translate a c program into assemble as follow
- From: DJ Delorie <dj@xxxxxxxxxxx>
- Date: Sat, 29 Oct 2005 19:57:35 +0000 (UTC)
Tim Roberts <spamtrap@xxxxxxxxxx> writes:
> Well, I assume there must be at least a few gcc developers who follow this
> newsgroup. I keep hoping that, some day, we'll get a reply saying "well, I
> checked the gcc source code, and the size of that subtraction is derived
> from the size of the locals plus the hour of the day rounded up to 32 bytes
> divided by 2" or something, but it hasn't happened yet.
Oh, all right, I'll reply ;-)
The stack is as follows:
old sp -> saved return addr for echo
pushed frame pointer
char buf[4] \
[padding] |
[padding] | this is the 20 byte adjustment
[padding] |
[padding] /
pushed arg
new sp -> saved return addr for gets
Note that the size of the whole frame is a multiple of 32 bytes. Yes,
this is for alignment purposes. Yes, it's for SSE. No, you don't
have to live with it.
$ gcc -Os -S test.c
$ cat test.s
echo:
pushl %ebp
movl %esp, %ebp
pushl %eax
leal -4(%ebp), %eax
pushl %eax
call gets
leave
ret
$ gcc -Os -S -fomit-frame-pointer test.c
$ cat test.s
echo:
pushl %ecx
movl %esp, %eax
pushl %eax
call gets
popl %eax
popl %edx
ret
The code in GCC that determines this is:
/* Validate -mpreferred-stack-boundary= value, or provide default.
The default of 128 bits is for Pentium III's SSE __m128, but we
don't want additional code to keep the stack aligned when
optimizing for code size. */
ix86_preferred_stack_boundary = (optimize_size
? TARGET_64BIT ? 128 : 32
: 128);
.
- Follow-Ups:
- Re: Why gcc translate a c program into assemble as follow
- From: wanderer83
- Re: Why gcc translate a c program into assemble as follow
- References:
- Why gcc translate a c program into assemble as follow
- From: Zheng Da
- Re: Why gcc translate a c program into assemble as follow
- From: Tim Roberts
- Re: Why gcc translate a c program into assemble as follow
- From: wanderer83
- Re: Why gcc translate a c program into assemble as follow
- From: Tim Roberts
- Why gcc translate a c program into assemble as follow
- Prev by Date: Re: improve strlen
- Next by Date: Re: improve strlen
- Previous by thread: Re: Why gcc translate a c program into assemble as follow
- Next by thread: Re: Why gcc translate a c program into assemble as follow
- Index(es):
Relevant Pages
|