]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/compiler-clang.h
Merge tag 'pm-5.14-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[mirror_ubuntu-jammy-kernel.git] / include / linux / compiler-clang.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
d1515582 2#ifndef __LINUX_COMPILER_TYPES_H
565cbdc2
MC
3#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
4#endif
5
3e2ffd65
MT
6/* Compiler specific definitions for Clang compiler */
7
b41c29b0
AB
8/* same as gcc, this was present in clang-2.6 so we can assume it works
9 * with any version that can compile the kernel
10 */
11#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
4ca59b14 12
53a98ed7
PL
13/* all clang versions usable with the kernel support KASAN ABI version 5 */
14#define KASAN_ABI_VERSION 5
15
540540d0
ME
16/*
17 * Note: Checking __has_feature(*_sanitizer) is only true if the feature is
18 * enabled. Therefore it is not required to additionally check defined(CONFIG_*)
19 * to avoid adding redundant attributes in other configurations.
20 */
21
2bd926b4 22#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
5cbaefe9 23/* Emulate GCC's __SANITIZE_ADDRESS__ flag */
53a98ed7 24#define __SANITIZE_ADDRESS__
2bd926b4
AK
25#define __no_sanitize_address \
26 __attribute__((no_sanitize("address", "hwaddress")))
27#else
28#define __no_sanitize_address
53a98ed7 29#endif
87358710 30
dfd402a4
ME
31#if __has_feature(thread_sanitizer)
32/* emulate gcc's __SANITIZE_THREAD__ flag */
33#define __SANITIZE_THREAD__
34#define __no_sanitize_thread \
35 __attribute__((no_sanitize("thread")))
36#else
37#define __no_sanitize_thread
38#endif
39
97e49102
AB
40#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
41#define __HAVE_BUILTIN_BSWAP32__
42#define __HAVE_BUILTIN_BSWAP64__
43#define __HAVE_BUILTIN_BSWAP16__
44#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
45
5144f8a8
ME
46#if __has_feature(undefined_behavior_sanitizer)
47/* GCC does not have __SANITIZE_UNDEFINED__ */
48#define __no_sanitize_undefined \
49 __attribute__((no_sanitize("undefined")))
50#else
51#define __no_sanitize_undefined
52#endif
53
540540d0
ME
54/*
55 * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together
56 * with no_sanitize("coverage"). Prior versions of Clang support coverage
57 * instrumentation, but cannot be queried for support by the preprocessor.
58 */
59#if __has_feature(coverage_sanitizer)
60#define __no_sanitize_coverage __attribute__((no_sanitize("coverage")))
61#else
62#define __no_sanitize_coverage
63#endif
64
f0907827 65/*
c5f748e2 66 * Not all versions of clang implement the type-generic versions
f0907827
RV
67 * of the builtin overflow checkers. Fortunately, clang implements
68 * __has_builtin allowing us to avoid awkward version
69 * checks. Unfortunately, we don't know which version of gcc clang
70 * pretends to be, so the macro may or may not be defined.
71 */
f0907827
RV
72#if __has_builtin(__builtin_mul_overflow) && \
73 __has_builtin(__builtin_add_overflow) && \
74 __has_builtin(__builtin_sub_overflow)
75#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
76#endif
815f0ddb 77
d08b9f0c
ST
78#if __has_feature(shadow_call_stack)
79# define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
80#endif
cf68fffb
ST
81
82#define __nocfi __attribute__((__no_sanitize__("cfi")))
ff301ceb 83#define __cficanonical __attribute__((__cfi_canonical_jump_table__))