hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/include/linux/compiler-clang.h
....@@ -3,9 +3,17 @@
33 #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
44 #endif
55
6
-/* Compiler specific definitions for Clang compiler */
6
+#define CLANG_VERSION (__clang_major__ * 10000 \
7
+ + __clang_minor__ * 100 \
8
+ + __clang_patchlevel__)
79
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 */
917
1018 /* same as gcc, this was present in clang-2.6 so we can assume it works
1119 * with any version that can compile the kernel
....@@ -15,11 +23,14 @@
1523 /* all clang versions usable with the kernel support KASAN ABI version 5 */
1624 #define KASAN_ABI_VERSION 5
1725
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
+ */
2031
2132 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
22
-/* emulate gcc's __SANITIZE_ADDRESS__ flag */
33
+/* Emulate GCC's __SANITIZE_ADDRESS__ flag */
2334 #define __SANITIZE_ADDRESS__
2435 #define __no_sanitize_address \
2536 __attribute__((no_sanitize("address", "hwaddress")))
....@@ -27,8 +38,42 @@
2738 #define __no_sanitize_address
2839 #endif
2940
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
+
3064 /*
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
3277 * of the builtin overflow checkers. Fortunately, clang implements
3378 * __has_builtin allowing us to avoid awkward version
3479 * checks. Unfortunately, we don't know which version of gcc clang
....@@ -40,25 +85,9 @@
4085 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
4186 #endif
4287
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
-
6088 #if __has_feature(shadow_call_stack)
6189 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
62
-#else
63
-# define __noscs
6490 #endif
91
+
92
+#define __nocfi __attribute__((__no_sanitize__("cfi")))
93
+#define __cficanonical __attribute__((__cfi_canonical_jump_table__))