3 ms·
Not quite true: there’s the weird thing where gcc on i*86 will align the stack on entry to a function called main but not any other. $ gcc -m32 -O2 -fno-pie
by mananaysiempre 5y ago
Not quite true: there’s the weird thing where gcc on i*86 will align the stack on entry to a function called main but not any other.
$ gcc -m32 -O2 -fno-pie -fno-asynchronous-unwind-tables -fomit-frame-pointer -S -masm=intel -xc -o - -
int foo(void); int main(void) { return foo(); }
^D
.file "<stdin>"
.intel_syntax noprefix
.text
.section .text.startup,"ax",@progbits
.p2align 4
.globl main
.type main, @function
main:
push ebp
mov ebp, esp
and esp, -16
call foo
leave
ret
.size main, .-main
.ident "GCC: (GNU) 11.1.0"
.section .note.GNU-stack,"",@progbits
It doesn’t do that if you set the historical stack alignment, though (-mpreferred-stack-boundary=2), or if you name the function anything else but main (it even does a tail call). Presumably it’s trying to (somewhat) recover from the time when the GCC authors accidentally the SysV i386 ABI[1,2].
[1]: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
[2]: https://stackoverflow.com/a/49397524 https://stackoverflow.com/a/49397524