Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'compiler-attributes-for-linus-4.20-rc1' of https://github.com/ojeda/linux

Pull compiler attribute updates from Miguel Ojeda:
"This is an effort to disentangle the include/linux/compiler*.h headers
and bring them up to date.

The main idea behind the series is to use feature checking macros
(i.e. __has_attribute) instead of compiler version checks (e.g.
GCC_VERSION), which are compiler-agnostic (so they can be shared,
reducing the size of compiler-specific headers) and version-agnostic.

Other related improvements have been performed in the headers as well,
which on top of the use of __has_attribute it has amounted to a
significant simplification of these headers (e.g. GCC_VERSION is now
only guarding a few non-attribute macros).

This series should also help the efforts to support compiling the
kernel with clang and icc. A fair amount of documentation and comments
have also been added, clarified or removed; and the headers are now
more readable, which should help kernel developers in general.

The series was triggered due to the move to gcc >= 4.6. In turn, this
series has also triggered Sparse to gain the ability to recognize
__has_attribute on its own.

Finally, the __nonstring variable attribute series has been also
applied on top; plus two related patches from Nick Desaulniers for
unreachable() that came a bit afterwards"

* tag 'compiler-attributes-for-linus-4.20-rc1' of https://github.com/ojeda/linux:
compiler-gcc: remove comment about gcc 4.5 from unreachable()
compiler.h: update definition of unreachable()
Compiler Attributes: ext4: remove local __nonstring definition
Compiler Attributes: auxdisplay: panel: use __nonstring
Compiler Attributes: enable -Wstringop-truncation on W=1 (gcc >= 8)
Compiler Attributes: add support for __nonstring (gcc >= 8)
Compiler Attributes: add MAINTAINERS entry
Compiler Attributes: add Doc/process/programming-language.rst
Compiler Attributes: remove uses of __attribute__ from compiler.h
Compiler Attributes: KENTRY used twice the "used" attribute
Compiler Attributes: use feature checks instead of version checks
Compiler Attributes: add missing SPDX ID in compiler_types.h
Compiler Attributes: remove unneeded sparse (__CHECKER__) tests
Compiler Attributes: homogenize __must_be_array
Compiler Attributes: remove unneeded tests
Compiler Attributes: always use the extra-underscores syntax
Compiler Attributes: remove unused attributes

+348 -191
+1
Documentation/process/index.rst
··· 25 25 code-of-conduct-interpretation 26 26 development-process 27 27 submitting-patches 28 + programming-language 28 29 coding-style 29 30 maintainer-pgp-guide 30 31 email-clients
+45
Documentation/process/programming-language.rst
··· 1 + .. _programming_language: 2 + 3 + Programming Language 4 + ==================== 5 + 6 + The kernel is written in the C programming language [c-language]_. 7 + More precisely, the kernel is typically compiled with ``gcc`` [gcc]_ 8 + under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90 9 + (including some C99 features). 10 + 11 + This dialect contains many extensions to the language [gnu-extensions]_, 12 + and many of them are used within the kernel as a matter of course. 13 + 14 + There is some support for compiling the kernel with ``clang`` [clang]_ 15 + and ``icc`` [icc]_ for several of the architectures, although at the time 16 + of writing it is not completed, requiring third-party patches. 17 + 18 + Attributes 19 + ---------- 20 + 21 + One of the common extensions used throughout the kernel are attributes 22 + [gcc-attribute-syntax]_. Attributes allow to introduce 23 + implementation-defined semantics to language entities (like variables, 24 + functions or types) without having to make significant syntactic changes 25 + to the language (e.g. adding a new keyword) [n2049]_. 26 + 27 + In some cases, attributes are optional (i.e. a compiler not supporting them 28 + should still produce proper code, even if it is slower or does not perform 29 + as many compile-time checks/diagnostics). 30 + 31 + The kernel defines pseudo-keywords (e.g. ``__pure``) instead of using 32 + directly the GNU attribute syntax (e.g. ``__attribute__((__pure__))``) 33 + in order to feature detect which ones can be used and/or to shorten the code. 34 + 35 + Please refer to ``include/linux/compiler_attributes.h`` for more information. 36 + 37 + .. [c-language] http://www.open-std.org/jtc1/sc22/wg14/www/standards 38 + .. [gcc] https://gcc.gnu.org 39 + .. [clang] https://clang.llvm.org 40 + .. [icc] https://software.intel.com/en-us/c-compilers 41 + .. [gcc-c-dialect-options] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html 42 + .. [gnu-extensions] https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html 43 + .. [gcc-attribute-syntax] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 44 + .. [n2049] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2049.pdf 45 +
+5
MAINTAINERS
··· 3737 3737 S: Maintained 3738 3738 F: drivers/platform/x86/compal-laptop.c 3739 3739 3740 + COMPILER ATTRIBUTES 3741 + M: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> 3742 + S: Maintained 3743 + F: include/linux/compiler_attributes.h 3744 + 3740 3745 CONEXANT ACCESSRUNNER USB DRIVER 3741 3746 L: accessrunner-general@lists.sourceforge.net 3742 3747 W: http://accessrunner.sourceforge.net/
+3 -4
drivers/auxdisplay/panel.c
··· 155 155 int release_data; 156 156 } std; 157 157 struct { /* valid when type == INPUT_TYPE_KBD */ 158 - /* strings can be non null-terminated */ 159 - char press_str[sizeof(void *) + sizeof(int)]; 160 - char repeat_str[sizeof(void *) + sizeof(int)]; 161 - char release_str[sizeof(void *) + sizeof(int)]; 158 + char press_str[sizeof(void *) + sizeof(int)] __nonstring; 159 + char repeat_str[sizeof(void *) + sizeof(int)] __nonstring; 160 + char release_str[sizeof(void *) + sizeof(int)] __nonstring; 162 161 } kbd; 163 162 } u; 164 163 };
-9
fs/ext4/ext4.h
··· 45 45 46 46 #include <linux/compiler.h> 47 47 48 - /* Until this gets included into linux/compiler-gcc.h */ 49 - #ifndef __nonstring 50 - #if defined(GCC_VERSION) && (GCC_VERSION >= 80000) 51 - #define __nonstring __attribute__((nonstring)) 52 - #else 53 - #define __nonstring 54 - #endif 55 - #endif 56 - 57 48 /* 58 49 * The fourth extended filesystem constants/structures 59 50 */
-5
include/linux/compiler-clang.h
··· 21 21 #define __SANITIZE_ADDRESS__ 22 22 #endif 23 23 24 - #define __no_sanitize_address __attribute__((no_sanitize("address"))) 25 - 26 24 /* 27 25 * Not all versions of clang implement the the type-generic versions 28 26 * of the builtin overflow checkers. Fortunately, clang implements ··· 39 41 * compilers, like ICC. 40 42 */ 41 43 #define barrier() __asm__ __volatile__("" : : : "memory") 42 - #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 43 - #define __assume_aligned(a, ...) \ 44 - __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
+7 -68
include/linux/compiler-gcc.h
··· 68 68 */ 69 69 #define uninitialized_var(x) x = x 70 70 71 - #ifdef __CHECKER__ 72 - #define __must_be_array(a) 0 73 - #else 74 - /* &a[0] degrades to a pointer: a different type from an array */ 75 - #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 76 - #endif 77 - 78 71 #ifdef RETPOLINE 79 - #define __noretpoline __attribute__((indirect_branch("keep"))) 72 + #define __noretpoline __attribute__((__indirect_branch__("keep"))) 80 73 #endif 81 74 82 75 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) 83 76 84 - #define __optimize(level) __attribute__((__optimize__(level))) 85 - 86 77 #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) 87 78 88 - #ifndef __CHECKER__ 89 - #define __compiletime_warning(message) __attribute__((warning(message))) 90 - #define __compiletime_error(message) __attribute__((error(message))) 79 + #define __compiletime_warning(message) __attribute__((__warning__(message))) 80 + #define __compiletime_error(message) __attribute__((__error__(message))) 91 81 92 - #ifdef LATENT_ENTROPY_PLUGIN 82 + #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) 93 83 #define __latent_entropy __attribute__((latent_entropy)) 94 84 #endif 95 - #endif /* __CHECKER__ */ 96 85 97 86 /* 98 87 * calling noreturn functions, __builtin_unreachable() and __builtin_trap() ··· 96 107 * Mark a position in code as unreachable. This can be used to 97 108 * suppress control flow warnings after asm blocks that transfer 98 109 * control elsewhere. 99 - * 100 - * Early snapshots of gcc 4.5 don't support this and we can't detect 101 - * this in the preprocessor, but we can live with this because they're 102 - * unreleased. Really, we need to have autoconf for the kernel. 103 110 */ 104 111 #define unreachable() \ 105 112 do { \ ··· 104 119 __builtin_unreachable(); \ 105 120 } while (0) 106 121 107 - /* Mark a function definition as prohibited from being cloned. */ 108 - #define __noclone __attribute__((__noclone__, __optimize__("no-tracer"))) 109 - 110 122 #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) 111 123 #define __randomize_layout __attribute__((randomize_layout)) 112 124 #define __no_randomize_layout __attribute__((no_randomize_layout)) 113 125 /* This anon struct can add padding, so only enable it under randstruct. */ 114 126 #define randomized_struct_fields_start struct { 115 127 #define randomized_struct_fields_end } __randomize_layout; 116 - #endif 117 - 118 - /* 119 - * When used with Link Time Optimization, gcc can optimize away C functions or 120 - * variables which are referenced only from assembly code. __visible tells the 121 - * optimizer that something else uses this function or variable, thus preventing 122 - * this. 123 - */ 124 - #define __visible __attribute__((externally_visible)) 125 - 126 - /* gcc version specific checks */ 127 - 128 - #if GCC_VERSION >= 40900 && !defined(__CHECKER__) 129 - /* 130 - * __assume_aligned(n, k): Tell the optimizer that the returned 131 - * pointer can be assumed to be k modulo n. The second argument is 132 - * optional (default 0), so we use a variadic macro to make the 133 - * shorthand. 134 - * 135 - * Beware: Do not apply this to functions which may return 136 - * ERR_PTRs. Also, it is probably unwise to apply it to functions 137 - * returning extra information in the low bits (but in that case the 138 - * compiler should see some alignment anyway, when the return value is 139 - * massaged by 'flags = ptr & 3; ptr &= ~3;'). 140 - */ 141 - #define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) 142 128 #endif 143 129 144 130 /* ··· 143 187 #define KASAN_ABI_VERSION 3 144 188 #endif 145 189 146 - #if GCC_VERSION >= 40902 147 190 /* 148 - * Tell the compiler that address safety instrumentation (KASAN) 149 - * should not be applied to that function. 150 - * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 191 + * Because __no_sanitize_address conflicts with inlining: 192 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 193 + * we do one or the other. 151 194 */ 152 - #define __no_sanitize_address __attribute__((no_sanitize_address)) 153 195 #ifdef CONFIG_KASAN 154 196 #define __no_sanitize_address_or_inline \ 155 197 __no_sanitize_address __maybe_unused notrace 156 198 #else 157 199 #define __no_sanitize_address_or_inline inline 158 200 #endif 159 - #endif 160 201 161 202 #if GCC_VERSION >= 50100 162 - /* 163 - * Mark structures as requiring designated initializers. 164 - * https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html 165 - */ 166 - #define __designated_init __attribute__((designated_init)) 167 203 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 168 - #endif 169 - 170 - #if !defined(__noclone) 171 - #define __noclone /* not needed */ 172 - #endif 173 - 174 - #if !defined(__no_sanitize_address) 175 - #define __no_sanitize_address 176 - #define __no_sanitize_address_or_inline inline 177 204 #endif 178 205 179 206 /*
-9
include/linux/compiler-intel.h
··· 29 29 */ 30 30 #define OPTIMIZER_HIDE_VAR(var) barrier() 31 31 32 - /* Intel ECC compiler doesn't support __builtin_types_compatible_p() */ 33 - #define __must_be_array(a) 0 34 - 35 32 #endif 36 33 37 34 /* icc has this, but it's called _bswap16 */ 38 35 #define __HAVE_BUILTIN_BSWAP16__ 39 36 #define __builtin_bswap16 _bswap16 40 - 41 - /* The following are for compatibility with GCC, from compiler-gcc.h, 42 - * and may be redefined here because they should not be shared with other 43 - * compilers, like clang. 44 - */ 45 - #define __visible __attribute__((externally_visible))
+13 -11
include/linux/compiler.h
··· 23 23 #define __branch_check__(x, expect, is_constant) ({ \ 24 24 long ______r; \ 25 25 static struct ftrace_likely_data \ 26 - __attribute__((__aligned__(4))) \ 27 - __attribute__((section("_ftrace_annotated_branch"))) \ 26 + __aligned(4) \ 27 + __section("_ftrace_annotated_branch") \ 28 28 ______f = { \ 29 29 .data.func = __func__, \ 30 30 .data.file = __FILE__, \ ··· 59 59 ({ \ 60 60 int ______r; \ 61 61 static struct ftrace_branch_data \ 62 - __attribute__((__aligned__(4))) \ 63 - __attribute__((section("_ftrace_branch"))) \ 62 + __aligned(4) \ 63 + __section("_ftrace_branch") \ 64 64 ______f = { \ 65 65 .func = __func__, \ 66 66 .file = __FILE__, \ ··· 115 115 # define ASM_UNREACHABLE 116 116 #endif 117 117 #ifndef unreachable 118 - # define unreachable() do { annotate_reachable(); do { } while (1); } while (0) 118 + # define unreachable() do { \ 119 + annotate_unreachable(); \ 120 + __builtin_unreachable(); \ 121 + } while (0) 119 122 #endif 120 123 121 124 /* ··· 140 137 extern typeof(sym) sym; \ 141 138 static const unsigned long __kentry_##sym \ 142 139 __used \ 143 - __attribute__((section("___kentry" "+" #sym ), used)) \ 140 + __section("___kentry" "+" #sym ) \ 144 141 = (unsigned long)&sym; 145 142 #endif 146 143 ··· 281 278 * visible to the compiler. 282 279 */ 283 280 #define __ADDRESSABLE(sym) \ 284 - static void * __attribute__((section(".discard.addressable"), used)) \ 281 + static void * __section(".discard.addressable") __used \ 285 282 __PASTE(__addressable_##sym, __LINE__) = (void *)&sym; 286 283 287 284 /** ··· 334 331 #endif /* __KERNEL__ */ 335 332 #endif /* __ASSEMBLY__ */ 336 333 337 - #ifndef __optimize 338 - # define __optimize(level) 339 - #endif 340 - 341 334 /* Compile time object size, -1 for unknown */ 342 335 #ifndef __compiletime_object_size 343 336 # define __compiletime_object_size(obj) -1 ··· 374 375 #define compiletime_assert_atomic_type(t) \ 375 376 compiletime_assert(__native_word(t), \ 376 377 "Need native word sized stores/loads for atomicity.") 378 + 379 + /* &a[0] degrades to a pointer: a different type from an array */ 380 + #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) 377 381 378 382 #endif /* __LINUX_COMPILER_H */
+258
include/linux/compiler_attributes.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __LINUX_COMPILER_ATTRIBUTES_H 3 + #define __LINUX_COMPILER_ATTRIBUTES_H 4 + 5 + /* 6 + * The attributes in this file are unconditionally defined and they directly 7 + * map to compiler attribute(s) -- except those that are optional. 8 + * 9 + * Any other "attributes" (i.e. those that depend on a configuration option, 10 + * on a compiler, on an architecture, on plugins, on other attributes...) 11 + * should be defined elsewhere (e.g. compiler_types.h or compiler-*.h). 12 + * 13 + * This file is meant to be sorted (by actual attribute name, 14 + * not by #define identifier). Use the __attribute__((__name__)) syntax 15 + * (i.e. with underscores) to avoid future collisions with other macros. 16 + * If an attribute is optional, state the reason in the comment. 17 + */ 18 + 19 + /* 20 + * To check for optional attributes, we use __has_attribute, which is supported 21 + * on gcc >= 5, clang >= 2.9 and icc >= 17. In the meantime, to support 22 + * 4.6 <= gcc < 5, we implement __has_attribute by hand. 23 + * 24 + * sparse does not support __has_attribute (yet) and defines __GNUC_MINOR__ 25 + * depending on the compiler used to build it; however, these attributes have 26 + * no semantic effects for sparse, so it does not matter. Also note that, 27 + * in order to avoid sparse's warnings, even the unsupported ones must be 28 + * defined to 0. 29 + */ 30 + #ifndef __has_attribute 31 + # define __has_attribute(x) __GCC4_has_attribute_##x 32 + # define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9) 33 + # define __GCC4_has_attribute___designated_init__ 0 34 + # define __GCC4_has_attribute___externally_visible__ 1 35 + # define __GCC4_has_attribute___noclone__ 1 36 + # define __GCC4_has_attribute___optimize__ 1 37 + # define __GCC4_has_attribute___nonstring__ 0 38 + # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) 39 + #endif 40 + 41 + /* 42 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute 43 + */ 44 + #define __alias(symbol) __attribute__((__alias__(#symbol))) 45 + 46 + /* 47 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute 48 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute 49 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute 50 + */ 51 + #define __aligned(x) __attribute__((__aligned__(x))) 52 + #define __aligned_largest __attribute__((__aligned__)) 53 + 54 + /* 55 + * Note: users of __always_inline currently do not write "inline" themselves, 56 + * which seems to be required by gcc to apply the attribute according 57 + * to its docs (and also "warning: always_inline function might not be 58 + * inlinable [-Wattributes]" is emitted). 59 + * 60 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute 61 + * clang: mentioned 62 + */ 63 + #define __always_inline inline __attribute__((__always_inline__)) 64 + 65 + /* 66 + * The second argument is optional (default 0), so we use a variadic macro 67 + * to make the shorthand. 68 + * 69 + * Beware: Do not apply this to functions which may return 70 + * ERR_PTRs. Also, it is probably unwise to apply it to functions 71 + * returning extra information in the low bits (but in that case the 72 + * compiler should see some alignment anyway, when the return value is 73 + * massaged by 'flags = ptr & 3; ptr &= ~3;'). 74 + * 75 + * Optional: only supported since gcc >= 4.9 76 + * Optional: not supported by icc 77 + * 78 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-assume_005faligned-function-attribute 79 + * clang: https://clang.llvm.org/docs/AttributeReference.html#assume-aligned 80 + */ 81 + #if __has_attribute(__assume_aligned__) 82 + # define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) 83 + #else 84 + # define __assume_aligned(a, ...) 85 + #endif 86 + 87 + /* 88 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-cold-function-attribute 89 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute 90 + */ 91 + #define __cold __attribute__((__cold__)) 92 + 93 + /* 94 + * Note the long name. 95 + * 96 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute 97 + */ 98 + #define __attribute_const__ __attribute__((__const__)) 99 + 100 + /* 101 + * Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated' 102 + * attribute warnings entirely and for good") for more information. 103 + * 104 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute 105 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-deprecated-type-attribute 106 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-deprecated-variable-attribute 107 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html#index-deprecated-enumerator-attribute 108 + * clang: https://clang.llvm.org/docs/AttributeReference.html#deprecated 109 + */ 110 + #define __deprecated 111 + 112 + /* 113 + * Optional: only supported since gcc >= 5.1 114 + * Optional: not supported by clang 115 + * Optional: not supported by icc 116 + * 117 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-designated_005finit-type-attribute 118 + */ 119 + #if __has_attribute(__designated_init__) 120 + # define __designated_init __attribute__((__designated_init__)) 121 + #else 122 + # define __designated_init 123 + #endif 124 + 125 + /* 126 + * Optional: not supported by clang 127 + * 128 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute 129 + */ 130 + #if __has_attribute(__externally_visible__) 131 + # define __visible __attribute__((__externally_visible__)) 132 + #else 133 + # define __visible 134 + #endif 135 + 136 + /* 137 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute 138 + * clang: https://clang.llvm.org/docs/AttributeReference.html#format 139 + */ 140 + #define __printf(a, b) __attribute__((__format__(printf, a, b))) 141 + #define __scanf(a, b) __attribute__((__format__(scanf, a, b))) 142 + 143 + /* 144 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-gnu_005finline-function-attribute 145 + * clang: https://clang.llvm.org/docs/AttributeReference.html#gnu-inline 146 + */ 147 + #define __gnu_inline __attribute__((__gnu_inline__)) 148 + 149 + /* 150 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute 151 + */ 152 + #define __malloc __attribute__((__malloc__)) 153 + 154 + /* 155 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-mode-type-attribute 156 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-mode-variable-attribute 157 + */ 158 + #define __mode(x) __attribute__((__mode__(x))) 159 + 160 + /* 161 + * Optional: not supported by clang 162 + * Note: icc does not recognize gcc's no-tracer 163 + * 164 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noclone-function-attribute 165 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-optimize-function-attribute 166 + */ 167 + #if __has_attribute(__noclone__) 168 + # if __has_attribute(__optimize__) 169 + # define __noclone __attribute__((__noclone__, __optimize__("no-tracer"))) 170 + # else 171 + # define __noclone __attribute__((__noclone__)) 172 + # endif 173 + #else 174 + # define __noclone 175 + #endif 176 + 177 + /* 178 + * Note the missing underscores. 179 + * 180 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute 181 + * clang: mentioned 182 + */ 183 + #define noinline __attribute__((__noinline__)) 184 + 185 + /* 186 + * Optional: only supported since gcc >= 8 187 + * Optional: not supported by clang 188 + * Optional: not supported by icc 189 + * 190 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute 191 + */ 192 + #if __has_attribute(__nonstring__) 193 + # define __nonstring __attribute__((__nonstring__)) 194 + #else 195 + # define __nonstring 196 + #endif 197 + 198 + /* 199 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute 200 + * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn 201 + * clang: https://clang.llvm.org/docs/AttributeReference.html#id1 202 + */ 203 + #define __noreturn __attribute__((__noreturn__)) 204 + 205 + /* 206 + * Optional: only supported since gcc >= 4.8 207 + * Optional: not supported by icc 208 + * 209 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fsanitize_005faddress-function-attribute 210 + * clang: https://clang.llvm.org/docs/AttributeReference.html#no-sanitize-address-no-address-safety-analysis 211 + */ 212 + #if __has_attribute(__no_sanitize_address__) 213 + # define __no_sanitize_address __attribute__((__no_sanitize_address__)) 214 + #else 215 + # define __no_sanitize_address 216 + #endif 217 + 218 + /* 219 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute 220 + * clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute 221 + */ 222 + #define __packed __attribute__((__packed__)) 223 + 224 + /* 225 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute 226 + */ 227 + #define __pure __attribute__((__pure__)) 228 + 229 + /* 230 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute 231 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute 232 + * clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate 233 + */ 234 + #define __section(S) __attribute__((__section__(#S))) 235 + 236 + /* 237 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute 238 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-unused-type-attribute 239 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-unused-variable-attribute 240 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-unused-label-attribute 241 + * clang: https://clang.llvm.org/docs/AttributeReference.html#maybe-unused-unused 242 + */ 243 + #define __always_unused __attribute__((__unused__)) 244 + #define __maybe_unused __attribute__((__unused__)) 245 + 246 + /* 247 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-used-function-attribute 248 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-used-variable-attribute 249 + */ 250 + #define __used __attribute__((__used__)) 251 + 252 + /* 253 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute 254 + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute 255 + */ 256 + #define __weak __attribute__((__weak__)) 257 + 258 + #endif /* __LINUX_COMPILER_ATTRIBUTES_H */
+15 -85
include/linux/compiler_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef __LINUX_COMPILER_TYPES_H 2 3 #define __LINUX_COMPILER_TYPES_H 3 4 ··· 55 54 56 55 #ifdef __KERNEL__ 57 56 57 + /* Attributes */ 58 + #include <linux/compiler_attributes.h> 59 + 58 60 /* Compiler specific macros. */ 59 61 #ifdef __clang__ 60 62 #include <linux/compiler-clang.h> ··· 82 78 #include <asm/compiler.h> 83 79 #endif 84 80 85 - /* 86 - * Generic compiler-independent macros required for kernel 87 - * build go below this comment. Actual compiler/compiler version 88 - * specific implementations come from the above header files 89 - */ 90 - 91 81 struct ftrace_branch_data { 92 82 const char *func; 93 83 const char *file; ··· 104 106 unsigned long constant; 105 107 }; 106 108 107 - /* Don't. Just don't. */ 108 - #define __deprecated 109 - #define __deprecated_for_modules 110 - 111 109 #endif /* __KERNEL__ */ 112 110 113 111 #endif /* __ASSEMBLY__ */ ··· 113 119 * compilers. We don't consider that to be an error, so set them to nothing. 114 120 * For example, some of them are for compiler specific plugins. 115 121 */ 116 - #ifndef __designated_init 117 - # define __designated_init 118 - #endif 119 - 120 122 #ifndef __latent_entropy 121 123 # define __latent_entropy 122 124 #endif ··· 130 140 # define randomized_struct_fields_end 131 141 #endif 132 142 133 - #ifndef __visible 134 - #define __visible 135 - #endif 136 - 137 - /* 138 - * Assume alignment of return value. 139 - */ 140 - #ifndef __assume_aligned 141 - #define __assume_aligned(a, ...) 142 - #endif 143 - 144 143 /* Are two types/vars the same type (ignoring qualifiers)? */ 145 144 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) 146 145 ··· 137 158 #define __native_word(t) \ 138 159 (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ 139 160 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) 140 - 141 - #ifndef __attribute_const__ 142 - #define __attribute_const__ __attribute__((__const__)) 143 - #endif 144 - 145 - #ifndef __noclone 146 - #define __noclone 147 - #endif 148 161 149 162 /* Helpers for emitting diagnostics in pragmas. */ 150 163 #ifndef __diag ··· 157 186 #define __diag_error(compiler, version, option, comment) \ 158 187 __diag_ ## compiler(version, error, option) 159 188 160 - /* 161 - * From the GCC manual: 162 - * 163 - * Many functions have no effects except the return value and their 164 - * return value depends only on the parameters and/or global 165 - * variables. Such a function can be subject to common subexpression 166 - * elimination and loop optimization just as an arithmetic operator 167 - * would be. 168 - * [...] 169 - */ 170 - #define __pure __attribute__((pure)) 171 - #define __aligned(x) __attribute__((aligned(x))) 172 - #define __printf(a, b) __attribute__((format(printf, a, b))) 173 - #define __scanf(a, b) __attribute__((format(scanf, a, b))) 174 - #define __maybe_unused __attribute__((unused)) 175 - #define __always_unused __attribute__((unused)) 176 - #define __mode(x) __attribute__((mode(x))) 177 - #define __malloc __attribute__((__malloc__)) 178 - #define __used __attribute__((__used__)) 179 - #define __noreturn __attribute__((noreturn)) 180 - #define __packed __attribute__((packed)) 181 - #define __weak __attribute__((weak)) 182 - #define __alias(symbol) __attribute__((alias(#symbol))) 183 - #define __cold __attribute__((cold)) 184 - #define __section(S) __attribute__((__section__(#S))) 185 - 186 - 187 189 #ifdef CONFIG_ENABLE_MUST_CHECK 188 - #define __must_check __attribute__((warn_unused_result)) 190 + #define __must_check __attribute__((__warn_unused_result__)) 189 191 #else 190 192 #define __must_check 191 193 #endif 192 194 193 - #if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__) 195 + #if defined(CC_USING_HOTPATCH) 194 196 #define notrace __attribute__((hotpatch(0, 0))) 195 197 #else 196 - #define notrace __attribute__((no_instrument_function)) 198 + #define notrace __attribute__((__no_instrument_function__)) 197 199 #endif 198 200 199 201 /* ··· 175 231 * stack and frame pointer being set up and there is no chance to 176 232 * restore the lr register to the value before mcount was called. 177 233 */ 178 - #define __naked __attribute__((naked)) notrace 234 + #define __naked __attribute__((__naked__)) notrace 179 235 180 236 #define __compiler_offsetof(a, b) __builtin_offsetof(a, b) 181 - 182 - /* 183 - * Feature detection for gnu_inline (gnu89 extern inline semantics). Either 184 - * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics, 185 - * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not 186 - * defined so the gnu89 semantics are the default. 187 - */ 188 - #ifdef __GNUC_STDC_INLINE__ 189 - # define __gnu_inline __attribute__((gnu_inline)) 190 - #else 191 - # define __gnu_inline 192 - #endif 193 237 194 238 /* 195 239 * Force always-inline if the user requests it so via the .config. ··· 190 258 * semantics rather than c99. This prevents multiple symbol definition errors 191 259 * of extern inline functions at link time. 192 260 * A lot of inline functions can cause havoc with function tracing. 261 + * Do not use __always_inline here, since currently it expands to inline again 262 + * (which would break users of __always_inline). 193 263 */ 194 264 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ 195 265 !defined(CONFIG_OPTIMIZE_INLINING) 196 - #define inline \ 197 - inline __attribute__((always_inline, unused)) notrace __gnu_inline 266 + #define inline inline __attribute__((__always_inline__)) __gnu_inline \ 267 + __maybe_unused notrace 198 268 #else 199 - #define inline inline __attribute__((unused)) notrace __gnu_inline 269 + #define inline inline __gnu_inline \ 270 + __maybe_unused notrace 200 271 #endif 201 272 202 273 #define __inline__ inline 203 - #define __inline inline 204 - #define noinline __attribute__((noinline)) 205 - 206 - #ifndef __always_inline 207 - #define __always_inline inline __attribute__((always_inline)) 208 - #endif 274 + #define __inline inline 209 275 210 276 /* 211 277 * Rather then using noinline to prevent stack consumption, use
+1
scripts/Makefile.extrawarn
··· 29 29 warning-1 += $(call cc-option, -Wunused-but-set-variable) 30 30 warning-1 += $(call cc-option, -Wunused-const-variable) 31 31 warning-1 += $(call cc-option, -Wpacked-not-aligned) 32 + warning-1 += $(call cc-option, -Wstringop-truncation) 32 33 warning-1 += $(call cc-disable-warning, missing-field-initializers) 33 34 warning-1 += $(call cc-disable-warning, sign-compare) 34 35