public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC substracting strange amount of bytes from esp
@ 2011-01-28 16:36 Bastian Ballmann
  2011-01-29 11:27 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Bastian Ballmann @ 2011-01-28 16:36 UTC (permalink / raw)
  To: gcc-help

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,

I've got a question concerning the assembly produced by gcc of
the following c code:

void test() {
   char buffer1[10];
   char buffer2[10];
   int *ret;
}

void main() {
  test();
}

If I disassemble the test function I see that gcc 4.5.2 produced the
following assembly:

   0x08048374 <+0>:     push   %ebp
   0x08048375 <+1>:     mov    %esp,%ebp
   0x08048377 <+3>:     sub    $0x20,%esp
   0x0804837a <+6>:     leave
   0x0804837b <+7>:     ret

I would expect that 0x1c or 0x18 byte will be substracted from esp, but
it's 0x20. 

Asking uncle Google I found an old bug report that gcc used to
substracted more from esp than necessary
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9624), but it's marked
fixed since 4.0.0.

I made a few tests with other gcc versions (2.9.5, 3.3, 4.0, 4.2, 4.4)
and all substract more bytes than necessary some more than others but
no version used the exact number of bytes.

Am I missing or misunderstanding something or is this a feature /
bug? :)
Thanks for any hint or link.
Have a nice day!

Balle
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk1C6hEACgkQEQHD8bvs9q1UQgCgofxlH74ybvN5rIvB3yIvvBRf
zqIAnj64oNkFVD/f2erCI973gUheWK1Y
=C/15
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: GCC substracting strange amount of bytes from esp
  2011-01-28 16:36 GCC substracting strange amount of bytes from esp Bastian Ballmann
@ 2011-01-29 11:27 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-01-29 11:27 UTC (permalink / raw)
  To: Bastian Ballmann; +Cc: gcc-help

Bastian Ballmann <balle@chaostal.de> writes:

> If I disassemble the test function I see that gcc 4.5.2 produced the
> following assembly:
>
>    0x08048374 <+0>:     push   %ebp
>    0x08048375 <+1>:     mov    %esp,%ebp
>    0x08048377 <+3>:     sub    $0x20,%esp
>    0x0804837a <+6>:     leave
>    0x0804837b <+7>:     ret
>
> I would expect that 0x1c or 0x18 byte will be substracted from esp, but
> it's 0x20. 

See the -mpreferred-stack-boundary option.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-29  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 16:36 GCC substracting strange amount of bytes from esp Bastian Ballmann
2011-01-29 11:27 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).