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 /* 13 /* 14 * This macro obfuscates arithmetic on a varia 14 * This macro obfuscates arithmetic on a variable address so that gcc 15 * shouldn't recognize the original var, and m 15 * shouldn't recognize the original var, and make assumptions about it. 16 * 16 * 17 * This is needed because the C standard makes 17 * This is needed because the C standard makes it undefined to do 18 * pointer arithmetic on "objects" outside the 18 * pointer arithmetic on "objects" outside their boundaries and the 19 * gcc optimizers assume this is the case. In 19 * gcc optimizers assume this is the case. In particular they 20 * assume such arithmetic does not wrap. 20 * assume such arithmetic does not wrap. 21 * 21 * 22 * A miscompilation has been observed because 22 * A miscompilation has been observed because of this on PPC. 23 * To work around it we hide the relationship 23 * To work around it we hide the relationship of the pointer and the object 24 * using this macro. 24 * using this macro. 25 * 25 * 26 * Versions of the ppc64 compiler before 4.1 h 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 27 * RELOC_HIDE could trash r30. The bug can be worked around by changing 28 * the inline assembly constraint from =g to = 28 * the inline assembly constraint from =g to =r, in this particular 29 * case either is valid. 29 * case either is valid. 30 */ 30 */ 31 #define RELOC_HIDE(ptr, off) 31 #define RELOC_HIDE(ptr, off) \ 32 ({ 32 ({ \ 33 unsigned long __ptr; 33 unsigned long __ptr; \ 34 __asm__ ("" : "=r"(__ptr) : ""(ptr)); 34 __asm__ ("" : "=r"(__ptr) : ""(ptr)); \ 35 (typeof(ptr)) (__ptr + (off)); 35 (typeof(ptr)) (__ptr + (off)); \ 36 }) 36 }) 37 37 38 #ifdef CONFIG_MITIGATION_RETPOLINE 38 #ifdef CONFIG_MITIGATION_RETPOLINE 39 #define __noretpoline __attribute__((__indirec 39 #define __noretpoline __attribute__((__indirect_branch__("keep"))) 40 #endif 40 #endif 41 41 42 #if defined(LATENT_ENTROPY_PLUGIN) && !defined 42 #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) 43 #define __latent_entropy __attribute__((latent 43 #define __latent_entropy __attribute__((latent_entropy)) 44 #endif 44 #endif 45 45 46 /* 46 /* 47 * calling noreturn functions, __builtin_unrea 47 * calling noreturn functions, __builtin_unreachable() and __builtin_trap() 48 * confuse the stack allocation in gcc, leadin 48 * confuse the stack allocation in gcc, leading to overly large stack 49 * frames, see https://gcc.gnu.org/bugzilla/sh 49 * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 50 * 50 * 51 * Adding an empty inline assembly before it w 51 * Adding an empty inline assembly before it works around the problem 52 */ 52 */ 53 #define barrier_before_unreachable() asm volat 53 #define barrier_before_unreachable() asm volatile("") 54 54 55 /* 55 /* 56 * Mark a position in code as unreachable. Th 56 * Mark a position in code as unreachable. This can be used to 57 * suppress control flow warnings after asm bl 57 * suppress control flow warnings after asm blocks that transfer 58 * control elsewhere. 58 * control elsewhere. 59 */ 59 */ 60 #define unreachable() \ 60 #define unreachable() \ 61 do { 61 do { \ 62 annotate_unreachable(); 62 annotate_unreachable(); \ 63 barrier_before_unreachable(); 63 barrier_before_unreachable(); \ 64 __builtin_unreachable(); 64 __builtin_unreachable(); \ 65 } while (0) 65 } while (0) 66 66 67 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) 67 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) 68 #define __HAVE_BUILTIN_BSWAP32__ 68 #define __HAVE_BUILTIN_BSWAP32__ 69 #define __HAVE_BUILTIN_BSWAP64__ 69 #define __HAVE_BUILTIN_BSWAP64__ 70 #define __HAVE_BUILTIN_BSWAP16__ 70 #define __HAVE_BUILTIN_BSWAP16__ 71 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ 71 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ 72 72 73 #if GCC_VERSION >= 70000 73 #if GCC_VERSION >= 70000 74 #define KASAN_ABI_VERSION 5 74 #define KASAN_ABI_VERSION 5 75 #else 75 #else 76 #define KASAN_ABI_VERSION 4 76 #define KASAN_ABI_VERSION 4 77 #endif 77 #endif 78 78 79 #ifdef CONFIG_SHADOW_CALL_STACK 79 #ifdef CONFIG_SHADOW_CALL_STACK 80 #define __noscs __attribute__((__no_sanitize__ 80 #define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) 81 #endif 81 #endif 82 82 83 #ifdef __SANITIZE_HWADDRESS__ 83 #ifdef __SANITIZE_HWADDRESS__ 84 #define __no_sanitize_address __attribute__((_ 84 #define __no_sanitize_address __attribute__((__no_sanitize__("hwaddress"))) 85 #else 85 #else 86 #define __no_sanitize_address __attribute__((_ 86 #define __no_sanitize_address __attribute__((__no_sanitize_address__)) 87 #endif 87 #endif 88 88 89 #if defined(__SANITIZE_THREAD__) 89 #if defined(__SANITIZE_THREAD__) 90 #define __no_sanitize_thread __attribute__((__ 90 #define __no_sanitize_thread __attribute__((__no_sanitize_thread__)) 91 #else 91 #else 92 #define __no_sanitize_thread 92 #define __no_sanitize_thread 93 #endif 93 #endif 94 94 95 #define __no_sanitize_undefined __attribute__( 95 #define __no_sanitize_undefined __attribute__((__no_sanitize_undefined__)) 96 96 97 /* 97 /* 98 * Only supported since gcc >= 12 98 * Only supported since gcc >= 12 99 */ 99 */ 100 #if defined(CONFIG_KCOV) && __has_attribute(__ 100 #if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__) 101 #define __no_sanitize_coverage __attribute__(( 101 #define __no_sanitize_coverage __attribute__((__no_sanitize_coverage__)) 102 #else 102 #else 103 #define __no_sanitize_coverage 103 #define __no_sanitize_coverage 104 #endif 104 #endif 105 105 106 /* 106 /* 107 * Treat __SANITIZE_HWADDRESS__ the same as __ 107 * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel, 108 * matching the defines used by Clang. 108 * matching the defines used by Clang. 109 */ 109 */ 110 #ifdef __SANITIZE_HWADDRESS__ 110 #ifdef __SANITIZE_HWADDRESS__ 111 #define __SANITIZE_ADDRESS__ 111 #define __SANITIZE_ADDRESS__ 112 #endif 112 #endif 113 113 114 /* 114 /* 115 * GCC does not support KMSAN. 115 * GCC does not support KMSAN. 116 */ 116 */ 117 #define __no_sanitize_memory 117 #define __no_sanitize_memory 118 #define __no_kmsan_checks 118 #define __no_kmsan_checks 119 119 120 /* 120 /* 121 * Turn individual warnings and errors on and 121 * Turn individual warnings and errors on and off locally, depending 122 * on version. 122 * on version. 123 */ 123 */ 124 #define __diag_GCC(version, severity, s) \ 124 #define __diag_GCC(version, severity, s) \ 125 __diag_GCC_ ## version(__diag_GCC_ ## 125 __diag_GCC_ ## version(__diag_GCC_ ## severity s) 126 126 127 /* Severity used in pragma directives */ 127 /* Severity used in pragma directives */ 128 #define __diag_GCC_ignore ignored 128 #define __diag_GCC_ignore ignored 129 #define __diag_GCC_warn warning 129 #define __diag_GCC_warn warning 130 #define __diag_GCC_error error 130 #define __diag_GCC_error error 131 131 132 #define __diag_str1(s) #s 132 #define __diag_str1(s) #s 133 #define __diag_str(s) __diag_str1(s) 133 #define __diag_str(s) __diag_str1(s) 134 #define __diag(s) _Pragma(__diag 134 #define __diag(s) _Pragma(__diag_str(GCC diagnostic s)) 135 135 136 #if GCC_VERSION >= 80000 136 #if GCC_VERSION >= 80000 137 #define __diag_GCC_8(s) __diag(s) 137 #define __diag_GCC_8(s) __diag(s) 138 #else 138 #else 139 #define __diag_GCC_8(s) 139 #define __diag_GCC_8(s) 140 #endif 140 #endif 141 141 142 #define __diag_ignore_all(option, comment) \ 142 #define __diag_ignore_all(option, comment) \ 143 __diag(__diag_GCC_ignore option) 143 __diag(__diag_GCC_ignore option) 144 144 145 /* 145 /* 146 * Prior to 9.1, -Wno-alloc-size-larger-than ( 146 * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size" 147 * attribute) do not work, and must be disable 147 * attribute) do not work, and must be disabled. 148 */ 148 */ 149 #if GCC_VERSION < 90100 149 #if GCC_VERSION < 90100 150 #undef __alloc_size__ 150 #undef __alloc_size__ 151 #endif 151 #endif 152 152
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.