Re: Why gcc translate a c program into assemble as follow




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);

.



Relevant Pages

  • Re: [2.6.16rc2] compile error
    ... else echo ' UPD ... 3ee68c4af3fd7228c1be63254b9f884614f9ebb2) Author: Sam Ravnborg ... to gcc in the check-lxdialog.sh script and gcc did ...
    (Linux-Kernel)
  • Re: [2.6.16rc2] compile error
    ... include/linux/version.h.tmp; else echo ' UPD ... to gcc in the check-lxdialog.sh script and gcc did ...
    (Linux-Kernel)
  • Openssl compilation and gcc options
    ... I am trying to compile openssl to build openssh. ... echo ' /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c ... gcc: unrecognized option `-Xa' ...
    (comp.security.ssh)
  • Re: Kernel ABI headers step #1: Gathering information
    ... they would be missing the GCC version in the log. ... echo "Linux kernel version:" ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Kernel ABI headers step #1: Gathering information
    ... As part of the kernel ABI headers project, ... GCC provides on a variety of architectures and configurations. ... echo "Linux kernel version:" ...
    (Linux-Kernel)