From patchwork Fri Mar 16 07:37:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 131910 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp411076ljb; Fri, 16 Mar 2018 00:38:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELtl/dJr4Sko7AbnI8VXPqc0hgrMdwZYwp+C9F8nJAd6oyUsHCVuA58M7kytxI8iLoFCe6Q7 X-Received: by 10.99.0.2 with SMTP id 2mr728760pga.106.1521185914665; Fri, 16 Mar 2018 00:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521185914; cv=none; d=google.com; s=arc-20160816; b=diAuM7jtqZ9xnCWBJrmLVwjKWN48HIuuCMfO6GTNJi4XIe4TKQRk87+J7jzurl/Clc sq3k87JTlxRHIKbNXwpPuiBttMXd4g2TPDuuKoJGWVD8I9uiguVQW7XNfujNWQ7lwfDY LeReO1J45aqFnr1DXaWwLuJh3jRt3IVZYcBfKf0DUwJjriaiz1m8Mf4Sl1yBidTX5VYT WZKIVbK+FIWEsiFi6fRAFB+LojrSGFupswKvpVAvdWJtlEmcUvqFCxEgr0pZFw7bXBq9 OK42BTP/IFyR3imL+fdLxDhAXH1XRKzS646t/2jheLRx5zqCcYWKPSLDklYhY7Syzhvl Ymgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=6rDL/XwfRynASy0/rXFA1CXXpq42YfBbSco4GMviIok=; b=jh/SGJLvaKkLNQj5SeK9OH8JR47zS5ymBzXieG3xiDJM9xOF75hXU2mcEvj5wGjpe7 i6umxXnEA5OU1ktDCYNKiKfdU2tG0h3SqNnBZ+24BVCXnJCjIa7K3VUl4U0OpuwYrQdS GZ72Ia5sil/RQCa33p6+1NpE6A15RIGiRGCpZBEPuDR7BVvILYJ9E9JIE1051fjYgJfP 8qUpC1MyQBIkJDgZUCfmRcXkhBo0fobI/hNnVcw0Nj5eAWZ6slrmrKtewimG4YEbflDM ThsUUmtBNQXeFkJ8rnKylS0cdAUoaU+/RpcPyXZCYog2qt3w2W0vkK4nwzJwP4wsvwwX XMgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=h06Er6be; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s18si4647364pgd.65.2018.03.16.00.38.34; Fri, 16 Mar 2018 00:38:34 -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=@nifty.com header.s=dec2015msa header.b=h06Er6be; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753404AbeCPHiR (ORCPT + 28 others); Fri, 16 Mar 2018 03:38:17 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:20835 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753316AbeCPHhs (ORCPT ); Fri, 16 Mar 2018 03:37:48 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w2G7bOaA029139; Fri, 16 Mar 2018 16:37:31 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w2G7bOaA029139 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521185851; bh=6rDL/XwfRynASy0/rXFA1CXXpq42YfBbSco4GMviIok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h06Er6bellSrG6nLQsWF/HntijHl8B42uS5PSWsjq9OFUUjW2yng/c8sfZDp7AATH cdbMKVlCS4dM0wPPWmJmdXRRACRBuI8ZEd2GMSpVMedqpNP9su/Dwjot3DE34FKK18 5HjJmFVstBc/JEbgxaUlHctBllz4drN3+rTmFNHaOhKOFh18/pSgAWMvi30IO74ERn nOItalMXax3cUbt0blnXPDs46lhL9+22T7qCfLe6l/Pt2dQ3f9AMzUcecLo990iCQb FoHKN+xINjJL05Fx+LZmf8fIk4zrIxaCpFgb/eHaZjE2Y7iojTuG0vROS+pcCzK1Zi QrCQNio/Bl/8A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Michal Marek , Nicolas Pitre , linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH v4 7/7] kbuild: link vmlinux only once for CONFIG_TRIM_UNUSED_KSYMS Date: Fri, 16 Mar 2018 16:37:15 +0900 Message-Id: <1521185836-19120-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521185836-19120-1-git-send-email-yamada.masahiro@socionext.com> References: <1521185836-19120-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 built up the dependency graph. Because if_changed is implemented based on $?, this issue can be narrowed down to how Make handles $?. You can test it with the following simple code: [Test Makefile] A: B @echo newer prerequisite: $? cp B A B: C cp C B touch A [Result] $ rm -f A B $ touch C $ make cp C B touch A newer prerequisite: B cp B A Here, 'A' has been touched in the recipe of 'B'. So, the dependency 'A: B' has already been met before the recipe of 'A' is executed. However, Make does not notice the fact that the recipe of 'B' also updates 'A' as a side-effect. The situation is similar in this case; the vmlinux has actually been updated in the vmlinux_prereq target. Make cannot predict this, so judges the vmlinux is old. link-vmlinux.sh is costly, so it is better to not run it when unneeded. Split CONFIG_TRIM_UNUSED_KSYMS recursion to a dedicated target. The reason of commit 2441e78b1919 ("kbuild: 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"). Signed-off-by: Masahiro Yamada Acked-by: Nicolas Pitre --- Changes in v4: - typo fix link-vmlinus.sh -> link-vmlinux.sh Changes in v3: - autoksyms_recursive should be surrounded by ifdef CONFIG_TRIM_UNUSED_KSYMS Changes in v2: - Discard my wrong change to adjust_autoksyms.sh - Add more commit log to explain how Make is working Makefile | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 5fee703..ff62b8e 100644 --- a/Makefile +++ b/Makefile @@ -998,17 +998,9 @@ 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 +# Recurse until adjust_autoksyms.sh is satisfied +PHONY += autoksyms_recursive +autoksyms_recursive: $(vmlinux-deps) ifdef CONFIG_TRIM_UNUSED_KSYMS $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \ "$(MAKE) -f $(srctree)/Makefile vmlinux" @@ -1034,7 +1026,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