aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/compiler-gcc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/compiler-gcc.h')
-rw-r--r--include/linux/compiler-gcc.h173
1 files changed, 17 insertions, 156 deletions
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 573f5a7d42d4..763bbad1e258 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -10,6 +10,10 @@
10 + __GNUC_MINOR__ * 100 \ 10 + __GNUC_MINOR__ * 100 \
11 + __GNUC_PATCHLEVEL__) 11 + __GNUC_PATCHLEVEL__)
12 12
13#if GCC_VERSION < 40600
14# error Sorry, your compiler is too old - please upgrade it.
15#endif
16
13/* Optimization barrier */ 17/* Optimization barrier */
14 18
15/* The "volatile" is due to gcc bugs */ 19/* The "volatile" is due to gcc bugs */
@@ -58,6 +62,12 @@
58#define OPTIMIZER_HIDE_VAR(var) \ 62#define OPTIMIZER_HIDE_VAR(var) \
59 __asm__ ("" : "=r" (var) : "0" (var)) 63 __asm__ ("" : "=r" (var) : "0" (var))
60 64
65/*
66 * A trick to suppress uninitialized variable warning without generating any
67 * code
68 */
69#define uninitialized_var(x) x = x
70
61#ifdef __CHECKER__ 71#ifdef __CHECKER__
62#define __must_be_array(a) 0 72#define __must_be_array(a) 0
63#else 73#else
@@ -65,49 +75,6 @@
65#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 75#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
66#endif 76#endif
67 77
68/*
69 * Feature detection for gnu_inline (gnu89 extern inline semantics). Either
70 * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics,
71 * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not
72 * defined so the gnu89 semantics are the default.
73 */
74#ifdef __GNUC_STDC_INLINE__
75# define __gnu_inline __attribute__((gnu_inline))
76#else
77# define __gnu_inline
78#endif
79
80/*
81 * Force always-inline if the user requests it so via the .config,
82 * or if gcc is too old.
83 * GCC does not warn about unused static inline functions for
84 * -Wunused-function. This turns out to avoid the need for complex #ifdef
85 * directives. Suppress the warning in clang as well by using "unused"
86 * function attribute, which is redundant but not harmful for gcc.
87 * Prefer gnu_inline, so that extern inline functions do not emit an
88 * externally visible function. This makes extern inline behave as per gnu89
89 * semantics rather than c99. This prevents multiple symbol definition errors
90 * of extern inline functions at link time.
91 * A lot of inline functions can cause havoc with function tracing.
92 */
93#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
94 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
95#define inline \
96 inline __attribute__((always_inline, unused)) notrace __gnu_inline
97#else
98#define inline inline __attribute__((unused)) notrace __gnu_inline
99#endif
100
101#define __inline__ inline
102#define __inline inline
103#define __always_inline inline __attribute__((always_inline))
104#define noinline __attribute__((noinline))
105
106#define __deprecated __attribute__((deprecated))
107#define __packed __attribute__((packed))
108#define __weak __attribute__((weak))
109#define __alias(symbol) __attribute__((alias(#symbol)))
110
111#ifdef RETPOLINE 78#ifdef RETPOLINE
112#define __noretpoline __attribute__((indirect_branch("keep"))) 79#define __noretpoline __attribute__((indirect_branch("keep")))
113#endif 80#endif
@@ -126,105 +93,20 @@
126 */ 93 */
127#define __naked __attribute__((naked)) noinline __noclone notrace 94#define __naked __attribute__((naked)) noinline __noclone notrace
128 95
129#define __noreturn __attribute__((noreturn))
130
131/*
132 * From the GCC manual:
133 *
134 * Many functions have no effects except the return value and their
135 * return value depends only on the parameters and/or global
136 * variables. Such a function can be subject to common subexpression
137 * elimination and loop optimization just as an arithmetic operator
138 * would be.
139 * [...]
140 */
141#define __pure __attribute__((pure))
142#define __aligned(x) __attribute__((aligned(x)))
143#define __aligned_largest __attribute__((aligned))
144#define __printf(a, b) __attribute__((format(printf, a, b)))
145#define __scanf(a, b) __attribute__((format(scanf, a, b)))
146#define __attribute_const__ __attribute__((__const__))
147#define __maybe_unused __attribute__((unused))
148#define __always_unused __attribute__((unused))
149#define __mode(x) __attribute__((mode(x)))
150
151/* gcc version specific checks */
152
153#if GCC_VERSION < 30200
154# error Sorry, your compiler is too old - please upgrade it.
155#endif
156
157#if GCC_VERSION < 30300
158# define __used __attribute__((__unused__))
159#else
160# define __used __attribute__((__used__))
161#endif
162
163#ifdef CONFIG_GCOV_KERNEL
164# if GCC_VERSION < 30400
165# error "GCOV profiling support for gcc versions below 3.4 not included"
166# endif /* __GNUC_MINOR__ */
167#endif /* CONFIG_GCOV_KERNEL */
168
169#if GCC_VERSION >= 30400
170#define __must_check __attribute__((warn_unused_result))
171#define __malloc __attribute__((__malloc__))
172#endif
173
174#if GCC_VERSION >= 40000
175
176/* GCC 4.1.[01] miscompiles __weak */
177#ifdef __KERNEL__
178# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
179# error Your version of gcc miscompiles the __weak directive
180# endif
181#endif
182
183#define __used __attribute__((__used__))
184#define __compiler_offsetof(a, b) \
185 __builtin_offsetof(a, b)
186
187#if GCC_VERSION >= 40100
188# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
189#endif
190
191#if GCC_VERSION >= 40300
192/* Mark functions as cold. gcc will assume any path leading to a call
193 * to them will be unlikely. This means a lot of manual unlikely()s
194 * are unnecessary now for any paths leading to the usual suspects
195 * like BUG(), printk(), panic() etc. [but let's keep them for now for
196 * older compilers]
197 *
198 * Early snapshots of gcc 4.3 don't support this and we can't detect this
199 * in the preprocessor, but we can live with this because they're unreleased.
200 * Maketime probing would be overkill here.
201 *
202 * gcc also has a __attribute__((__hot__)) to move hot functions into
203 * a special section, but I don't see any sense in this right now in
204 * the kernel context
205 */
206#define __cold __attribute__((__cold__))
207
208#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) 96#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
209 97
210#ifndef __CHECKER__
211# define __compiletime_warning(message) __attribute__((warning(message)))
212# define __compiletime_error(message) __attribute__((error(message)))
213#endif /* __CHECKER__ */
214#endif /* GCC_VERSION >= 40300 */
215
216#if GCC_VERSION >= 40400
217#define __optimize(level) __attribute__((__optimize__(level))) 98#define __optimize(level) __attribute__((__optimize__(level)))
218#define __nostackprotector __optimize("no-stack-protector")
219#endif /* GCC_VERSION >= 40400 */
220 99
221#if GCC_VERSION >= 40500 100#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
222 101
223#ifndef __CHECKER__ 102#ifndef __CHECKER__
103#define __compiletime_warning(message) __attribute__((warning(message)))
104#define __compiletime_error(message) __attribute__((error(message)))
105
224#ifdef LATENT_ENTROPY_PLUGIN 106#ifdef LATENT_ENTROPY_PLUGIN
225#define __latent_entropy __attribute__((latent_entropy)) 107#define __latent_entropy __attribute__((latent_entropy))
226#endif 108#endif
227#endif 109#endif /* __CHECKER__ */
228 110
229/* 111/*
230 * calling noreturn functions, __builtin_unreachable() and __builtin_trap() 112 * calling noreturn functions, __builtin_unreachable() and __builtin_trap()
@@ -262,10 +144,6 @@
262#define randomized_struct_fields_end } __randomize_layout; 144#define randomized_struct_fields_end } __randomize_layout;
263#endif 145#endif
264 146
265#endif /* GCC_VERSION >= 40500 */
266
267#if GCC_VERSION >= 40600
268
269/* 147/*
270 * When used with Link Time Optimization, gcc can optimize away C functions or 148 * When used with Link Time Optimization, gcc can optimize away C functions or
271 * variables which are referenced only from assembly code. __visible tells the 149 * variables which are referenced only from assembly code. __visible tells the
@@ -274,8 +152,7 @@
274 */ 152 */
275#define __visible __attribute__((externally_visible)) 153#define __visible __attribute__((externally_visible))
276 154
277#endif /* GCC_VERSION >= 40600 */ 155/* gcc version specific checks */
278
279 156
280#if GCC_VERSION >= 40900 && !defined(__CHECKER__) 157#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
281/* 158/*
@@ -309,10 +186,8 @@
309 * folding in __builtin_bswap*() (yet), so don't set these for it. 186 * folding in __builtin_bswap*() (yet), so don't set these for it.
310 */ 187 */
311#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__) 188#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__)
312#if GCC_VERSION >= 40400
313#define __HAVE_BUILTIN_BSWAP32__ 189#define __HAVE_BUILTIN_BSWAP32__
314#define __HAVE_BUILTIN_BSWAP64__ 190#define __HAVE_BUILTIN_BSWAP64__
315#endif
316#if GCC_VERSION >= 40800 191#if GCC_VERSION >= 40800
317#define __HAVE_BUILTIN_BSWAP16__ 192#define __HAVE_BUILTIN_BSWAP16__
318#endif 193#endif
@@ -341,10 +216,9 @@
341 * https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html 216 * https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
342 */ 217 */
343#define __designated_init __attribute__((designated_init)) 218#define __designated_init __attribute__((designated_init))
219#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
344#endif 220#endif
345 221
346#endif /* gcc version >= 40000 specific checks */
347
348#if !defined(__noclone) 222#if !defined(__noclone)
349#define __noclone /* not needed */ 223#define __noclone /* not needed */
350#endif 224#endif
@@ -354,16 +228,6 @@
354#endif 228#endif
355 229
356/* 230/*
357 * A trick to suppress uninitialized variable warning without generating any
358 * code
359 */
360#define uninitialized_var(x) x = x
361
362#if GCC_VERSION >= 50100
363#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
364#endif
365
366/*
367 * Turn individual warnings and errors on and off locally, depending 231 * Turn individual warnings and errors on and off locally, depending
368 * on version. 232 * on version.
369 */ 233 */
@@ -375,12 +239,9 @@
375#define __diag_GCC_warn warning 239#define __diag_GCC_warn warning
376#define __diag_GCC_error error 240#define __diag_GCC_error error
377 241
378/* Compilers before gcc-4.6 do not understand "#pragma GCC diagnostic push" */
379#if GCC_VERSION >= 40600
380#define __diag_str1(s) #s 242#define __diag_str1(s) #s
381#define __diag_str(s) __diag_str1(s) 243#define __diag_str(s) __diag_str1(s)
382#define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) 244#define __diag(s) _Pragma(__diag_str(GCC diagnostic s))
383#endif
384 245
385#if GCC_VERSION >= 80000 246#if GCC_VERSION >= 80000
386#define __diag_GCC_8(s) __diag(s) 247#define __diag_GCC_8(s) __diag(s)