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.
10 /* Optimization barrier */
11 /* The "volatile" is due to gcc bugs */
12 #define barrier() __asm__ __volatile__("": : :"memory")
15 * This macro obfuscates arithmetic on a variable address so that gcc
16 * shouldn't recognize the original var, and make assumptions about it.
18 * This is needed because the C standard makes it undefined to do
19 * pointer arithmetic on "objects" outside their boundaries and the
20 * gcc optimizers assume this is the case. In particular they
21 * assume such arithmetic does not wrap.
23 * A miscompilation has been observed because of this on PPC.
24 * To work around it we hide the relationship of the pointer and the object
27 * Versions of the ppc64 compiler before 4.1 had a bug where use of
28 * RELOC_HIDE could trash r30. The bug can be worked around by changing
29 * the inline assembly constraint from =g to =r, in this particular
30 * case either is valid.
32 #define RELOC_HIDE(ptr, off) \
33 ({ unsigned long __ptr; \
34 __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
35 (typeof(ptr)) (__ptr + (off)); })
38 #define __must_be_array(arr) 0
40 /* &a[0] degrades to a pointer: a different type from an array */
41 #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
45 * Force always-inline if the user requests it so via the .config,
46 * or if gcc is too old:
48 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
49 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
50 # define inline inline __attribute__((always_inline))
51 # define __inline__ __inline__ __attribute__((always_inline))
52 # define __inline __inline __attribute__((always_inline))
54 /* A lot of inline functions can cause havoc with function tracing */
55 # define inline inline notrace
56 # define __inline__ __inline__ notrace
57 # define __inline __inline notrace
60 #define __deprecated __attribute__((deprecated))
61 #define __packed __attribute__((packed))
62 #define __weak __attribute__((weak))
65 * it doesn't make sense on ARM (currently the only user of __naked) to trace
66 * naked functions because then mcount is called without stack and frame pointer
67 * being set up and there is no chance to restore the lr register to the value
68 * before mcount was called.
70 * The asm() bodies of naked functions often depend on standard calling conventions,
71 * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce
72 * this, so we must do so ourselves. See GCC PR44290.
74 #define __naked __attribute__((naked)) noinline __noclone notrace
76 #define __noreturn __attribute__((noreturn))
79 * From the GCC manual:
81 * Many functions have no effects except the return value and their
82 * return value depends only on the parameters and/or global
83 * variables. Such a function can be subject to common subexpression
84 * elimination and loop optimization just as an arithmetic operator
88 #define __pure __attribute__((pure))
89 #define __aligned(x) __attribute__((aligned(x)))
90 #define __printf(a, b) __attribute__((format(printf, a, b)))
91 #define __scanf(a, b) __attribute__((format(scanf, a, b)))
92 #define noinline __attribute__((noinline))
93 #define __attribute_const__ __attribute__((__const__))
94 #define __maybe_unused __attribute__((unused))
95 #define __always_unused __attribute__((unused))
97 /* gcc version specific checks */
99 #if GCC_VERSION < 30200
100 # error Sorry, your compiler is too old - please upgrade it.
103 #if GCC_VERSION < 30300
104 # define __used __attribute__((__unused__))
106 # define __used __attribute__((__used__))
109 #ifdef CONFIG_GCOV_KERNEL
110 # if GCC_VERSION < 30400
111 # error "GCOV profiling support for gcc versions below 3.4 not included"
112 # endif /* __GNUC_MINOR__ */
113 #endif /* CONFIG_GCOV_KERNEL */
115 #if GCC_VERSION >= 30400
116 #define __must_check __attribute__((warn_unused_result))
119 #if GCC_VERSION >= 40000
121 /* GCC 4.1.[01] miscompiles __weak */
123 # if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
124 # error Your version of gcc miscompiles the __weak directive
128 #define __used __attribute__((__used__))
129 #define __compiler_offsetof(a, b) \
130 __builtin_offsetof(a, b)
132 #if GCC_VERSION >= 40100 && GCC_VERSION < 40600
133 # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
136 #if GCC_VERSION >= 40300
137 /* Mark functions as cold. gcc will assume any path leading to a call
138 * to them will be unlikely. This means a lot of manual unlikely()s
139 * are unnecessary now for any paths leading to the usual suspects
140 * like BUG(), printk(), panic() etc. [but let's keep them for now for
143 * Early snapshots of gcc 4.3 don't support this and we can't detect this
144 * in the preprocessor, but we can live with this because they're unreleased.
145 * Maketime probing would be overkill here.
147 * gcc also has a __attribute__((__hot__)) to move hot functions into
148 * a special section, but I don't see any sense in this right now in
151 #define __cold __attribute__((__cold__))
153 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
156 # define __compiletime_warning(message) __attribute__((warning(message)))
157 # define __compiletime_error(message) __attribute__((error(message)))
158 #endif /* __CHECKER__ */
159 #endif /* GCC_VERSION >= 40300 */
161 #if GCC_VERSION >= 40500
163 * Mark a position in code as unreachable. This can be used to
164 * suppress control flow warnings after asm blocks that transfer
167 * Early snapshots of gcc 4.5 don't support this and we can't detect
168 * this in the preprocessor, but we can live with this because they're
169 * unreleased. Really, we need to have autoconf for the kernel.
171 #define unreachable() __builtin_unreachable()
173 /* Mark a function definition as prohibited from being cloned. */
174 #define __noclone __attribute__((__noclone__))
176 #endif /* GCC_VERSION >= 40500 */
178 #if GCC_VERSION >= 40600
180 * Tell the optimizer that something else uses this function or variable.
182 #define __visible __attribute__((externally_visible))
186 * GCC 'asm goto' miscompiles certain code sequences:
188 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
190 * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
192 * (asm goto is automatically volatile - the naming reflects this.)
194 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
196 #ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
197 #if GCC_VERSION >= 40400
198 #define __HAVE_BUILTIN_BSWAP32__
199 #define __HAVE_BUILTIN_BSWAP64__
201 #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
202 #define __HAVE_BUILTIN_BSWAP16__
204 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
206 #if GCC_VERSION >= 50000
207 #define KASAN_ABI_VERSION 4
208 #elif GCC_VERSION >= 40902
209 #define KASAN_ABI_VERSION 3
212 #endif /* gcc version >= 40000 specific checks */
214 #if !defined(__noclone)
215 #define __noclone /* not needed */
219 * A trick to suppress uninitialized variable warning without generating any
222 #define uninitialized_var(x) x = x
224 #define __always_inline inline __attribute__((always_inline))