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 # error Sorry, your version of Clang is too old - please use 10.0.1 or newer. 12 #endif 13 14 /* Compiler specific definitions for Clang compiler */ 15 16 /* same as gcc, this was present in clang-2.6 so we can assume it works 17 * with any version that can compile the kernel 18 */ 19 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) 20 21 /* all clang versions usable with the kernel support KASAN ABI version 5 */ 22 #define KASAN_ABI_VERSION 5 23 24 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) 25 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */ 26 #define __SANITIZE_ADDRESS__ 27 #define __no_sanitize_address \ 28 __attribute__((no_sanitize("address", "hwaddress"))) 29 #else 30 #define __no_sanitize_address 31 #endif 32 33 #if __has_feature(thread_sanitizer) 34 /* emulate gcc's __SANITIZE_THREAD__ flag */ 35 #define __SANITIZE_THREAD__ 36 #define __no_sanitize_thread \ 37 __attribute__((no_sanitize("thread"))) 38 #else 39 #define __no_sanitize_thread 40 #endif 41 42 #if __has_feature(undefined_behavior_sanitizer) 43 /* GCC does not have __SANITIZE_UNDEFINED__ */ 44 #define __no_sanitize_undefined \ 45 __attribute__((no_sanitize("undefined"))) 46 #else 47 #define __no_sanitize_undefined 48 #endif 49 50 /* 51 * Not all versions of clang implement the type-generic versions 52 * of the builtin overflow checkers. Fortunately, clang implements 53 * __has_builtin allowing us to avoid awkward version 54 * checks. Unfortunately, we don't know which version of gcc clang 55 * pretends to be, so the macro may or may not be defined. 56 */ 57 #if __has_builtin(__builtin_mul_overflow) && \ 58 __has_builtin(__builtin_add_overflow) && \ 59 __has_builtin(__builtin_sub_overflow) 60 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 61 #endif 62 63 #if __has_feature(shadow_call_stack) 64 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) 65 #endif 66