Received: by 10.213.65.68 with SMTP id h4csp114454imn; Thu, 15 Mar 2018 19:21:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELsMmzxsMAk4FD+CCNCBzHq29MY7tYI5NzfgUQQT0/iZQIlGZr0tVO/eS+xSJdU7KxtnpYKT X-Received: by 2002:a17:902:5410:: with SMTP id d16-v6mr160351pli.176.1521166875463; Thu, 15 Mar 2018 19:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521166875; cv=none; d=google.com; s=arc-20160816; b=nttq/flwP8jBlIsW1bMlI9M2yrCSTttWCRVrTuv/1iYFvMB0Eo+wWHBuxSc9yzMkTj f3na6Mne/ov6qAopO1D6WvUOndxQfKyZGikVbiBt2st1yOunkqgm1hgewMJrz01QcGwE UFwZHq6fpdQlTHl+04xzlzDsoz/U31XBXt99asKjmLaJYuXMIL5gr7csPjGvzojR7lsN 40ZNe7LuF/QQs7eU3t4hoWLPF4JVmPQFhYljTzND2jpgRCyj0EwV0e+RTZp7Rt1fF7m7 pTweYUjQVtcTis7R9iA0iNc0GEXd9E4l6Ua+udKf+gAYZavRACwOYi2BS1CyTV+x4nBQ bfjg== 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=pKL4xNzW3+P38Gp7A3/RpIx3HLB3Ws8GbF2lt3zGUZk=; b=TZBjxQVkgCvKQh1AnOLxVaW3OCZkiW8ByrPtKGC+/6UvGyu+nWTrK+QdSTWLWC9ci1 wl2/5/H62Q+PhGpjXyroRHa9Pce+iHR9UbwD2Lspy+yn9q21m2Zvx6hmeC5fjIRwAxZe lPAe6PfKN/FjB1nKjha1w12wbLkjYaRNGsciYiCz/jFaPL8V+ORkAEaw4q0uTxunpHA1 48tI1VSQgkObXsYOgXXlsX4jb0FTCaHL/UkTchO6wJROtG8OPrdoa8kRqYwyUy87mvmg u6TVQe6XKnlA6u5O9WXtXOOHjOd0dlyLyH10SXx84ZAvyTdzWopbhuC3ajJi1wH8GgrY sOdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=CXG7F1vJ; 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 p2-v6si5189804plo.33.2018.03.15.19.20.54; Thu, 15 Mar 2018 19:21:15 -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=CXG7F1vJ; 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 S932568AbeCPCTO (ORCPT + 99 others); Thu, 15 Mar 2018 22:19:14 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:44533 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbeCPCTM (ORCPT ); Thu, 15 Mar 2018 22:19:12 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id w2G2IoBS003525; Fri, 16 Mar 2018 11:18:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com w2G2IoBS003525 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521166735; bh=pKL4xNzW3+P38Gp7A3/RpIx3HLB3Ws8GbF2lt3zGUZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CXG7F1vJXILOADe4IACwOnRrmzSiyyvb2JOGIbK5A/ThUqmVipMV9qLBrqs7VOl/s FuMQj0cKf7orV1pkKUtb6L6avCmLkAHJWFJQMgjn73Lx+afZ5fgkQsoO7JFCVB2bbe +8+MoGXXs91nWXGcDhv1XHTj4ffcEbrqxb2McnAn06nYOhxprcU/v8eay7hXFeC2m0 nRDejtBXmlnivmITdSz0F04oeiKIqPX2qUmbbykJtuteOlmdJZTvcFHAaP7koyQUtv pQN1FTKKZqs1YMiPbVSgkQhQbOaIn3W2YZTZODA33pHWptstF8Zj9hzu98RRK73LyA HLqApPJlR3heA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Nicolas Pitre , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] kbuild: link vmlinux only once for CONFIG_TRIM_UNUSED_KSYMS Date: Fri, 16 Mar 2018 11:18:44 +0900 Message-Id: <1521166725-24157-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521166725-24157-1-git-send-email-yamada.masahiro@socionext.com> References: <1521166725-24157-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 cp B A @echo newer prerequisite: $? B: C cp C B touch A [Result] $ rm -f A B $ touch C $ make cp C B touch A cp B A newer prerequisite: B 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 v2: - Discard my wrong change to adjust_autoksyms.sh - Add more commit log to explain how Make is working Makefile | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 5fee703..3e871d2 100644 --- a/Makefile +++ b/Makefile @@ -998,21 +998,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 \ +# 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 vmlinux" -endif # For the kernel to actually contain only the needed exported symbols, # we have to build modules as well to determine what those symbols are. @@ -1034,7 +1024,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