From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Desaulniers Subject: Re: [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly Date: Mon, 30 Sep 2019 15:34:41 -0700 Message-ID: References: <20190830034304.24259-1-yamada.masahiro@socionext.com> <20190930112636.vx2qxo4hdysvxibl@willie-the-truck> <20190930121803.n34i63scet2ec7ll@willie-the-truck> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Miguel Ojeda Cc: Will Deacon , Masahiro Yamada , Linus Torvalds , Nicolas Saenz Julienne , Andrew Morton , Ingo Molnar , Borislav Petkov , linux-arch , LKML , Catalin Marinas , Russell King , Stefan Wahren , Kees Cook List-Id: linux-arch.vger.kernel.org On Mon, Sep 30, 2019 at 3:08 PM Miguel Ojeda wrote: > > On Mon, Sep 30, 2019 at 11:50 PM Nick Desaulniers > wrote: > > > > So __attribute__((always_inline)) doesn't guarantee that code will be > > inlined. [...] inline and __attribute__((always_inline)) > > are a heuristic laden mess and should not be relied upon. > > Small note: in GCC, __attribute__((always_inline)) is documented as > actually guaranteeing to either inline or error otherwise (although > see the remark for indirect calls): > > "Failure to inline such a function is diagnosed as an error. Note Not an error, but a warning at least: https://godbolt.org/z/_V5im1. That's interesting, so it has multiple semantics, because it's also documented to inline even when no optimizations are specified. So when someone uses __attribute__((always_inline)) without a comment, it's not clear whether they mean for there to be a warning when this is not inlined, or for it to be inlined at -O0 (guess not for the kernel), or both. If the kernel wants to enforce the former, why not set `-Werror=attributes`? Maybe that warning is too broad? Seems like a recipe for subtly broken code found at runtime, when we'd rather have stronger compile time guarantees. > that if such a function is called indirectly the compiler may or may > not inline it depending on optimization level and a failure to inline > an indirect call may or may not be diagnosed." > > As for LLVM/Clang, no idea, since it does not say anything about it in > the docs -- but from what you say, it is a weaker guarantee. Filed https://bugs.llvm.org/show_bug.cgi?id=43517 -- Thanks, ~Nick Desaulniers From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f196.google.com ([209.85.210.196]:35183 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbfI3Wey (ORCPT ); Mon, 30 Sep 2019 18:34:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id 205so6429795pfw.2 for ; Mon, 30 Sep 2019 15:34:53 -0700 (PDT) MIME-Version: 1.0 References: <20190830034304.24259-1-yamada.masahiro@socionext.com> <20190930112636.vx2qxo4hdysvxibl@willie-the-truck> <20190930121803.n34i63scet2ec7ll@willie-the-truck> In-Reply-To: From: Nick Desaulniers Date: Mon, 30 Sep 2019 15:34:41 -0700 Message-ID: Subject: Re: [PATCH] compiler: enable CONFIG_OPTIMIZE_INLINING forcibly Content-Type: text/plain; charset="UTF-8" Sender: linux-arch-owner@vger.kernel.org List-ID: To: Miguel Ojeda Cc: Will Deacon , Masahiro Yamada , Linus Torvalds , Nicolas Saenz Julienne , Andrew Morton , Ingo Molnar , Borislav Petkov , linux-arch , LKML , Catalin Marinas , Russell King , Stefan Wahren , Kees Cook Message-ID: <20190930223441.FNY-7OE4Vuz-Fiz1L7g3YS99vfJk6KPeSRW1U_K2ovk@z> On Mon, Sep 30, 2019 at 3:08 PM Miguel Ojeda wrote: > > On Mon, Sep 30, 2019 at 11:50 PM Nick Desaulniers > wrote: > > > > So __attribute__((always_inline)) doesn't guarantee that code will be > > inlined. [...] inline and __attribute__((always_inline)) > > are a heuristic laden mess and should not be relied upon. > > Small note: in GCC, __attribute__((always_inline)) is documented as > actually guaranteeing to either inline or error otherwise (although > see the remark for indirect calls): > > "Failure to inline such a function is diagnosed as an error. Note Not an error, but a warning at least: https://godbolt.org/z/_V5im1. That's interesting, so it has multiple semantics, because it's also documented to inline even when no optimizations are specified. So when someone uses __attribute__((always_inline)) without a comment, it's not clear whether they mean for there to be a warning when this is not inlined, or for it to be inlined at -O0 (guess not for the kernel), or both. If the kernel wants to enforce the former, why not set `-Werror=attributes`? Maybe that warning is too broad? Seems like a recipe for subtly broken code found at runtime, when we'd rather have stronger compile time guarantees. > that if such a function is called indirectly the compiler may or may > not inline it depending on optimization level and a failure to inline > an indirect call may or may not be diagnosed." > > As for LLVM/Clang, no idea, since it does not say anything about it in > the docs -- but from what you say, it is a weaker guarantee. Filed https://bugs.llvm.org/show_bug.cgi?id=43517 -- Thanks, ~Nick Desaulniers