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