|
23 | 23 | #define KASAN_ABI_VERSION 5
|
24 | 24 |
|
25 | 25 | /*
|
| 26 | + * Clang 22 added preprocessor macros to match GCC, in hopes of eventually |
| 27 | + * dropping __has_feature support for sanitizers: |
| 28 | + * https://github.com/llvm/llvm-project/commit/568c23bbd3303518c5056d7f03444dae4fdc8a9c |
| 29 | + * Create these macros for older versions of clang so that it is easy to clean |
| 30 | + * up once the minimum supported version of LLVM for building the kernel always |
| 31 | + * creates these macros. |
| 32 | + * |
26 | 33 | * Note: Checking __has_feature(*_sanitizer) is only true if the feature is
|
27 | 34 | * enabled. Therefore it is not required to additionally check defined(CONFIG_*)
|
28 | 35 | * to avoid adding redundant attributes in other configurations.
|
29 | 36 | */
|
| 37 | +#if __has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__) |
| 38 | +#define __SANITIZE_ADDRESS__ |
| 39 | +#endif |
| 40 | +#if __has_feature(hwaddress_sanitizer) && !defined(__SANITIZE_HWADDRESS__) |
| 41 | +#define __SANITIZE_HWADDRESS__ |
| 42 | +#endif |
| 43 | +#if __has_feature(thread_sanitizer) && !defined(__SANITIZE_THREAD__) |
| 44 | +#define __SANITIZE_THREAD__ |
| 45 | +#endif |
30 | 46 |
|
31 |
| -#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) |
32 |
| -/* Emulate GCC's __SANITIZE_ADDRESS__ flag */ |
| 47 | +/* |
| 48 | + * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel. |
| 49 | + */ |
| 50 | +#ifdef __SANITIZE_HWADDRESS__ |
33 | 51 | #define __SANITIZE_ADDRESS__
|
| 52 | +#endif |
| 53 | + |
| 54 | +#ifdef __SANITIZE_ADDRESS__ |
34 | 55 | #define __no_sanitize_address \
|
35 | 56 | __attribute__((no_sanitize("address", "hwaddress")))
|
36 | 57 | #else
|
37 | 58 | #define __no_sanitize_address
|
38 | 59 | #endif
|
39 | 60 |
|
40 |
| -#if __has_feature(thread_sanitizer) |
41 |
| -/* emulate gcc's __SANITIZE_THREAD__ flag */ |
42 |
| -#define __SANITIZE_THREAD__ |
| 61 | +#ifdef __SANITIZE_THREAD__ |
43 | 62 | #define __no_sanitize_thread \
|
44 | 63 | __attribute__((no_sanitize("thread")))
|
45 | 64 | #else
|
|
0 commit comments