diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-11-01 21:34:46 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-11-01 21:34:46 -0400 |
| commit | e468f5c06b5ebef3f6f3c187e51aa6daab667e57 (patch) | |
| tree | be59927a66ffdf5dec86154a2ccb4ea51602450e | |
| parent | baa888d25ea64d0c59344d474284ca99cfdd449a (diff) | |
| parent | 1ff2fea5e30ca15752777441ecb64a169fe22e9e (diff) | |
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
| -rw-r--r-- | Documentation/process/index.rst | 1 | ||||
| -rw-r--r-- | Documentation/process/programming-language.rst | 45 | ||||
| -rw-r--r-- | MAINTAINERS | 5 | ||||
| -rw-r--r-- | drivers/auxdisplay/panel.c | 7 | ||||
| -rw-r--r-- | fs/ext4/ext4.h | 9 | ||||
| -rw-r--r-- | include/linux/compiler-clang.h | 5 | ||||
| -rw-r--r-- | include/linux/compiler-gcc.h | 75 | ||||
| -rw-r--r-- | include/linux/compiler-intel.h | 9 | ||||
| -rw-r--r-- | include/linux/compiler.h | 24 | ||||
| -rw-r--r-- | include/linux/compiler_attributes.h | 258 | ||||
| -rw-r--r-- | include/linux/compiler_types.h | 100 | ||||
| -rw-r--r-- | scripts/Makefile.extrawarn | 1 |
12 files changed, 348 insertions, 191 deletions
diff --git a/Documentation/process/index.rst b/Documentation/process/index.rst index 757808526d9a..878ebfda7eef 100644 --- a/Documentation/process/index.rst +++ b/Documentation/process/index.rst | |||
| @@ -25,6 +25,7 @@ Below are the essential guides that every developer should read. | |||
| 25 | code-of-conduct-interpretation | 25 | code-of-conduct-interpretation |
| 26 | development-process | 26 | development-process |
| 27 | submitting-patches | 27 | submitting-patches |
| 28 | programming-language | ||
| 28 | coding-style | 29 | coding-style |
| 29 | maintainer-pgp-guide | 30 | maintainer-pgp-guide |
| 30 | email-clients | 31 | email-clients |
diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst new file mode 100644 index 000000000000..e5f5f065dc24 --- /dev/null +++ b/Documentation/process/programming-language.rst | |||
| @@ -0,0 +1,45 @@ | |||
| 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 | |||
diff --git a/MAINTAINERS b/MAINTAINERS index bb97067d0568..f4855974f325 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -3737,6 +3737,11 @@ L: platform-driver-x86@vger.kernel.org | |||
| 3737 | S: Maintained | 3737 | S: Maintained |
| 3738 | F: drivers/platform/x86/compal-laptop.c | 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 | CONEXANT ACCESSRUNNER USB DRIVER | 3745 | CONEXANT ACCESSRUNNER USB DRIVER |
| 3741 | L: accessrunner-general@lists.sourceforge.net | 3746 | L: accessrunner-general@lists.sourceforge.net |
| 3742 | W: http://accessrunner.sourceforge.net/ | 3747 | W: http://accessrunner.sourceforge.net/ |
diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c index 3b25a643058c..21b9b2f2470a 100644 --- a/drivers/auxdisplay/panel.c +++ b/drivers/auxdisplay/panel.c | |||
| @@ -155,10 +155,9 @@ struct logical_input { | |||
| 155 | int release_data; | 155 | int release_data; |
| 156 | } std; | 156 | } std; |
| 157 | struct { /* valid when type == INPUT_TYPE_KBD */ | 157 | struct { /* valid when type == INPUT_TYPE_KBD */ |
| 158 | /* strings can be non null-terminated */ | 158 | char press_str[sizeof(void *) + sizeof(int)] __nonstring; |
| 159 | char press_str[sizeof(void *) + sizeof(int)]; | 159 | char repeat_str[sizeof(void *) + sizeof(int)] __nonstring; |
| 160 | char repeat_str[sizeof(void *) + sizeof(int)]; | 160 | char release_str[sizeof(void *) + sizeof(int)] __nonstring; |
| 161 | char release_str[sizeof(void *) + sizeof(int)]; | ||
| 162 | } kbd; | 161 | } kbd; |
| 163 | } u; | 162 | } u; |
| 164 | }; | 163 | }; |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 12f90d48ba61..3f89d0ab08fc 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
| @@ -45,15 +45,6 @@ | |||
| 45 | 45 | ||
| 46 | #include <linux/compiler.h> | 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 | * The fourth extended filesystem constants/structures | 49 | * The fourth extended filesystem constants/structures |
| 59 | */ | 50 | */ |
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index b1ce500fe8b3..3e7dafb3ea80 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h | |||
| @@ -21,8 +21,6 @@ | |||
| 21 | #define __SANITIZE_ADDRESS__ | 21 | #define __SANITIZE_ADDRESS__ |
| 22 | #endif | 22 | #endif |
| 23 | 23 | ||
| 24 | #define __no_sanitize_address __attribute__((no_sanitize("address"))) | ||
| 25 | |||
| 26 | /* | 24 | /* |
| 27 | * Not all versions of clang implement the the type-generic versions | 25 | * Not all versions of clang implement the the type-generic versions |
| 28 | * of the builtin overflow checkers. Fortunately, clang implements | 26 | * of the builtin overflow checkers. Fortunately, clang implements |
| @@ -41,6 +39,3 @@ | |||
| 41 | * compilers, like ICC. | 39 | * compilers, like ICC. |
| 42 | */ | 40 | */ |
| 43 | #define barrier() __asm__ __volatile__("" : : : "memory") | 41 | #define barrier() __asm__ __volatile__("" : : : "memory") |
| 44 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) | ||
| 45 | #define __assume_aligned(a, ...) \ | ||
| 46 | __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) | ||
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 90ddfefb6c2b..c0f5db3a9621 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h | |||
| @@ -68,31 +68,20 @@ | |||
| 68 | */ | 68 | */ |
| 69 | #define uninitialized_var(x) x = x | 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 | #ifdef RETPOLINE | 71 | #ifdef RETPOLINE |
| 79 | #define __noretpoline __attribute__((indirect_branch("keep"))) | 72 | #define __noretpoline __attribute__((__indirect_branch__("keep"))) |
| 80 | #endif | 73 | #endif |
| 81 | 74 | ||
| 82 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) | 75 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) |
| 83 | 76 | ||
| 84 | #define __optimize(level) __attribute__((__optimize__(level))) | ||
| 85 | |||
| 86 | #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) | 77 | #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) |
| 87 | 78 | ||
| 88 | #ifndef __CHECKER__ | 79 | #define __compiletime_warning(message) __attribute__((__warning__(message))) |
| 89 | #define __compiletime_warning(message) __attribute__((warning(message))) | 80 | #define __compiletime_error(message) __attribute__((__error__(message))) |
| 90 | #define __compiletime_error(message) __attribute__((error(message))) | ||
| 91 | 81 | ||
| 92 | #ifdef LATENT_ENTROPY_PLUGIN | 82 | #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) |
| 93 | #define __latent_entropy __attribute__((latent_entropy)) | 83 | #define __latent_entropy __attribute__((latent_entropy)) |
| 94 | #endif | 84 | #endif |
| 95 | #endif /* __CHECKER__ */ | ||
| 96 | 85 | ||
| 97 | /* | 86 | /* |
| 98 | * calling noreturn functions, __builtin_unreachable() and __builtin_trap() | 87 | * calling noreturn functions, __builtin_unreachable() and __builtin_trap() |
| @@ -107,10 +96,6 @@ | |||
| 107 | * Mark a position in code as unreachable. This can be used to | 96 | * Mark a position in code as unreachable. This can be used to |
| 108 | * suppress control flow warnings after asm blocks that transfer | 97 | * suppress control flow warnings after asm blocks that transfer |
| 109 | * control elsewhere. | 98 | * control elsewhere. |
| 110 | * | ||
| 111 | * Early snapshots of gcc 4.5 don't support this and we can't detect | ||
| 112 | * this in the preprocessor, but we can live with this because they're | ||
| 113 | * unreleased. Really, we need to have autoconf for the kernel. | ||
| 114 | */ | 99 | */ |
| 115 | #define unreachable() \ | 100 | #define unreachable() \ |
| 116 | do { \ | 101 | do { \ |
| @@ -119,9 +104,6 @@ | |||
| 119 | __builtin_unreachable(); \ | 104 | __builtin_unreachable(); \ |
| 120 | } while (0) | 105 | } while (0) |
| 121 | 106 | ||
| 122 | /* Mark a function definition as prohibited from being cloned. */ | ||
| 123 | #define __noclone __attribute__((__noclone__, __optimize__("no-tracer"))) | ||
| 124 | |||
| 125 | #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) | 107 | #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) |
| 126 | #define __randomize_layout __attribute__((randomize_layout)) | 108 | #define __randomize_layout __attribute__((randomize_layout)) |
| 127 | #define __no_randomize_layout __attribute__((no_randomize_layout)) | 109 | #define __no_randomize_layout __attribute__((no_randomize_layout)) |
| @@ -131,32 +113,6 @@ | |||
| 131 | #endif | 113 | #endif |
| 132 | 114 | ||
| 133 | /* | 115 | /* |
| 134 | * When used with Link Time Optimization, gcc can optimize away C functions or | ||
| 135 | * variables which are referenced only from assembly code. __visible tells the | ||
| 136 | * optimizer that something else uses this function or variable, thus preventing | ||
| 137 | * this. | ||
| 138 | */ | ||
| 139 | #define __visible __attribute__((externally_visible)) | ||
| 140 | |||
| 141 | /* gcc version specific checks */ | ||
| 142 | |||
| 143 | #if GCC_VERSION >= 40900 && !defined(__CHECKER__) | ||
| 144 | /* | ||
| 145 | * __assume_aligned(n, k): Tell the optimizer that the returned | ||
| 146 | * pointer can be assumed to be k modulo n. The second argument is | ||
| 147 | * optional (default 0), so we use a variadic macro to make the | ||
| 148 | * shorthand. | ||
| 149 | * | ||
| 150 | * Beware: Do not apply this to functions which may return | ||
| 151 | * ERR_PTRs. Also, it is probably unwise to apply it to functions | ||
| 152 | * returning extra information in the low bits (but in that case the | ||
| 153 | * compiler should see some alignment anyway, when the return value is | ||
| 154 | * massaged by 'flags = ptr & 3; ptr &= ~3;'). | ||
| 155 | */ | ||
| 156 | #define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) | ||
| 157 | #endif | ||
| 158 | |||
| 159 | /* | ||
| 160 | * GCC 'asm goto' miscompiles certain code sequences: | 116 | * GCC 'asm goto' miscompiles certain code sequences: |
| 161 | * | 117 | * |
| 162 | * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 | 118 | * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 |
| @@ -187,39 +143,22 @@ | |||
| 187 | #define KASAN_ABI_VERSION 3 | 143 | #define KASAN_ABI_VERSION 3 |
| 188 | #endif | 144 | #endif |
| 189 | 145 | ||
| 190 | #if GCC_VERSION >= 40902 | ||
| 191 | /* | 146 | /* |
| 192 | * Tell the compiler that address safety instrumentation (KASAN) | 147 | * Because __no_sanitize_address conflicts with inlining: |
| 193 | * should not be applied to that function. | 148 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 |
| 194 | * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 | 149 | * we do one or the other. |
| 195 | */ | 150 | */ |
| 196 | #define __no_sanitize_address __attribute__((no_sanitize_address)) | ||
| 197 | #ifdef CONFIG_KASAN | 151 | #ifdef CONFIG_KASAN |
| 198 | #define __no_sanitize_address_or_inline \ | 152 | #define __no_sanitize_address_or_inline \ |
| 199 | __no_sanitize_address __maybe_unused notrace | 153 | __no_sanitize_address __maybe_unused notrace |
| 200 | #else | 154 | #else |
| 201 | #define __no_sanitize_address_or_inline inline | 155 | #define __no_sanitize_address_or_inline inline |
| 202 | #endif | 156 | #endif |
| 203 | #endif | ||
| 204 | 157 | ||
| 205 | #if GCC_VERSION >= 50100 | 158 | #if GCC_VERSION >= 50100 |
| 206 | /* | ||
| 207 | * Mark structures as requiring designated initializers. | ||
| 208 | * https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html | ||
| 209 | */ | ||
| 210 | #define __designated_init __attribute__((designated_init)) | ||
| 211 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 | 159 | #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 |
| 212 | #endif | 160 | #endif |
| 213 | 161 | ||
| 214 | #if !defined(__noclone) | ||
| 215 | #define __noclone /* not needed */ | ||
| 216 | #endif | ||
| 217 | |||
| 218 | #if !defined(__no_sanitize_address) | ||
| 219 | #define __no_sanitize_address | ||
| 220 | #define __no_sanitize_address_or_inline inline | ||
| 221 | #endif | ||
| 222 | |||
| 223 | /* | 162 | /* |
| 224 | * Turn individual warnings and errors on and off locally, depending | 163 | * Turn individual warnings and errors on and off locally, depending |
| 225 | * on version. | 164 | * on version. |
diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h index 4c7f9befa9f6..517bd14e1222 100644 --- a/include/linux/compiler-intel.h +++ b/include/linux/compiler-intel.h | |||
| @@ -29,17 +29,8 @@ | |||
| 29 | */ | 29 | */ |
| 30 | #define OPTIMIZER_HIDE_VAR(var) barrier() | 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 | #endif | 32 | #endif |
| 36 | 33 | ||
| 37 | /* icc has this, but it's called _bswap16 */ | 34 | /* icc has this, but it's called _bswap16 */ |
| 38 | #define __HAVE_BUILTIN_BSWAP16__ | 35 | #define __HAVE_BUILTIN_BSWAP16__ |
| 39 | #define __builtin_bswap16 _bswap16 | 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)) | ||
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 4170fcee5adb..18c80cfa4fc4 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
| @@ -23,8 +23,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, | |||
| 23 | #define __branch_check__(x, expect, is_constant) ({ \ | 23 | #define __branch_check__(x, expect, is_constant) ({ \ |
| 24 | long ______r; \ | 24 | long ______r; \ |
| 25 | static struct ftrace_likely_data \ | 25 | static struct ftrace_likely_data \ |
| 26 | __attribute__((__aligned__(4))) \ | 26 | __aligned(4) \ |
| 27 | __attribute__((section("_ftrace_annotated_branch"))) \ | 27 | __section("_ftrace_annotated_branch") \ |
| 28 | ______f = { \ | 28 | ______f = { \ |
| 29 | .data.func = __func__, \ | 29 | .data.func = __func__, \ |
| 30 | .data.file = __FILE__, \ | 30 | .data.file = __FILE__, \ |
| @@ -59,8 +59,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, | |||
| 59 | ({ \ | 59 | ({ \ |
| 60 | int ______r; \ | 60 | int ______r; \ |
| 61 | static struct ftrace_branch_data \ | 61 | static struct ftrace_branch_data \ |
| 62 | __attribute__((__aligned__(4))) \ | 62 | __aligned(4) \ |
| 63 | __attribute__((section("_ftrace_branch"))) \ | 63 | __section("_ftrace_branch") \ |
| 64 | ______f = { \ | 64 | ______f = { \ |
| 65 | .func = __func__, \ | 65 | .func = __func__, \ |
| 66 | .file = __FILE__, \ | 66 | .file = __FILE__, \ |
| @@ -115,7 +115,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, | |||
| 115 | # define ASM_UNREACHABLE | 115 | # define ASM_UNREACHABLE |
| 116 | #endif | 116 | #endif |
| 117 | #ifndef unreachable | 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 | #endif | 122 | #endif |
| 120 | 123 | ||
| 121 | /* | 124 | /* |
| @@ -137,7 +140,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, | |||
| 137 | extern typeof(sym) sym; \ | 140 | extern typeof(sym) sym; \ |
| 138 | static const unsigned long __kentry_##sym \ | 141 | static const unsigned long __kentry_##sym \ |
| 139 | __used \ | 142 | __used \ |
| 140 | __attribute__((section("___kentry" "+" #sym ), used)) \ | 143 | __section("___kentry" "+" #sym ) \ |
| 141 | = (unsigned long)&sym; | 144 | = (unsigned long)&sym; |
| 142 | #endif | 145 | #endif |
| 143 | 146 | ||
| @@ -278,7 +281,7 @@ unsigned long read_word_at_a_time(const void *addr) | |||
| 278 | * visible to the compiler. | 281 | * visible to the compiler. |
| 279 | */ | 282 | */ |
| 280 | #define __ADDRESSABLE(sym) \ | 283 | #define __ADDRESSABLE(sym) \ |
| 281 | static void * __attribute__((section(".discard.addressable"), used)) \ | 284 | static void * __section(".discard.addressable") __used \ |
| 282 | __PASTE(__addressable_##sym, __LINE__) = (void *)&sym; | 285 | __PASTE(__addressable_##sym, __LINE__) = (void *)&sym; |
| 283 | 286 | ||
| 284 | /** | 287 | /** |
| @@ -331,10 +334,6 @@ static inline void *offset_to_ptr(const int *off) | |||
| 331 | #endif /* __KERNEL__ */ | 334 | #endif /* __KERNEL__ */ |
| 332 | #endif /* __ASSEMBLY__ */ | 335 | #endif /* __ASSEMBLY__ */ |
| 333 | 336 | ||
| 334 | #ifndef __optimize | ||
| 335 | # define __optimize(level) | ||
| 336 | #endif | ||
| 337 | |||
| 338 | /* Compile time object size, -1 for unknown */ | 337 | /* Compile time object size, -1 for unknown */ |
| 339 | #ifndef __compiletime_object_size | 338 | #ifndef __compiletime_object_size |
| 340 | # define __compiletime_object_size(obj) -1 | 339 | # define __compiletime_object_size(obj) -1 |
| @@ -376,4 +375,7 @@ static inline void *offset_to_ptr(const int *off) | |||
| 376 | compiletime_assert(__native_word(t), \ | 375 | compiletime_assert(__native_word(t), \ |
| 377 | "Need native word sized stores/loads for atomicity.") | 376 | "Need native word sized stores/loads for atomicity.") |
| 378 | 377 | ||
| 378 | /* &a[0] degrades to a pointer: a different type from an array */ | ||
| 379 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) | ||
| 380 | |||
| 379 | #endif /* __LINUX_COMPILER_H */ | 381 | #endif /* __LINUX_COMPILER_H */ |
diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h new file mode 100644 index 000000000000..6b28c1b7310c --- /dev/null +++ b/include/linux/compiler_attributes.h | |||
| @@ -0,0 +1,258 @@ | |||
| 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 */ | ||
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 97cfe29b3f0a..3439d7d0249a 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 1 | #ifndef __LINUX_COMPILER_TYPES_H | 2 | #ifndef __LINUX_COMPILER_TYPES_H |
| 2 | #define __LINUX_COMPILER_TYPES_H | 3 | #define __LINUX_COMPILER_TYPES_H |
| 3 | 4 | ||
| @@ -54,6 +55,9 @@ extern void __chk_io_ptr(const volatile void __iomem *); | |||
| 54 | 55 | ||
| 55 | #ifdef __KERNEL__ | 56 | #ifdef __KERNEL__ |
| 56 | 57 | ||
| 58 | /* Attributes */ | ||
| 59 | #include <linux/compiler_attributes.h> | ||
| 60 | |||
| 57 | /* Compiler specific macros. */ | 61 | /* Compiler specific macros. */ |
| 58 | #ifdef __clang__ | 62 | #ifdef __clang__ |
| 59 | #include <linux/compiler-clang.h> | 63 | #include <linux/compiler-clang.h> |
| @@ -78,12 +82,6 @@ extern void __chk_io_ptr(const volatile void __iomem *); | |||
| 78 | #include <asm/compiler.h> | 82 | #include <asm/compiler.h> |
| 79 | #endif | 83 | #endif |
| 80 | 84 | ||
| 81 | /* | ||
| 82 | * Generic compiler-independent macros required for kernel | ||
| 83 | * build go below this comment. Actual compiler/compiler version | ||
| 84 | * specific implementations come from the above header files | ||
| 85 | */ | ||
| 86 | |||
| 87 | struct ftrace_branch_data { | 85 | struct ftrace_branch_data { |
| 88 | const char *func; | 86 | const char *func; |
| 89 | const char *file; | 87 | const char *file; |
| @@ -106,10 +104,6 @@ struct ftrace_likely_data { | |||
| 106 | unsigned long constant; | 104 | unsigned long constant; |
| 107 | }; | 105 | }; |
| 108 | 106 | ||
| 109 | /* Don't. Just don't. */ | ||
| 110 | #define __deprecated | ||
| 111 | #define __deprecated_for_modules | ||
| 112 | |||
| 113 | #endif /* __KERNEL__ */ | 107 | #endif /* __KERNEL__ */ |
| 114 | 108 | ||
| 115 | #endif /* __ASSEMBLY__ */ | 109 | #endif /* __ASSEMBLY__ */ |
| @@ -119,10 +113,6 @@ struct ftrace_likely_data { | |||
| 119 | * compilers. We don't consider that to be an error, so set them to nothing. | 113 | * compilers. We don't consider that to be an error, so set them to nothing. |
| 120 | * For example, some of them are for compiler specific plugins. | 114 | * For example, some of them are for compiler specific plugins. |
| 121 | */ | 115 | */ |
| 122 | #ifndef __designated_init | ||
| 123 | # define __designated_init | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #ifndef __latent_entropy | 116 | #ifndef __latent_entropy |
| 127 | # define __latent_entropy | 117 | # define __latent_entropy |
| 128 | #endif | 118 | #endif |
| @@ -140,17 +130,6 @@ struct ftrace_likely_data { | |||
| 140 | # define randomized_struct_fields_end | 130 | # define randomized_struct_fields_end |
| 141 | #endif | 131 | #endif |
| 142 | 132 | ||
| 143 | #ifndef __visible | ||
| 144 | #define __visible | ||
| 145 | #endif | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Assume alignment of return value. | ||
| 149 | */ | ||
| 150 | #ifndef __assume_aligned | ||
| 151 | #define __assume_aligned(a, ...) | ||
| 152 | #endif | ||
| 153 | |||
| 154 | /* Are two types/vars the same type (ignoring qualifiers)? */ | 133 | /* Are two types/vars the same type (ignoring qualifiers)? */ |
| 155 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) | 134 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) |
| 156 | 135 | ||
| @@ -159,14 +138,6 @@ struct ftrace_likely_data { | |||
| 159 | (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ | 138 | (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ |
| 160 | sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) | 139 | sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) |
| 161 | 140 | ||
| 162 | #ifndef __attribute_const__ | ||
| 163 | #define __attribute_const__ __attribute__((__const__)) | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifndef __noclone | ||
| 167 | #define __noclone | ||
| 168 | #endif | ||
| 169 | |||
| 170 | /* Helpers for emitting diagnostics in pragmas. */ | 141 | /* Helpers for emitting diagnostics in pragmas. */ |
| 171 | #ifndef __diag | 142 | #ifndef __diag |
| 172 | #define __diag(string) | 143 | #define __diag(string) |
| @@ -186,43 +157,16 @@ struct ftrace_likely_data { | |||
| 186 | #define __diag_error(compiler, version, option, comment) \ | 157 | #define __diag_error(compiler, version, option, comment) \ |
| 187 | __diag_ ## compiler(version, error, option) | 158 | __diag_ ## compiler(version, error, option) |
| 188 | 159 | ||
| 189 | /* | ||
| 190 | * From the GCC manual: | ||
| 191 | * | ||
| 192 | * Many functions have no effects except the return value and their | ||
| 193 | * return value depends only on the parameters and/or global | ||
| 194 | * variables. Such a function can be subject to common subexpression | ||
| 195 | * elimination and loop optimization just as an arithmetic operator | ||
| 196 | * would be. | ||
| 197 | * [...] | ||
| 198 | */ | ||
| 199 | #define __pure __attribute__((pure)) | ||
| 200 | #define __aligned(x) __attribute__((aligned(x))) | ||
| 201 | #define __printf(a, b) __attribute__((format(printf, a, b))) | ||
| 202 | #define __scanf(a, b) __attribute__((format(scanf, a, b))) | ||
| 203 | #define __maybe_unused __attribute__((unused)) | ||
| 204 | #define __always_unused __attribute__((unused)) | ||
| 205 | #define __mode(x) __attribute__((mode(x))) | ||
| 206 | #define __malloc __attribute__((__malloc__)) | ||
| 207 | #define __used __attribute__((__used__)) | ||
| 208 | #define __noreturn __attribute__((noreturn)) | ||
| 209 | #define __packed __attribute__((packed)) | ||
| 210 | #define __weak __attribute__((weak)) | ||
| 211 | #define __alias(symbol) __attribute__((alias(#symbol))) | ||
| 212 | #define __cold __attribute__((cold)) | ||
| 213 | #define __section(S) __attribute__((__section__(#S))) | ||
| 214 | |||
| 215 | |||
| 216 | #ifdef CONFIG_ENABLE_MUST_CHECK | 160 | #ifdef CONFIG_ENABLE_MUST_CHECK |
| 217 | #define __must_check __attribute__((warn_unused_result)) | 161 | #define __must_check __attribute__((__warn_unused_result__)) |
| 218 | #else | 162 | #else |
| 219 | #define __must_check | 163 | #define __must_check |
| 220 | #endif | 164 | #endif |
| 221 | 165 | ||
| 222 | #if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__) | 166 | #if defined(CC_USING_HOTPATCH) |
| 223 | #define notrace __attribute__((hotpatch(0, 0))) | 167 | #define notrace __attribute__((hotpatch(0, 0))) |
| 224 | #else | 168 | #else |
| 225 | #define notrace __attribute__((no_instrument_function)) | 169 | #define notrace __attribute__((__no_instrument_function__)) |
| 226 | #endif | 170 | #endif |
| 227 | 171 | ||
| 228 | /* | 172 | /* |
| @@ -231,23 +175,11 @@ struct ftrace_likely_data { | |||
| 231 | * stack and frame pointer being set up and there is no chance to | 175 | * stack and frame pointer being set up and there is no chance to |
| 232 | * restore the lr register to the value before mcount was called. | 176 | * restore the lr register to the value before mcount was called. |
| 233 | */ | 177 | */ |
| 234 | #define __naked __attribute__((naked)) notrace | 178 | #define __naked __attribute__((__naked__)) notrace |
| 235 | 179 | ||
| 236 | #define __compiler_offsetof(a, b) __builtin_offsetof(a, b) | 180 | #define __compiler_offsetof(a, b) __builtin_offsetof(a, b) |
| 237 | 181 | ||
| 238 | /* | 182 | /* |
| 239 | * Feature detection for gnu_inline (gnu89 extern inline semantics). Either | ||
| 240 | * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics, | ||
| 241 | * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not | ||
| 242 | * defined so the gnu89 semantics are the default. | ||
| 243 | */ | ||
| 244 | #ifdef __GNUC_STDC_INLINE__ | ||
| 245 | # define __gnu_inline __attribute__((gnu_inline)) | ||
| 246 | #else | ||
| 247 | # define __gnu_inline | ||
| 248 | #endif | ||
| 249 | |||
| 250 | /* | ||
| 251 | * Force always-inline if the user requests it so via the .config. | 183 | * Force always-inline if the user requests it so via the .config. |
| 252 | * GCC does not warn about unused static inline functions for | 184 | * GCC does not warn about unused static inline functions for |
| 253 | * -Wunused-function. This turns out to avoid the need for complex #ifdef | 185 | * -Wunused-function. This turns out to avoid the need for complex #ifdef |
| @@ -258,22 +190,20 @@ struct ftrace_likely_data { | |||
| 258 | * semantics rather than c99. This prevents multiple symbol definition errors | 190 | * semantics rather than c99. This prevents multiple symbol definition errors |
| 259 | * of extern inline functions at link time. | 191 | * of extern inline functions at link time. |
| 260 | * A lot of inline functions can cause havoc with function tracing. | 192 | * A lot of inline functions can cause havoc with function tracing. |
| 193 | * Do not use __always_inline here, since currently it expands to inline again | ||
| 194 | * (which would break users of __always_inline). | ||
| 261 | */ | 195 | */ |
| 262 | #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ | 196 | #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ |
| 263 | !defined(CONFIG_OPTIMIZE_INLINING) | 197 | !defined(CONFIG_OPTIMIZE_INLINING) |
| 264 | #define inline \ | 198 | #define inline inline __attribute__((__always_inline__)) __gnu_inline \ |
| 265 | inline __attribute__((always_inline, unused)) notrace __gnu_inline | 199 | __maybe_unused notrace |
| 266 | #else | 200 | #else |
| 267 | #define inline inline __attribute__((unused)) notrace __gnu_inline | 201 | #define inline inline __gnu_inline \ |
| 202 | __maybe_unused notrace | ||
| 268 | #endif | 203 | #endif |
| 269 | 204 | ||
| 270 | #define __inline__ inline | 205 | #define __inline__ inline |
| 271 | #define __inline inline | 206 | #define __inline inline |
| 272 | #define noinline __attribute__((noinline)) | ||
| 273 | |||
| 274 | #ifndef __always_inline | ||
| 275 | #define __always_inline inline __attribute__((always_inline)) | ||
| 276 | #endif | ||
| 277 | 207 | ||
| 278 | /* | 208 | /* |
| 279 | * Rather then using noinline to prevent stack consumption, use | 209 | * Rather then using noinline to prevent stack consumption, use |
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 24b2fb1d1297..cf6cd0ef6975 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn | |||
| @@ -29,6 +29,7 @@ warning-1 += $(call cc-option, -Wmissing-include-dirs) | |||
| 29 | warning-1 += $(call cc-option, -Wunused-but-set-variable) | 29 | warning-1 += $(call cc-option, -Wunused-but-set-variable) |
| 30 | warning-1 += $(call cc-option, -Wunused-const-variable) | 30 | warning-1 += $(call cc-option, -Wunused-const-variable) |
| 31 | warning-1 += $(call cc-option, -Wpacked-not-aligned) | 31 | warning-1 += $(call cc-option, -Wpacked-not-aligned) |
| 32 | warning-1 += $(call cc-option, -Wstringop-truncation) | ||
| 32 | warning-1 += $(call cc-disable-warning, missing-field-initializers) | 33 | warning-1 += $(call cc-disable-warning, missing-field-initializers) |
| 33 | warning-1 += $(call cc-disable-warning, sign-compare) | 34 | warning-1 += $(call cc-disable-warning, sign-compare) |
| 34 | 35 | ||
