Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp287955imm; Wed, 30 May 2018 23:52:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL7RZVQXRpkgt5iz7iavxiJlOuzMFduxaPeY0onREPPNIYlvnn6vGNOsolrBZ5opBsAXp7W X-Received: by 2002:a63:9e42:: with SMTP id r2-v6mr4542998pgo.436.1527749531017; Wed, 30 May 2018 23:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527749530; cv=none; d=google.com; s=arc-20160816; b=vMRSgBmp4RKUGmkPeTHzaFjdiEDefLwZas3U3Glahh1YwIHb2ldYK8dCa9legeDR4/ JwDDcPDRqQF7UIs+3sY0KijgCHIz135O7BEuoTsqFo0vbJuDHT7IFHPXjpGPuzB5bXf+ 8deT19cP9JO4o3ujDsHM6obwimdK2V6IoRbAeIuIv+56Urnqm6KxR2CK9Rcro/zYT0ws jh5OWkN8bpIDEXZ9CzIs8OCGj9vBysYjDjOVLacSr0m7FfYu3lHBkMfxBAIfODvKJj53 SKkPWLgcWWu+m5QBU1KEBP45fbMSWACSx++trfyGgrUPAfBhBIXyWCwnzbAi6DKBXYF6 ZBTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=3sQgNkztLyfezlATl9GZxH2h+GWNAXbH8nClUd8QRZ0=; b=msK8MTkecOPzKggOLo1Itjuw93nJmYi737NVWbw7wMcb0jLljKKPjuO130HqUEfyKM yNfVusnJtmL6bKdUFKwXRpB6pc46Vjy8Hxd6pqBuiYoUcr8MaM3ZpS+Um28t7+3L3t8Q 1fAZIxF1nCrE7TwP1BhsrV3mz5eWW7SzjHyZNBzUSxc+KkAdLkby+2Tzc995U9VM557G p0VOkxVu2cSqJsCe5YPZf7tAJ7VDsq8un7ef16J7FoBVp6umB+FOZxUuJNIqtdSxKckz hTR5uOjhTEhxj9MHwlxZlUY7gPHv1W+G9K1v+guQetXlU6n820rA0yvtbjz2HBe0rvPa x7Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=spvwhgmk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19-v6si3050167pgq.71.2018.05.30.23.51.57; Wed, 30 May 2018 23:52:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=spvwhgmk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754023AbeEaGup (ORCPT + 99 others); Thu, 31 May 2018 02:50:45 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36510 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753934AbeEaGul (ORCPT ); Thu, 31 May 2018 02:50:41 -0400 Received: by mail-pl0-f65.google.com with SMTP id v24-v6so12638530plo.3 for ; Wed, 30 May 2018 23:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3sQgNkztLyfezlATl9GZxH2h+GWNAXbH8nClUd8QRZ0=; b=spvwhgmkTmzKTwN6kr6t3ShfHOeNWcznKIEyIIWXrTYF5VpmpJnyHNs0p6we1VVDK6 Ki/PhujAncKTuqF9Q14as73YwOS0CdLKEGVjmUFRTnGK7nF+dEaOIJyEwoMT1R8elCBM Mjgn1u4+tqenN+tx/C8noQWDAmOxBQtFhy7P2t3kEgmyQQOSfRlEY7HSuslLJNcYqZJf 7skOrV4QuwdtRuQUNyxN/iOjIPfVdEhBDu5izSOU5APt7uQctTTW95MoVNP1kMa2nvFi vEOHNdfFS3eMc5hT8oGsYTN5/oDmGIQPYTaBISxnh1HH5T4NXLvKBtmVvp3uxlz/2aSS 0DzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3sQgNkztLyfezlATl9GZxH2h+GWNAXbH8nClUd8QRZ0=; b=axIuxTWUOyb+O/mrrE/x7jvlpC/vkDn/OK75NRkc2/9Padairij2o354WJMICqpIY1 0sYoHG4UYiPvPTyHn/HVQgWFqm+HO0HgClwz4fGHAa8tFSIjbCX94KcvcWIeYGIzcWYJ niax/4rIe3pvcciQLPlSGqvVIvjkdqcXVnGkC4/szCgmsfZ2nkMA3HQgljJNq4Ex8Ep5 2ik+ttaa3LFYQQ/NYIZn7tYtakgFwMjnFO1vJsMS5Qmz/VrQsTbX0d3VFSeKtZWnGb2u Cyk/parNU4ElGQdb3g2RebULdndfFOtTB59ssMRTmhQLIuYIxelZzFi/GRU3Mche5gwK 72yw== X-Gm-Message-State: ALKqPwc+HHCBUMHmP9Y5pbr/U9dwJz/TLQ/LR/N6uWJJjY6NHgaSznYQ OY1W4XN05IDRDatQ3zAWS2Jn/W+PdPoKr24EwKGNrg== X-Received: by 2002:a17:902:d891:: with SMTP id b17-v6mr5942516plz.0.1527749441027; Wed, 30 May 2018 23:50:41 -0700 (PDT) MIME-Version: 1.0 References: <26B017D5-4063-46CB-8768-B0E5E7CD3838@zytor.com> <319FB971-ABB6-4BE7-969B-D87D84853196@zytor.com> <31A5469A-176F-451F-886A-ECD649DDC78C@zytor.com> <38f21c66-fa34-3a77-33bc-d15065c15af9@zytor.com> In-Reply-To: From: Nick Desaulniers Date: Wed, 30 May 2018 23:50:28 -0700 Message-ID: Subject: Re: [clang] stack protector and f1f029c7bf To: hpa@zytor.com Cc: Alistair Strachan , Manoj Gupta , Matthias Kaehlcke , Greg Hackmann , sedat.dilek@gmail.com, tstellar@redhat.com, LKML , Kees Cook , Masahiro Yamada , Michal Marek , Linux Kbuild mailing list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 25, 2018 at 3:38 PM Nick Desaulniers wrote: > > On Fri, May 25, 2018 at 2:06 PM H. Peter Anvin wrote: > > On 05/25/18 13:36, Nick Desaulniers wrote: > > > On Fri, May 25, 2018 at 10:56 AM wrote: > > >> You need the extern inline in the .h file and the out-of-line .S file > > > I don't see how you can specify to the linker from assembly source that > > > this function should be treated as `extern inline`? > > "extern inline" is a C directive. In the header file you should provide > > the inlinable implementation (which is already there.) It means that "if > > you don't want to inline this there is an external implementation > > available." > > oh you put `extern inline` on the definition, not the declaration?! What?! > > http://m68hc11.serveftp.org/inline-1.php > > in fact documents that trick. Wow, I've never seen that before. Seems > like there's not too many instances in the kernel. > > This seems to inline native_save_fl() properly into the call sites, but the > boot code now fails to link due to multiple definitions when trying link > the objects from arch/x86/boot/compressed/ into vmlinux. > > When disassembling the the arch/x86/boot/compressed/ objects, I can see > they're pulling in the `extern inline` c versions, but still outlining > them! (gcc and clang). > > That seems to contradict the statement from the above link: > "In no case is the function compiled on its own, not even if you refer to > its address explicitly" > > This is kind of funny; first we were wondering why native_save_fl was > getting outlined as a static inline function, which Alistair tracked down > to the incorrect use as a function pointer. Now I'm playing why is > native_save_fl getting outlined as an extern inline function. > > If I move the .S file to be in arch/x86/kernel/boot/compressed, the boot > code now links but then paravirt.o fails to link. Referring to the .S from > both Makefiles results in multiple definitions that the linker doesn't > like. (and the boot code still containing outlines). > > I don't understand how `extern inline` signals to the linker that "this > version should be taken if you find no others". From what I can tell with > `readelf -a` and `objdump -d`, a function marked `extern inline` vs not > look similar. > > Then again, arch/x86/boot/compressed/Makefile completely resets > KBUILD_CFLAGS and KBUILD_AFLAGS, which may be problematic (if there's some > kind of command line flag that affects `extern inline` linkage). Aha! This (wiping away CFLAGS) was it! The rules for `extern inline` for gnu89 and c99 are exactly the opposite! [0][1] c99: "a function defined extern inline will always, emit an externally visible function." but then gnu89: "gnu89 semantics of inline and extern inline are essentially the exact opposite of those in C99" This is elaborated more concisely in [2]. If I add `-std=gnu89` to the KBUILD_CFLAGS for compilation units that are missing that flag but include irqflags.h, I stop getting multiple definition linkage errors and link the expected kernel image! This is something to seriously consider for whoever might ever want to change the kernel's C standard: that you'll end up flipping the semantics of `extern inline`. Sounds like `-fgnu89-inline` compiler flag or `gnu_inline` attribute could be used to correct such a situation. + KBUILD maintainers and mailing list. Completely overwriting the KBUILD_CFLAGS from sub directory Makefiles (using the := operator) has been making me feel uneasy, since we very carefully try to set the necessary flags for Clang in the top level Makefile. In this case, the C standard is different for at least 2 subdirectories, which has implications for at least the above case with the linkage of `extern inline` functions. Will do further testing and cut a patch set tomorrow. [0] https://en.wikipedia.org/wiki/Inline_function#C99 [1] https://en.wikipedia.org/wiki/Inline_function#gnu89 [2] http://blahg.josefsipek.net/?p=529 -- Thanks, ~Nick Desaulniers