diff options
Diffstat (limited to 'include/linux/compiler-gcc.h')
-rw-r--r-- | include/linux/compiler-gcc.h | 207 |
1 files changed, 162 insertions, 45 deletions
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 371e560d13cf..dfaa7b3e9ae9 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h | |||
@@ -5,9 +5,9 @@ | |||
5 | /* | 5 | /* |
6 | * Common definitions for all gcc versions go here. | 6 | * Common definitions for all gcc versions go here. |
7 | */ | 7 | */ |
8 | #define GCC_VERSION (__GNUC__ * 10000 \ | 8 | #define GCC_VERSION (__GNUC__ * 10000 \ |
9 | + __GNUC_MINOR__ * 100 \ | 9 | + __GNUC_MINOR__ * 100 \ |
10 | + __GNUC_PATCHLEVEL__) | 10 | + __GNUC_PATCHLEVEL__) |
11 | 11 | ||
12 | /* Optimization barrier */ | 12 | /* Optimization barrier */ |
13 | 13 | ||
@@ -46,55 +46,63 @@ | |||
46 | * the inline assembly constraint from =g to =r, in this particular | 46 | * the inline assembly constraint from =g to =r, in this particular |
47 | * case either is valid. | 47 | * case either is valid. |
48 | */ | 48 | */ |
49 | #define RELOC_HIDE(ptr, off) \ | 49 | #define RELOC_HIDE(ptr, off) \ |
50 | ({ unsigned long __ptr; \ | 50 | ({ \ |
51 | __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ | 51 | unsigned long __ptr; \ |
52 | (typeof(ptr)) (__ptr + (off)); }) | 52 | __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ |
53 | (typeof(ptr)) (__ptr + (off)); \ | ||
54 | }) | ||
53 | 55 | ||
54 | /* Make the optimizer believe the variable can be manipulated arbitrarily. */ | 56 | /* Make the optimizer believe the variable can be manipulated arbitrarily. */ |
55 | #define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var)) | 57 | #define OPTIMIZER_HIDE_VAR(var) \ |
58 | __asm__ ("" : "=r" (var) : "0" (var)) | ||
56 | 59 | ||
57 | #ifdef __CHECKER__ | 60 | #ifdef __CHECKER__ |
58 | #define __must_be_array(arr) 0 | 61 | #define __must_be_array(a) 0 |
59 | #else | 62 | #else |
60 | /* &a[0] degrades to a pointer: a different type from an array */ | 63 | /* &a[0] degrades to a pointer: a different type from an array */ |
61 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) | 64 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) |
62 | #endif | 65 | #endif |
63 | 66 | ||
64 | /* | 67 | /* |
65 | * Force always-inline if the user requests it so via the .config, | 68 | * Force always-inline if the user requests it so via the .config, |
66 | * or if gcc is too old: | 69 | * or if gcc is too old: |
67 | */ | 70 | */ |
68 | #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ | 71 | #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ |
69 | !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) | 72 | !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) |
70 | # define inline inline __attribute__((always_inline)) notrace | 73 | #define inline inline __attribute__((always_inline)) notrace |
71 | # define __inline__ __inline__ __attribute__((always_inline)) notrace | 74 | #define __inline__ __inline__ __attribute__((always_inline)) notrace |
72 | # define __inline __inline __attribute__((always_inline)) notrace | 75 | #define __inline __inline __attribute__((always_inline)) notrace |
73 | #else | 76 | #else |
74 | /* A lot of inline functions can cause havoc with function tracing */ | 77 | /* A lot of inline functions can cause havoc with function tracing */ |
75 | # define inline inline notrace | 78 | #define inline inline notrace |
76 | # define __inline__ __inline__ notrace | 79 | #define __inline__ __inline__ notrace |
77 | # define __inline __inline notrace | 80 | #define __inline __inline notrace |
78 | #endif | 81 | #endif |
79 | 82 | ||
80 | #define __deprecated __attribute__((deprecated)) | 83 | #define __always_inline inline __attribute__((always_inline)) |
81 | #define __packed __attribute__((packed)) | 84 | #define noinline __attribute__((noinline)) |
82 | #define __weak __attribute__((weak)) | 85 | |
83 | #define __alias(symbol) __attribute__((alias(#symbol))) | 86 | #define __deprecated __attribute__((deprecated)) |
87 | #define __packed __attribute__((packed)) | ||
88 | #define __weak __attribute__((weak)) | ||
89 | #define __alias(symbol) __attribute__((alias(#symbol))) | ||
84 | 90 | ||
85 | /* | 91 | /* |
86 | * it doesn't make sense on ARM (currently the only user of __naked) to trace | 92 | * it doesn't make sense on ARM (currently the only user of __naked) |
87 | * naked functions because then mcount is called without stack and frame pointer | 93 | * to trace naked functions because then mcount is called without |
88 | * being set up and there is no chance to restore the lr register to the value | 94 | * stack and frame pointer being set up and there is no chance to |
89 | * before mcount was called. | 95 | * restore the lr register to the value before mcount was called. |
96 | * | ||
97 | * The asm() bodies of naked functions often depend on standard calling | ||
98 | * conventions, therefore they must be noinline and noclone. | ||
90 | * | 99 | * |
91 | * The asm() bodies of naked functions often depend on standard calling conventions, | 100 | * GCC 4.[56] currently fail to enforce this, so we must do so ourselves. |
92 | * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce | 101 | * See GCC PR44290. |
93 | * this, so we must do so ourselves. See GCC PR44290. | ||
94 | */ | 102 | */ |
95 | #define __naked __attribute__((naked)) noinline __noclone notrace | 103 | #define __naked __attribute__((naked)) noinline __noclone notrace |
96 | 104 | ||
97 | #define __noreturn __attribute__((noreturn)) | 105 | #define __noreturn __attribute__((noreturn)) |
98 | 106 | ||
99 | /* | 107 | /* |
100 | * From the GCC manual: | 108 | * From the GCC manual: |
@@ -106,19 +114,130 @@ | |||
106 | * would be. | 114 | * would be. |
107 | * [...] | 115 | * [...] |
108 | */ | 116 | */ |
109 | #define __pure __attribute__((pure)) | 117 | #define __pure __attribute__((pure)) |
110 | #define __aligned(x) __attribute__((aligned(x))) | 118 | #define __aligned(x) __attribute__((aligned(x))) |
111 | #define __printf(a, b) __attribute__((format(printf, a, b))) | 119 | #define __printf(a, b) __attribute__((format(printf, a, b))) |
112 | #define __scanf(a, b) __attribute__((format(scanf, a, b))) | 120 | #define __scanf(a, b) __attribute__((format(scanf, a, b))) |
113 | #define noinline __attribute__((noinline)) | 121 | #define __attribute_const__ __attribute__((__const__)) |
114 | #define __attribute_const__ __attribute__((__const__)) | 122 | #define __maybe_unused __attribute__((unused)) |
115 | #define __maybe_unused __attribute__((unused)) | 123 | #define __always_unused __attribute__((unused)) |
116 | #define __always_unused __attribute__((unused)) | 124 | |
117 | 125 | /* gcc version specific checks */ | |
118 | #define __gcc_header(x) #x | 126 | |
119 | #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h) | 127 | #if GCC_VERSION < 30200 |
120 | #define gcc_header(x) _gcc_header(x) | 128 | # error Sorry, your compiler is too old - please upgrade it. |
121 | #include gcc_header(__GNUC__) | 129 | #endif |
130 | |||
131 | #if GCC_VERSION < 30300 | ||
132 | # define __used __attribute__((__unused__)) | ||
133 | #else | ||
134 | # define __used __attribute__((__used__)) | ||
135 | #endif | ||
136 | |||
137 | #ifdef CONFIG_GCOV_KERNEL | ||
138 | # if GCC_VERSION < 30400 | ||
139 | # error "GCOV profiling support for gcc versions below 3.4 not included" | ||
140 | # endif /* __GNUC_MINOR__ */ | ||
141 | #endif /* CONFIG_GCOV_KERNEL */ | ||
142 | |||
143 | #if GCC_VERSION >= 30400 | ||
144 | #define __must_check __attribute__((warn_unused_result)) | ||
145 | #endif | ||
146 | |||
147 | #if GCC_VERSION >= 40000 | ||
148 | |||
149 | /* GCC 4.1.[01] miscompiles __weak */ | ||
150 | #ifdef __KERNEL__ | ||
151 | # if GCC_VERSION >= 40100 && GCC_VERSION <= 40101 | ||
152 | # error Your version of gcc miscompiles the __weak directive | ||
153 | # endif | ||
154 | #endif | ||
155 | |||
156 | #define __used __attribute__((__used__)) | ||
157 | #define __compiler_offsetof(a, b) \ | ||
158 | __builtin_offsetof(a, b) | ||
159 | |||
160 | #if GCC_VERSION >= 40100 && GCC_VERSION < 40600 | ||
161 | # define __compiletime_object_size(obj) __builtin_object_size(obj, 0) | ||
162 | #endif | ||
163 | |||
164 | #if GCC_VERSION >= 40300 | ||
165 | /* Mark functions as cold. gcc will assume any path leading to a call | ||
166 | * to them will be unlikely. This means a lot of manual unlikely()s | ||
167 | * are unnecessary now for any paths leading to the usual suspects | ||
168 | * like BUG(), printk(), panic() etc. [but let's keep them for now for | ||
169 | * older compilers] | ||
170 | * | ||
171 | * Early snapshots of gcc 4.3 don't support this and we can't detect this | ||
172 | * in the preprocessor, but we can live with this because they're unreleased. | ||
173 | * Maketime probing would be overkill here. | ||
174 | * | ||
175 | * gcc also has a __attribute__((__hot__)) to move hot functions into | ||
176 | * a special section, but I don't see any sense in this right now in | ||
177 | * the kernel context | ||
178 | */ | ||
179 | #define __cold __attribute__((__cold__)) | ||
180 | |||
181 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) | ||
182 | |||
183 | #ifndef __CHECKER__ | ||
184 | # define __compiletime_warning(message) __attribute__((warning(message))) | ||
185 | # define __compiletime_error(message) __attribute__((error(message))) | ||
186 | #endif /* __CHECKER__ */ | ||
187 | #endif /* GCC_VERSION >= 40300 */ | ||
188 | |||
189 | #if GCC_VERSION >= 40500 | ||
190 | /* | ||
191 | * Mark a position in code as unreachable. This can be used to | ||
192 | * suppress control flow warnings after asm blocks that transfer | ||
193 | * control elsewhere. | ||
194 | * | ||
195 | * Early snapshots of gcc 4.5 don't support this and we can't detect | ||
196 | * this in the preprocessor, but we can live with this because they're | ||
197 | * unreleased. Really, we need to have autoconf for the kernel. | ||
198 | */ | ||
199 | #define unreachable() __builtin_unreachable() | ||
200 | |||
201 | /* Mark a function definition as prohibited from being cloned. */ | ||
202 | #define __noclone __attribute__((__noclone__)) | ||
203 | |||
204 | #endif /* GCC_VERSION >= 40500 */ | ||
205 | |||
206 | #if GCC_VERSION >= 40600 | ||
207 | /* | ||
208 | * Tell the optimizer that something else uses this function or variable. | ||
209 | */ | ||
210 | #define __visible __attribute__((externally_visible)) | ||
211 | #endif | ||
212 | |||
213 | /* | ||
214 | * GCC 'asm goto' miscompiles certain code sequences: | ||
215 | * | ||
216 | * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 | ||
217 | * | ||
218 | * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. | ||
219 | * | ||
220 | * (asm goto is automatically volatile - the naming reflects this.) | ||
221 | */ | ||
222 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) | ||
223 | |||
224 | #ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP | ||
225 | #if GCC_VERSION >= 40400 | ||
226 | #define __HAVE_BUILTIN_BSWAP32__ | ||
227 | #define __HAVE_BUILTIN_BSWAP64__ | ||
228 | #endif | ||
229 | #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600) | ||
230 | #define __HAVE_BUILTIN_BSWAP16__ | ||
231 | #endif | ||
232 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ | ||
233 | |||
234 | #if GCC_VERSION >= 50000 | ||
235 | #define KASAN_ABI_VERSION 4 | ||
236 | #elif GCC_VERSION >= 40902 | ||
237 | #define KASAN_ABI_VERSION 3 | ||
238 | #endif | ||
239 | |||
240 | #endif /* gcc version >= 40000 specific checks */ | ||
122 | 241 | ||
123 | #if !defined(__noclone) | 242 | #if !defined(__noclone) |
124 | #define __noclone /* not needed */ | 243 | #define __noclone /* not needed */ |
@@ -129,5 +248,3 @@ | |||
129 | * code | 248 | * code |
130 | */ | 249 | */ |
131 | #define uninitialized_var(x) x = x | 250 | #define uninitialized_var(x) x = x |
132 | |||
133 | #define __always_inline inline __attribute__((always_inline)) | ||