Received: by 10.213.65.68 with SMTP id h4csp1185203imn; Wed, 14 Mar 2018 12:09:27 -0700 (PDT) X-Google-Smtp-Source: AG47ELt4hE5ORPZGOtsG7RIsp/GSV+HTrAZArmkNZ/n72vCHX4qMiMCvi+KEGb/EXkIRFrAbLl0+ X-Received: by 10.99.109.72 with SMTP id i69mr4670357pgc.417.1521054567848; Wed, 14 Mar 2018 12:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521054567; cv=none; d=google.com; s=arc-20160816; b=EgHj2H9LB3yOnVrxTWXr0M1R5wS56Bemd/I7glWuJVGC2zxL/wSfYjWludtMCIABR5 tJOZKiyk72h9XiGt02Um5sbh5MFyMuY1XCFunCg4HhTRQ52/p1XiPSKUJRCJdOyAGrD9 qx/s2IV30dCTWSZBizS3oINEqzMDl6l0P+iuZ5Z1rkqN7qkiW4+CC/VhSARaB6qKgTCt f5P3360zrQ85tzFi7vajPkJo8ZKU5907G3NfbBw6tXmwlRHujLszmJNCDQP26jvyFrDU 7u6VAQLLboBZjTkcGSd302ezmqZvQrZUCekVETV91rA8yTtXhf8io6iD+6uGYIkvSIy5 T6RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=GTl70I3VImdHXFcfkCWch28oRlarp4PD9w8xue2RUDQ=; b=pPQ39iDPaYbkKu2lSw8h+Yc1XvZsu5McFk6js8LifkhlbQQC/lKeO9uhlgsTf38IXS 6sKeM6kKRZI1GzZeZrV+WpOl931Yfl/1NIEte3GUPywICmzxkh9p9NV5HkKJdfYC0q+5 YTclswqqjana2uZcA1muOmyH4+V9V2TqX8Q8irfPuoL+j0BzSJ4BmGb7BeE7lL+ryR3x x2xpq2XAuLx48WzEDrcja/Qy2oLOp8zIlIphXwCd+z5rdSMH7KoGuXNKB7KoWz8O3rkn rgwSKSSIDXeyNy0SpN10bC7cTD/GfujwQwhdSh0G4YTgk3G0+O+oBIrSsTU2GTU2hDIX Ax0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gGxH83zx; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si2186188pgc.818.2018.03.14.12.09.12; Wed, 14 Mar 2018 12:09:27 -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=@linaro.org header.s=google header.b=gGxH83zx; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751700AbeCNTGW (ORCPT + 99 others); Wed, 14 Mar 2018 15:06:22 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:40325 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751420AbeCNTGU (ORCPT ); Wed, 14 Mar 2018 15:06:20 -0400 Received: by mail-qt0-f195.google.com with SMTP id y6so4643579qtm.7 for ; Wed, 14 Mar 2018 12:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=GTl70I3VImdHXFcfkCWch28oRlarp4PD9w8xue2RUDQ=; b=gGxH83zxVsQTQitW1GodGKyYsUHLJL7j9svzJGMU30IQq07et8kywZkkeJZHGIXyTt 5ABxk5mvyTufJzEtf8ZHBTLxiPEcqEBHLgnRe01y0RyAUaEJZURBRdW/kJxJjuyGW2Zn +Le0+X5UJ7t+k7l/AnWNTtLYHtlzTD7ywgTeE= 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:in-reply-to:message-id :references:user-agent:mime-version; bh=GTl70I3VImdHXFcfkCWch28oRlarp4PD9w8xue2RUDQ=; b=kxi9A0A46bAJeTTnZ5fg1w4p5MkrCnIaBVm4aDTuIX4UQXQBJc81bWKTfc6spNV3k2 aaVYLox/vwgYx12/brpuuzb1mwl7j8qAXLA3iygI6PxpNj6EEjjkPZM12MWDWrCHR1fv 3eEKHrgbP5M65cTDTxnHp9Q7aFAse5mfw0U9Aqb/VlqhLHC+7QC8BYSsNwHHIlphApZg /yLxPC8XDtL2pPVfrYYRSsIop3sgNZCLxEsSlKoY2WYAtknNR6SLae1bT/Q8gistvG3e sg4NSJ27TEc9wRXYAN5MHysSGPakJbjgCdP2rgrqlpQYLcKaxpZJ02DR2mg8+p2jzqbR 8gew== X-Gm-Message-State: AElRT7Hwa+po5x80N8DFNXY1NaZAWdBajjXUR/IOcej1ii7QB3ZESBgF 0TISDxuXRx4xGPJ+RE6d022wMw== X-Received: by 10.237.32.226 with SMTP id 89mr9089176qtb.150.1521054379339; Wed, 14 Mar 2018 12:06:19 -0700 (PDT) Received: from xanadu.home (modemcable228.104-82-70.mc.videotron.ca. [70.82.104.228]) by smtp.gmail.com with ESMTPSA id 10sm2555897qtv.21.2018.03.14.12.06.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Mar 2018 12:06:18 -0700 (PDT) Date: Wed, 14 Mar 2018 15:06:17 -0400 (EDT) From: Nicolas Pitre To: Masahiro Yamada cc: linux-kbuild@vger.kernel.org, Jarod Wilson , Prarit Bhargava , Michal Marek , linux-kernel@vger.kernel.org Subject: Re: [PATCH 7/7] kbuild: link vmlinux just once for CONFIG_TRIM_UNUSED_KSYMS In-Reply-To: <1521045861-22418-8-git-send-email-yamada.masahiro@socionext.com> Message-ID: References: <1521045861-22418-1-git-send-email-yamada.masahiro@socionext.com> <1521045861-22418-8-git-send-email-yamada.masahiro@socionext.com> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Mar 2018, Masahiro Yamada wrote: > If CONFIG_TRIM_UNUSED_KSYMS is enabled and the kernel is built from > a pristine state, the vmlinux is linked twice. > > [1] A user runs "make" > > [2] First build with empty autoksyms.h > > [3] adjust_autoksyms.sh updates autoksyms.h and recurses "make vmlinux" > > --------(begin sub-make)-------- > [4] Second build with new autoksyms.h > > [5] link-vmlinux.sh is invoked because "vmlinux" is missing > ---------(end sub-make)--------- > > [6] link-vmlinux.sh is invoked again despite "vmlinux" is up-to-date. > > The reason of [6] is probably because Make already decided to update > "vmlinux" at the time of [2] because "vmlinux" was missing when Make > generated the dependency list. But the dependency list for vmlinux contains FORCE so the target is always remade in (2) anyway. The decision to actually invoke link-vmlinux.sh comes from "if_changed". Why is $(call if_changed,...) in (6) not noticing that vmlinux is up to date? > > link-vmlinus.sh is costly, so it is better to not run it when unneeded. > Split CONFIG_TRIM_UNUSED_KSYMS handling to a dedicated target. > > The reason of commit 2441e78b1919 ("krbuild: better abstract vmlinux > sequential prerequisites") was to cater to CONFIG_BUILD_DOCSRC, but > it was later removed by commit 184892925118 ("samples: move blackfin > gptimers-example from Documentation"). > > I also changed adjust_autoksyms.sh to simply exit with 1 or 0 to make > it look straightforward. That is wrong. If the script fails for some reason (it runs with -e set) then this will trigger an endless recursive make instead of failing the build. > Signed-off-by: Masahiro Yamada > --- > > Makefile | 28 ++++++++++++---------------- > scripts/adjust_autoksyms.sh | 3 +-- > 2 files changed, 13 insertions(+), 18 deletions(-) > > diff --git a/Makefile b/Makefile > index 1dab647..0a7bab6 100644 > --- a/Makefile > +++ b/Makefile > @@ -987,21 +987,11 @@ export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Doc > > vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) $(KBUILD_VMLINUX_LIBS) > > -# Include targets which we want to execute sequentially if the rest of the > -# kernel build went well. If CONFIG_TRIM_UNUSED_KSYMS is set, this might be > -# evaluated more than once. > -PHONY += vmlinux_prereq > -vmlinux_prereq: $(vmlinux-deps) FORCE > -ifdef CONFIG_HEADERS_CHECK > - $(Q)$(MAKE) -f $(srctree)/Makefile headers_check > -endif > -ifdef CONFIG_GDB_SCRIPTS > - $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) > -endif > -ifdef CONFIG_TRIM_UNUSED_KSYMS > - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ > - "$(MAKE) -f $(srctree)/Makefile vmlinux" > -endif > +# Recurse until adjust_autoksyms.sh is satisfied > +PHONY += autoksyms_recursive > +autoksyms_recursive: $(vmlinux-deps) > + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh || \ > + $(MAKE) -f $(srctree)/Makefile autoksyms_recursive > > # For the kernel to actually contain only the needed exported symbols, > # we have to build modules as well to determine what those symbols are. > @@ -1023,7 +1013,13 @@ cmd_link-vmlinux = \ > $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \ > $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) > > -vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE > +vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE > +ifdef CONFIG_HEADERS_CHECK > + $(Q)$(MAKE) -f $(srctree)/Makefile headers_check > +endif > +ifdef CONFIG_GDB_SCRIPTS > + $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) > +endif > +$(call if_changed,link-vmlinux) > > # Build samples along the rest of the kernel > diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh > index 7bb3618..1377cf8 100755 > --- a/scripts/adjust_autoksyms.sh > +++ b/scripts/adjust_autoksyms.sh > @@ -95,8 +95,7 @@ if [ $changed -gt 0 ]; then > info "KSYMS" "symbols: before=$old, after=$new, changed=$changed" > info "UPD" "$cur_ksyms_file" > mv -f "$new_ksyms_file" "$cur_ksyms_file" > - # Then trigger a rebuild of affected source files > - exec $@ > + exit 1 > else > rm -f "$new_ksyms_file" > fi > -- > 2.7.4 > >