Tail call optimization may remove stack frames, certain tests assert stack frames are present. Previously these tests would use __attribute__((optimize("no-optimize-sibling-calls"))), however, the use of the optimize attribute shouldn't occur in production code as per the FAQ: https://gcc.gnu.org/wiki/FAQ#optimize_attribute_broken The attribute disable_tail_calls is used in other compilers for this situation: https://clang.llvm.org/docs/AttributeReference.html#disable-tail-calls A situation where this has come up is in Linux: https://lore.kernel.org/lkml/20201028081123.GT2628@hirez.programming.kicks-ass.net/ https://lore.kernel.org/lkml/20201114000803.909530-1-irogers@google.com/
I can think of a simple way disabling tail calls: static void disabletailcallfunc(void*) __attribute__((noipa)); static void disabletailcallfunc(void *x){} #define disabletailcall() do {int a; disabletailcallfunc(&a);}while(0); int functionwhichIwantToDisableTailCallFrom(...) { disabletailcall(); } The overhead for this extra variable and call is small in terms of things.
I think this was rejected 3 years ago: https://gcc.gnu.org/legacy-ml/gcc-patches/2017-05/msg02221.html
(In reply to Andrew Pinski from comment #2) And see https://gcc.gnu.org/legacy-ml/gcc-patches/2017-07/msg00130.html
In the case of glibc, the callee needs to be marked as not a tail callable and not the caller.