Skip to main content

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)

code:
int test(){     int x = 10;     return x; }
when compiled -m32 -s produces

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

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:

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
24 bytes plus saved ebp , return address 32.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Stack alignment x86/x64 question


Ubuntu

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account