.. | .. |
---|
3 | 3 | #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead." |
---|
4 | 4 | #endif |
---|
5 | 5 | |
---|
6 | | -/* Compiler specific definitions for Clang compiler */ |
---|
| 6 | +#define CLANG_VERSION (__clang_major__ * 10000 \ |
---|
| 7 | + + __clang_minor__ * 100 \ |
---|
| 8 | + + __clang_patchlevel__) |
---|
7 | 9 | |
---|
8 | | -#define uninitialized_var(x) x = *(&(x)) |
---|
| 10 | +#if CLANG_VERSION < 100001 |
---|
| 11 | +#ifndef __BPF_TRACING__ |
---|
| 12 | +# error Sorry, your version of Clang is too old - please use 10.0.1 or newer. |
---|
| 13 | +#endif |
---|
| 14 | +#endif |
---|
| 15 | + |
---|
| 16 | +/* Compiler specific definitions for Clang compiler */ |
---|
9 | 17 | |
---|
10 | 18 | /* same as gcc, this was present in clang-2.6 so we can assume it works |
---|
11 | 19 | * with any version that can compile the kernel |
---|
.. | .. |
---|
15 | 23 | /* all clang versions usable with the kernel support KASAN ABI version 5 */ |
---|
16 | 24 | #define KASAN_ABI_VERSION 5 |
---|
17 | 25 | |
---|
18 | | -/* __no_sanitize_address has been already defined compiler-gcc.h */ |
---|
19 | | -#undef __no_sanitize_address |
---|
| 26 | +/* |
---|
| 27 | + * Note: Checking __has_feature(*_sanitizer) is only true if the feature is |
---|
| 28 | + * enabled. Therefore it is not required to additionally check defined(CONFIG_*) |
---|
| 29 | + * to avoid adding redundant attributes in other configurations. |
---|
| 30 | + */ |
---|
20 | 31 | |
---|
21 | 32 | #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) |
---|
22 | | -/* emulate gcc's __SANITIZE_ADDRESS__ flag */ |
---|
| 33 | +/* Emulate GCC's __SANITIZE_ADDRESS__ flag */ |
---|
23 | 34 | #define __SANITIZE_ADDRESS__ |
---|
24 | 35 | #define __no_sanitize_address \ |
---|
25 | 36 | __attribute__((no_sanitize("address", "hwaddress"))) |
---|
.. | .. |
---|
27 | 38 | #define __no_sanitize_address |
---|
28 | 39 | #endif |
---|
29 | 40 | |
---|
| 41 | +#if __has_feature(thread_sanitizer) |
---|
| 42 | +/* emulate gcc's __SANITIZE_THREAD__ flag */ |
---|
| 43 | +#define __SANITIZE_THREAD__ |
---|
| 44 | +#define __no_sanitize_thread \ |
---|
| 45 | + __attribute__((no_sanitize("thread"))) |
---|
| 46 | +#else |
---|
| 47 | +#define __no_sanitize_thread |
---|
| 48 | +#endif |
---|
| 49 | + |
---|
| 50 | +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) |
---|
| 51 | +#define __HAVE_BUILTIN_BSWAP32__ |
---|
| 52 | +#define __HAVE_BUILTIN_BSWAP64__ |
---|
| 53 | +#define __HAVE_BUILTIN_BSWAP16__ |
---|
| 54 | +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ |
---|
| 55 | + |
---|
| 56 | +#if __has_feature(undefined_behavior_sanitizer) |
---|
| 57 | +/* GCC does not have __SANITIZE_UNDEFINED__ */ |
---|
| 58 | +#define __no_sanitize_undefined \ |
---|
| 59 | + __attribute__((no_sanitize("undefined"))) |
---|
| 60 | +#else |
---|
| 61 | +#define __no_sanitize_undefined |
---|
| 62 | +#endif |
---|
| 63 | + |
---|
30 | 64 | /* |
---|
31 | | - * Not all versions of clang implement the the type-generic versions |
---|
| 65 | + * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together |
---|
| 66 | + * with no_sanitize("coverage"). Prior versions of Clang support coverage |
---|
| 67 | + * instrumentation, but cannot be queried for support by the preprocessor. |
---|
| 68 | + */ |
---|
| 69 | +#if __has_feature(coverage_sanitizer) |
---|
| 70 | +#define __no_sanitize_coverage __attribute__((no_sanitize("coverage"))) |
---|
| 71 | +#else |
---|
| 72 | +#define __no_sanitize_coverage |
---|
| 73 | +#endif |
---|
| 74 | + |
---|
| 75 | +/* |
---|
| 76 | + * Not all versions of clang implement the type-generic versions |
---|
32 | 77 | * of the builtin overflow checkers. Fortunately, clang implements |
---|
33 | 78 | * __has_builtin allowing us to avoid awkward version |
---|
34 | 79 | * checks. Unfortunately, we don't know which version of gcc clang |
---|
.. | .. |
---|
40 | 85 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 |
---|
41 | 86 | #endif |
---|
42 | 87 | |
---|
43 | | -/* The following are for compatibility with GCC, from compiler-gcc.h, |
---|
44 | | - * and may be redefined here because they should not be shared with other |
---|
45 | | - * compilers, like ICC. |
---|
46 | | - */ |
---|
47 | | -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) |
---|
48 | | -#define __assume_aligned(a, ...) \ |
---|
49 | | - __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) |
---|
50 | | - |
---|
51 | | -#ifdef CONFIG_LTO_CLANG |
---|
52 | | -#ifdef CONFIG_FTRACE_MCOUNT_RECORD |
---|
53 | | -#define __norecordmcount \ |
---|
54 | | - __attribute__((__section__(".text..ftrace"))) |
---|
55 | | -#endif |
---|
56 | | - |
---|
57 | | -#define __nocfi __attribute__((no_sanitize("cfi"))) |
---|
58 | | -#endif |
---|
59 | | - |
---|
60 | 88 | #if __has_feature(shadow_call_stack) |
---|
61 | 89 | # define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) |
---|
62 | | -#else |
---|
63 | | -# define __noscs |
---|
64 | 90 | #endif |
---|
| 91 | + |
---|
| 92 | +#define __nocfi __attribute__((__no_sanitize__("cfi"))) |
---|
| 93 | +#define __cficanonical __attribute__((__cfi_canonical_jump_table__)) |
---|