Stack alignment on x86

有些话、适合烂在心里 提交于 2021-02-18 21:12:17

问题


I had a mysterious bus error that occurred, on a x86 (32-bit) platform, when running code compiled with gcc-4.8.1 with -march=pentium4. I traced the problem to an SSE instruction:

movdqa %xmm5,0x50(%esp)

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

The problem does not occur if 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-byte. Thus, it seems weird that the code generator should choose to use movdqa, without some kind of alignment check, even though there is an instruction movdqu for possibly unaligned accesses.

So, this looks like there is a bug in gcc.

I'm not an expert on SSE and x86 ABI, and I'd appreciate feedback before I send a bug report.


回答1:


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

Problems can thus occur if gcc code using SSE is called from code generated by other compilers which have different stack alignment assumptions, such as OCaml (see discussion on the OCaml bug tracker).



来源:https://stackoverflow.com/questions/21748272/stack-alignment-on-x86

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!