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 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) 27 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */ 28 #define __SANITIZE_ADDRESS__ 29 #define __no_sanitize_address \ 30 __attribute__((no_sanitize("address", "hwaddress"))) 31 #else 32 #define __no_sanitize_address 33 #endif 34 35 #if __has_feature(thread_sanitizer) 36 /* emulate gcc's __SANITIZE_THREAD__ flag */ 37 #define __SANITIZE_THREAD__ 38 #define __no_sanitize_thread \ 39 __attribute__((no_sanitize("thread"))) 40 #else 41 #define __no_sanitize_thread 42 #endif 43 44 #if __has_feature(undefined_behavior_sanitizer) 45 /* GCC does not have __SANITIZE_UNDEFINED__ */ 46 #define __no_sanitize_undefined \ 47 __attribute__((no_sanitize("undefined"))) 48 #else 49 #define __no_sanitize_undefined 50 #endif 51 52 /* 53 * Not all versions of clang implement the type-generic versions 54 * of the builtin overflow checkers. Fortunately, clang implements 55 * __has_builtin allowing us to avoid awkward version 56 * checks. Unfortunately, we don't know which version of gcc clang 57 * pretends to be, so the macro may or may not be defined. 58 */ 59 #if __has_builtin(__builtin_mul_overflow) && \ 60 __has_builtin(__builtin_add_overflow) && \ 61 __has_builtin(__builtin_sub_overflow) 62 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 63 #endif 64 65 #if __has_feature(shadow_call_stack) 66 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) 67 #endif 68