GNU Linux-libre 5.10.217-gnu1
[releases.git] / include / linux / compiler-clang.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_COMPILER_TYPES_H
3 #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
4 #endif
5
6 #define CLANG_VERSION (__clang_major__ * 10000  \
7                      + __clang_minor__ * 100    \
8                      + __clang_patchlevel__)
9
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 */
17
18 /* same as gcc, this was present in clang-2.6 so we can assume it works
19  * with any version that can compile the kernel
20  */
21 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
22
23 /* all clang versions usable with the kernel support KASAN ABI version 5 */
24 #define KASAN_ABI_VERSION 5
25
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  */
31
32 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
33 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
34 #define __SANITIZE_ADDRESS__
35 #define __no_sanitize_address \
36                 __attribute__((no_sanitize("address", "hwaddress")))
37 #else
38 #define __no_sanitize_address
39 #endif
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
64 /*
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
77  * of the builtin overflow checkers. Fortunately, clang implements
78  * __has_builtin allowing us to avoid awkward version
79  * checks. Unfortunately, we don't know which version of gcc clang
80  * pretends to be, so the macro may or may not be defined.
81  */
82 #if __has_builtin(__builtin_mul_overflow) && \
83     __has_builtin(__builtin_add_overflow) && \
84     __has_builtin(__builtin_sub_overflow)
85 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
86 #endif
87
88 #if __has_feature(shadow_call_stack)
89 # define __noscs        __attribute__((__no_sanitize__("shadow-call-stack")))
90 #endif