Skip to content

Commit cb984d1

Browse files
JoePerchestorvalds
authored andcommitted
compiler-gcc: integrate the various compiler-gcc[345].h files
As gcc major version numbers are going to advance rather rapidly in the future, there's no real value in separate files for each compiler version. Deduplicate some of the macros #defined in each file too. Neaten comments using normal kernel commenting style. Signed-off-by: Joe Perches <joe@perches.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Michal Marek <mmarek@suse.cz> Cc: Segher Boessenkool <segher@kernel.crashing.org> Cc: Sasha Levin <levinsasha928@gmail.com> Cc: Anton Blanchard <anton@samba.org> Cc: Alan Modra <amodra@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f6d133f commit cb984d1

File tree

4 files changed

+116
-185
lines changed

4 files changed

+116
-185
lines changed

include/linux/compiler-gcc.h

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,122 @@
122122
#define __maybe_unused __attribute__((unused))
123123
#define __always_unused __attribute__((unused))
124124

125-
#define __gcc_header(x) #x
126-
#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
127-
#define gcc_header(x) _gcc_header(x)
128-
#include gcc_header(__GNUC__)
125+
/* gcc version specific checks */
126+
127+
#if GCC_VERSION < 30200
128+
# error Sorry, your compiler is too old - please upgrade it.
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 */
129241

130242
#if !defined(__noclone)
131243
#define __noclone /* not needed */

include/linux/compiler-gcc3.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

include/linux/compiler-gcc4.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

include/linux/compiler-gcc5.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)