blob: 9ff8122a9a468c10f05eeb926f12dc855cdbe040 [file] [log] [blame]
Mark Charlebois565cbdc2012-11-20 22:13:10 +01001#ifndef __LINUX_COMPILER_H
2#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
3#endif
4
5/* Some compiler specific definitions are overwritten here
6 * for Clang compiler
7 */
8
9#ifdef uninitialized_var
10#undef uninitialized_var
11#define uninitialized_var(x) x = *(&(x))
12#endif
Arnd Bergmannb41c29b2016-02-08 15:38:32 +010013
14/* same as gcc, this was present in clang-2.6 so we can assume it works
15 * with any version that can compile the kernel
16 */
17#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
Sami Tolvanen7bd125e2017-06-16 12:52:57 -070018
Andrey Konovalov50bed432018-04-20 14:55:52 -070019#undef __no_sanitize_address
20#define __no_sanitize_address __attribute__((no_sanitize("address")))
21
David Woodhouse6123a6b2018-02-19 10:50:57 +000022/* Clang doesn't have a way to turn it off per-function, yet. */
23#ifdef __noretpoline
24#undef __noretpoline
25#endif
Greg Kroah-Hartmanf85543b2018-08-15 18:30:15 +020026
Sami Tolvanen7bd125e2017-06-16 12:52:57 -070027#ifdef CONFIG_LTO_CLANG
28#ifdef CONFIG_FTRACE_MCOUNT_RECORD
29#define __norecordmcount \
30 __attribute__((__section__(".text..ftrace")))
31#endif
Sami Tolvanen00a195e2017-05-11 15:03:36 -070032
33#define __nocfi __attribute__((no_sanitize("cfi")))
Sami Tolvanen7bd125e2017-06-16 12:52:57 -070034#endif
Paul Lawrence08da6752018-02-06 15:36:03 -080035
36/* all clang versions usable with the kernel support KASAN ABI version 5 */
37#define KASAN_ABI_VERSION 5
38
39/* emulate gcc's __SANITIZE_ADDRESS__ flag */
40#if __has_feature(address_sanitizer)
41#define __SANITIZE_ADDRESS__
42#endif
Greg Kroah-Hartman27c2fe32019-01-31 08:36:51 +010043
Rasmus Villemoes1777fa92018-05-08 00:36:27 +020044/*
45 * Not all versions of clang implement the the type-generic versions
46 * of the builtin overflow checkers. Fortunately, clang implements
47 * __has_builtin allowing us to avoid awkward version
48 * checks. Unfortunately, we don't know which version of gcc clang
49 * pretends to be, so the macro may or may not be defined.
50 */
51#undef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW
52#if __has_builtin(__builtin_mul_overflow) && \
53 __has_builtin(__builtin_add_overflow) && \
54 __has_builtin(__builtin_sub_overflow)
55#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
56#endif