x86_64 and stack alignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, list.

Are there any gcc-specific rules about stack alignment on x86_64?
I reached quite strange behavior of my program when it passes some float to a function that accepts variable length arguments list
and %rsp contains aligned on 16 bytes boundary address.

For example:
 float var = 0.0;
 printf("%f", var);

If %rsp contains 16 bytes aligned address(like 0x7fffffffe300) before printf is called, program generates general protection fault
when it tries to deal with stack in _IO_printf:
0000000000400de0 <_IO_printf>:
...
  400e14:       4c 89 44 24 40          mov    %r8,0x40(%rsp)
  400e19:       4c 89 4c 24 48          mov    %r9,0x48(%rsp)
  400e1e:       ff e0                   jmpq   *%rax
  400e20:       0f 29 7a f1             movaps %xmm7,-0xf(%rdx)
  400e24:       0f 29 72 e1             movaps %xmm6,-0x1f(%rdx)
  400e28:       0f 29 6a d1             movaps %xmm5,-0x2f(%rdx)
  400e2c:       0f 29 62 c1             movaps %xmm4,-0x3f(%rdx)
  400e30:       0f 29 5a b1             movaps %xmm3,-0x4f(%rdx)
  400e34:       0f 29 52 a1             movaps %xmm2,-0x5f(%rdx)
  400e38:       0f 29 4a 91             movaps %xmm1,-0x6f(%rdx)
  400e3c:       0f 29 42 81             movaps %xmm0,-0x7f(%rdx) // <-- #GPF
  400e40:       48 8d 84 24 e0 00 00    lea    0xe0(%rsp),%rax
...

#GPF occurs because -0x7f(%rdx) produces unaligned on 16 bytes boundary address. As I can see, gcc expects that stack is always aligned
on 8 bytes boundary and never on 16.
Can somebody explain me why gcc acts this way?
"AMD64 architecture programmers manual. Vol. 1" only says that in 64 bit mode stack should be aligned on 8 bytes boundary. I didn't find any
other stack alignment related restrictions there.

I attached simple program that reproduces described above behavior.
Thanks.

Attachment: x86_64.stack_alignment.tar.gz
Description: GNU Zip compressed data


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux