Received: by 10.213.65.68 with SMTP id h4csp139405imn; Thu, 15 Mar 2018 20:35:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELsDWWr8gUZev7v5tQHNO6gsI1at2ldRnM62i/hNb+tfgtGO9LC6ov1xSDG01FvkoT4+YO9f X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr376635plc.178.1521171350586; Thu, 15 Mar 2018 20:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521171350; cv=none; d=google.com; s=arc-20160816; b=tevCQkgTssMboZf1+HgeG2HB+R10omjhO5IGxrJATZiLjTeFhea4R+akYR7VyFjBe4 MRMWELVBef3JppCDvCxnicRSdyK8veAtso5ZkM1avHlMEN9CNhKjI8luW/q2wyasYPMC cL+PeJQ1nTUE7kUQIZvai1x9GCMBWuiSElJ3XapdGgHltP58dbz6Q7fiQWstlyX9sEEW eTmyVICd1gFoaKHkeHRZ4bY6w7NKVUhCZqFrJS5VZwtjhPrRShS6TsV6mvspCI6frMDp KzS+VnO10gGLWbsnvZkfSogbqr222jx2ExKU9JjkE/GSJyuBoaqojUZ3tbNbyOf01NQK 2joQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=J+AmADuvKr1pNOj85HI2mArvnIKkbybxqqbo8GBH/ek=; b=RK9ZgYVz8KU30IUMRiaiPU+tsggeoGW5e7Ek+ZhH3SFUAH+vRRty0QFpVdm6BNaG9+ 303fP56QdQBF13hFEx6HUhYnZTSIQBMRkprCl8REFrNlndMrYST8/gN3rikAuBAJ7vBi NAvHpkaWaMtI5txcGcwBlGhVu0DL8K0WBF8hL8B/770gvh83YIqDcBgYHJ1zvPHto586 ttEVwkApTE9faALShwm5wt5dPmpMVZLKbdCv2NV09IicOC7gD3Gu2MhNDjtsjIoYugFY r86NgRZBEzutfN96sZ2CXBUnjJ9XOqzzMwfTCgILi2d9Zf/T6V/JjeUhr/wu0OWXRfIS Up9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=NGL64nL7; 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 j8si4429271pgt.582.2018.03.15.20.35.36; Thu, 15 Mar 2018 20:35:50 -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=NGL64nL7; 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 S932985AbeCPDVV (ORCPT + 99 others); Thu, 15 Mar 2018 23:21:21 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:23931 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751791AbeCPDVT (ORCPT ); Thu, 15 Mar 2018 23:21:19 -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 w2G3Ku2k020621; Fri, 16 Mar 2018 12:20:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w2G3Ku2k020621 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521170457; bh=J+AmADuvKr1pNOj85HI2mArvnIKkbybxqqbo8GBH/ek=; h=From:To:Cc:Subject:Date:From; b=NGL64nL741TLL0ZqF2kJYJiebw/bnczfFDqrx1GGhcUl788JZWNui5AMpfUi/nriA 5DrMWtLykB95O0TuBOAXd8cqxk3k41cUXHpBQI0Na4miQ15bFAolvyYDajdPz19Ot/ LD56nxJzJg5zbP2U4GgUeS/j/GiqDLgwwxwXuLDlLw7X+hbusiIL/eYFenxpgH8uZO oFQln/yL+BHS4GAL+0JxCoCer1GwsP4FeqeoF/YBBvdctZ9GP1KmG14FN4s/Iz1VeS QlnqgaJwiFnxdj6UqQUpx4zwbg4aN1+aP8voOJjAQWWxQOJ3s8oiFWvM+X8YlbWtpU qFZ6j7koFJ5Ug== 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 v3 7/7] kbuild: link vmlinux only once for CONFIG_TRIM_UNUSED_KSYMS Date: Fri, 16 Mar 2018 12:20:49 +0900 Message-Id: <1521170449-31194-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 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; 'vmlinux' has actually been updated in the 'vmlinux_prereq' target. Make cannot predict this, so judges 'vmlinux' is old. link-vmlinus.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 --- 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(-) 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 -- 2.7.4