at v5.8-rc2 10 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __LINUX_COMPILER_TYPES_H 3#define __LINUX_COMPILER_TYPES_H 4 5#ifndef __ASSEMBLY__ 6 7#ifdef __CHECKER__ 8# define __kernel __attribute__((address_space(0))) 9# define __user __attribute__((noderef, address_space(__user))) 10# define __safe __attribute__((safe)) 11# define __force __attribute__((force)) 12# define __nocast __attribute__((nocast)) 13# define __iomem __attribute__((noderef, address_space(__iomem))) 14# define __must_hold(x) __attribute__((context(x,1,1))) 15# define __acquires(x) __attribute__((context(x,0,1))) 16# define __releases(x) __attribute__((context(x,1,0))) 17# define __acquire(x) __context__(x,1) 18# define __release(x) __context__(x,-1) 19# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) 20# define __percpu __attribute__((noderef, address_space(__percpu))) 21# define __rcu __attribute__((noderef, address_space(__rcu))) 22# define __private __attribute__((noderef)) 23extern void __chk_user_ptr(const volatile void __user *); 24extern void __chk_io_ptr(const volatile void __iomem *); 25# define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member)) 26#else /* __CHECKER__ */ 27# ifdef STRUCTLEAK_PLUGIN 28# define __user __attribute__((user)) 29# else 30# define __user 31# endif 32# define __kernel 33# define __safe 34# define __force 35# define __nocast 36# define __iomem 37# define __chk_user_ptr(x) (void)0 38# define __chk_io_ptr(x) (void)0 39# define __builtin_warning(x, y...) (1) 40# define __must_hold(x) 41# define __acquires(x) 42# define __releases(x) 43# define __acquire(x) (void)0 44# define __release(x) (void)0 45# define __cond_lock(x,c) (c) 46# define __percpu 47# define __rcu 48# define __private 49# define ACCESS_PRIVATE(p, member) ((p)->member) 50#endif /* __CHECKER__ */ 51 52/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ 53#define ___PASTE(a,b) a##b 54#define __PASTE(a,b) ___PASTE(a,b) 55 56#ifdef __KERNEL__ 57 58/* Attributes */ 59#include <linux/compiler_attributes.h> 60 61/* Compiler specific macros. */ 62#ifdef __clang__ 63#include <linux/compiler-clang.h> 64#elif defined(__INTEL_COMPILER) 65#include <linux/compiler-intel.h> 66#elif defined(__GNUC__) 67/* The above compilers also define __GNUC__, so order is important here. */ 68#include <linux/compiler-gcc.h> 69#else 70#error "Unknown compiler" 71#endif 72 73/* 74 * Some architectures need to provide custom definitions of macros provided 75 * by linux/compiler-*.h, and can do so using asm/compiler.h. We include that 76 * conditionally rather than using an asm-generic wrapper in order to avoid 77 * build failures if any C compilation, which will include this file via an 78 * -include argument in c_flags, occurs prior to the asm-generic wrappers being 79 * generated. 80 */ 81#ifdef CONFIG_HAVE_ARCH_COMPILER_H 82#include <asm/compiler.h> 83#endif 84 85struct ftrace_branch_data { 86 const char *func; 87 const char *file; 88 unsigned line; 89 union { 90 struct { 91 unsigned long correct; 92 unsigned long incorrect; 93 }; 94 struct { 95 unsigned long miss; 96 unsigned long hit; 97 }; 98 unsigned long miss_hit[2]; 99 }; 100}; 101 102struct ftrace_likely_data { 103 struct ftrace_branch_data data; 104 unsigned long constant; 105}; 106 107#ifdef CONFIG_ENABLE_MUST_CHECK 108#define __must_check __attribute__((__warn_unused_result__)) 109#else 110#define __must_check 111#endif 112 113#if defined(CC_USING_HOTPATCH) 114#define notrace __attribute__((hotpatch(0, 0))) 115#elif defined(CC_USING_PATCHABLE_FUNCTION_ENTRY) 116#define notrace __attribute__((patchable_function_entry(0, 0))) 117#else 118#define notrace __attribute__((__no_instrument_function__)) 119#endif 120 121/* Section for code which can't be instrumented at all */ 122#define noinstr \ 123 noinline notrace __attribute((__section__(".noinstr.text"))) 124 125/* 126 * it doesn't make sense on ARM (currently the only user of __naked) 127 * to trace naked functions because then mcount is called without 128 * stack and frame pointer being set up and there is no chance to 129 * restore the lr register to the value before mcount was called. 130 */ 131#define __naked __attribute__((__naked__)) notrace 132 133#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) 134 135/* 136 * Prefer gnu_inline, so that extern inline functions do not emit an 137 * externally visible function. This makes extern inline behave as per gnu89 138 * semantics rather than c99. This prevents multiple symbol definition errors 139 * of extern inline functions at link time. 140 * A lot of inline functions can cause havoc with function tracing. 141 */ 142#define inline inline __gnu_inline __inline_maybe_unused notrace 143 144/* 145 * gcc provides both __inline__ and __inline as alternate spellings of 146 * the inline keyword, though the latter is undocumented. New kernel 147 * code should only use the inline spelling, but some existing code 148 * uses __inline__. Since we #define inline above, to ensure 149 * __inline__ has the same semantics, we need this #define. 150 * 151 * However, the spelling __inline is strictly reserved for referring 152 * to the bare keyword. 153 */ 154#define __inline__ inline 155 156/* 157 * GCC does not warn about unused static inline functions for -Wunused-function. 158 * Suppress the warning in clang as well by using __maybe_unused, but enable it 159 * for W=1 build. This will allow clang to find unused functions. Remove the 160 * __inline_maybe_unused entirely after fixing most of -Wunused-function warnings. 161 */ 162#ifdef KBUILD_EXTRA_WARN1 163#define __inline_maybe_unused 164#else 165#define __inline_maybe_unused __maybe_unused 166#endif 167 168/* 169 * Rather then using noinline to prevent stack consumption, use 170 * noinline_for_stack instead. For documentation reasons. 171 */ 172#define noinline_for_stack noinline 173 174/* 175 * Sanitizer helper attributes: Because using __always_inline and 176 * __no_sanitize_* conflict, provide helper attributes that will either expand 177 * to __no_sanitize_* in compilation units where instrumentation is enabled 178 * (__SANITIZE_*__), or __always_inline in compilation units without 179 * instrumentation (__SANITIZE_*__ undefined). 180 */ 181#ifdef __SANITIZE_ADDRESS__ 182/* 183 * We can't declare function 'inline' because __no_sanitize_address conflicts 184 * with inlining. Attempt to inline it may cause a build failure. 185 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 186 * '__maybe_unused' allows us to avoid defined-but-not-used warnings. 187 */ 188# define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused 189# define __no_sanitize_or_inline __no_kasan_or_inline 190#else 191# define __no_kasan_or_inline __always_inline 192#endif 193 194#define __no_kcsan __no_sanitize_thread 195#ifdef __SANITIZE_THREAD__ 196# define __no_kcsan_or_inline __no_kcsan notrace __maybe_unused 197# define __no_sanitize_or_inline __no_kcsan_or_inline 198#else 199# define __no_kcsan_or_inline __always_inline 200#endif 201 202#ifndef __no_sanitize_or_inline 203#define __no_sanitize_or_inline __always_inline 204#endif 205 206#endif /* __KERNEL__ */ 207 208#endif /* __ASSEMBLY__ */ 209 210/* 211 * The below symbols may be defined for one or more, but not ALL, of the above 212 * compilers. We don't consider that to be an error, so set them to nothing. 213 * For example, some of them are for compiler specific plugins. 214 */ 215#ifndef __latent_entropy 216# define __latent_entropy 217#endif 218 219#ifndef __randomize_layout 220# define __randomize_layout __designated_init 221#endif 222 223#ifndef __no_randomize_layout 224# define __no_randomize_layout 225#endif 226 227#ifndef randomized_struct_fields_start 228# define randomized_struct_fields_start 229# define randomized_struct_fields_end 230#endif 231 232#ifndef __noscs 233# define __noscs 234#endif 235 236#ifndef asm_volatile_goto 237#define asm_volatile_goto(x...) asm goto(x) 238#endif 239 240#ifdef CONFIG_CC_HAS_ASM_INLINE 241#define asm_inline asm __inline 242#else 243#define asm_inline asm 244#endif 245 246#ifndef __no_fgcse 247# define __no_fgcse 248#endif 249 250/* Are two types/vars the same type (ignoring qualifiers)? */ 251#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 252 253/* 254 * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving 255 * non-scalar types unchanged. 256 */ 257#if (defined(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 40900) || defined(__CHECKER__) 258/* 259 * We build this out of a couple of helper macros in a vain attempt to 260 * help you keep your lunch down while reading it. 261 */ 262#define __pick_scalar_type(x, type, otherwise) \ 263 __builtin_choose_expr(__same_type(x, type), (type)0, otherwise) 264 265/* 266 * 'char' is not type-compatible with either 'signed char' or 'unsigned char', 267 * so we include the naked type here as well as the signed/unsigned variants. 268 */ 269#define __pick_integer_type(x, type, otherwise) \ 270 __pick_scalar_type(x, type, \ 271 __pick_scalar_type(x, unsigned type, \ 272 __pick_scalar_type(x, signed type, otherwise))) 273 274#define __unqual_scalar_typeof(x) typeof( \ 275 __pick_integer_type(x, char, \ 276 __pick_integer_type(x, short, \ 277 __pick_integer_type(x, int, \ 278 __pick_integer_type(x, long, \ 279 __pick_integer_type(x, long long, x)))))) 280#else 281/* 282 * If supported, prefer C11 _Generic for better compile-times. As above, 'char' 283 * is not type-compatible with 'signed char', and we define a separate case. 284 */ 285#define __scalar_type_to_expr_cases(type) \ 286 unsigned type: (unsigned type)0, \ 287 signed type: (signed type)0 288 289#define __unqual_scalar_typeof(x) typeof( \ 290 _Generic((x), \ 291 char: (char)0, \ 292 __scalar_type_to_expr_cases(char), \ 293 __scalar_type_to_expr_cases(short), \ 294 __scalar_type_to_expr_cases(int), \ 295 __scalar_type_to_expr_cases(long), \ 296 __scalar_type_to_expr_cases(long long), \ 297 default: (x))) 298#endif 299 300/* Is this type a native word size -- useful for atomic operations */ 301#define __native_word(t) \ 302 (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ 303 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) 304 305/* Helpers for emitting diagnostics in pragmas. */ 306#ifndef __diag 307#define __diag(string) 308#endif 309 310#ifndef __diag_GCC 311#define __diag_GCC(version, severity, string) 312#endif 313 314#define __diag_push() __diag(push) 315#define __diag_pop() __diag(pop) 316 317#define __diag_ignore(compiler, version, option, comment) \ 318 __diag_ ## compiler(version, ignore, option) 319#define __diag_warn(compiler, version, option, comment) \ 320 __diag_ ## compiler(version, warn, option) 321#define __diag_error(compiler, version, option, comment) \ 322 __diag_ ## compiler(version, error, option) 323 324#endif /* __LINUX_COMPILER_TYPES_H */