aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2018-06-21 12:23:22 -0400
committerIngo Molnar <mingo@kernel.org>2018-07-03 04:56:27 -0400
commitd03db2bc26f0e4a6849ad649a09c9c73fccdc656 (patch)
treeb594261f9de2cd27f88c017999b91021a3c62e7b
parent4fb5f58e8d191f7c81637ad81284e4848afb4244 (diff)
compiler-gcc.h: Add __attribute__((gnu_inline)) to all inline declarations
Functions marked extern inline do not emit an externally visible function when the gnu89 C standard is used. Some KBUILD Makefiles overwrite KBUILD_CFLAGS. This is an issue for GCC 5.1+ users as without an explicit C standard specified, the default is gnu11. Since c99, the semantics of extern inline have changed such that an externally visible function is always emitted. This can lead to multiple definition errors of extern inline functions at link time of compilation units whose build files have removed an explicit C standard compiler flag for users of GCC 5.1+ or Clang. Suggested-by: Arnd Bergmann <arnd@arndb.de> Suggested-by: H. Peter Anvin <hpa@zytor.com> Suggested-by: Joe Perches <joe@perches.com> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Acked-by: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: acme@redhat.com Cc: akataria@vmware.com Cc: akpm@linux-foundation.org Cc: andrea.parri@amarulasolutions.com Cc: ard.biesheuvel@linaro.org Cc: aryabinin@virtuozzo.com Cc: astrachan@google.com Cc: boris.ostrovsky@oracle.com Cc: brijesh.singh@amd.com Cc: caoj.fnst@cn.fujitsu.com Cc: geert@linux-m68k.org Cc: ghackmann@google.com Cc: gregkh@linuxfoundation.org Cc: jan.kiszka@siemens.com Cc: jarkko.sakkinen@linux.intel.com Cc: jpoimboe@redhat.com Cc: keescook@google.com Cc: kirill.shutemov@linux.intel.com Cc: kstewart@linuxfoundation.org Cc: linux-efi@vger.kernel.org Cc: linux-kbuild@vger.kernel.org Cc: manojgupta@google.com Cc: mawilcox@microsoft.com Cc: michal.lkml@markovi.net Cc: mjg59@google.com Cc: mka@chromium.org Cc: pombredanne@nexb.com Cc: rientjes@google.com Cc: rostedt@goodmis.org Cc: sedat.dilek@gmail.com Cc: thomas.lendacky@amd.com Cc: tstellar@redhat.com Cc: tweek@google.com Cc: virtualization@lists.linux-foundation.org Cc: will.deacon@arm.com Cc: yamada.masahiro@socionext.com Link: http://lkml.kernel.org/r/20180621162324.36656-2-ndesaulniers@google.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/linux/compiler-gcc.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index fd282c7d3e5e..573f5a7d42d4 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -66,25 +66,40 @@
66#endif 66#endif
67 67
68/* 68/*
69 * Feature detection for gnu_inline (gnu89 extern inline semantics). Either
70 * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics,
71 * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not
72 * defined so the gnu89 semantics are the default.
73 */
74#ifdef __GNUC_STDC_INLINE__
75# define __gnu_inline __attribute__((gnu_inline))
76#else
77# define __gnu_inline
78#endif
79
80/*
69 * Force always-inline if the user requests it so via the .config, 81 * Force always-inline if the user requests it so via the .config,
70 * or if gcc is too old. 82 * or if gcc is too old.
71 * GCC does not warn about unused static inline functions for 83 * GCC does not warn about unused static inline functions for
72 * -Wunused-function. This turns out to avoid the need for complex #ifdef 84 * -Wunused-function. This turns out to avoid the need for complex #ifdef
73 * directives. Suppress the warning in clang as well by using "unused" 85 * directives. Suppress the warning in clang as well by using "unused"
74 * function attribute, which is redundant but not harmful for gcc. 86 * function attribute, which is redundant but not harmful for gcc.
87 * Prefer gnu_inline, so that extern inline functions do not emit an
88 * externally visible function. This makes extern inline behave as per gnu89
89 * semantics rather than c99. This prevents multiple symbol definition errors
90 * of extern inline functions at link time.
91 * A lot of inline functions can cause havoc with function tracing.
75 */ 92 */
76#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ 93#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
77 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) 94 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
78#define inline inline __attribute__((always_inline,unused)) notrace 95#define inline \
79#define __inline__ __inline__ __attribute__((always_inline,unused)) notrace 96 inline __attribute__((always_inline, unused)) notrace __gnu_inline
80#define __inline __inline __attribute__((always_inline,unused)) notrace
81#else 97#else
82/* A lot of inline functions can cause havoc with function tracing */ 98#define inline inline __attribute__((unused)) notrace __gnu_inline
83#define inline inline __attribute__((unused)) notrace
84#define __inline__ __inline__ __attribute__((unused)) notrace
85#define __inline __inline __attribute__((unused)) notrace
86#endif 99#endif
87 100
101#define __inline__ inline
102#define __inline inline
88#define __always_inline inline __attribute__((always_inline)) 103#define __always_inline inline __attribute__((always_inline))
89#define noinline __attribute__((noinline)) 104#define noinline __attribute__((noinline))
90 105