* some questions about gcc4
@ 2010-02-23 15:55 Alex
2010-02-23 16:19 ` Cedric Roux
0 siblings, 1 reply; 2+ messages in thread
From: Alex @ 2010-02-23 15:55 UTC (permalink / raw)
To: gcc-help
Hello.
I need some hints. I have compiled simple source:
(gdb) list
1 void main (void) {
2 int i;
3 i = 1;
4 }
And disassembling this code is:
Dump of assembler code for function main:
0x08048394 <main+0>: push ebp
0x08048395 <main+1>: mov ebp,esp
0x08048397 <main+3>: sub esp,0x10
0x0804839a <main+6>: mov DWORD PTR [ebp-0x4],0x1
0x080483a1 <main+13>: leave
0x080483a2 <main+14>: ret
End of assembler dump.
I have only 1 int variable. My system is 32Bit. But why for 1 int
variable compiler make sub esp,0x10 ?
1 int variable located in 4 bytes. What in another 12 ?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: some questions about gcc4
2010-02-23 15:55 some questions about gcc4 Alex
@ 2010-02-23 16:19 ` Cedric Roux
0 siblings, 0 replies; 2+ messages in thread
From: Cedric Roux @ 2010-02-23 16:19 UTC (permalink / raw)
To: gcc-help; +Cc: pppsss7
Alex wrote:
> I have only 1 int variable. My system is 32Bit. But why for 1 int
> variable compiler make sub esp,0x10 ?
> 1 int variable located in 4 bytes. What in another 12 ?
gcc man page says:
-mpreferred-stack-boundary=num
Attempt to keep the stack boundary aligned to a 2 raised to num
byte boundary. If -mpreferred-stack-boundary is not specified, the
default is 4 (16 bytes or 128 bits).
so do a gcc -mpreferred-stack-boundary=2 and you're done.
I think they set to 4 by default for performances' reasons, when you use SSE
data that likes to be aligned to 16 bytes. (Or maybe because the AMD64
ABI says the stack is 16 bytes aligned...) But let a gcc programmer answer
that if one has time to. :-) (And by the way I'm not sure of what I write,
so don't take it for the truth.)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-02-23 16:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-23 15:55 some questions about gcc4 Alex
2010-02-23 16:19 ` Cedric Roux
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).