1 #ifndef __LINUX_COMPILER_H
2 #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
6 * Common definitions for all gcc versions go here.
8 #define GCC_VERSION (__GNUC__ * 10000 \
9 + __GNUC_MINOR__ * 100 \
10 + __GNUC_PATCHLEVEL__)
13 /* Optimization barrier */
14 /* The "volatile" is due to gcc bugs */
15 #define barrier() __asm__ __volatile__("": : :"memory")
18 * This macro obfuscates arithmetic on a variable address so that gcc
19 * shouldn't recognize the original var, and make assumptions about it.
21 * This is needed because the C standard makes it undefined to do
22 * pointer arithmetic on "objects" outside their boundaries and the
23 * gcc optimizers assume this is the case. In particular they
24 * assume such arithmetic does not wrap.
26 * A miscompilation has been observed because of this on PPC.
27 * To work around it we hide the relationship of the pointer and the object
30 * Versions of the ppc64 compiler before 4.1 had a bug where use of
31 * RELOC_HIDE could trash r30. The bug can be worked around by changing
32 * the inline assembly constraint from =g to =r, in this particular
33 * case either is valid.
35 #define RELOC_HIDE(ptr, off) \
37 unsigned long __ptr; \
38 __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
39 (typeof(ptr)) (__ptr + (off)); \
42 /* Make the optimizer believe the variable can be manipulated arbitrarily. */
43 #define OPTIMIZER_HIDE_VAR(var) \
44 __asm__ ("" : "=r" (var) : "0" (var))
47 #define __must_be_array(a) 0
49 /* &a[0] degrades to a pointer: a different type from an array */
50 #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
54 * Force always-inline if the user requests it so via the .config,
55 * or if gcc is too old:
57 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
58 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
59 #define inline inline __attribute__((always_inline)) notrace
60 #define __inline__ __inline__ __attribute__((always_inline)) notrace
61 #define __inline __inline __attribute__((always_inline)) notrace
63 /* A lot of inline functions can cause havoc with function tracing */
64 #define inline inline notrace
65 #define __inline__ __inline__ notrace
66 #define __inline __inline notrace
69 #define __always_inline inline __attribute__((always_inline))
70 #define noinline __attribute__((noinline))
72 #define __deprecated __attribute__((deprecated))
73 #define __packed __attribute__((packed))
74 #define __weak __attribute__((weak))
75 #define __alias(symbol) __attribute__((alias(#symbol)))
78 * it doesn't make sense on ARM (currently the only user of __naked)
79 * to trace naked functions because then mcount is called without
80 * stack and frame pointer being set up and there is no chance to
81 * restore the lr register to the value before mcount was called.
83 * The asm() bodies of naked functions often depend on standard calling
84 * conventions, therefore they must be noinline and noclone.
86 * GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
89 #define __naked __attribute__((naked)) noinline __noclone notrace
91 #define __noreturn __attribute__((noreturn))
94 * From the GCC manual:
96 * Many functions have no effects except the return value and their
97 * return value depends only on the parameters and/or global
98 * variables. Such a function can be subject to common subexpression
99 * elimination and loop optimization just as an arithmetic operator
103 #define __pure __attribute__((pure))
104 #define __aligned(x) __attribute__((aligned(x)))
105 #define __printf(a, b) __attribute__((format(printf, a, b)))
106 #define __scanf(a, b) __attribute__((format(scanf, a, b)))
107 #define __attribute_const__ __attribute__((__const__))
108 #define __maybe_unused __attribute__((unused))
109 #define __always_unused __attribute__((unused))
111 /* gcc version specific checks */
113 #if GCC_VERSION < 30200
114 # error Sorry, your compiler is too old - please upgrade it.
117 #if GCC_VERSION < 30300
118 # define __used __attribute__((__unused__))
120 # define __used __attribute__((__used__))
123 #ifdef CONFIG_GCOV_KERNEL
124 # if GCC_VERSION < 30400
125 # error "GCOV profiling support for gcc versions below 3.4 not included"
126 # endif /* __GNUC_MINOR__ */
127 #endif /* CONFIG_GCOV_KERNEL */
129 #if GCC_VERSION >= 30400
130 #define __must_check __attribute__((warn_unused_result))
133 #if GCC_VERSION >= 40000
135 /* GCC 4.1.[01] miscompiles __weak */
137 # if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
138 # error Your version of gcc miscompiles the __weak directive
142 #define __used __attribute__((__used__))
143 #define __compiler_offsetof(a, b) \
144 __builtin_offsetof(a, b)
146 #if GCC_VERSION >= 40100 && GCC_VERSION < 40600
147 # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
150 #if GCC_VERSION >= 40300
151 /* Mark functions as cold. gcc will assume any path leading to a call
152 * to them will be unlikely. This means a lot of manual unlikely()s
153 * are unnecessary now for any paths leading to the usual suspects
154 * like BUG(), printk(), panic() etc. [but let's keep them for now for
157 * Early snapshots of gcc 4.3 don't support this and we can't detect this
158 * in the preprocessor, but we can live with this because they're unreleased.
159 * Maketime probing would be overkill here.
161 * gcc also has a __attribute__((__hot__)) to move hot functions into
162 * a special section, but I don't see any sense in this right now in
165 #define __cold __attribute__((__cold__))
167 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
170 # define __compiletime_warning(message) __attribute__((warning(message)))
171 # define __compiletime_error(message) __attribute__((error(message)))
172 #endif /* __CHECKER__ */
173 #endif /* GCC_VERSION >= 40300 */
175 #if GCC_VERSION >= 40500
177 * Mark a position in code as unreachable. This can be used to
178 * suppress control flow warnings after asm blocks that transfer
181 * Early snapshots of gcc 4.5 don't support this and we can't detect
182 * this in the preprocessor, but we can live with this because they're
183 * unreleased. Really, we need to have autoconf for the kernel.
185 #define unreachable() __builtin_unreachable()
187 /* Mark a function definition as prohibited from being cloned. */
188 #define __noclone __attribute__((__noclone__))
190 #endif /* GCC_VERSION >= 40500 */
192 #if GCC_VERSION >= 40600
194 * Tell the optimizer that something else uses this function or variable.
196 #define __visible __attribute__((externally_visible))
200 * GCC 'asm goto' miscompiles certain code sequences:
202 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
204 * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
206 * (asm goto is automatically volatile - the naming reflects this.)
208 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
210 #ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
211 #if GCC_VERSION >= 40400
212 #define __HAVE_BUILTIN_BSWAP32__
213 #define __HAVE_BUILTIN_BSWAP64__
215 #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
216 #define __HAVE_BUILTIN_BSWAP16__
218 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
220 #if GCC_VERSION >= 50000
221 #define KASAN_ABI_VERSION 4
222 #elif GCC_VERSION >= 40902
223 #define KASAN_ABI_VERSION 3
226 #endif /* gcc version >= 40000 specific checks */
228 #if !defined(__noclone)
229 #define __noclone /* not needed */
233 * A trick to suppress uninitialized variable warning without generating any
236 #define uninitialized_var(x) x = x