gcc -mpreferred-stack-boundary 选项选项、mpreferred、gcc、boundary

2023-09-07 10:07:02 作者:雅痞紳士

我想知道在 GNU 编译器编译过程中 -mpreferred-stack-boundary 选项有什么用.我已经检查了文档,但我失去了解释.谁能解释一下.

I want to know what's the use of -mpreferred-stack-boundary option during compilation in GNU compiler. I've checked the documentation but the explanation is lost on me. Could someone please explain it.

推荐答案

我想知道在 GNU 调试器中编译期间 -mpreferred-stack-boundary 选项的用途.

I want to know what's the use of -mpreferred-stack-boundary option during compilation in GNU debugger.

该选项与调试器完全无关.

它会影响二进制文件中生成的代码.默认情况下,GCC 将安排事情,以便每个函数在进入时立即将其堆栈指针对齐在 16 字节边界上(如果您有局部变量并启用 sse2 指令,这可能很重要).

It affects generated code in your binary. By default, GCC will arrange things so that every function, immediately upon entry, has its stack pointer aligned on 16-byte boundary (this may be important if you have local variables, and enable sse2 instructions).

如果您将默认设置更改为例如-mpreferred-stack-boundary=2,则 GCC 将在 4 字节边界上对齐堆栈指针.这将减少您的例程的堆栈需求,但如果您的代码(或您调用的代码)确实使用 sse2 则会崩溃,因此通常不安全.

If you change the default to e.g. -mpreferred-stack-boundary=2, then GCC will align stack pointer on 4-byte boundary. This will reduce stack requirements of your routines, but will crash if your code (or code you call) does use sse2, so is generally not safe.