X86 stack alignment

I had a mysterious x86-based bus error (32-bit) when running code compiled with gcc-4.8.1 with -march=pentium4 . I traced the issue with the SSE instruction:

 movdqa %xmm5,0x50(%esp) 

with esp = 0xbfffedac. movdqa requires the address to be 16 byte aligned, which is not the case here, so a bus error.

The problem does not occur when compiling with -march=native (this is a Core-i3 processor).

As far as I know, the only stack alignment guaranteed on Linux / x86 is 4 bytes. Thus, it seems odd that the code generator should select movdqa without any alignment check, even if there is a movdqu command for possibly low access.

So it looks like there is an error in gcc.

I am not an expert on SSE and x86 ABI, and I will be grateful for the feedback before submitting a bug report.

+8
gcc x86 linux sse
source share
1 answer

Now the default value in gcc is -mpreferred-stack-boundary=4 (16-byte alignment), which sets -mincoming-stack-boundary=4 .

Therefore, problems can occur if gcc code using SSE is called from code generated by other compilers that have different stack alignment assumptions, such as OCaml (see discussion in the OCaml error tracker).

+5
source share

All Articles