blob: 00d0657bd69fe5d0cc4d3aef3fe12d80e421accd [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Hans de Goede <hdegoede@redhat.com>
2Date: Sat, 7 Feb 2015 21:52:40 +0000 (+0100)
3Subject: Add linux/compiler-gcc6.h to fix builds with gcc6
4X-Git-Tag: v2015.04-rc2~31
5X-Git-Url: http://git.denx.de/?p=u-boot.git;a=commitdiff_plain;h=478b02f1a7043b673565075ea5016376f3293b23
6
7Add linux/compiler-gcc6.h to fix builds with gcc6
8
9Add linux/compiler-gcc6/h from the kernel sources at:
10
11commit 5631b8fba640a4ab2f8a954f63a603fa34eda96b
12Author: Steven Noonan <steven@uplinklabs.net>
13Date: Sat Oct 25 15:09:42 2014 -0700
14
15 compiler/gcc4+: Remove inaccurate comment about 'asm goto' miscompiles
16
17Signed-off-by: Hans de Goede <hdegoede@redhat.com>
18---
19
20--- /dev/null
21+++ b/include/linux/compiler-gcc6.h
22@@ -0,0 +1,284 @@
23+#ifndef __LINUX_COMPILER_H
24+#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
25+#endif
26+
27+/*
28+ * Common definitions for all gcc versions go here.
29+ */
30+#define GCC_VERSION (__GNUC__ * 10000 \
31+ + __GNUC_MINOR__ * 100 \
32+ + __GNUC_PATCHLEVEL__)
33+
34+/* Optimization barrier */
35+
36+/* The "volatile" is due to gcc bugs */
37+#define barrier() __asm__ __volatile__("": : :"memory")
38+/*
39+ * This version is i.e. to prevent dead stores elimination on @ptr
40+ * where gcc and llvm may behave differently when otherwise using
41+ * normal barrier(): while gcc behavior gets along with a normal
42+ * barrier(), llvm needs an explicit input variable to be assumed
43+ * clobbered. The issue is as follows: while the inline asm might
44+ * access any memory it wants, the compiler could have fit all of
45+ * @ptr into memory registers instead, and since @ptr never escaped
46+ * from that, it proofed that the inline asm wasn't touching any of
47+ * it. This version works well with both compilers, i.e. we're telling
48+ * the compiler that the inline asm absolutely may see the contents
49+ * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
50+ */
51+#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
52+
53+/*
54+ * This macro obfuscates arithmetic on a variable address so that gcc
55+ * shouldn't recognize the original var, and make assumptions about it.
56+ *
57+ * This is needed because the C standard makes it undefined to do
58+ * pointer arithmetic on "objects" outside their boundaries and the
59+ * gcc optimizers assume this is the case. In particular they
60+ * assume such arithmetic does not wrap.
61+ *
62+ * A miscompilation has been observed because of this on PPC.
63+ * To work around it we hide the relationship of the pointer and the object
64+ * using this macro.
65+ *
66+ * Versions of the ppc64 compiler before 4.1 had a bug where use of
67+ * RELOC_HIDE could trash r30. The bug can be worked around by changing
68+ * the inline assembly constraint from =g to =r, in this particular
69+ * case either is valid.
70+ */
71+#define RELOC_HIDE(ptr, off) \
72+({ \
73+ unsigned long __ptr; \
74+ __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
75+ (typeof(ptr)) (__ptr + (off)); \
76+})
77+
78+/* Make the optimizer believe the variable can be manipulated arbitrarily. */
79+#define OPTIMIZER_HIDE_VAR(var) \
80+ __asm__ ("" : "=r" (var) : "0" (var))
81+
82+#ifdef __CHECKER__
83+#define __must_be_array(a) 0
84+#else
85+/* &a[0] degrades to a pointer: a different type from an array */
86+#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
87+#endif
88+
89+/*
90+ * Force always-inline if the user requests it so via the .config,
91+ * or if gcc is too old:
92+ */
93+#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
94+ !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
95+#define inline inline __attribute__((always_inline)) notrace
96+#define __inline__ __inline__ __attribute__((always_inline)) notrace
97+#define __inline __inline __attribute__((always_inline)) notrace
98+#else
99+/* A lot of inline functions can cause havoc with function tracing */
100+#define inline inline notrace
101+#define __inline__ __inline__ notrace
102+#define __inline __inline notrace
103+#endif
104+
105+#define __always_inline inline __attribute__((always_inline))
106+#define noinline __attribute__((noinline))
107+
108+#define __deprecated __attribute__((deprecated))
109+#define __packed __attribute__((packed))
110+#define __weak __attribute__((weak))
111+#define __alias(symbol) __attribute__((alias(#symbol)))
112+
113+/*
114+ * it doesn't make sense on ARM (currently the only user of __naked)
115+ * to trace naked functions because then mcount is called without
116+ * stack and frame pointer being set up and there is no chance to
117+ * restore the lr register to the value before mcount was called.
118+ *
119+ * The asm() bodies of naked functions often depend on standard calling
120+ * conventions, therefore they must be noinline and noclone.
121+ *
122+ * GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
123+ * See GCC PR44290.
124+ */
125+#define __naked __attribute__((naked)) noinline __noclone notrace
126+
127+#define __noreturn __attribute__((noreturn))
128+
129+/*
130+ * From the GCC manual:
131+ *
132+ * Many functions have no effects except the return value and their
133+ * return value depends only on the parameters and/or global
134+ * variables. Such a function can be subject to common subexpression
135+ * elimination and loop optimization just as an arithmetic operator
136+ * would be.
137+ * [...]
138+ */
139+#define __pure __attribute__((pure))
140+#define __aligned(x) __attribute__((aligned(x)))
141+#define __printf(a, b) __attribute__((format(printf, a, b)))
142+#define __scanf(a, b) __attribute__((format(scanf, a, b)))
143+#define __attribute_const__ __attribute__((__const__))
144+#define __maybe_unused __attribute__((unused))
145+#define __always_unused __attribute__((unused))
146+
147+/* gcc version specific checks */
148+
149+#if GCC_VERSION < 30200
150+# error Sorry, your compiler is too old - please upgrade it.
151+#endif
152+
153+#if GCC_VERSION < 30300
154+# define __used __attribute__((__unused__))
155+#else
156+# define __used __attribute__((__used__))
157+#endif
158+
159+#ifdef CONFIG_GCOV_KERNEL
160+# if GCC_VERSION < 30400
161+# error "GCOV profiling support for gcc versions below 3.4 not included"
162+# endif /* __GNUC_MINOR__ */
163+#endif /* CONFIG_GCOV_KERNEL */
164+
165+#if GCC_VERSION >= 30400
166+#define __must_check __attribute__((warn_unused_result))
167+#define __malloc __attribute__((__malloc__))
168+#endif
169+
170+#if GCC_VERSION >= 40000
171+
172+/* GCC 4.1.[01] miscompiles __weak */
173+#ifdef __KERNEL__
174+# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
175+# error Your version of gcc miscompiles the __weak directive
176+# endif
177+#endif
178+
179+#define __used __attribute__((__used__))
180+#define __compiler_offsetof(a, b) \
181+ __builtin_offsetof(a, b)
182+
183+#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
184+# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
185+#endif
186+
187+#if GCC_VERSION >= 40300
188+/* Mark functions as cold. gcc will assume any path leading to a call
189+ * to them will be unlikely. This means a lot of manual unlikely()s
190+ * are unnecessary now for any paths leading to the usual suspects
191+ * like BUG(), printk(), panic() etc. [but let's keep them for now for
192+ * older compilers]
193+ *
194+ * Early snapshots of gcc 4.3 don't support this and we can't detect this
195+ * in the preprocessor, but we can live with this because they're unreleased.
196+ * Maketime probing would be overkill here.
197+ *
198+ * gcc also has a __attribute__((__hot__)) to move hot functions into
199+ * a special section, but I don't see any sense in this right now in
200+ * the kernel context
201+ */
202+#define __cold __attribute__((__cold__))
203+
204+#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
205+
206+#ifndef __CHECKER__
207+# define __compiletime_warning(message) __attribute__((warning(message)))
208+# define __compiletime_error(message) __attribute__((error(message)))
209+#endif /* __CHECKER__ */
210+#endif /* GCC_VERSION >= 40300 */
211+
212+#if GCC_VERSION >= 40500
213+/*
214+ * Mark a position in code as unreachable. This can be used to
215+ * suppress control flow warnings after asm blocks that transfer
216+ * control elsewhere.
217+ *
218+ * Early snapshots of gcc 4.5 don't support this and we can't detect
219+ * this in the preprocessor, but we can live with this because they're
220+ * unreleased. Really, we need to have autoconf for the kernel.
221+ */
222+#define unreachable() __builtin_unreachable()
223+
224+/* Mark a function definition as prohibited from being cloned. */
225+#define __noclone __attribute__((__noclone__, __optimize__("no-tracer")))
226+
227+#endif /* GCC_VERSION >= 40500 */
228+
229+#if GCC_VERSION >= 40600
230+/*
231+ * When used with Link Time Optimization, gcc can optimize away C functions or
232+ * variables which are referenced only from assembly code. __visible tells the
233+ * optimizer that something else uses this function or variable, thus preventing
234+ * this.
235+ */
236+#define __visible __attribute__((externally_visible))
237+#endif
238+
239+
240+#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
241+/*
242+ * __assume_aligned(n, k): Tell the optimizer that the returned
243+ * pointer can be assumed to be k modulo n. The second argument is
244+ * optional (default 0), so we use a variadic macro to make the
245+ * shorthand.
246+ *
247+ * Beware: Do not apply this to functions which may return
248+ * ERR_PTRs. Also, it is probably unwise to apply it to functions
249+ * returning extra information in the low bits (but in that case the
250+ * compiler should see some alignment anyway, when the return value is
251+ * massaged by 'flags = ptr & 3; ptr &= ~3;').
252+ */
253+#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
254+#endif
255+
256+/*
257+ * GCC 'asm goto' miscompiles certain code sequences:
258+ *
259+ * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
260+ *
261+ * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
262+ *
263+ * (asm goto is automatically volatile - the naming reflects this.)
264+ */
265+#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
266+
267+#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
268+#if GCC_VERSION >= 40400
269+#define __HAVE_BUILTIN_BSWAP32__
270+#define __HAVE_BUILTIN_BSWAP64__
271+#endif
272+#if GCC_VERSION >= 40800
273+#define __HAVE_BUILTIN_BSWAP16__
274+#endif
275+#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
276+
277+#if GCC_VERSION >= 50000
278+#define KASAN_ABI_VERSION 4
279+#elif GCC_VERSION >= 40902
280+#define KASAN_ABI_VERSION 3
281+#endif
282+
283+#if GCC_VERSION >= 40902
284+/*
285+ * Tell the compiler that address safety instrumentation (KASAN)
286+ * should not be applied to that function.
287+ * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
288+ */
289+#define __no_sanitize_address __attribute__((no_sanitize_address))
290+#endif
291+
292+#endif /* gcc version >= 40000 specific checks */
293+
294+#if !defined(__noclone)
295+#define __noclone /* not needed */
296+#endif
297+
298+#if !defined(__no_sanitize_address)
299+#define __no_sanitize_address
300+#endif
301+
302+/*
303+ * A trick to suppress uninitialized variable warning without generating any
304+ * code
305+ */
306+#define uninitialized_var(x) x = x