Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | f1ea2fa | 2008-08-21 22:26:06 | [diff] [blame] | 4 | |
| 5 | #ifndef BASE_COMPILER_SPECIFIC_H_ |
| 6 | #define BASE_COMPILER_SPECIFIC_H_ |
| 7 | |
| 8 | #include "build/build_config.h" |
| 9 | |
Nico Weber | fb053cc | 2020-03-03 13:33:05 | [diff] [blame] | 10 | #if defined(COMPILER_MSVC) && !defined(__clang__) |
Nico Weber | 5979181 | 2019-07-27 04:02:11 | [diff] [blame] | 11 | #error "Only clang-cl is supported on Windows, see https://crbug.com/988071" |
| 12 | #endif |
| 13 | |
Jan Wilken Dörrie | f8d479d | 2020-11-23 12:21:13 | [diff] [blame] | 14 | // This is a wrapper around `__has_cpp_attribute`, which can be used to test for |
| 15 | // the presence of an attribute. In case the compiler does not support this |
| 16 | // macro it will simply evaluate to 0. |
| 17 | // |
| 18 | // References: |
| 19 | // https://wg21.link/sd6#testing-for-the-presence-of-an-attribute-__has_cpp_attribute |
| 20 | // https://wg21.link/cpp.cond#:__has_cpp_attribute |
| 21 | #if defined(__has_cpp_attribute) |
| 22 | #define HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) |
| 23 | #else |
| 24 | #define HAS_CPP_ATTRIBUTE(x) 0 |
| 25 | #endif |
| 26 | |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 27 | // A wrapper around `__has_attribute`, similar to HAS_CPP_ATTRIBUTE. |
| 28 | #if defined(__has_attribute) |
| 29 | #define HAS_ATTRIBUTE(x) __has_attribute(x) |
| 30 | #else |
| 31 | #define HAS_ATTRIBUTE(x) 0 |
| 32 | #endif |
| 33 | |
Jann Horn | 9e4b4855 | 2021-03-04 14:34:27 | [diff] [blame] | 34 | // A wrapper around `__has_builtin`, similar to HAS_CPP_ATTRIBUTE. |
| 35 | #if defined(__has_builtin) |
| 36 | #define HAS_BUILTIN(x) __has_builtin(x) |
| 37 | #else |
| 38 | #define HAS_BUILTIN(x) 0 |
| 39 | #endif |
| 40 | |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 41 | // Annotate a function indicating it should not be inlined. |
| 42 | // Use like: |
| 43 | // NOINLINE void DoStuff() { ... } |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 44 | #if defined(__clang__) && HAS_ATTRIBUTE(noinline) |
| 45 | #define NOINLINE [[clang::noinline]] |
| 46 | #elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) |
[email protected] | 2149cc62 | 2012-02-14 01:12:12 | [diff] [blame] | 47 | #define NOINLINE __attribute__((noinline)) |
| 48 | #elif defined(COMPILER_MSVC) |
| 49 | #define NOINLINE __declspec(noinline) |
| 50 | #else |
[email protected] | 50795a0 | 2011-05-09 20:11:01 | [diff] [blame] | 51 | #define NOINLINE |
[email protected] | f5059510 | 2010-10-08 16:20:32 | [diff] [blame] | 52 | #endif |
| 53 | |
Jose Dapena Paz | 7cc1b1d4 | 2023-11-08 18:37:28 | [diff] [blame] | 54 | // Annotate a function indicating it should not be optimized. |
| 55 | #if defined(__clang__) && HAS_ATTRIBUTE(optnone) |
| 56 | #define NOOPT [[clang::optnone]] |
| 57 | #elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(optimize) |
| 58 | #define NOOPT __attribute__((optimize(0))) |
| 59 | #else |
| 60 | #define NOOPT |
| 61 | #endif |
| 62 | |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 63 | #if defined(__clang__) && defined(NDEBUG) && HAS_ATTRIBUTE(always_inline) |
| 64 | #define ALWAYS_INLINE [[clang::always_inline]] inline |
| 65 | #elif defined(COMPILER_GCC) && defined(NDEBUG) && HAS_ATTRIBUTE(always_inline) |
palmer | 58184a828 | 2016-11-08 19:15:39 | [diff] [blame] | 66 | #define ALWAYS_INLINE inline __attribute__((__always_inline__)) |
Ivan Krasin | 9c098a0d | 2018-08-05 03:57:57 | [diff] [blame] | 67 | #elif defined(COMPILER_MSVC) && defined(NDEBUG) |
palmer | 58184a828 | 2016-11-08 19:15:39 | [diff] [blame] | 68 | #define ALWAYS_INLINE __forceinline |
| 69 | #else |
| 70 | #define ALWAYS_INLINE inline |
| 71 | #endif |
| 72 | |
Olivier Li | 19d8925 | 2020-05-13 17:57:55 | [diff] [blame] | 73 | // Annotate a function indicating it should never be tail called. Useful to make |
| 74 | // sure callers of the annotated function are never omitted from call-stacks. |
| 75 | // To provide the complementary behavior (prevent the annotated function from |
| 76 | // being omitted) look at NOINLINE. Also note that this doesn't prevent code |
| 77 | // folding of multiple identical caller functions into a single signature. To |
Bruce Dawson | 7915efd | 2021-01-27 18:07:58 | [diff] [blame] | 78 | // prevent code folding, see NO_CODE_FOLDING() in base/debug/alias.h. |
Olivier Li | 19d8925 | 2020-05-13 17:57:55 | [diff] [blame] | 79 | // Use like: |
Daniel Cheng | ddf1b22 | 2023-02-02 02:41:52 | [diff] [blame] | 80 | // NOT_TAIL_CALLED void FooBar(); |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 81 | #if defined(__clang__) && HAS_ATTRIBUTE(not_tail_called) |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 82 | #define NOT_TAIL_CALLED [[clang::not_tail_called]] |
Olivier Li | 19d8925 | 2020-05-13 17:57:55 | [diff] [blame] | 83 | #else |
| 84 | #define NOT_TAIL_CALLED |
| 85 | #endif |
| 86 | |
mikt | 2a4fdf0 | 2024-07-09 18:47:57 | [diff] [blame^] | 87 | // Annotate a function indicating it must be tail called. |
| 88 | // Can be used only on return statements, even for functions returning void. |
| 89 | // Caller and callee must have the same number of arguments and its types must |
| 90 | // be "similar". |
| 91 | #if defined(__clang__) && HAS_ATTRIBUTE(musttail) |
| 92 | #define MUSTTAIL [[clang::musttail]] |
| 93 | #else |
| 94 | #define MUSTTAIL |
| 95 | #endif |
| 96 | |
[email protected] | cd924d6 | 2012-02-23 17:52:20 | [diff] [blame] | 97 | // Specify memory alignment for structs, classes, etc. |
| 98 | // Use like: |
| 99 | // class ALIGNAS(16) MyClass { ... } |
| 100 | // ALIGNAS(16) int array[4]; |
brettw | 16289b3e | 2017-06-13 21:58:40 | [diff] [blame] | 101 | // |
| 102 | // In most places you can use the C++11 keyword "alignas", which is preferred. |
| 103 | // |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 104 | // Historically, compilers had trouble mixing __attribute__((...)) syntax with |
| 105 | // alignas(...) syntax. However, at least Clang is very accepting nowadays. It |
| 106 | // may be that this macro can be removed entirely. |
| 107 | #if defined(__clang__) |
| 108 | #define ALIGNAS(byte_alignment) alignas(byte_alignment) |
| 109 | #elif defined(COMPILER_MSVC) |
[email protected] | cd924d6 | 2012-02-23 17:52:20 | [diff] [blame] | 110 | #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 111 | #elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(aligned) |
[email protected] | cd924d6 | 2012-02-23 17:52:20 | [diff] [blame] | 112 | #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
| 113 | #endif |
| 114 | |
Jan Wilken Dörrie | f8d479d | 2020-11-23 12:21:13 | [diff] [blame] | 115 | // In case the compiler supports it NO_UNIQUE_ADDRESS evaluates to the C++20 |
| 116 | // attribute [[no_unique_address]]. This allows annotating data members so that |
| 117 | // they need not have an address distinct from all other non-static data members |
| 118 | // of its class. |
| 119 | // |
| 120 | // References: |
| 121 | // * https://en.cppreference.com/w/cpp/language/attributes/no_unique_address |
| 122 | // * https://wg21.link/dcl.attr.nouniqueaddr |
Peter Kasting | 8bc046d2 | 2023-11-14 00:38:03 | [diff] [blame] | 123 | #if defined(COMPILER_MSVC) && HAS_CPP_ATTRIBUTE(msvc::no_unique_address) |
| 124 | // Unfortunately MSVC ignores [[no_unique_address]] (see |
| 125 | // https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#msvc-extensions-and-abi), |
| 126 | // and clang-cl matches it for ABI compatibility reasons. We need to prefer |
| 127 | // [[msvc::no_unique_address]] when available if we actually want any effect. |
Helmut Januschka | 13cd38b | 2023-12-22 03:31:47 | [diff] [blame] | 128 | #define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
Peter Kasting | 8bc046d2 | 2023-11-14 00:38:03 | [diff] [blame] | 129 | #elif HAS_CPP_ATTRIBUTE(no_unique_address) |
Jan Wilken Dörrie | f8d479d | 2020-11-23 12:21:13 | [diff] [blame] | 130 | #define NO_UNIQUE_ADDRESS [[no_unique_address]] |
| 131 | #else |
| 132 | #define NO_UNIQUE_ADDRESS |
| 133 | #endif |
| 134 | |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 135 | // Tells the compiler a function is using a printf-style format string. |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 136 | // |format_param| is the one-based index of the format string parameter; |
| 137 | // |dots_param| is the one-based index of the "..." parameter. |
| 138 | // For v*printf functions (which take a va_list), pass 0 for dots_param. |
| 139 | // (This is undocumented but matches what the system C headers do.) |
Nico Weber | fc7c8dd | 2019-02-28 21:28:44 | [diff] [blame] | 140 | // For member functions, the implicit this parameter counts as index 1. |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 141 | #if (defined(COMPILER_GCC) || defined(__clang__)) && HAS_ATTRIBUTE(format) |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 142 | #define PRINTF_FORMAT(format_param, dots_param) \ |
Vitaly Buka | 2b79076 | 2019-12-20 21:11:48 | [diff] [blame] | 143 | __attribute__((format(printf, format_param, dots_param))) |
[email protected] | f5059510 | 2010-10-08 16:20:32 | [diff] [blame] | 144 | #else |
| 145 | #define PRINTF_FORMAT(format_param, dots_param) |
| 146 | #endif |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 147 | |
| 148 | // WPRINTF_FORMAT is the same, but for wide format strings. |
[email protected] | f5059510 | 2010-10-08 16:20:32 | [diff] [blame] | 149 | // This doesn't appear to yet be implemented in any compiler. |
[email protected] | 34b2b00 | 2009-11-20 06:53:28 | [diff] [blame] | 150 | // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 . |
| 151 | #define WPRINTF_FORMAT(format_param, dots_param) |
| 152 | // If available, it would look like: |
| 153 | // __attribute__((format(wprintf, format_param, dots_param))) |
| 154 | |
etienneb | 4e9250a | 2016-11-18 18:47:53 | [diff] [blame] | 155 | // Sanitizers annotations. |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 156 | #if HAS_ATTRIBUTE(no_sanitize) |
etienneb | 4e9250a | 2016-11-18 18:47:53 | [diff] [blame] | 157 | #define NO_SANITIZE(what) __attribute__((no_sanitize(what))) |
| 158 | #endif |
etienneb | 4e9250a | 2016-11-18 18:47:53 | [diff] [blame] | 159 | #if !defined(NO_SANITIZE) |
| 160 | #define NO_SANITIZE(what) |
| 161 | #endif |
| 162 | |
[email protected] | 75086be | 2013-03-20 21:18:22 | [diff] [blame] | 163 | // MemorySanitizer annotations. |
Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 164 | #if defined(MEMORY_SANITIZER) && !BUILDFLAG(IS_NACL) |
[email protected] | eb82dfb | 2014-02-03 19:51:17 | [diff] [blame] | 165 | #include <sanitizer/msan_interface.h> |
[email protected] | 75086be | 2013-03-20 21:18:22 | [diff] [blame] | 166 | |
| 167 | // Mark a memory region fully initialized. |
| 168 | // Use this to annotate code that deliberately reads uninitialized data, for |
| 169 | // example a GC scavenging root set pointers from the stack. |
Vitaly Buka | 2b79076 | 2019-12-20 21:11:48 | [diff] [blame] | 170 | #define MSAN_UNPOISON(p, size) __msan_unpoison(p, size) |
thestig | 1a42b407 | 2015-03-16 22:36:55 | [diff] [blame] | 171 | |
| 172 | // Check a memory region for initializedness, as if it was being used here. |
| 173 | // If any bits are uninitialized, crash with an MSan report. |
| 174 | // Use this to sanitize data which MSan won't be able to track, e.g. before |
| 175 | // passing data to another process via shared memory. |
| 176 | #define MSAN_CHECK_MEM_IS_INITIALIZED(p, size) \ |
Vitaly Buka | 2b79076 | 2019-12-20 21:11:48 | [diff] [blame] | 177 | __msan_check_mem_is_initialized(p, size) |
[email protected] | 75086be | 2013-03-20 21:18:22 | [diff] [blame] | 178 | #else // MEMORY_SANITIZER |
thestig | 1a42b407 | 2015-03-16 22:36:55 | [diff] [blame] | 179 | #define MSAN_UNPOISON(p, size) |
| 180 | #define MSAN_CHECK_MEM_IS_INITIALIZED(p, size) |
[email protected] | 75086be | 2013-03-20 21:18:22 | [diff] [blame] | 181 | #endif // MEMORY_SANITIZER |
| 182 | |
krasin | 825ce48 | 2016-08-27 11:01:11 | [diff] [blame] | 183 | // DISABLE_CFI_PERF -- Disable Control Flow Integrity for perf reasons. |
| 184 | #if !defined(DISABLE_CFI_PERF) |
krasin | 40f7c78 | 2016-09-22 19:04:27 | [diff] [blame] | 185 | #if defined(__clang__) && defined(OFFICIAL_BUILD) |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 186 | #define DISABLE_CFI_PERF NO_SANITIZE("cfi") |
krasin | 825ce48 | 2016-08-27 11:01:11 | [diff] [blame] | 187 | #else |
| 188 | #define DISABLE_CFI_PERF |
| 189 | #endif |
| 190 | #endif |
| 191 | |
Will Harris | 9a033b0 | 2020-07-11 01:26:54 | [diff] [blame] | 192 | // DISABLE_CFI_ICALL -- Disable Control Flow Integrity indirect call checks. |
Alex Gough | 3657980 | 2022-07-25 20:20:46 | [diff] [blame] | 193 | // Security Note: if you just need to allow calling of dlsym functions use |
| 194 | // DISABLE_CFI_DLSYM. |
Will Harris | 9a033b0 | 2020-07-11 01:26:54 | [diff] [blame] | 195 | #if !defined(DISABLE_CFI_ICALL) |
Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 196 | #if BUILDFLAG(IS_WIN) |
Will Harris | 9a033b0 | 2020-07-11 01:26:54 | [diff] [blame] | 197 | // Windows also needs __declspec(guard(nocf)). |
| 198 | #define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall") __declspec(guard(nocf)) |
| 199 | #else |
| 200 | #define DISABLE_CFI_ICALL NO_SANITIZE("cfi-icall") |
| 201 | #endif |
| 202 | #endif |
| 203 | #if !defined(DISABLE_CFI_ICALL) |
| 204 | #define DISABLE_CFI_ICALL |
| 205 | #endif |
| 206 | |
Alex Gough | 3657980 | 2022-07-25 20:20:46 | [diff] [blame] | 207 | // DISABLE_CFI_DLSYM -- applies DISABLE_CFI_ICALL on platforms where dlsym |
| 208 | // functions must be called. Retains CFI checks on platforms where loaded |
| 209 | // modules participate in CFI (e.g. Windows). |
| 210 | #if !defined(DISABLE_CFI_DLSYM) |
| 211 | #if BUILDFLAG(IS_WIN) |
| 212 | // Windows modules register functions when loaded so can be checked by CFG. |
| 213 | #define DISABLE_CFI_DLSYM |
| 214 | #else |
| 215 | #define DISABLE_CFI_DLSYM DISABLE_CFI_ICALL |
| 216 | #endif |
| 217 | #endif |
| 218 | #if !defined(DISABLE_CFI_DLSYM) |
| 219 | #define DISABLE_CFI_DLSYM |
| 220 | #endif |
| 221 | |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 222 | // Macro useful for writing cross-platform function pointers. |
| 223 | #if !defined(CDECL) |
Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 224 | #if BUILDFLAG(IS_WIN) |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 225 | #define CDECL __cdecl |
Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 226 | #else // BUILDFLAG(IS_WIN) |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 227 | #define CDECL |
Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 228 | #endif // BUILDFLAG(IS_WIN) |
[email protected] | 5a8d4ce | 2013-12-18 17:42:27 | [diff] [blame] | 229 | #endif // !defined(CDECL) |
| 230 | |
[email protected] | 2bc0c699 | 2014-02-13 16:11:04 | [diff] [blame] | 231 | // Macro for hinting that an expression is likely to be false. |
| 232 | #if !defined(UNLIKELY) |
Vladimir Levin | 6b77771 | 2017-09-09 00:12:05 | [diff] [blame] | 233 | #if defined(COMPILER_GCC) || defined(__clang__) |
[email protected] | 2bc0c699 | 2014-02-13 16:11:04 | [diff] [blame] | 234 | #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
| 235 | #else |
| 236 | #define UNLIKELY(x) (x) |
| 237 | #endif // defined(COMPILER_GCC) |
| 238 | #endif // !defined(UNLIKELY) |
| 239 | |
palmer | 58184a828 | 2016-11-08 19:15:39 | [diff] [blame] | 240 | #if !defined(LIKELY) |
Vladimir Levin | 6b77771 | 2017-09-09 00:12:05 | [diff] [blame] | 241 | #if defined(COMPILER_GCC) || defined(__clang__) |
Chris Palmer | ad4cb83f | 2016-11-18 20:02:25 | [diff] [blame] | 242 | #define LIKELY(x) __builtin_expect(!!(x), 1) |
palmer | 58184a828 | 2016-11-08 19:15:39 | [diff] [blame] | 243 | #else |
| 244 | #define LIKELY(x) (x) |
| 245 | #endif // defined(COMPILER_GCC) |
| 246 | #endif // !defined(LIKELY) |
| 247 | |
jfb | d81c1ce | 2016-04-05 20:50:35 | [diff] [blame] | 248 | // Compiler feature-detection. |
jfb | a8dc9dd8 | 2016-04-06 20:20:31 | [diff] [blame] | 249 | // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension |
| 250 | #if defined(__has_feature) |
| 251 | #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) |
| 252 | #else |
| 253 | #define HAS_FEATURE(FEATURE) 0 |
jfb | d81c1ce | 2016-04-05 20:50:35 | [diff] [blame] | 254 | #endif |
| 255 | |
Alex Clarke | 23c6cf7 | 2018-11-21 13:22:27 | [diff] [blame] | 256 | #if defined(COMPILER_GCC) |
| 257 | #define PRETTY_FUNCTION __PRETTY_FUNCTION__ |
| 258 | #elif defined(COMPILER_MSVC) |
| 259 | #define PRETTY_FUNCTION __FUNCSIG__ |
| 260 | #else |
| 261 | // See https://en.cppreference.com/w/c/language/function_definition#func |
| 262 | #define PRETTY_FUNCTION __func__ |
| 263 | #endif |
| 264 | |
Henrique Ferreiro | 6daf71db | 2019-04-03 13:12:42 | [diff] [blame] | 265 | #if !defined(CPU_ARM_NEON) |
Matt Reynolds | 96ad225 | 2023-06-05 20:01:48 | [diff] [blame] | 266 | #if defined(__arm__) |
| 267 | #if !defined(__ARMEB__) && !defined(__ARM_EABI__) && !defined(__EABI__) && \ |
| 268 | !defined(__VFP_FP__) && !defined(_WIN32_WCE) && !defined(ANDROID) |
| 269 | #error Chromium does not support middle endian architecture |
| 270 | #endif |
| 271 | #if defined(__ARM_NEON__) |
Henrique Ferreiro | 6daf71db | 2019-04-03 13:12:42 | [diff] [blame] | 272 | #define CPU_ARM_NEON 1 |
| 273 | #endif |
Matt Reynolds | 96ad225 | 2023-06-05 20:01:48 | [diff] [blame] | 274 | #endif // defined(__arm__) |
Henrique Ferreiro | 6daf71db | 2019-04-03 13:12:42 | [diff] [blame] | 275 | #endif // !defined(CPU_ARM_NEON) |
| 276 | |
| 277 | #if !defined(HAVE_MIPS_MSA_INTRINSICS) |
| 278 | #if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5) |
| 279 | #define HAVE_MIPS_MSA_INTRINSICS 1 |
| 280 | #endif |
| 281 | #endif |
| 282 | |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 283 | #if defined(__clang__) && HAS_ATTRIBUTE(uninitialized) |
Vitaly Buka | 2b79076 | 2019-12-20 21:11:48 | [diff] [blame] | 284 | // Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for |
| 285 | // the specified variable. |
| 286 | // Library-wide alternative is |
| 287 | // 'configs -= [ "//build/config/compiler:default_init_stack_vars" ]' in .gn |
| 288 | // file. |
| 289 | // |
| 290 | // See "init_stack_vars" in build/config/compiler/BUILD.gn and |
| 291 | // http://crbug.com/977230 |
| 292 | // "init_stack_vars" is enabled for non-official builds and we hope to enable it |
| 293 | // in official build in 2020 as well. The flag writes fixed pattern into |
| 294 | // uninitialized parts of all local variables. In rare cases such initialization |
| 295 | // is undesirable and attribute can be used: |
| 296 | // 1. Degraded performance |
| 297 | // In most cases compiler is able to remove additional stores. E.g. if memory is |
| 298 | // never accessed or properly initialized later. Preserved stores mostly will |
| 299 | // not affect program performance. However if compiler failed on some |
| 300 | // performance critical code we can get a visible regression in a benchmark. |
| 301 | // 2. memset, memcpy calls |
| 302 | // Compiler may replaces some memory writes with memset or memcpy calls. This is |
| 303 | // not -ftrivial-auto-var-init specific, but it can happen more likely with the |
| 304 | // flag. It can be a problem if code is not linked with C run-time library. |
| 305 | // |
| 306 | // Note: The flag is security risk mitigation feature. So in future the |
| 307 | // attribute uses should be avoided when possible. However to enable this |
| 308 | // mitigation on the most of the code we need to be less strict now and minimize |
| 309 | // number of exceptions later. So if in doubt feel free to use attribute, but |
| 310 | // please document the problem for someone who is going to cleanup it later. |
| 311 | // E.g. platform, bot, benchmark or test name in patch description or next to |
| 312 | // the attribute. |
Peter Kasting | f541f778 | 2023-03-10 23:44:46 | [diff] [blame] | 313 | #define STACK_UNINITIALIZED [[clang::uninitialized]] |
Vitaly Buka | 2b79076 | 2019-12-20 21:11:48 | [diff] [blame] | 314 | #else |
| 315 | #define STACK_UNINITIALIZED |
| 316 | #endif |
| 317 | |
Matthew Denton | bb0b03e | 2021-07-22 16:18:13 | [diff] [blame] | 318 | // Attribute "no_stack_protector" disables -fstack-protector for the specified |
| 319 | // function. |
| 320 | // |
| 321 | // "stack_protector" is enabled on most POSIX builds. The flag adds a canary |
| 322 | // to each stack frame, which on function return is checked against a reference |
| 323 | // canary. If the canaries do not match, it's likely that a stack buffer |
| 324 | // overflow has occurred, so immediately crashing will prevent exploitation in |
| 325 | // many cases. |
| 326 | // |
| 327 | // In some cases it's desirable to remove this, e.g. on hot functions, or if |
| 328 | // we have purposely changed the reference canary. |
| 329 | #if defined(COMPILER_GCC) || defined(__clang__) |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 330 | #if HAS_ATTRIBUTE(__no_stack_protector__) |
Stephan Hartmann | 4b456e7 | 2021-08-10 03:25:02 | [diff] [blame] | 331 | #define NO_STACK_PROTECTOR __attribute__((__no_stack_protector__)) |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 332 | #else |
Stephan Hartmann | 4b456e7 | 2021-08-10 03:25:02 | [diff] [blame] | 333 | #define NO_STACK_PROTECTOR __attribute__((__optimize__("-fno-stack-protector"))) |
| 334 | #endif |
Matthew Denton | bb0b03e | 2021-07-22 16:18:13 | [diff] [blame] | 335 | #else |
| 336 | #define NO_STACK_PROTECTOR |
| 337 | #endif |
| 338 | |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 339 | // The ANALYZER_ASSUME_TRUE(bool arg) macro adds compiler-specific hints |
| 340 | // to Clang which control what code paths are statically analyzed, |
| 341 | // and is meant to be used in conjunction with assert & assert-like functions. |
| 342 | // The expression is passed straight through if analysis isn't enabled. |
| 343 | // |
| 344 | // ANALYZER_SKIP_THIS_PATH() suppresses static analysis for the current |
| 345 | // codepath and any other branching codepaths that might follow. |
| 346 | #if defined(__clang_analyzer__) |
| 347 | |
| 348 | inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) { |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | inline constexpr bool AnalyzerAssumeTrue(bool arg) { |
| 353 | // AnalyzerNoReturn() is invoked and analysis is terminated if |arg| is |
| 354 | // false. |
| 355 | return arg || AnalyzerNoReturn(); |
| 356 | } |
| 357 | |
George Burgess IV | a09d235d | 2020-04-17 13:32:50 | [diff] [blame] | 358 | #define ANALYZER_ASSUME_TRUE(arg) ::AnalyzerAssumeTrue(!!(arg)) |
| 359 | #define ANALYZER_SKIP_THIS_PATH() static_cast<void>(::AnalyzerNoReturn()) |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 360 | |
| 361 | #else // !defined(__clang_analyzer__) |
| 362 | |
| 363 | #define ANALYZER_ASSUME_TRUE(arg) (arg) |
| 364 | #define ANALYZER_SKIP_THIS_PATH() |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 365 | |
| 366 | #endif // defined(__clang_analyzer__) |
| 367 | |
Zequan Wu | 9909f14 | 2021-02-10 03:26:00 | [diff] [blame] | 368 | // Use nomerge attribute to disable optimization of merging multiple same calls. |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 369 | #if defined(__clang__) && HAS_ATTRIBUTE(nomerge) |
Zequan Wu | 9909f14 | 2021-02-10 03:26:00 | [diff] [blame] | 370 | #define NOMERGE [[clang::nomerge]] |
| 371 | #else |
| 372 | #define NOMERGE |
| 373 | #endif |
| 374 | |
Jeremy Roman | 810d98d | 2021-04-06 16:46:07 | [diff] [blame] | 375 | // Marks a type as being eligible for the "trivial" ABI despite having a |
| 376 | // non-trivial destructor or copy/move constructor. Such types can be relocated |
| 377 | // after construction by simply copying their memory, which makes them eligible |
| 378 | // to be passed in registers. The canonical example is std::unique_ptr. |
| 379 | // |
| 380 | // Use with caution; this has some subtle effects on constructor/destructor |
| 381 | // ordering and will be very incorrect if the type relies on its address |
| 382 | // remaining constant. When used as a function argument (by value), the value |
| 383 | // may be constructed in the caller's stack frame, passed in a register, and |
| 384 | // then used and destructed in the callee's stack frame. A similar thing can |
| 385 | // occur when values are returned. |
| 386 | // |
| 387 | // TRIVIAL_ABI is not needed for types which have a trivial destructor and |
| 388 | // copy/move constructors, such as base::TimeTicks and other POD. |
| 389 | // |
| 390 | // It is also not likely to be effective on types too large to be passed in one |
| 391 | // or two registers on typical target ABIs. |
| 392 | // |
| 393 | // See also: |
| 394 | // https://clang.llvm.org/docs/AttributeReference.html#trivial-abi |
| 395 | // https://libcxx.llvm.org/docs/DesignDocs/UniquePtrTrivialAbi.html |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 396 | #if defined(__clang__) && HAS_ATTRIBUTE(trivial_abi) |
Jeremy Roman | 810d98d | 2021-04-06 16:46:07 | [diff] [blame] | 397 | #define TRIVIAL_ABI [[clang::trivial_abi]] |
| 398 | #else |
| 399 | #define TRIVIAL_ABI |
| 400 | #endif |
| 401 | |
Adam Rice | fb288d0 | 2023-10-13 08:36:21 | [diff] [blame] | 402 | // Detect whether a type is trivially relocatable, ie. a move-and-destroy |
| 403 | // sequence can replaced with memmove(). This can be used to optimise the |
| 404 | // implementation of containers. This is automatically true for types that were |
| 405 | // defined with TRIVIAL_ABI such as scoped_refptr. |
| 406 | // |
| 407 | // See also: |
| 408 | // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r8.html |
| 409 | // https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable |
| 410 | #if defined(__clang__) && HAS_BUILTIN(__is_trivially_relocatable) |
| 411 | #define IS_TRIVIALLY_RELOCATABLE(t) __is_trivially_relocatable(t) |
| 412 | #else |
| 413 | #define IS_TRIVIALLY_RELOCATABLE(t) false |
| 414 | #endif |
| 415 | |
Lukasz Anforowicz | 3be38fbb | 2021-04-14 20:29:29 | [diff] [blame] | 416 | // Marks a member function as reinitializing a moved-from variable. |
| 417 | // See also |
Lei Zhang | dd1e6fe | 2024-02-01 08:51:35 | [diff] [blame] | 418 | // https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html#reinitialization |
Peter Kasting | 64c67dd | 2022-05-12 18:11:51 | [diff] [blame] | 419 | #if defined(__clang__) && HAS_ATTRIBUTE(reinitializes) |
Lukasz Anforowicz | 3be38fbb | 2021-04-14 20:29:29 | [diff] [blame] | 420 | #define REINITIALIZES_AFTER_MOVE [[clang::reinitializes]] |
| 421 | #else |
| 422 | #define REINITIALIZES_AFTER_MOVE |
| 423 | #endif |
| 424 | |
danakj | ceb1702 | 2022-02-11 23:52:01 | [diff] [blame] | 425 | #if defined(__clang__) |
Daniel Cheng | 8ac305b | 2022-02-17 00:05:11 | [diff] [blame] | 426 | #define GSL_OWNER [[gsl::Owner]] |
danakj | ceb1702 | 2022-02-11 23:52:01 | [diff] [blame] | 427 | #define GSL_POINTER [[gsl::Pointer]] |
| 428 | #else |
Jose Dapena Paz | 1183b14 | 2022-02-18 16:28:25 | [diff] [blame] | 429 | #define GSL_OWNER |
danakj | ceb1702 | 2022-02-11 23:52:01 | [diff] [blame] | 430 | #define GSL_POINTER |
| 431 | #endif |
| 432 | |
Daniel Cheng | f2c0538 | 2022-09-16 02:51:42 | [diff] [blame] | 433 | // Adds the "logically_const" tag to a symbol's mangled name. The "Mutable |
| 434 | // Constants" check [1] detects instances of constants that aren't in .rodata, |
| 435 | // e.g. due to a missing `const`. Using this tag suppresses the check for this |
| 436 | // symbol, allowing it to live outside .rodata without a warning. |
| 437 | // |
| 438 | // [1]: |
| 439 | // https://crsrc.org/c/docs/speed/binary_size/android_binary_size_trybot.md#Mutable-Constants |
Anthony Vallee-Dubois | 9dbbbda3 | 2022-08-26 01:25:31 | [diff] [blame] | 440 | #if defined(COMPILER_GCC) || defined(__clang__) |
| 441 | #define LOGICALLY_CONST [[gnu::abi_tag("logically_const")]] |
| 442 | #else |
| 443 | #define LOGICALLY_CONST |
| 444 | #endif |
| 445 | |
Anton Bikineev | 4d23e84 | 2023-06-14 10:46:19 | [diff] [blame] | 446 | // preserve_most clang's calling convention. Reduces register pressure for the |
| 447 | // caller and as such can be used for cold calls. Support for the |
| 448 | // "preserve_most" attribute is limited: |
| 449 | // - 32-bit platforms do not implement it, |
| 450 | // - component builds fail because _dl_runtime_resolve() clobbers registers, |
| 451 | // - there are crashes on arm64 on Windows (https://crbug.com/v8/14065), which |
| 452 | // can hopefully be fixed in the future. |
| 453 | // Additionally, the initial implementation in clang <= 16 overwrote the return |
| 454 | // register(s) in the epilogue of a preserve_most function, so we only use |
| 455 | // preserve_most in clang >= 17 (see https://reviews.llvm.org/D143425). |
kxxt | 120045d | 2024-02-13 04:22:39 | [diff] [blame] | 456 | // Clang only supports preserve_most on X86-64 and AArch64 for now. |
Anton Bikineev | 4d23e84 | 2023-06-14 10:46:19 | [diff] [blame] | 457 | // See https://clang.llvm.org/docs/AttributeReference.html#preserve-most for |
| 458 | // more details. |
kxxt | 120045d | 2024-02-13 04:22:39 | [diff] [blame] | 459 | #if (defined(ARCH_CPU_ARM64) || defined(ARCH_CPU_X86_64)) && \ |
| 460 | !(BUILDFLAG(IS_WIN) && defined(ARCH_CPU_ARM64)) && \ |
| 461 | !defined(COMPONENT_BUILD) && defined(__clang__) && \ |
Anton Bikineev | 4d23e84 | 2023-06-14 10:46:19 | [diff] [blame] | 462 | __clang_major__ >= 17 && HAS_ATTRIBUTE(preserve_most) |
| 463 | #define PRESERVE_MOST __attribute__((preserve_most)) |
| 464 | #else |
| 465 | #define PRESERVE_MOST |
| 466 | #endif |
| 467 | |
danakj | c077a30e | 2024-03-22 19:25:36 | [diff] [blame] | 468 | // Mark parameters or return types as having a lifetime attached to the class. |
| 469 | // |
| 470 | // When used to mark a method's pointer/reference parameter, the compiler is |
| 471 | // made aware that it will be stored internally in the class and the pointee |
| 472 | // must outlive the class. Typically used on constructor arguments. It should |
| 473 | // appear to the right of the parameter's variable name. |
| 474 | // |
| 475 | // Example: |
| 476 | // ``` |
| 477 | // struct S { |
| 478 | // S(int* p LIFETIME_BOUND) : ptr_(p) {} |
| 479 | // |
| 480 | // int* ptr_; |
| 481 | // }; |
| 482 | // ``` |
| 483 | // |
| 484 | // When used on a method with a return value, the compiler is made aware that |
| 485 | // the returned type is/has a pointer to the internals of the class, and must |
| 486 | // not outlive the class object. It should appear after any method qualifiers. |
| 487 | // |
| 488 | // Example: |
| 489 | // ``` |
| 490 | // struct S { |
| 491 | // int* GetPtr() const LIFETIME_BOUND { return i_; }; |
| 492 | // |
| 493 | // int i_; |
| 494 | // }; |
| 495 | // ``` |
| 496 | // |
| 497 | // This allows the compiler to warn in (a limited set of) cases where the |
| 498 | // pointer would otherwise be left dangling, especially in cases where the |
| 499 | // pointee would be a destroyed temporary. |
| 500 | // |
| 501 | // Docs: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound |
| 502 | #if defined(__clang__) |
| 503 | #define LIFETIME_BOUND [[clang::lifetimebound]] |
| 504 | #else |
| 505 | #define LIFETIME_BOUND |
| 506 | #endif |
| 507 | |
| 508 | // Mark a function as pure, meaning that it does not have side effects, meaning |
| 509 | // that it does not write anything external to the function's local variables |
| 510 | // and return value. |
| 511 | // |
| 512 | // WARNING: If this attribute is mis-used it will result in UB and |
| 513 | // miscompilation, as the optimizator may fold multiple calls into one and |
| 514 | // reorder them inappropriately. This shouldn't appear outside of key vocabulary |
| 515 | // types. It allows callers to work with the vocab type directly, and call its |
| 516 | // methods without having to worry about caching things into local variables in |
| 517 | // hot code. |
| 518 | // |
| 519 | // This attribute must not appear on functions that make use of function |
| 520 | // pointers, virtual methods, or methods of templates (including operators like |
| 521 | // comparison), as the "pure" function can not know what those functions do and |
| 522 | // can not guarantee there will never be sideeffects. |
| 523 | #if defined(COMPILER_GCC) || defined(__clang__) |
| 524 | #define PURE_FUNCTION [[gnu::pure]] |
| 525 | #else |
| 526 | #define PURE_FUNCTION |
| 527 | #endif |
| 528 | |
danakj | 59f56d9 | 2024-02-01 15:31:35 | [diff] [blame] | 529 | // Functions should be marked with UNSAFE_BUFFER_USAGE when they lead to |
| 530 | // out-of-bounds bugs when called with incorrect inputs. |
| 531 | // |
| 532 | // Ideally such functions should be paired with a safer version that works with |
| 533 | // safe primitives like `base::span`. Otherwise, another safer coding pattern |
| 534 | // should be documented along side the use of `UNSAFE_BUFFER_USAGE`. |
| 535 | // |
| 536 | // All functions marked with UNSAFE_BUFFER_USAGE should come with a safety |
David Benjamin | 34f6c2d0 | 2024-04-16 17:43:54 | [diff] [blame] | 537 | // comment that explains the requirements of the function to prevent an |
| 538 | // out-of-bounds bug. For example: |
danakj | 59f56d9 | 2024-02-01 15:31:35 | [diff] [blame] | 539 | // ``` |
| 540 | // // Function to do things between `input` and `end`. |
| 541 | // // |
| 542 | // // # Safety |
| 543 | // // The `input` must point to an array with size at least 5. The `end` must |
| 544 | // // point within the same allocation of `input` and not come before `input`. |
| 545 | // ``` |
David Benjamin | 34f6c2d0 | 2024-04-16 17:43:54 | [diff] [blame] | 546 | // |
| 547 | // The requirements described in the safety comment must be sufficient to |
| 548 | // guarantee that the function never goes out of bounds. Annotating a function |
| 549 | // in this way means that all callers will be required to wrap the call in an |
| 550 | // `UNSAFE_BUFFERS()` macro (see below), with a comment justifying how it meets |
| 551 | // the requirements. |
danakj | 59f56d9 | 2024-02-01 15:31:35 | [diff] [blame] | 552 | #if defined(__clang__) && HAS_ATTRIBUTE(unsafe_buffer_usage) |
| 553 | #define UNSAFE_BUFFER_USAGE [[clang::unsafe_buffer_usage]] |
| 554 | #else |
| 555 | #define UNSAFE_BUFFER_USAGE |
| 556 | #endif |
| 557 | |
| 558 | // UNSAFE_BUFFERS() wraps code that violates the -Wunsafe-buffer-usage warning, |
| 559 | // such as: |
| 560 | // - pointer arithmetic, |
| 561 | // - pointer subscripting, and |
| 562 | // - calls to functions annotated with UNSAFE_BUFFER_USAGE. |
| 563 | // |
David Benjamin | 34f6c2d0 | 2024-04-16 17:43:54 | [diff] [blame] | 564 | // This indicates code whose bounds correctness cannot be ensured |
| 565 | // systematically, and thus requires manual review. |
| 566 | // |
| 567 | // ** USE OF THIS MACRO SHOULD BE VERY RARE.** This should only be used when |
| 568 | // strictly necessary. Prefer to use `base::span` instead of pointers, or other |
| 569 | // safer coding patterns (like std containers) that avoid the opportunity for |
| 570 | // out-of-bounds bugs to creep into the code. Any use of UNSAFE_BUFFERS() can |
| 571 | // lead to a critical security bug if any assumptions are wrong, or ever become |
| 572 | // wrong in the future. |
danakj | 59f56d9 | 2024-02-01 15:31:35 | [diff] [blame] | 573 | // |
| 574 | // The macro should be used to wrap the minimum necessary code, to make it clear |
| 575 | // what is unsafe, and prevent accidentally opting extra things out of the |
| 576 | // warning. |
| 577 | // |
| 578 | // All usage of UNSAFE_BUFFERS() should come with a `// SAFETY: ...` comment |
David Benjamin | 34f6c2d0 | 2024-04-16 17:43:54 | [diff] [blame] | 579 | // that explains how we have guaranteed that the pointer usage can never go |
| 580 | // out-of-bounds, or that the requirements of the UNSAFE_BUFFER_USAGE function |
| 581 | // are met. The safety comment should allow a reader to check that all |
| 582 | // requirements have been met, using only local invariants. Examples of local |
| 583 | // invariants include: |
| 584 | // - Runtime conditions or CHECKs near the UNSAFE_BUFFERS macros |
| 585 | // - Invariants guaranteed by types in the surrounding code |
| 586 | // - Invariants guaranteed by function calls in the surrounding code |
| 587 | // - Caller requirements, if the containing function is itself marked with |
| 588 | // UNSAFE_BUFFER_USAGE |
| 589 | // |
| 590 | // The last case should be an option of last resort. It is less safe and will |
| 591 | // require the caller also use the UNSAFE_BUFFERS() macro. Prefer directly |
| 592 | // capturing such invariants in types like `base::span`. |
| 593 | // |
| 594 | // Safety explanations may not rely on invariants that are not fully |
| 595 | // encapsulated close to the UNSAFE_BUFFERS() usage. Instead, use safer coding |
| 596 | // patterns or stronger invariants. |
danakj | 59f56d9 | 2024-02-01 15:31:35 | [diff] [blame] | 597 | #if defined(__clang__) |
| 598 | // clang-format off |
| 599 | // Formatting is off so that we can put each _Pragma on its own line, as |
| 600 | // recommended by the gcc docs. |
| 601 | #define UNSAFE_BUFFERS(...) \ |
| 602 | _Pragma("clang unsafe_buffer_usage begin") \ |
| 603 | __VA_ARGS__ \ |
| 604 | _Pragma("clang unsafe_buffer_usage end") |
| 605 | // clang-format on |
| 606 | #else |
| 607 | #define UNSAFE_BUFFERS(...) __VA_ARGS__ |
| 608 | #endif |
| 609 | |
danakj | c077a30e | 2024-03-22 19:25:36 | [diff] [blame] | 610 | // Defines a condition for a function to be checked at compile time if the |
| 611 | // parameter's value is known at compile time. If the condition is failed, the |
| 612 | // function is omitted from the overload set resolution, much like `requires`. |
| 613 | // |
| 614 | // If the parameter is a runtime value, then the condition is unable to be |
| 615 | // checked and the function will be omitted from the overload set resolution. |
| 616 | // This ensures the function can only be called with values known at compile |
| 617 | // time. This is a clang extension. |
| 618 | // |
| 619 | // Example: |
| 620 | // ``` |
| 621 | // void f(int a) ENABLE_IF_ATTR(a > 0) {} |
| 622 | // f(1); // Ok. |
| 623 | // f(0); // Error: no valid f() found. |
| 624 | // ``` |
| 625 | // |
| 626 | // The `ENABLE_IF_ATTR` annotation is preferred over `consteval` with a check |
| 627 | // that breaks compile because metaprogramming does not observe such checks. So |
| 628 | // with `consteval`, the function looks callable to concepts/type_traits but is |
| 629 | // not and will fail to compile even though it reports it's usable. Whereas |
| 630 | // `ENABLE_IF_ATTR` interacts correctly with metaprogramming. This is especially |
| 631 | // painful for constructors. See also |
| 632 | // https://github.com/chromium/subspace/issues/266. |
| 633 | #if defined(__clang__) |
| 634 | #define ENABLE_IF_ATTR(cond, msg) __attribute__((enable_if(cond, msg))) |
| 635 | #else |
| 636 | #define ENABLE_IF_ATTR(cond, msg) |
| 637 | #endif |
| 638 | |
[email protected] | dd9afc0b | 2008-11-21 23:58:09 | [diff] [blame] | 639 | #endif // BASE_COMPILER_SPECIFIC_H_ |