如何禁用在海湾合作委员会尾调用优化 [英] How do I disable tailcall optimizations in gcc
问题描述
想知道,如果有人知道的标志GCC禁用尾调用优化。基本上在尾调用优化,当从被调用函数的返回值是通过传递(通过return),或者没有什么事情发生在函数GCC将替换堆栈帧。
Wondering if anyone knows the flag for gcc to disable tailcall optimizations. Basically in a tailcall optimization, gcc will replace a stack frame when the return value from a called function is passed through (via return) or nothing else happens in the function.
即,在
void main() {
foo();
}
void foo() {
bar();
}
void bar() {
/* at this point in code, the foo() stack frame no longer exists! */
}
在调用foo的酒吧,海湾合作委员会发出code替换foo的堆栈帧,而不是添加一个新的堆栈帧。
When foo calls bar, gcc emits code that replaces the stack frame for foo, rather than adding a new stack frame.
我公司有一个堆栈开卷,可以从code的任意点打印出堆栈跟踪。尾调用优化使堆栈帧消失,这可以在一定程度混淆堆栈跟踪。
My company has a stack unwinder that can print out a stack trace from any point in code. tailcall optimization makes stack frames disappear, which can confuse the stack trace somewhat.
我使用gcc4.3编译为X86-64。
I am compiling for x86-64 using gcc4.3.
在此先感谢!
P
Thanks in advance! P
推荐答案
GCC手册:
-foptimize-sibling-calls
Optimize sibling and tail recursive calls.
Enabled at levels -O2, -O3, -Os.
所以,无论是与 -O0
/ -O1
编译或使用 -fno-优化同胞通话
。
这篇关于如何禁用在海湾合作委员会尾调用优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!