Skip to content

Commit d03db2b

Browse files
nickdesaulniersIngo Molnar
authored andcommitted
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>
1 parent 4fb5f58 commit d03db2b

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

include/linux/compiler-gcc.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,41 @@
6565
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
6666
#endif
6767

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+
6880
/*
6981
* Force always-inline if the user requests it so via the .config,
7082
* or if gcc is too old.
7183
* GCC does not warn about unused static inline functions for
7284
* -Wunused-function. This turns out to avoid the need for complex #ifdef
7385
* directives. Suppress the warning in clang as well by using "unused"
7486
* 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.
7592
*/
7693
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
7794
!defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
78-
#define inline inline __attribute__((always_inline,unused)) notrace
79-
#define __inline__ __inline__ __attribute__((always_inline,unused)) notrace
80-
#define __inline __inline __attribute__((always_inline,unused)) notrace
95+
#define inline \
96+
inline __attribute__((always_inline, unused)) notrace __gnu_inline
8197
#else
82-
/* A lot of inline functions can cause havoc with function tracing */
83-
#define inline inline __attribute__((unused)) notrace
84-
#define __inline__ __inline__ __attribute__((unused)) notrace
85-
#define __inline __inline __attribute__((unused)) notrace
98+
#define inline inline __attribute__((unused)) notrace __gnu_inline
8699
#endif
87100

101+
#define __inline__ inline
102+
#define __inline inline
88103
#define __always_inline inline __attribute__((always_inline))
89104
#define noinline __attribute__((noinline))
90105

0 commit comments

Comments
 (0)