Thread: Stack alignment x86/x64 question
i understand x86 requires 16 byte stack alignment fast use sse instructions, don't how gcc function. following example (x86-32)
when compiled -m32 -s producescode:int test(){ int x = 10; return x; }
i subl $16, %esp don't there pushl %ebp long 4 bytes, won't make alignment off 4 bytes? arguments in other functions don't seem taken account (similar pushl).code:.cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 subl $16, %esp movb $10, -1(%ebp) movzbl -1(%ebp), %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc
curious because making compiler, , want able use sse instructions in future.
in advance can provide.
as understand it, 16-bit alignment of esp required @ function calls. since function not call anything, 16-bit alignment not required. compare with:
24 bytes plus saved ebp , return address 32.code:firas@itsuki ~ % cat test.c void bar(void); int test(void) { int x = 10; bar(); return x; } firas@itsuki ~ % gcc -std=c99 -pedantic -wall -wextra -m32 -s test.c firas@itsuki ~ % cat test.s .file "test.c" .text .globl test .type test, @function test: .lfb0: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 subl $24, %esp movl $10, -12(%ebp) call bar movl -12(%ebp), %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc .lfe0: .size test, .-test .ident "gcc: (ubuntu/linaro 4.6.1-9ubuntu3) 4.6.1" .section .note.gnu-stack,"",@progbits
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Stack alignment x86/x64 question
Ubuntu
Comments
Post a Comment