compiler_types.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_COMPILER_TYPES_H
  3. #define __LINUX_COMPILER_TYPES_H
  4. #ifndef __ASSEMBLY__
  5. #ifdef __CHECKER__
  6. # define __user __attribute__((noderef, address_space(1)))
  7. # define __kernel __attribute__((address_space(0)))
  8. # define __safe __attribute__((safe))
  9. # define __force __attribute__((force))
  10. # define __nocast __attribute__((nocast))
  11. # define __iomem __attribute__((noderef, address_space(2)))
  12. # define __must_hold(x) __attribute__((context(x,1,1)))
  13. # define __acquires(x) __attribute__((context(x,0,1)))
  14. # define __releases(x) __attribute__((context(x,1,0)))
  15. # define __acquire(x) __context__(x,1)
  16. # define __release(x) __context__(x,-1)
  17. # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
  18. # define __percpu __attribute__((noderef, address_space(3)))
  19. # define __rcu __attribute__((noderef, address_space(4)))
  20. # define __private __attribute__((noderef))
  21. extern void __chk_user_ptr(const volatile void __user *);
  22. extern void __chk_io_ptr(const volatile void __iomem *);
  23. # define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
  24. #else /* __CHECKER__ */
  25. # ifdef STRUCTLEAK_PLUGIN
  26. # define __user __attribute__((user))
  27. # else
  28. # define __user
  29. # endif
  30. # define __kernel
  31. # define __safe
  32. # define __force
  33. # define __nocast
  34. # define __iomem
  35. # define __chk_user_ptr(x) (void)0
  36. # define __chk_io_ptr(x) (void)0
  37. # define __builtin_warning(x, y...) (1)
  38. # define __must_hold(x)
  39. # define __acquires(x)
  40. # define __releases(x)
  41. # define __acquire(x) (void)0
  42. # define __release(x) (void)0
  43. # define __cond_lock(x,c) (c)
  44. # define __percpu
  45. # define __rcu
  46. # define __private
  47. # define ACCESS_PRIVATE(p, member) ((p)->member)
  48. #endif /* __CHECKER__ */
  49. /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
  50. #define ___PASTE(a,b) a##b
  51. #define __PASTE(a,b) ___PASTE(a,b)
  52. #ifdef __KERNEL__
  53. /* Attributes */
  54. #include <linux/compiler_attributes.h>
  55. /* Compiler specific macros. */
  56. #ifdef __clang__
  57. #include <linux/compiler-clang.h>
  58. #elif defined(__INTEL_COMPILER)
  59. #include <linux/compiler-intel.h>
  60. #elif defined(__GNUC__)
  61. /* The above compilers also define __GNUC__, so order is important here. */
  62. #include <linux/compiler-gcc.h>
  63. #else
  64. #error "Unknown compiler"
  65. #endif
  66. /*
  67. * Some architectures need to provide custom definitions of macros provided
  68. * by linux/compiler-*.h, and can do so using asm/compiler.h. We include that
  69. * conditionally rather than using an asm-generic wrapper in order to avoid
  70. * build failures if any C compilation, which will include this file via an
  71. * -include argument in c_flags, occurs prior to the asm-generic wrappers being
  72. * generated.
  73. */
  74. #ifdef CONFIG_HAVE_ARCH_COMPILER_H
  75. #include <asm/compiler.h>
  76. #endif
  77. struct ftrace_branch_data {
  78. const char *func;
  79. const char *file;
  80. unsigned line;
  81. union {
  82. struct {
  83. unsigned long correct;
  84. unsigned long incorrect;
  85. };
  86. struct {
  87. unsigned long miss;
  88. unsigned long hit;
  89. };
  90. unsigned long miss_hit[2];
  91. };
  92. };
  93. struct ftrace_likely_data {
  94. struct ftrace_branch_data data;
  95. unsigned long constant;
  96. };
  97. #ifdef CONFIG_ENABLE_MUST_CHECK
  98. #define __must_check __attribute__((__warn_unused_result__))
  99. #else
  100. #define __must_check
  101. #endif
  102. #if defined(CC_USING_HOTPATCH)
  103. #define notrace __attribute__((hotpatch(0, 0)))
  104. #elif defined(CC_USING_PATCHABLE_FUNCTION_ENTRY)
  105. #define notrace __attribute__((patchable_function_entry(0, 0)))
  106. #else
  107. #define notrace __attribute__((__no_instrument_function__))
  108. #endif
  109. /*
  110. * it doesn't make sense on ARM (currently the only user of __naked)
  111. * to trace naked functions because then mcount is called without
  112. * stack and frame pointer being set up and there is no chance to
  113. * restore the lr register to the value before mcount was called.
  114. */
  115. #define __naked __attribute__((__naked__)) notrace
  116. #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
  117. /*
  118. * Force always-inline if the user requests it so via the .config.
  119. * Prefer gnu_inline, so that extern inline functions do not emit an
  120. * externally visible function. This makes extern inline behave as per gnu89
  121. * semantics rather than c99. This prevents multiple symbol definition errors
  122. * of extern inline functions at link time.
  123. * A lot of inline functions can cause havoc with function tracing.
  124. * Do not use __always_inline here, since currently it expands to inline again
  125. * (which would break users of __always_inline).
  126. */
  127. #if !CONFIG_IS_ENABLED(OPTIMIZE_INLINING)
  128. #define inline inline __attribute__((__always_inline__)) __gnu_inline \
  129. __inline_maybe_unused notrace
  130. #else
  131. #define inline inline __gnu_inline \
  132. __inline_maybe_unused notrace
  133. #endif
  134. /*
  135. * gcc provides both __inline__ and __inline as alternate spellings of
  136. * the inline keyword, though the latter is undocumented. New kernel
  137. * code should only use the inline spelling, but some existing code
  138. * uses __inline__. Since we #define inline above, to ensure
  139. * __inline__ has the same semantics, we need this #define.
  140. *
  141. * However, the spelling __inline is strictly reserved for referring
  142. * to the bare keyword.
  143. */
  144. #define __inline__ inline
  145. /*
  146. * GCC does not warn about unused static inline functions for -Wunused-function.
  147. * Suppress the warning in clang as well by using __maybe_unused, but enable it
  148. * for W=1 build. This will allow clang to find unused functions. Remove the
  149. * __inline_maybe_unused entirely after fixing most of -Wunused-function warnings.
  150. */
  151. #ifdef KBUILD_EXTRA_WARN1
  152. #define __inline_maybe_unused
  153. #else
  154. #define __inline_maybe_unused __maybe_unused
  155. #endif
  156. /*
  157. * Rather then using noinline to prevent stack consumption, use
  158. * noinline_for_stack instead. For documentation reasons.
  159. */
  160. #define noinline_for_stack noinline
  161. #endif /* __KERNEL__ */
  162. #endif /* __ASSEMBLY__ */
  163. /*
  164. * The below symbols may be defined for one or more, but not ALL, of the above
  165. * compilers. We don't consider that to be an error, so set them to nothing.
  166. * For example, some of them are for compiler specific plugins.
  167. */
  168. #ifndef __latent_entropy
  169. # define __latent_entropy
  170. #endif
  171. #ifndef __randomize_layout
  172. # define __randomize_layout __designated_init
  173. #endif
  174. #ifndef __no_randomize_layout
  175. # define __no_randomize_layout
  176. #endif
  177. #ifndef randomized_struct_fields_start
  178. # define randomized_struct_fields_start
  179. # define randomized_struct_fields_end
  180. #endif
  181. #ifndef asm_volatile_goto
  182. #define asm_volatile_goto(x...) asm goto(x)
  183. #endif
  184. #ifdef CONFIG_CC_HAS_ASM_INLINE
  185. #define asm_inline asm __inline
  186. #else
  187. #define asm_inline asm
  188. #endif
  189. #ifndef __no_fgcse
  190. # define __no_fgcse
  191. #endif
  192. /* Are two types/vars the same type (ignoring qualifiers)? */
  193. #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
  194. /* Is this type a native word size -- useful for atomic operations */
  195. #define __native_word(t) \
  196. (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
  197. sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
  198. /* Helpers for emitting diagnostics in pragmas. */
  199. #ifndef __diag
  200. #define __diag(string)
  201. #endif
  202. #ifndef __diag_GCC
  203. #define __diag_GCC(version, severity, string)
  204. #endif
  205. #define __diag_push() __diag(push)
  206. #define __diag_pop() __diag(pop)
  207. #define __diag_ignore(compiler, version, option, comment) \
  208. __diag_ ## compiler(version, ignore, option)
  209. #define __diag_warn(compiler, version, option, comment) \
  210. __diag_ ## compiler(version, warn, option)
  211. #define __diag_error(compiler, version, option, comment) \
  212. __diag_ ## compiler(version, error, option)
  213. #endif /* __LINUX_COMPILER_TYPES_H */