Go programs expect to be able to call runtime.Callers to get their call stack. The libbacktrace library currently can not handle tail calls, and it's not clear that it can ever be completely reliable in handling tail calls. This patch to the Go frontend disables tail call optimization, unless it is specifically requested. This will permit Go programs that call runtime.Callers to work as expected. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch.
Ian 2013-12-11 Ian Lance Taylor <i...@google.com> * go-lang.c (go_langhook_post_options): Disable sibling calls by default.
Index: go-lang.c =================================================================== --- go-lang.c (revision 205872) +++ go-lang.c (working copy) @@ -270,6 +270,10 @@ go_langhook_post_options (const char **p if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT) flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD; + /* Tail call optimizations can confuse uses of runtime.Callers. */ + if (!global_options_set.x_flag_optimize_sibling_calls) + global_options.x_flag_optimize_sibling_calls = 0; + /* Returning false means that the backend should be used. */ return false; }