Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_COMPILER_TYPES_H
0003 #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
0004 #endif
0005 
0006 /* Compiler specific definitions for Clang compiler */
0007 
0008 /* same as gcc, this was present in clang-2.6 so we can assume it works
0009  * with any version that can compile the kernel
0010  */
0011 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
0012 
0013 /* all clang versions usable with the kernel support KASAN ABI version 5 */
0014 #define KASAN_ABI_VERSION 5
0015 
0016 /*
0017  * Note: Checking __has_feature(*_sanitizer) is only true if the feature is
0018  * enabled. Therefore it is not required to additionally check defined(CONFIG_*)
0019  * to avoid adding redundant attributes in other configurations.
0020  */
0021 
0022 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
0023 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
0024 #define __SANITIZE_ADDRESS__
0025 #define __no_sanitize_address \
0026         __attribute__((no_sanitize("address", "hwaddress")))
0027 #else
0028 #define __no_sanitize_address
0029 #endif
0030 
0031 #if __has_feature(thread_sanitizer)
0032 /* emulate gcc's __SANITIZE_THREAD__ flag */
0033 #define __SANITIZE_THREAD__
0034 #define __no_sanitize_thread \
0035         __attribute__((no_sanitize("thread")))
0036 #else
0037 #define __no_sanitize_thread
0038 #endif
0039 
0040 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
0041 #define __HAVE_BUILTIN_BSWAP32__
0042 #define __HAVE_BUILTIN_BSWAP64__
0043 #define __HAVE_BUILTIN_BSWAP16__
0044 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
0045 
0046 #if __has_feature(undefined_behavior_sanitizer)
0047 /* GCC does not have __SANITIZE_UNDEFINED__ */
0048 #define __no_sanitize_undefined \
0049         __attribute__((no_sanitize("undefined")))
0050 #else
0051 #define __no_sanitize_undefined
0052 #endif
0053 
0054 /*
0055  * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together
0056  * with no_sanitize("coverage"). Prior versions of Clang support coverage
0057  * instrumentation, but cannot be queried for support by the preprocessor.
0058  */
0059 #if __has_feature(coverage_sanitizer)
0060 #define __no_sanitize_coverage __attribute__((no_sanitize("coverage")))
0061 #else
0062 #define __no_sanitize_coverage
0063 #endif
0064 
0065 #if __has_feature(shadow_call_stack)
0066 # define __noscs    __attribute__((__no_sanitize__("shadow-call-stack")))
0067 #endif
0068 
0069 #define __nocfi     __attribute__((__no_sanitize__("cfi")))
0070 #define __cficanonical  __attribute__((__cfi_canonical_jump_table__))
0071 
0072 #if defined(CONFIG_CFI_CLANG)
0073 /*
0074  * With CONFIG_CFI_CLANG, the compiler replaces function address
0075  * references with the address of the function's CFI jump table
0076  * entry. The function_nocfi macro always returns the address of the
0077  * actual function instead.
0078  */
0079 #define function_nocfi(x)   __builtin_function_start(x)
0080 #endif
0081 
0082 /*
0083  * Turn individual warnings and errors on and off locally, depending
0084  * on version.
0085  */
0086 #define __diag_clang(version, severity, s) \
0087     __diag_clang_ ## version(__diag_clang_ ## severity s)
0088 
0089 /* Severity used in pragma directives */
0090 #define __diag_clang_ignore ignored
0091 #define __diag_clang_warn   warning
0092 #define __diag_clang_error  error
0093 
0094 #define __diag_str1(s)      #s
0095 #define __diag_str(s)       __diag_str1(s)
0096 #define __diag(s)       _Pragma(__diag_str(clang diagnostic s))
0097 
0098 #if CONFIG_CLANG_VERSION >= 110000
0099 #define __diag_clang_11(s)  __diag(s)
0100 #else
0101 #define __diag_clang_11(s)
0102 #endif
0103 
0104 #define __diag_ignore_all(option, comment) \
0105     __diag_clang(11, ignore, option)