fix gcc6 build error
[profile/mobile/platform/kernel/u-boot-tm1.git] / include / linux / compiler-gcc.h
1 #ifndef __LINUX_COMPILER_H
2 #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
3 #endif
4
5 /*
6  * Common definitions for all gcc versions go here.
7  */
8 #define GCC_VERSION (__GNUC__ * 10000 \
9                    + __GNUC_MINOR__ * 100 \
10                    + __GNUC_PATCHLEVEL__)
11
12 /* Optimization barrier */
13 /* The "volatile" is due to gcc bugs */
14 #define barrier() __asm__ __volatile__("": : :"memory")
15
16 /*
17  * This macro obfuscates arithmetic on a variable address so that gcc
18  * shouldn't recognize the original var, and make assumptions about it.
19  *
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.
24  *
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
27  * using this macro.
28  *
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.
33  */
34 #define RELOC_HIDE(ptr, off)                                    \
35   ({ unsigned long __ptr;                                       \
36     __asm__ ("" : "=r"(__ptr) : "0"(ptr));              \
37     (typeof(ptr)) (__ptr + (off)); })
38
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])))
42
43 /*
44  * Force always-inline if the user requests it so via the .config,
45  * or if gcc is too old:
46  */
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__))
53 #endif
54
55 #define __deprecated                    __attribute__((deprecated))
56 #define __packed                        __attribute__((packed))
57 #define __weak                          __attribute__((weak))
58
59 /*
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.
64  */
65 #define __naked                         __attribute__((naked)) notrace
66
67 #define __noreturn                      __attribute__((noreturn))
68
69 /*
70  * From the GCC manual:
71  *
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
76  * would be.
77  * [...]
78  */
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))
86
87 /* gcc version specific checks */
88
89 #if GCC_VERSION < 30200
90 # error Sorry, your compiler is too old - please upgrade it.
91 #endif
92
93 #if GCC_VERSION < 30300
94 # define __used                 __attribute__((__unused__))
95 #else
96 # define __used                 __attribute__((__used__))
97 #endif
98
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 */
104
105 #if GCC_VERSION >= 30400
106 #define __must_check            __attribute__((warn_unused_result))
107 #endif
108
109 #if GCC_VERSION >= 40000
110
111 /* GCC 4.1.[01] miscompiles __weak */
112 #ifdef __KERNEL__
113 # if GCC_VERSION >= 40100 &&  GCC_VERSION <= 40101
114 #  error Your version of gcc miscompiles the __weak directive
115 # endif
116 #endif
117
118 #define __used                  __attribute__((__used__))
119 #define __compiler_offsetof(a, b)                                       \
120         __builtin_offsetof(a, b)
121
122 #if GCC_VERSION >= 40100 && GCC_VERSION < 40600
123 # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
124 #endif
125
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
131  * older compilers]
132  *
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.
136  *
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
139  * the kernel context
140  */
141 #define __cold                  __attribute__((__cold__))
142
143 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
144
145 #ifndef __CHECKER__
146 # define __compiletime_warning(message) __attribute__((warning(message)))
147 # define __compiletime_error(message) __attribute__((error(message)))
148 #endif /* __CHECKER__ */
149 #endif /* GCC_VERSION >= 40300 */
150
151 #if GCC_VERSION >= 40500
152 /*
153  * Mark a position in code as unreachable.  This can be used to
154  * suppress control flow warnings after asm blocks that transfer
155  * control elsewhere.
156  *
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.
160  */
161 #define unreachable() __builtin_unreachable()
162
163 /* Mark a function definition as prohibited from being cloned. */
164 #define __noclone       __attribute__((__noclone__))
165
166 #endif /* GCC_VERSION >= 40500 */
167
168 #if GCC_VERSION >= 40600
169 /*
170  * Tell the optimizer that something else uses this function or variable.
171  */
172 #define __visible       __attribute__((externally_visible))
173 #endif
174
175 /*
176  * GCC 'asm goto' miscompiles certain code sequences:
177  *
178  *   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
179  *
180  * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
181  *
182  * (asm goto is automatically volatile - the naming reflects this.)
183  */
184 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
185
186 #ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
187 #if GCC_VERSION >= 40400
188 #define __HAVE_BUILTIN_BSWAP32__
189 #define __HAVE_BUILTIN_BSWAP64__
190 #endif
191 #if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
192 #define __HAVE_BUILTIN_BSWAP16__
193 #endif
194 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
195
196 #endif  /* gcc version >= 40000 specific checks */