Skip to content

Commit 21f2b7c

Browse files
captain5050acmel
authored andcommitted
tools compiler.h: Add attribute to disable tail calls
Tail call optimizations can remove stack frames that are used in unwinding tests. Add an attribute that can be used to disable the tail call optimization. Tested on clang and GCC. Committer notes: Old versions of clang don't like that __attribute__((optimize)), so add an ifdef to make it go away. Signed-off-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: [email protected] Cc: Jakub Kicinski <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Monnet <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9300acc commit 21f2b7c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tools/include/linux/compiler-gcc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
#define __pure __attribute__((pure))
2828
#endif
2929
#define noinline __attribute__((noinline))
30+
#ifdef __has_attribute
31+
#if __has_attribute(disable_tail_calls)
32+
#define __no_tail_call __attribute__((disable_tail_calls))
33+
#endif
34+
#endif
35+
#ifndef __no_tail_call
36+
#if GCC_VERSION > 40201
37+
#define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls")))
38+
#else
39+
#define __no_tail_call
40+
#endif
41+
#endif
3042
#ifndef __packed
3143
#define __packed __attribute__((packed))
3244
#endif

tools/include/linux/compiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#ifndef noinline
4848
#define noinline
4949
#endif
50+
#ifndef __no_tail_call
51+
#define __no_tail_call
52+
#endif
5053

5154
/* Are two types/vars the same type (ignoring qualifiers)? */
5255
#ifndef __same_type

0 commit comments

Comments
 (0)