]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/compiler-clang.h
Merge tag 'printk-for-5.13-fixup' of git://git.kernel.org/pub/scm/linux/kernel/git...
[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
2bd926b4 16#if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
5cbaefe9 17/* Emulate GCC's __SANITIZE_ADDRESS__ flag */
53a98ed7 18#define __SANITIZE_ADDRESS__
2bd926b4
AK
19#define __no_sanitize_address \
20 __attribute__((no_sanitize("address", "hwaddress")))
21#else
22#define __no_sanitize_address
53a98ed7 23#endif
87358710 24
dfd402a4
ME
25#if __has_feature(thread_sanitizer)
26/* emulate gcc's __SANITIZE_THREAD__ flag */
27#define __SANITIZE_THREAD__
28#define __no_sanitize_thread \
29 __attribute__((no_sanitize("thread")))
30#else
31#define __no_sanitize_thread
32#endif
33
97e49102
AB
34#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
35#define __HAVE_BUILTIN_BSWAP32__
36#define __HAVE_BUILTIN_BSWAP64__
37#define __HAVE_BUILTIN_BSWAP16__
38#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
39
5144f8a8
ME
40#if __has_feature(undefined_behavior_sanitizer)
41/* GCC does not have __SANITIZE_UNDEFINED__ */
42#define __no_sanitize_undefined \
43 __attribute__((no_sanitize("undefined")))
44#else
45#define __no_sanitize_undefined
46#endif
47
f0907827 48/*
c5f748e2 49 * Not all versions of clang implement the type-generic versions
f0907827
RV
50 * of the builtin overflow checkers. Fortunately, clang implements
51 * __has_builtin allowing us to avoid awkward version
52 * checks. Unfortunately, we don't know which version of gcc clang
53 * pretends to be, so the macro may or may not be defined.
54 */
f0907827
RV
55#if __has_builtin(__builtin_mul_overflow) && \
56 __has_builtin(__builtin_add_overflow) && \
57 __has_builtin(__builtin_sub_overflow)
58#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
59#endif
815f0ddb 60
d08b9f0c
ST
61#if __has_feature(shadow_call_stack)
62# define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
63#endif
cf68fffb
ST
64
65#define __nocfi __attribute__((__no_sanitize__("cfi")))
ff301ceb 66#define __cficanonical __attribute__((__cfi_canonical_jump_table__))