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__)
12 /* Optimization barrier */
13 /* The "volatile" is due to gcc bugs */
14 #define barrier() __asm__ __volatile__("": : :"memory")
17 * This macro obfuscates arithmetic on a variable address so that gcc
18 * shouldn't recognize the original var, and make assumptions about it.
20 * This is needed because the C standard makes it undefined to do
21 * pointer arithmetic on "objects" outside their boundaries and the
22 * gcc optimizers assume this is the case. In particular they
23 * assume such arithmetic does not wrap.
25 * A miscompilation has been observed because of this on PPC.
26 * To work around it we hide the relationship of the pointer and the object
29 * Versions of the ppc64 compiler before 4.1 had a bug where use of
30 * RELOC_HIDE could trash r30. The bug can be worked around by changing
31 * the inline assembly constraint from =g to =r, in this particular
32 * case either is valid.
34 #define RELOC_HIDE(ptr, off) \
35 ({ unsigned long __ptr; \
36 __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
37 (typeof(ptr)) (__ptr + (off)); })
39 /* &a[0] degrades to a pointer: a different type from an array */
40 #define __must_be_array(a) \
41 BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
44 * Force always-inline if the user requests it so via the .config,
45 * or if gcc is too old:
47 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
48 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
49 /* XXX: check __GNUC_STDC_INLINE__, fix line length */
50 # define inline inline __attribute__((always_inline)) __attribute__((__gnu_inline__))
51 # define __inline__ __inline__ __attribute__((always_inline)) __attribute__((__gnu_inline__))
52 # define __inline __inline __attribute__((always_inline)) __attribute__((__gnu_inline__))
55 #define __deprecated __attribute__((deprecated))
56 #define __packed __attribute__((packed))
57 #define __weak __attribute__((weak))
60 * it doesn't make sense on ARM (currently the only user of __naked) to trace
61 * naked functions because then mcount is called without stack and frame pointer
62 * being set up and there is no chance to restore the lr register to the value
63 * before mcount was called.
65 #define __naked __attribute__((naked)) notrace
67 #define __noreturn __attribute__((noreturn))
70 * From the GCC manual:
72 * Many functions have no effects except the return value and their
73 * return value depends only on the parameters and/or global
74 * variables. Such a function can be subject to common subexpression
75 * elimination and loop optimization just as an arithmetic operator
79 #define __pure __attribute__((pure))
80 #define __aligned(x) __attribute__((aligned(x)))
81 #define __printf(a,b) __attribute__((format(printf,a,b)))
82 #define noinline __attribute__((noinline))
83 #define __attribute_const__ __attribute__((__const__))
84 #define __maybe_unused __attribute__((unused))
85 #define __always_unused __attribute__((unused))
87 /* gcc version specific checks */
89 #if GCC_VERSION < 30200
90 # error Sorry, your compiler is too old - please upgrade it.
93 #if GCC_VERSION < 30300
94 # define __used __attribute__((__unused__))
96 # define __used __attribute__((__used__))
99 #ifdef CONFIG_GCOV_KERNEL
100 # if GCC_VERSION < 30400
101 # error "GCOV profiling support for gcc versions below 3.4 not included"
102 # endif /* __GNUC_MINOR__ */
103 #endif /* CONFIG_GCOV_KERNEL */
105 #if GCC_VERSION >= 30400
106 #define __must_check __attribute__((warn_unused_result))
109 #if GCC_VERSION >= 40000
111 /* GCC 4.1.[01] miscompiles __weak */
113 # if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
114 # error Your version of gcc miscompiles the __weak directive
118 #define __used __attribute__((__used__))
119 #define __compiler_offsetof(a, b) \
120 __builtin_offsetof(a, b)
122 #if GCC_VERSION >= 40100 && GCC_VERSION < 40600
123 # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
126 #if GCC_VERSION >= 40300
127 /* Mark functions as cold. gcc will assume any path leading to a call
128 * to them will be unlikely. This means a lot of manual unlikely()s
129 * are unnecessary now for any paths leading to the usual suspects
130 * like BUG(), printk(), panic() etc. [but let's keep them for now for
133 * Early snapshots of gcc 4.3 don't support this and we can't detect this
134 * in the preprocessor, but we can live with this because they're unreleased.
135 * Maketime probing would be overkill here.
137 * gcc also has a __attribute__((__hot__)) to move hot functions into
138 * a special section, but I don't see any sense in this right now in
141 #define __cold __attribute__((__cold__))
143 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
146 # define __compiletime_warning(message) __attribute__((warning(message)))
147 # define __compiletime_error(message) __attribute__((error(message)))
148 #endif /* __CHECKER__ */
149 #endif /* GCC_VERSION >= 40300 */
151 #if GCC_VERSION >= 40500
153 * Mark a position in code as unreachable. This can be used to
154 * suppress control flow warnings after asm blocks that transfer
157 * Early snapshots of gcc 4.5 don't support this and we can't detect
158 * this in the preprocessor, but we can live with this because they're
159 * unreleased. Really, we need to have autoconf for the kernel.
161 #define unreachable() __builtin_unreachable()
163 /* Mark a function definition as prohibited from being cloned. */
164 #define __noclone __attribute__((__noclone__))
166 #endif /* GCC_VERSION >= 40500 */
168 #if GCC_VERSION >= 40600
170 * Tell the optimizer that something else uses this function or variable.
172 #define __visible __attribute__((externally_visible))
176 * GCC 'asm goto' miscompiles certain code sequences:
178 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
180 * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
182 * (asm goto is automatically volatile - the naming reflects this.)
184 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
186 #ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
187 #if GCC_VERSION >= 40400
188 #define __HAVE_BUILTIN_BSWAP32__
189 #define __HAVE_BUILTIN_BSWAP64__
191 #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
192 #define __HAVE_BUILTIN_BSWAP16__
194 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
196 #endif /* gcc version >= 40000 specific checks */