1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_COMPILER_TYPES_H 2 #ifndef __LINUX_COMPILER_TYPES_H 3 #error "Please don't include <linux/compiler-g 3 #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead." 4 #endif 4 #endif 5 5 6 /* 6 /* 7 * Common definitions for all gcc versions go 7 * Common definitions for all gcc versions go here. 8 */ 8 */ 9 #define GCC_VERSION (__GNUC__ * 10000 9 #define GCC_VERSION (__GNUC__ * 10000 \ 10 + __GNUC_MINOR__ * 100 10 + __GNUC_MINOR__ * 100 \ 11 + __GNUC_PATCHLEVEL__) 11 + __GNUC_PATCHLEVEL__) 12 12 >> 13 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 */ >> 14 #if GCC_VERSION < 40900 >> 15 # error Sorry, your version of GCC is too old - please use 4.9 or newer. >> 16 #elif defined(CONFIG_ARM64) && GCC_VERSION < 50100 >> 17 /* >> 18 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 >> 19 * https://lore.kernel.org/r/20210107111841.GN1551@shell.armlinux.org.uk >> 20 */ >> 21 # error Sorry, your version of GCC is too old - please use 5.1 or newer. >> 22 #endif >> 23 13 /* 24 /* 14 * This macro obfuscates arithmetic on a varia 25 * This macro obfuscates arithmetic on a variable address so that gcc 15 * shouldn't recognize the original var, and m 26 * shouldn't recognize the original var, and make assumptions about it. 16 * 27 * 17 * This is needed because the C standard makes 28 * This is needed because the C standard makes it undefined to do 18 * pointer arithmetic on "objects" outside the 29 * pointer arithmetic on "objects" outside their boundaries and the 19 * gcc optimizers assume this is the case. In 30 * gcc optimizers assume this is the case. In particular they 20 * assume such arithmetic does not wrap. 31 * assume such arithmetic does not wrap. 21 * 32 * 22 * A miscompilation has been observed because 33 * A miscompilation has been observed because of this on PPC. 23 * To work around it we hide the relationship 34 * To work around it we hide the relationship of the pointer and the object 24 * using this macro. 35 * using this macro. 25 * 36 * 26 * Versions of the ppc64 compiler before 4.1 h 37 * Versions of the ppc64 compiler before 4.1 had a bug where use of 27 * RELOC_HIDE could trash r30. The bug can be 38 * RELOC_HIDE could trash r30. The bug can be worked around by changing 28 * the inline assembly constraint from =g to = 39 * the inline assembly constraint from =g to =r, in this particular 29 * case either is valid. 40 * case either is valid. 30 */ 41 */ 31 #define RELOC_HIDE(ptr, off) 42 #define RELOC_HIDE(ptr, off) \ 32 ({ 43 ({ \ 33 unsigned long __ptr; 44 unsigned long __ptr; \ 34 __asm__ ("" : "=r"(__ptr) : ""(ptr)); 45 __asm__ ("" : "=r"(__ptr) : ""(ptr)); \ 35 (typeof(ptr)) (__ptr + (off)); 46 (typeof(ptr)) (__ptr + (off)); \ 36 }) 47 }) 37 48 38 #ifdef CONFIG_MITIGATION_RETPOLINE !! 49 #ifdef CONFIG_RETPOLINE 39 #define __noretpoline __attribute__((__indirec 50 #define __noretpoline __attribute__((__indirect_branch__("keep"))) 40 #endif 51 #endif 41 52 >> 53 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) >> 54 >> 55 #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) >> 56 >> 57 #define __compiletime_warning(message) __attribute__((__warning__(message))) >> 58 #define __compiletime_error(message) __attribute__((__error__(message))) >> 59 42 #if defined(LATENT_ENTROPY_PLUGIN) && !defined 60 #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) 43 #define __latent_entropy __attribute__((latent 61 #define __latent_entropy __attribute__((latent_entropy)) 44 #endif 62 #endif 45 63 46 /* 64 /* 47 * calling noreturn functions, __builtin_unrea 65 * calling noreturn functions, __builtin_unreachable() and __builtin_trap() 48 * confuse the stack allocation in gcc, leadin 66 * confuse the stack allocation in gcc, leading to overly large stack 49 * frames, see https://gcc.gnu.org/bugzilla/sh 67 * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 50 * 68 * 51 * Adding an empty inline assembly before it w 69 * Adding an empty inline assembly before it works around the problem 52 */ 70 */ 53 #define barrier_before_unreachable() asm volat 71 #define barrier_before_unreachable() asm volatile("") 54 72 55 /* 73 /* 56 * Mark a position in code as unreachable. Th 74 * Mark a position in code as unreachable. This can be used to 57 * suppress control flow warnings after asm bl 75 * suppress control flow warnings after asm blocks that transfer 58 * control elsewhere. 76 * control elsewhere. 59 */ 77 */ 60 #define unreachable() \ 78 #define unreachable() \ 61 do { 79 do { \ 62 annotate_unreachable(); 80 annotate_unreachable(); \ 63 barrier_before_unreachable(); 81 barrier_before_unreachable(); \ 64 __builtin_unreachable(); 82 __builtin_unreachable(); \ 65 } while (0) 83 } while (0) 66 84 67 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) !! 85 #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) >> 86 #define __randomize_layout __attribute__((randomize_layout)) >> 87 #define __no_randomize_layout __attribute__((no_randomize_layout)) >> 88 /* This anon struct can add padding, so only enable it under randstruct. */ >> 89 #define randomized_struct_fields_start struct { >> 90 #define randomized_struct_fields_end } __randomize_layout; >> 91 #endif >> 92 >> 93 /* >> 94 * GCC 'asm goto' miscompiles certain code sequences: >> 95 * >> 96 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 >> 97 * >> 98 * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. >> 99 * >> 100 * (asm goto is automatically volatile - the naming reflects this.) >> 101 */ >> 102 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) >> 103 >> 104 /* >> 105 * sparse (__CHECKER__) pretends to be gcc, but can't do constant >> 106 * folding in __builtin_bswap*() (yet), so don't set these for it. >> 107 */ >> 108 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__) 68 #define __HAVE_BUILTIN_BSWAP32__ 109 #define __HAVE_BUILTIN_BSWAP32__ 69 #define __HAVE_BUILTIN_BSWAP64__ 110 #define __HAVE_BUILTIN_BSWAP64__ 70 #define __HAVE_BUILTIN_BSWAP16__ 111 #define __HAVE_BUILTIN_BSWAP16__ 71 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ !! 112 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */ 72 113 73 #if GCC_VERSION >= 70000 114 #if GCC_VERSION >= 70000 74 #define KASAN_ABI_VERSION 5 115 #define KASAN_ABI_VERSION 5 75 #else !! 116 #elif GCC_VERSION >= 50000 76 #define KASAN_ABI_VERSION 4 117 #define KASAN_ABI_VERSION 4 >> 118 #elif GCC_VERSION >= 40902 >> 119 #define KASAN_ABI_VERSION 3 77 #endif 120 #endif 78 121 79 #ifdef CONFIG_SHADOW_CALL_STACK !! 122 #if __has_attribute(__no_sanitize_address__) 80 #define __noscs __attribute__((__no_sanitize__ !! 123 #define __no_sanitize_address __attribute__((no_sanitize_address)) 81 #endif << 82 << 83 #ifdef __SANITIZE_HWADDRESS__ << 84 #define __no_sanitize_address __attribute__((_ << 85 #else 124 #else 86 #define __no_sanitize_address __attribute__((_ !! 125 #define __no_sanitize_address 87 #endif 126 #endif 88 127 89 #if defined(__SANITIZE_THREAD__) !! 128 #if defined(__SANITIZE_THREAD__) && __has_attribute(__no_sanitize_thread__) 90 #define __no_sanitize_thread __attribute__((__ !! 129 #define __no_sanitize_thread __attribute__((no_sanitize_thread)) 91 #else 130 #else 92 #define __no_sanitize_thread 131 #define __no_sanitize_thread 93 #endif 132 #endif 94 133 95 #define __no_sanitize_undefined __attribute__( !! 134 #if __has_attribute(__no_sanitize_undefined__) 96 !! 135 #define __no_sanitize_undefined __attribute__((no_sanitize_undefined)) 97 /* << 98 * Only supported since gcc >= 12 << 99 */ << 100 #if defined(CONFIG_KCOV) && __has_attribute(__ << 101 #define __no_sanitize_coverage __attribute__(( << 102 #else 136 #else 103 #define __no_sanitize_coverage !! 137 #define __no_sanitize_undefined 104 #endif 138 #endif 105 139 106 /* !! 140 #if GCC_VERSION >= 50100 107 * Treat __SANITIZE_HWADDRESS__ the same as __ !! 141 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 108 * matching the defines used by Clang. << 109 */ << 110 #ifdef __SANITIZE_HWADDRESS__ << 111 #define __SANITIZE_ADDRESS__ << 112 #endif 142 #endif 113 143 114 /* 144 /* 115 * GCC does not support KMSAN. << 116 */ << 117 #define __no_sanitize_memory << 118 #define __no_kmsan_checks << 119 << 120 /* << 121 * Turn individual warnings and errors on and 145 * Turn individual warnings and errors on and off locally, depending 122 * on version. 146 * on version. 123 */ 147 */ 124 #define __diag_GCC(version, severity, s) \ 148 #define __diag_GCC(version, severity, s) \ 125 __diag_GCC_ ## version(__diag_GCC_ ## 149 __diag_GCC_ ## version(__diag_GCC_ ## severity s) 126 150 127 /* Severity used in pragma directives */ 151 /* Severity used in pragma directives */ 128 #define __diag_GCC_ignore ignored 152 #define __diag_GCC_ignore ignored 129 #define __diag_GCC_warn warning 153 #define __diag_GCC_warn warning 130 #define __diag_GCC_error error 154 #define __diag_GCC_error error 131 155 132 #define __diag_str1(s) #s 156 #define __diag_str1(s) #s 133 #define __diag_str(s) __diag_str1(s) 157 #define __diag_str(s) __diag_str1(s) 134 #define __diag(s) _Pragma(__diag 158 #define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) 135 159 136 #if GCC_VERSION >= 80000 160 #if GCC_VERSION >= 80000 137 #define __diag_GCC_8(s) __diag(s) 161 #define __diag_GCC_8(s) __diag(s) 138 #else 162 #else 139 #define __diag_GCC_8(s) 163 #define __diag_GCC_8(s) 140 #endif << 141 << 142 #define __diag_ignore_all(option, comment) \ << 143 __diag(__diag_GCC_ignore option) << 144 << 145 /* << 146 * Prior to 9.1, -Wno-alloc-size-larger-than ( << 147 * attribute) do not work, and must be disable << 148 */ << 149 #if GCC_VERSION < 90100 << 150 #undef __alloc_size__ << 151 #endif 164 #endif 152 165
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.