From patchwork Thu Jun 21 16:23:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 10480185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3E776053C for ; Thu, 21 Jun 2018 16:26:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DFA52929C for ; Thu, 21 Jun 2018 16:26:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B667292DB; Thu, 21 Jun 2018 16:26:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D870D292AC for ; Thu, 21 Jun 2018 16:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933436AbeFUQXj (ORCPT ); Thu, 21 Jun 2018 12:23:39 -0400 Received: from mail-qt0-f201.google.com ([209.85.216.201]:50779 "EHLO mail-qt0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933420AbeFUQXf (ORCPT ); Thu, 21 Jun 2018 12:23:35 -0400 Received: by mail-qt0-f201.google.com with SMTP id z26-v6so2818429qto.17 for ; Thu, 21 Jun 2018 09:23:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=/vQmHl8cd2NT8hl07OE94mYUyQt2yjyU18WcKiSTNXc=; b=t3zuQvQz0nhoKtkxb/zaSWjV1xb+x/+sou3GorvnWq06x7zhVhUqbt/zHauWLLqS9A up7wDGzzZ9tVW0cydrETItaN4dGoA+320bX3bm1qaJMG6CPGTzj4NIJpQPe5gtumSuBM 8kDGCBDAn/SvRMKDh9T7Qz5zx0Tt10jQgqP41OHAREugwAciZwhXTzRzWUyRQxMR/NmR vuzICd6iuvf8eeT/Jjc8vx3u8I7pRaBxr6b/6GiZL1+LD0+Ii9LHeJWBtCgC/UW9lYTU hfcjn+OXuSX1D8MOqaEZ6HBMmo2rXVOxMBrkQH0zC3K5PK91+PCi/8jat1awbRHjnrdI 46lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=/vQmHl8cd2NT8hl07OE94mYUyQt2yjyU18WcKiSTNXc=; b=KWEW6OhEo/MgYM0RA7p88qxlJmitw4PRN/ipiRno2wrr+xk5UnWMpctMxmuf01eDo2 SvSGGNptnxeWKzUFfkGpdJcBIFONG6S25CJv6yHg4XJmPUXtdyDxBOGwfX3jkmKxhzmF NZpJS5AurIAJFMLAdvxuHlRp8XJZlTYHk+CvEG0GayGxIvx9XOlQhw2h4oiqxOCtIlf3 604Y56ebQLvWxAuJdzc6BvhW2uqEnCOngFaSd0zu+vEJ/BTGgez6HHIVNfV8khxJoDix f322TNHFdfFyKX7k+etmbLXfaKqckTTSVp2LhSTWbN/YUTJ7opfrjduWrROHNMulP2ya /JRA== X-Gm-Message-State: APt69E16dLhij8LCxziJqQ5AigdvLFwR5SlUtTe3iq4I99XOs4iKQTzV McgqG1Qb/psNVqKkCsIBhanj7nXUgbAJZUnD8Y4= X-Google-Smtp-Source: ADUXVKJSWC1eDCch2QV7phR6Iez+/IhWRJhSdLMrAZ0OsF6ErYJXMNegfe6cDog0v/FHE6YH5UeGnYq7GVnIprhHldk= MIME-Version: 1.0 X-Received: by 2002:ac8:4508:: with SMTP id q8-v6mr14100098qtn.39.1529598214186; Thu, 21 Jun 2018 09:23:34 -0700 (PDT) Date: Thu, 21 Jun 2018 09:23:22 -0700 In-Reply-To: <20180621162324.36656-1-ndesaulniers@google.com> Message-Id: <20180621162324.36656-2-ndesaulniers@google.com> References: <20180621162324.36656-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog Subject: [PATCH v6 1/3] compiler-gcc.h: add gnu_inline to all inline declarations From: Nick Desaulniers To: mingo@redhat.com, tglx@linutronix.de Cc: akpm@linux-foundation.org, hpa@zytor.com, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux-foundation.org, astrachan@google.com, manojgupta@google.com, ghackmann@google.com, sedat.dilek@gmail.com, tstellar@redhat.com, keescook@google.com, yamada.masahiro@socionext.com, michal.lkml@markovi.net, linux-kbuild@vger.kernel.org, geert@linux-m68k.org, will.deacon@arm.com, mawilcox@microsoft.com, arnd@arndb.de, rientjes@google.com, acme@redhat.com, pombredanne@nexb.com, aryabinin@virtuozzo.com, kstewart@linuxfoundation.org, boris.ostrovsky@oracle.com, jan.kiszka@siemens.com, rostedt@goodmis.org, kirill.shutemov@linux.intel.com, ard.biesheuvel@linaro.org, akataria@vmware.com, brijesh.singh@amd.com, caoj.fnst@cn.fujitsu.com, gregkh@linuxfoundation.org, jarkko.sakkinen@linux.intel.com, jgross@suse.com, jpoimboe@redhat.com, mka@chromium.org, ndesaulniers@google.com, thomas.lendacky@amd.com, tweek@google.com, mjg59@google.com, joe@perches.com, andrea.parri@amarulasolutions.com Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Acked-by: Juergen Gross Signed-off-by: Nick Desaulniers Suggested-by: Arnd Bergmann Suggested-by: H. Peter Anvin Suggested-by: Joe Perches --- include/linux/compiler-gcc.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index b4bf73f5e38f..c7cfca4ba02b 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -65,6 +65,18 @@ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) #endif +/* + * Feature detection for gnu_inline (gnu89 extern inline semantics). Either + * __GNUC_STDC_INLINE__ is defined (not using gnu89 extern inline semantics, + * and we opt in to the gnu89 semantics), or __GNUC_STDC_INLINE__ is not + * defined so the gnu89 semantics are the default. + */ +#ifdef __GNUC_STDC_INLINE__ +#define __gnu_inline __attribute__((gnu_inline)) +#else +#define __gnu_inline +#endif + /* * Force always-inline if the user requests it so via the .config, * or if gcc is too old. @@ -72,19 +84,22 @@ * -Wunused-function. This turns out to avoid the need for complex #ifdef * directives. Suppress the warning in clang as well by using "unused" * function attribute, which is redundant but not harmful for gcc. + * Prefer gnu_inline, so that extern inline functions do not emit an + * externally visible function. This makes extern inline behave as per gnu89 + * semantics rather than c99. This prevents multiple symbol definition errors + * of extern inline functions at link time. + * A lot of inline functions can cause havoc with function tracing. */ #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) -#define inline inline __attribute__((always_inline,unused)) notrace -#define __inline__ __inline__ __attribute__((always_inline,unused)) notrace -#define __inline __inline __attribute__((always_inline,unused)) notrace +#define inline \ + inline __attribute__((always_inline, unused)) notrace __gnu_inline #else -/* A lot of inline functions can cause havoc with function tracing */ -#define inline inline __attribute__((unused)) notrace -#define __inline__ __inline__ __attribute__((unused)) notrace -#define __inline __inline __attribute__((unused)) notrace +#define inline inline __attribute__((unused)) notrace __gnu_inline #endif +#define __inline__ inline +#define __inline inline #define __always_inline inline __attribute__((always_inline)) #define noinline __attribute__((noinline))