101-gcc-compiler-linux-3-16.patch 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. From fb8ffd7cfc68b3dc44e182356a207d784cb30b34 Mon Sep 17 00:00:00 2001
  2. From: Masahiro Yamada <[email protected]>
  3. Date: Thu, 4 Sep 2014 02:40:58 +0900
  4. Subject: compiler*.h: sync include/linux/compiler*.h with Linux 3.16
  5. Copy them from Linux v3.16 tag.
  6. My main motivation of this commit is to add compiler-clang.h.
  7. Signed-off-by: Masahiro Yamada <[email protected]>
  8. Cc: Jeroen Hofstee <[email protected]>
  9. ---
  10. include/linux/compiler-clang.h | 12 ++++++
  11. include/linux/compiler-gcc.h | 57 ++++++++++++++++++--------
  12. include/linux/compiler-gcc3.h | 20 ++++-----
  13. include/linux/compiler-gcc4.h | 59 +++++++++++++++++++--------
  14. include/linux/compiler-intel.h | 40 ++++++++++++++++++
  15. include/linux/compiler.h | 92 +++++++++++++++++++++++++++++++++++++++++-
  16. 6 files changed, 236 insertions(+), 44 deletions(-)
  17. create mode 100644 include/linux/compiler-clang.h
  18. create mode 100644 include/linux/compiler-intel.h
  19. --- /dev/null
  20. +++ b/include/linux/compiler-clang.h
  21. @@ -0,0 +1,12 @@
  22. +#ifndef __LINUX_COMPILER_H
  23. +#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
  24. +#endif
  25. +
  26. +/* Some compiler specific definitions are overwritten here
  27. + * for Clang compiler
  28. + */
  29. +
  30. +#ifdef uninitialized_var
  31. +#undef uninitialized_var
  32. +#define uninitialized_var(x) x = *(&(x))
  33. +#endif
  34. --- a/include/linux/compiler-gcc.h
  35. +++ b/include/linux/compiler-gcc.h
  36. @@ -5,6 +5,9 @@
  37. /*
  38. * Common definitions for all gcc versions go here.
  39. */
  40. +#define GCC_VERSION (__GNUC__ * 10000 \
  41. + + __GNUC_MINOR__ * 100 \
  42. + + __GNUC_PATCHLEVEL__)
  43. /* Optimization barrier */
  44. @@ -34,9 +37,15 @@
  45. __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
  46. (typeof(ptr)) (__ptr + (off)); })
  47. +/* Make the optimizer believe the variable can be manipulated arbitrarily. */
  48. +#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var))
  49. +
  50. +#ifdef __CHECKER__
  51. +#define __must_be_array(arr) 0
  52. +#else
  53. /* &a[0] degrades to a pointer: a different type from an array */
  54. -#define __must_be_array(a) \
  55. - BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
  56. +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
  57. +#endif
  58. /*
  59. * Force always-inline if the user requests it so via the .config,
  60. @@ -44,15 +53,18 @@
  61. */
  62. #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
  63. !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
  64. -# define inline inline __attribute__((always_inline))
  65. -# define __inline__ __inline__ __attribute__((always_inline))
  66. -# define __inline __inline __attribute__((always_inline))
  67. +# define inline inline __attribute__((always_inline)) notrace
  68. +# define __inline__ __inline__ __attribute__((always_inline)) notrace
  69. +# define __inline __inline __attribute__((always_inline)) notrace
  70. +#else
  71. +/* A lot of inline functions can cause havoc with function tracing */
  72. +# define inline inline notrace
  73. +# define __inline__ __inline__ notrace
  74. +# define __inline __inline notrace
  75. #endif
  76. #define __deprecated __attribute__((deprecated))
  77. -#ifndef __packed
  78. -# define __packed __attribute__((packed))
  79. -#endif
  80. +#define __packed __attribute__((packed))
  81. #define __weak __attribute__((weak))
  82. /*
  83. @@ -60,8 +72,12 @@
  84. * naked functions because then mcount is called without stack and frame pointer
  85. * being set up and there is no chance to restore the lr register to the value
  86. * before mcount was called.
  87. + *
  88. + * The asm() bodies of naked functions often depend on standard calling conventions,
  89. + * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce
  90. + * this, so we must do so ourselves. See GCC PR44290.
  91. */
  92. -#define __naked __attribute__((naked)) notrace
  93. +#define __naked __attribute__((naked)) noinline __noclone notrace
  94. #define __noreturn __attribute__((noreturn))
  95. @@ -75,13 +91,10 @@
  96. * would be.
  97. * [...]
  98. */
  99. -#ifndef __pure
  100. -# define __pure __attribute__((pure))
  101. -#endif
  102. -#ifndef __aligned
  103. -# define __aligned(x) __attribute__((aligned(x)))
  104. -#endif
  105. -#define __printf(a,b) __attribute__((format(printf,a,b)))
  106. +#define __pure __attribute__((pure))
  107. +#define __aligned(x) __attribute__((aligned(x)))
  108. +#define __printf(a, b) __attribute__((format(printf, a, b)))
  109. +#define __scanf(a, b) __attribute__((format(scanf, a, b)))
  110. #define noinline __attribute__((noinline))
  111. #define __attribute_const__ __attribute__((__const__))
  112. #define __maybe_unused __attribute__((unused))
  113. @@ -91,3 +104,15 @@
  114. #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
  115. #define gcc_header(x) _gcc_header(x)
  116. #include gcc_header(__GNUC__)
  117. +
  118. +#if !defined(__noclone)
  119. +#define __noclone /* not needed */
  120. +#endif
  121. +
  122. +/*
  123. + * A trick to suppress uninitialized variable warning without generating any
  124. + * code
  125. + */
  126. +#define uninitialized_var(x) x = x
  127. +
  128. +#define __always_inline inline __attribute__((always_inline))
  129. --- a/include/linux/compiler-gcc3.h
  130. +++ b/include/linux/compiler-gcc3.h
  131. @@ -2,20 +2,22 @@
  132. #error "Please don't include <linux/compiler-gcc3.h> directly, include <linux/compiler.h> instead."
  133. #endif
  134. -#if __GNUC_MINOR__ >= 3
  135. +#if GCC_VERSION < 30200
  136. +# error Sorry, your compiler is too old - please upgrade it.
  137. +#endif
  138. +
  139. +#if GCC_VERSION >= 30300
  140. # define __used __attribute__((__used__))
  141. #else
  142. # define __used __attribute__((__unused__))
  143. #endif
  144. -#if __GNUC_MINOR__ >= 4
  145. +#if GCC_VERSION >= 30400
  146. #define __must_check __attribute__((warn_unused_result))
  147. #endif
  148. -/*
  149. - * A trick to suppress uninitialized variable warning without generating any
  150. - * code
  151. - */
  152. -#define uninitialized_var(x) x = x
  153. -
  154. -#define __always_inline inline __attribute__((always_inline))
  155. +#ifdef CONFIG_GCOV_KERNEL
  156. +# if GCC_VERSION < 30400
  157. +# error "GCOV profiling support for gcc versions below 3.4 not included"
  158. +# endif /* __GNUC_MINOR__ */
  159. +#endif /* CONFIG_GCOV_KERNEL */
  160. --- a/include/linux/compiler-gcc4.h
  161. +++ b/include/linux/compiler-gcc4.h
  162. @@ -4,7 +4,7 @@
  163. /* GCC 4.1.[01] miscompiles __weak */
  164. #ifdef __KERNEL__
  165. -# if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1
  166. +# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
  167. # error Your version of gcc miscompiles the __weak directive
  168. # endif
  169. #endif
  170. @@ -12,17 +12,12 @@
  171. #define __used __attribute__((__used__))
  172. #define __must_check __attribute__((warn_unused_result))
  173. #define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
  174. -#ifndef __always_inline
  175. -# define __always_inline inline __attribute__((always_inline))
  176. -#endif
  177. -/*
  178. - * A trick to suppress uninitialized variable warning without generating any
  179. - * code
  180. - */
  181. -#define uninitialized_var(x) x = x
  182. +#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
  183. +# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
  184. +#endif
  185. -#if __GNUC_MINOR__ >= 3
  186. +#if GCC_VERSION >= 40300
  187. /* Mark functions as cold. gcc will assume any path leading to a call
  188. to them will be unlikely. This means a lot of manual unlikely()s
  189. are unnecessary now for any paths leading to the usual suspects
  190. @@ -38,8 +33,15 @@
  191. the kernel context */
  192. #define __cold __attribute__((__cold__))
  193. +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
  194. -#if __GNUC_MINOR__ >= 5
  195. +#ifndef __CHECKER__
  196. +# define __compiletime_warning(message) __attribute__((warning(message)))
  197. +# define __compiletime_error(message) __attribute__((error(message)))
  198. +#endif /* __CHECKER__ */
  199. +#endif /* GCC_VERSION >= 40300 */
  200. +
  201. +#if GCC_VERSION >= 40500
  202. /*
  203. * Mark a position in code as unreachable. This can be used to
  204. * suppress control flow warnings after asm blocks that transfer
  205. @@ -50,14 +52,37 @@
  206. * unreleased. Really, we need to have autoconf for the kernel.
  207. */
  208. #define unreachable() __builtin_unreachable()
  209. -#endif
  210. +/* Mark a function definition as prohibited from being cloned. */
  211. +#define __noclone __attribute__((__noclone__))
  212. +
  213. +#endif /* GCC_VERSION >= 40500 */
  214. +
  215. +#if GCC_VERSION >= 40600
  216. +/*
  217. + * Tell the optimizer that something else uses this function or variable.
  218. + */
  219. +#define __visible __attribute__((externally_visible))
  220. #endif
  221. -#if __GNUC_MINOR__ > 0
  222. -#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
  223. +/*
  224. + * GCC 'asm goto' miscompiles certain code sequences:
  225. + *
  226. + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
  227. + *
  228. + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
  229. + * Fixed in GCC 4.8.2 and later versions.
  230. + *
  231. + * (asm goto is automatically volatile - the naming reflects this.)
  232. + */
  233. +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
  234. +
  235. +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
  236. +#if GCC_VERSION >= 40400
  237. +#define __HAVE_BUILTIN_BSWAP32__
  238. +#define __HAVE_BUILTIN_BSWAP64__
  239. #endif
  240. -#if __GNUC_MINOR__ >= 4
  241. -#define __compiletime_warning(message) __attribute__((warning(message)))
  242. -#define __compiletime_error(message) __attribute__((error(message)))
  243. +#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
  244. +#define __HAVE_BUILTIN_BSWAP16__
  245. #endif
  246. +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
  247. --- /dev/null
  248. +++ b/include/linux/compiler-intel.h
  249. @@ -0,0 +1,40 @@
  250. +#ifndef __LINUX_COMPILER_H
  251. +#error "Please don't include <linux/compiler-intel.h> directly, include <linux/compiler.h> instead."
  252. +#endif
  253. +
  254. +#ifdef __ECC
  255. +
  256. +/* Some compiler specific definitions are overwritten here
  257. + * for Intel ECC compiler
  258. + */
  259. +
  260. +#include <asm/intrinsics.h>
  261. +
  262. +/* Intel ECC compiler doesn't support gcc specific asm stmts.
  263. + * It uses intrinsics to do the equivalent things.
  264. + */
  265. +#undef RELOC_HIDE
  266. +#undef OPTIMIZER_HIDE_VAR
  267. +
  268. +#define RELOC_HIDE(ptr, off) \
  269. + ({ unsigned long __ptr; \
  270. + __ptr = (unsigned long) (ptr); \
  271. + (typeof(ptr)) (__ptr + (off)); })
  272. +
  273. +/* This should act as an optimization barrier on var.
  274. + * Given that this compiler does not have inline assembly, a compiler barrier
  275. + * is the best we can do.
  276. + */
  277. +#define OPTIMIZER_HIDE_VAR(var) barrier()
  278. +
  279. +/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */
  280. +#define __must_be_array(a) 0
  281. +
  282. +#endif
  283. +
  284. +#ifndef __HAVE_BUILTIN_BSWAP16__
  285. +/* icc has this, but it's called _bswap16 */
  286. +#define __HAVE_BUILTIN_BSWAP16__
  287. +#define __builtin_bswap16 _bswap16
  288. +#endif
  289. +
  290. --- a/include/linux/compiler.h
  291. +++ b/include/linux/compiler.h
  292. @@ -5,16 +5,23 @@
  293. #ifdef __CHECKER__
  294. # define __user __attribute__((noderef, address_space(1)))
  295. -# define __kernel /* default address space */
  296. +# define __kernel __attribute__((address_space(0)))
  297. # define __safe __attribute__((safe))
  298. # define __force __attribute__((force))
  299. # define __nocast __attribute__((nocast))
  300. # define __iomem __attribute__((noderef, address_space(2)))
  301. +# define __must_hold(x) __attribute__((context(x,1,1)))
  302. # define __acquires(x) __attribute__((context(x,0,1)))
  303. # define __releases(x) __attribute__((context(x,1,0)))
  304. # define __acquire(x) __context__(x,1)
  305. # define __release(x) __context__(x,-1)
  306. # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
  307. +# define __percpu __attribute__((noderef, address_space(3)))
  308. +#ifdef CONFIG_SPARSE_RCU_POINTER
  309. +# define __rcu __attribute__((noderef, address_space(4)))
  310. +#else
  311. +# define __rcu
  312. +#endif
  313. extern void __chk_user_ptr(const volatile void __user *);
  314. extern void __chk_io_ptr(const volatile void __iomem *);
  315. #else
  316. @@ -27,13 +34,20 @@ extern void __chk_io_ptr(const volatile
  317. # define __chk_user_ptr(x) (void)0
  318. # define __chk_io_ptr(x) (void)0
  319. # define __builtin_warning(x, y...) (1)
  320. +# define __must_hold(x)
  321. # define __acquires(x)
  322. # define __releases(x)
  323. # define __acquire(x) (void)0
  324. # define __release(x) (void)0
  325. # define __cond_lock(x,c) (c)
  326. +# define __percpu
  327. +# define __rcu
  328. #endif
  329. +/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
  330. +#define ___PASTE(a,b) a##b
  331. +#define __PASTE(a,b) ___PASTE(a,b)
  332. +
  333. #ifdef __KERNEL__
  334. #ifdef __GNUC__
  335. @@ -49,6 +63,13 @@ extern void __chk_io_ptr(const volatile
  336. # include <linux/compiler-intel.h>
  337. #endif
  338. +/* Clang compiler defines __GNUC__. So we will overwrite implementations
  339. + * coming from above header files here
  340. + */
  341. +#ifdef __clang__
  342. +#include <linux/compiler-clang.h>
  343. +#endif
  344. +
  345. /*
  346. * Generic compiler-dependent macros required for kernel
  347. * build go below this comment. Actual compiler/compiler version
  348. @@ -156,6 +177,15 @@ void ftrace_likely_update(struct ftrace_
  349. (typeof(ptr)) (__ptr + (off)); })
  350. #endif
  351. +#ifndef OPTIMIZER_HIDE_VAR
  352. +#define OPTIMIZER_HIDE_VAR(var) barrier()
  353. +#endif
  354. +
  355. +/* Not-quite-unique ID. */
  356. +#ifndef __UNIQUE_ID
  357. +# define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
  358. +#endif
  359. +
  360. #endif /* __KERNEL__ */
  361. #endif /* __ASSEMBLY__ */
  362. @@ -228,7 +258,7 @@ void ftrace_likely_update(struct ftrace_
  363. /*
  364. * Rather then using noinline to prevent stack consumption, use
  365. - * noinline_for_stack instead. For documentaiton reasons.
  366. + * noinline_for_stack instead. For documentation reasons.
  367. */
  368. #define noinline_for_stack noinline
  369. @@ -270,11 +300,20 @@ void ftrace_likely_update(struct ftrace_
  370. # define __section(S) __attribute__ ((__section__(#S)))
  371. #endif
  372. +#ifndef __visible
  373. +#define __visible
  374. +#endif
  375. +
  376. /* Are two types/vars the same type (ignoring qualifiers)? */
  377. #ifndef __same_type
  378. # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
  379. #endif
  380. +/* Is this type a native word size -- useful for atomic operations */
  381. +#ifndef __native_word
  382. +# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
  383. +#endif
  384. +
  385. /* Compile time object size, -1 for unknown */
  386. #ifndef __compiletime_object_size
  387. # define __compiletime_object_size(obj) -1
  388. @@ -284,7 +323,48 @@ void ftrace_likely_update(struct ftrace_
  389. #endif
  390. #ifndef __compiletime_error
  391. # define __compiletime_error(message)
  392. +/*
  393. + * Sparse complains of variable sized arrays due to the temporary variable in
  394. + * __compiletime_assert. Unfortunately we can't just expand it out to make
  395. + * sparse see a constant array size without breaking compiletime_assert on old
  396. + * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
  397. + */
  398. +# ifndef __CHECKER__
  399. +# define __compiletime_error_fallback(condition) \
  400. + do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
  401. +# endif
  402. #endif
  403. +#ifndef __compiletime_error_fallback
  404. +# define __compiletime_error_fallback(condition) do { } while (0)
  405. +#endif
  406. +
  407. +#define __compiletime_assert(condition, msg, prefix, suffix) \
  408. + do { \
  409. + bool __cond = !(condition); \
  410. + extern void prefix ## suffix(void) __compiletime_error(msg); \
  411. + if (__cond) \
  412. + prefix ## suffix(); \
  413. + __compiletime_error_fallback(__cond); \
  414. + } while (0)
  415. +
  416. +#define _compiletime_assert(condition, msg, prefix, suffix) \
  417. + __compiletime_assert(condition, msg, prefix, suffix)
  418. +
  419. +/**
  420. + * compiletime_assert - break build and emit msg if condition is false
  421. + * @condition: a compile-time constant condition to check
  422. + * @msg: a message to emit if condition is false
  423. + *
  424. + * In tradition of POSIX assert, this macro will break the build if the
  425. + * supplied condition is *false*, emitting the supplied error message if the
  426. + * compiler has support to do so.
  427. + */
  428. +#define compiletime_assert(condition, msg) \
  429. + _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
  430. +
  431. +#define compiletime_assert_atomic_type(t) \
  432. + compiletime_assert(__native_word(t), \
  433. + "Need native word sized stores/loads for atomicity.")
  434. /*
  435. * Prevent the compiler from merging or refetching accesses. The compiler
  436. @@ -300,4 +380,12 @@ void ftrace_likely_update(struct ftrace_
  437. */
  438. #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
  439. +/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
  440. +#ifdef CONFIG_KPROBES
  441. +# define __kprobes __attribute__((__section__(".kprobes.text")))
  442. +# define nokprobe_inline __always_inline
  443. +#else
  444. +# define __kprobes
  445. +# define nokprobe_inline inline
  446. +#endif
  447. #endif /* __LINUX_COMPILER_H */