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.
想知道是否有人知道gcc禁用尾调优化的标志。基本上在尾调用优化中,当被调用函数的返回值通过(通过返回)或函数中没有其他任何内容发生时,gcc将替换堆栈帧。
That is, in
也就是说,在
void main() {
foo();
}
void foo() {
bar();
}
void bar() {
/* at this point in code, the foo() stack frame no longer exists! */
}
When foo calls bar, gcc emits code that replaces the stack frame for foo, rather than adding a new stack frame.
当foo调用bar时,gcc会发出代替foo的堆栈帧的代码,而不是添加新的堆栈帧。
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.
我公司有一个堆栈展开器,可以从代码中的任何一点打印出堆栈跟踪。 tailcall优化使堆栈帧消失,这可能会在一定程度上混淆堆栈跟踪。
I am compiling for x86-64 using gcc4.3.
我正在使用gcc4.3编译x86-64。
Thanks in advance! P
提前致谢! P
2 个解决方案
#1
26
GCC manual:
-foptimize-sibling-calls
Optimize sibling and tail recursive calls.
Enabled at levels -O2, -O3, -Os.
So either compile with -O0
/-O1
, or use -fno-optimize-sibling-calls
.
因此要么使用-O0 / -O1进行编译,要么使用-fno-optimize-sibling-calls。
#1
26
GCC manual:
-foptimize-sibling-calls
Optimize sibling and tail recursive calls.
Enabled at levels -O2, -O3, -Os.
So either compile with -O0
/-O1
, or use -fno-optimize-sibling-calls
.
因此要么使用-O0 / -O1进行编译,要么使用-fno-optimize-sibling-calls。