From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75E94C433E2 for ; Thu, 3 Sep 2020 22:21:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 391C220716 for ; Thu, 3 Sep 2020 22:21:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="C4bVPgSZ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jxDHCE4P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 391C220716 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3otz4xKgnjuZdL9HoJzXJzQX/R2Ckkl7zj+u30U1N7M=; b=C4bVPgSZVoxAsZ6J+QEnUqZkt s/B6ixw9jBzjTtBTfpXBOzOpMuejYO8LJKAYHxyvAmpp0wawpulrZFyYmtu3XXk+lGtUsqg+dXTjP 5JZaqN2T8+NPzIU3rH42VnNXPNvxAZ1G5y6xV+2W4N7IiUBEuDzjKm1DFPc+yNz6sG9GDAizZEEse JVQCGBOrVYbJPiTCOv2rE+YEVGTXjzqIyT/HY+fs4sZ1tptPoMEp3KvLizpEHKwBZJStlpGACIIVR ftSb0YRgjkcB5RLwkB3U9pyozM1M6OFWJUr6qalxXF9TL/bN8M70dVOflNPnNBsowh1oH8YY6hyGY VIJ3UNz2g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDxaA-00084j-C7; Thu, 03 Sep 2020 22:19:50 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDxa7-00083U-La for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 22:19:48 +0000 Received: by mail-pg1-x543.google.com with SMTP id w186so3224593pgb.8 for ; Thu, 03 Sep 2020 15:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MWNxdRC9o4O5cBaQMtBrWZaTyq9NHomAWBLJ5BXZ/Cg=; b=jxDHCE4PSws5lQZxdXVDEjhRQTdgtlSfRbx8rYkpCfQICEnOWSuKZ7dWjeNOju7dHs JEdGW0U96wxe5VP81V1HIKryHZ+2sUEbGwgPTUa5Or2pgLw9K4kqUUj39f1wAlZHuNJ6 G7nevfW8wKYTznCuyu42z91ddeu7fJXntaESc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MWNxdRC9o4O5cBaQMtBrWZaTyq9NHomAWBLJ5BXZ/Cg=; b=kguw+oeO41lz9vPxUsYZi5jZUSUm5IwWgM2ENfIdwt93S7OHnPl4EvbHc9mWGZTp+D Bj70UZN9u2YDNoAbEgf5xvVkNYX2AR14huFpNig1l6pl95DTMfD8bPDRBb2LWUsyxOLD AjqtmoFYhrxi7V3u28X47IJfkaYUjxQLeZDFSDzAH7/kRRbSXcOySD/5cqZdcOqSUU6i EhXQSy+QXcQqxD62N+lC3yw/YOKtC24scCZCyTDE3jA2WNI21oIH7UQIkMxQsgMgQldC tMDqUJMbbtLBAGcEncxu5JFt4v7YzZXbVRoJNHLqRzxYXmJFkIsJcp+ko/sMBF9wOCFi detw== X-Gm-Message-State: AOAM533USTsuluVKyXzhnMrTyNphCJd61jLTEChLgR2Mokj0gtwC4TnG RxCHwake7Di8Qn4QaWJYhAWyLA== X-Google-Smtp-Source: ABdhPJyiQdJtuSv4chDGmJRkFDeKEEXRJWc13sRcliVwROf2KadwLW6WYWrupCYc5UO95rWT0iVSnQ== X-Received: by 2002:a05:6a00:14ce:: with SMTP id w14mr5536446pfu.119.1599171585674; Thu, 03 Sep 2020 15:19:45 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c1sm4139792pfi.136.2020.09.03.15.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 15:19:44 -0700 (PDT) Date: Thu, 3 Sep 2020 15:19:43 -0700 From: Kees Cook To: Sami Tolvanen Subject: Re: [PATCH v2 11/28] kbuild: lto: postpone objtool Message-ID: <202009031513.B558594FB9@keescook> References: <20200624203200.78870-1-samitolvanen@google.com> <20200903203053.3411268-1-samitolvanen@google.com> <20200903203053.3411268-12-samitolvanen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200903203053.3411268-12-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_181947_724043_2427E5C8 X-CRM114-Status: GOOD ( 24.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, x86@kernel.org, "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Peter Zijlstra , Greg Kroah-Hartman , Masahiro Yamada , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Steven Rostedt , clang-built-linux@googlegroups.com, linux-pci@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 03, 2020 at 01:30:36PM -0700, Sami Tolvanen wrote: > With LTO, LLVM bitcode won't be compiled into native code until > modpost_link, or modfinal for modules. This change postpones calls > to objtool until after these steps. > > Signed-off-by: Sami Tolvanen For a "fail fast" style of building, it makes sense to have objtool run as early as possible, so it makes sense to keep the current behavior in non-LTO mode. I do wonder, though, if there is a real benefit to having "fail fast" case. I imagine a lot of automated builds are using --keep-going with make, and actually waiting until the end to do the validation means more code will get build-tested before objtool rejects the results. *shrug* > --- > arch/Kconfig | 2 +- > scripts/Makefile.build | 2 ++ > scripts/Makefile.modfinal | 24 ++++++++++++++++++++++-- > scripts/link-vmlinux.sh | 23 ++++++++++++++++++++++- > 4 files changed, 47 insertions(+), 4 deletions(-) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 71392e4a8900..7a418907e686 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -599,7 +599,7 @@ config LTO_CLANG > depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm) > depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm) > depends on ARCH_SUPPORTS_LTO_CLANG > - depends on !FTRACE_MCOUNT_RECORD > + depends on HAVE_OBJTOOL_MCOUNT || !(X86_64 && DYNAMIC_FTRACE) > depends on !KASAN > depends on !GCOV_KERNEL > select LTO > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > index c348e6d6b436..b8f1f0d65a73 100644 > --- a/scripts/Makefile.build > +++ b/scripts/Makefile.build > @@ -218,6 +218,7 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), > endif # USE_RECORDMCOUNT > > ifdef CONFIG_STACK_VALIDATION > +ifndef CONFIG_LTO_CLANG > ifneq ($(SKIP_STACK_VALIDATION),1) > > __objtool_obj := $(objtree)/tools/objtool/objtool > @@ -253,6 +254,7 @@ objtool_obj = $(if $(patsubst y%,, \ > $(__objtool_obj)) > > endif # SKIP_STACK_VALIDATION > +endif # CONFIG_LTO_CLANG > endif # CONFIG_STACK_VALIDATION > > # Rebuild all objects when objtool changes, or is enabled/disabled. > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal > index 1005b147abd0..909bd509edb4 100644 > --- a/scripts/Makefile.modfinal > +++ b/scripts/Makefile.modfinal > @@ -34,10 +34,30 @@ ifdef CONFIG_LTO_CLANG > # With CONFIG_LTO_CLANG, reuse the object file we compiled for modpost to > # avoid a second slow LTO link > prelink-ext := .lto > -endif > + > +# ELF processing was skipped earlier because we didn't have native code, > +# so let's now process the prelinked binary before we link the module. > + > +ifdef CONFIG_STACK_VALIDATION > +ifneq ($(SKIP_STACK_VALIDATION),1) > +cmd_ld_ko_o += \ > + $(objtree)/tools/objtool/objtool \ > + $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ > + --module \ > + $(if $(CONFIG_FRAME_POINTER),,--no-fp) \ > + $(if $(CONFIG_GCOV_KERNEL),--no-unreachable,) \ > + $(if $(CONFIG_RETPOLINE),--retpoline,) \ > + $(if $(CONFIG_X86_SMAP),--uaccess,) \ > + $(if $(USE_OBJTOOL_MCOUNT),--mcount,) \ > + $(@:.ko=$(prelink-ext).o); > + > +endif # SKIP_STACK_VALIDATION > +endif # CONFIG_STACK_VALIDATION I wonder if objtool_args could be reused here instead of having two places to keep in sync? It looks like that might mean moving things around a bit before this patch, since I can't quite see if Makefile.build's variables are visible to Makefile.modfinal? > + > +endif # CONFIG_LTO_CLANG > > quiet_cmd_ld_ko_o = LD [M] $@ > - cmd_ld_ko_o = \ > + cmd_ld_ko_o += \ > $(LD) -r $(KBUILD_LDFLAGS) \ > $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ > $(addprefix -T , $(KBUILD_LDS_MODULE)) \ > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh > index 3e99a19b9195..a352a5ad9ef7 100755 > --- a/scripts/link-vmlinux.sh > +++ b/scripts/link-vmlinux.sh > @@ -93,8 +93,29 @@ objtool_link() > { > local objtoolopt; > > + if [ "${CONFIG_LTO_CLANG} ${CONFIG_STACK_VALIDATION}" = "y y" ]; then > + # Don't perform vmlinux validation unless explicitly requested, > + # but run objtool on vmlinux.o now that we have an object file. > + if [ -n "${CONFIG_UNWINDER_ORC}" ]; then > + objtoolopt="orc generate" > + else > + objtoolopt="check" > + fi > + > + if [ -n ${USE_OBJTOOL_MCOUNT} ]; then > + objtoolopt="${objtoolopt} --mcount" > + fi > + fi > + > if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then > - objtoolopt="check --vmlinux" > + if [ -z "${objtoolopt}" ]; then > + objtoolopt="check --vmlinux" > + else > + objtoolopt="${objtoolopt} --vmlinux" > + fi > + fi > + > + if [ -n "${objtoolopt}" ]; then > if [ -z "${CONFIG_FRAME_POINTER}" ]; then > objtoolopt="${objtoolopt} --no-fp" > fi > -- > 2.28.0.402.g5ffc5be6b7-goog > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel