]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
d1515582 | 2 | #ifndef __LINUX_COMPILER_TYPES_H |
94f582f8 RD |
3 | #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead." |
4 | #endif | |
1da177e4 LT |
5 | |
6 | /* | |
7 | * Common definitions for all gcc versions go here. | |
8 | */ | |
f6d133f8 JP |
9 | #define GCC_VERSION (__GNUC__ * 10000 \ |
10 | + __GNUC_MINOR__ * 100 \ | |
11 | + __GNUC_PATCHLEVEL__) | |
1da177e4 | 12 | |
c8d52465 | 13 | /* |
85c210ed AK |
14 | * This macro obfuscates arithmetic on a variable address so that gcc |
15 | * shouldn't recognize the original var, and make assumptions about it. | |
16 | * | |
17 | * This is needed because the C standard makes it undefined to do | |
18 | * pointer arithmetic on "objects" outside their boundaries and the | |
19 | * gcc optimizers assume this is the case. In particular they | |
20 | * assume such arithmetic does not wrap. | |
21 | * | |
22 | * A miscompilation has been observed because of this on PPC. | |
23 | * To work around it we hide the relationship of the pointer and the object | |
24 | * using this macro. | |
25 | * | |
c8d52465 AB |
26 | * Versions of the ppc64 compiler before 4.1 had a bug where use of |
27 | * RELOC_HIDE could trash r30. The bug can be worked around by changing | |
28 | * the inline assembly constraint from =g to =r, in this particular | |
29 | * case either is valid. | |
30 | */ | |
f6d133f8 JP |
31 | #define RELOC_HIDE(ptr, off) \ |
32 | ({ \ | |
33 | unsigned long __ptr; \ | |
34 | __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ | |
35 | (typeof(ptr)) (__ptr + (off)); \ | |
36 | }) | |
a1365647 | 37 | |
e4f35891 | 38 | #ifdef CONFIG_RETPOLINE |
5c67a52f | 39 | #define __noretpoline __attribute__((__indirect_branch__("keep"))) |
87358710 DW |
40 | #endif |
41 | ||
cb984d10 JP |
42 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) |
43 | ||
cafa0010 | 44 | #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) |
0766f788 | 45 | |
5c67a52f MO |
46 | #define __compiletime_warning(message) __attribute__((__warning__(message))) |
47 | #define __compiletime_error(message) __attribute__((__error__(message))) | |
cafa0010 | 48 | |
989bd500 | 49 | #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) |
0766f788 ER |
50 | #define __latent_entropy __attribute__((latent_entropy)) |
51 | #endif | |
0766f788 | 52 | |
173a3efd AB |
53 | /* |
54 | * calling noreturn functions, __builtin_unreachable() and __builtin_trap() | |
55 | * confuse the stack allocation in gcc, leading to overly large stack | |
56 | * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 | |
57 | * | |
58 | * Adding an empty inline assembly before it works around the problem | |
59 | */ | |
60 | #define barrier_before_unreachable() asm volatile("") | |
61 | ||
cb984d10 JP |
62 | /* |
63 | * Mark a position in code as unreachable. This can be used to | |
64 | * suppress control flow warnings after asm blocks that transfer | |
65 | * control elsewhere. | |
cb984d10 | 66 | */ |
4e4636cf | 67 | #define unreachable() \ |
173a3efd AB |
68 | do { \ |
69 | annotate_unreachable(); \ | |
70 | barrier_before_unreachable(); \ | |
71 | __builtin_unreachable(); \ | |
72 | } while (0) | |
cb984d10 | 73 | |
a3d6c976 | 74 | #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) |
313dd1b6 KC |
75 | #define __randomize_layout __attribute__((randomize_layout)) |
76 | #define __no_randomize_layout __attribute__((no_randomize_layout)) | |
2cfe0d30 KC |
77 | /* This anon struct can add padding, so only enable it under randstruct. */ |
78 | #define randomized_struct_fields_start struct { | |
79 | #define randomized_struct_fields_end } __randomize_layout; | |
313dd1b6 KC |
80 | #endif |
81 | ||
cb984d10 JP |
82 | /* |
83 | * GCC 'asm goto' miscompiles certain code sequences: | |
84 | * | |
85 | * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 | |
86 | * | |
87 | * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. | |
88 | * | |
89 | * (asm goto is automatically volatile - the naming reflects this.) | |
90 | */ | |
91 | #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) | |
92 | ||
d991bb1c | 93 | #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) |
cb984d10 JP |
94 | #define __HAVE_BUILTIN_BSWAP32__ |
95 | #define __HAVE_BUILTIN_BSWAP64__ | |
cb984d10 | 96 | #define __HAVE_BUILTIN_BSWAP16__ |
d991bb1c | 97 | #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ |
cb984d10 | 98 | |
045d599a DV |
99 | #if GCC_VERSION >= 70000 |
100 | #define KASAN_ABI_VERSION 5 | |
101 | #elif GCC_VERSION >= 50000 | |
cb984d10 JP |
102 | #define KASAN_ABI_VERSION 4 |
103 | #elif GCC_VERSION >= 40902 | |
104 | #define KASAN_ABI_VERSION 3 | |
105 | #endif | |
106 | ||
2bd926b4 AK |
107 | #if __has_attribute(__no_sanitize_address__) |
108 | #define __no_sanitize_address __attribute__((no_sanitize_address)) | |
109 | #else | |
110 | #define __no_sanitize_address | |
111 | #endif | |
112 | ||
dfd402a4 | 113 | #if defined(__SANITIZE_THREAD__) && __has_attribute(__no_sanitize_thread__) |
e33f9a16 | 114 | #define __no_sanitize_thread __attribute__((no_sanitize_thread)) |
dfd402a4 ME |
115 | #else |
116 | #define __no_sanitize_thread | |
117 | #endif | |
118 | ||
5144f8a8 ME |
119 | #if __has_attribute(__no_sanitize_undefined__) |
120 | #define __no_sanitize_undefined __attribute__((no_sanitize_undefined)) | |
121 | #else | |
122 | #define __no_sanitize_undefined | |
123 | #endif | |
124 | ||
0aa5e49c | 125 | #if GCC_VERSION >= 50100 |
cafa0010 | 126 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 |
0aa5e49c KC |
127 | #endif |
128 | ||
8793bb7f AB |
129 | /* |
130 | * Turn individual warnings and errors on and off locally, depending | |
131 | * on version. | |
132 | */ | |
133 | #define __diag_GCC(version, severity, s) \ | |
134 | __diag_GCC_ ## version(__diag_GCC_ ## severity s) | |
135 | ||
136 | /* Severity used in pragma directives */ | |
137 | #define __diag_GCC_ignore ignored | |
138 | #define __diag_GCC_warn warning | |
139 | #define __diag_GCC_error error | |
140 | ||
8793bb7f AB |
141 | #define __diag_str1(s) #s |
142 | #define __diag_str(s) __diag_str1(s) | |
143 | #define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) | |
8793bb7f AB |
144 | |
145 | #if GCC_VERSION >= 80000 | |
146 | #define __diag_GCC_8(s) __diag(s) | |
147 | #else | |
148 | #define __diag_GCC_8(s) | |
149 | #endif |