Bug 97831 - Lack of disable_tail_calls attribute
Summary: Lack of disable_tail_calls attribute
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 10.2.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-14 20:31 UTC by Ian Rogers
Modified: 2021-09-02 05:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Rogers 2020-11-14 20:31:29 UTC
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/
Comment 1 Andrew Pinski 2020-11-14 20:47:21 UTC
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.
Comment 2 Andrew Pinski 2020-11-14 20:56:56 UTC
I think this was rejected 3 years ago:
https://gcc.gnu.org/legacy-ml/gcc-patches/2017-05/msg02221.html
Comment 3 Andrew Pinski 2020-11-14 20:57:48 UTC
(In reply to Andrew Pinski from comment #2)
And see https://gcc.gnu.org/legacy-ml/gcc-patches/2017-07/msg00130.html
Comment 4 Andrew Pinski 2021-09-02 05:38:07 UTC
In the case of glibc, the callee needs to be marked as not a tail callable and not the caller.