Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
d1515582 | 2 | #ifndef __LINUX_COMPILER_TYPES_H |
94f582f8 RD |
3 | #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead." |
4 | #endif | |
1da177e4 LT |
5 | |
6 | /* | |
7 | * Common definitions for all gcc versions go here. | |
8 | */ | |
f6d133f8 JP |
9 | #define GCC_VERSION (__GNUC__ * 10000 \ |
10 | + __GNUC_MINOR__ * 100 \ | |
11 | + __GNUC_PATCHLEVEL__) | |
1da177e4 | 12 | |
c8d52465 | 13 | /* |
85c210ed AK |
14 | * This macro obfuscates arithmetic on a variable address so that gcc |
15 | * shouldn't recognize the original var, and make assumptions about it. | |
16 | * | |
17 | * This is needed because the C standard makes it undefined to do | |
18 | * pointer arithmetic on "objects" outside their boundaries and the | |
19 | * gcc optimizers assume this is the case. In particular they | |
20 | * assume such arithmetic does not wrap. | |
21 | * | |
22 | * A miscompilation has been observed because of this on PPC. | |
23 | * To work around it we hide the relationship of the pointer and the object | |
24 | * using this macro. | |
25 | * | |
c8d52465 AB |
26 | * Versions of the ppc64 compiler before 4.1 had a bug where use of |
27 | * RELOC_HIDE could trash r30. The bug can be worked around by changing | |
28 | * the inline assembly constraint from =g to =r, in this particular | |
29 | * case either is valid. | |
30 | */ | |
f6d133f8 JP |
31 | #define RELOC_HIDE(ptr, off) \ |
32 | ({ \ | |
33 | unsigned long __ptr; \ | |
34 | __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ | |
35 | (typeof(ptr)) (__ptr + (off)); \ | |
36 | }) | |
a1365647 | 37 | |
e4f35891 | 38 | #ifdef CONFIG_RETPOLINE |
5c67a52f | 39 | #define __noretpoline __attribute__((__indirect_branch__("keep"))) |
87358710 DW |
40 | #endif |
41 | ||
cb984d10 JP |
42 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) |
43 | ||
989bd500 | 44 | #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) |
0766f788 ER |
45 | #define __latent_entropy __attribute__((latent_entropy)) |
46 | #endif | |
0766f788 | 47 | |
173a3efd AB |
48 | /* |
49 | * calling noreturn functions, __builtin_unreachable() and __builtin_trap() | |
50 | * confuse the stack allocation in gcc, leading to overly large stack | |
51 | * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 | |
52 | * | |
53 | * Adding an empty inline assembly before it works around the problem | |
54 | */ | |
55 | #define barrier_before_unreachable() asm volatile("") | |
56 | ||
cb984d10 JP |
57 | /* |
58 | * Mark a position in code as unreachable. This can be used to | |
59 | * suppress control flow warnings after asm blocks that transfer | |
60 | * control elsewhere. | |
cb984d10 | 61 | */ |
4e4636cf | 62 | #define unreachable() \ |
173a3efd AB |
63 | do { \ |
64 | annotate_unreachable(); \ | |
65 | barrier_before_unreachable(); \ | |
66 | __builtin_unreachable(); \ | |
67 | } while (0) | |
cb984d10 | 68 | |
d991bb1c | 69 | #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) |
cb984d10 JP |
70 | #define __HAVE_BUILTIN_BSWAP32__ |
71 | #define __HAVE_BUILTIN_BSWAP64__ | |
cb984d10 | 72 | #define __HAVE_BUILTIN_BSWAP16__ |
d991bb1c | 73 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ |
cb984d10 | 74 | |
045d599a DV |
75 | #if GCC_VERSION >= 70000 |
76 | #define KASAN_ABI_VERSION 5 | |
4e59869a | 77 | #else |
cb984d10 | 78 | #define KASAN_ABI_VERSION 4 |
cb984d10 JP |
79 | #endif |
80 | ||
afcf5441 DL |
81 | #ifdef CONFIG_SHADOW_CALL_STACK |
82 | #define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) | |
83 | #endif | |
84 | ||
6e2be1f2 | 85 | #define __no_sanitize_address __attribute__((__no_sanitize_address__)) |
2bd926b4 | 86 | |
095ac076 | 87 | #if defined(__SANITIZE_THREAD__) |
6e2be1f2 | 88 | #define __no_sanitize_thread __attribute__((__no_sanitize_thread__)) |
dfd402a4 ME |
89 | #else |
90 | #define __no_sanitize_thread | |
91 | #endif | |
92 | ||
6e2be1f2 | 93 | #define __no_sanitize_undefined __attribute__((__no_sanitize_undefined__)) |
5144f8a8 | 94 | |
f39556bc MO |
95 | /* |
96 | * Only supported since gcc >= 12 | |
97 | */ | |
540540d0 | 98 | #if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__) |
6e2be1f2 | 99 | #define __no_sanitize_coverage __attribute__((__no_sanitize_coverage__)) |
540540d0 ME |
100 | #else |
101 | #define __no_sanitize_coverage | |
102 | #endif | |
103 | ||
9a48e756 KC |
104 | /* |
105 | * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel, | |
106 | * matching the defines used by Clang. | |
107 | */ | |
108 | #ifdef __SANITIZE_HWADDRESS__ | |
109 | #define __SANITIZE_ADDRESS__ | |
110 | #endif | |
111 | ||
9b448bc2 AP |
112 | /* |
113 | * GCC does not support KMSAN. | |
114 | */ | |
115 | #define __no_sanitize_memory | |
116 | #define __no_kmsan_checks | |
117 | ||
8793bb7f AB |
118 | /* |
119 | * Turn individual warnings and errors on and off locally, depending | |
120 | * on version. | |
121 | */ | |
122 | #define __diag_GCC(version, severity, s) \ | |
123 | __diag_GCC_ ## version(__diag_GCC_ ## severity s) | |
124 | ||
125 | /* Severity used in pragma directives */ | |
126 | #define __diag_GCC_ignore ignored | |
127 | #define __diag_GCC_warn warning | |
128 | #define __diag_GCC_error error | |
129 | ||
8793bb7f AB |
130 | #define __diag_str1(s) #s |
131 | #define __diag_str(s) __diag_str1(s) | |
132 | #define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) | |
8793bb7f AB |
133 | |
134 | #if GCC_VERSION >= 80000 | |
135 | #define __diag_GCC_8(s) __diag(s) | |
136 | #else | |
137 | #define __diag_GCC_8(s) | |
138 | #endif | |
86cffecd | 139 | |
4d1ea705 KKD |
140 | #define __diag_ignore_all(option, comment) \ |
141 | __diag_GCC(8, ignore, option) | |
142 | ||
86cffecd KC |
143 | /* |
144 | * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size" | |
145 | * attribute) do not work, and must be disabled. | |
146 | */ | |
147 | #if GCC_VERSION < 90100 | |
148 | #undef __alloc_size__ | |
149 | #endif |