All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 06/37] kbuild: update modules.order only when contained modules are updated
Date: Mon,  1 Jun 2020 14:57:00 +0900	[thread overview]
Message-ID: <20200601055731.3006266-6-masahiroy@kernel.org> (raw)
In-Reply-To: <20200601055731.3006266-1-masahiroy@kernel.org>

Make modules.order depend on $(obj-m), and use if_changed to build it.
This will avoid unneeded update of modules.order, which will be useful
to optimize the modpost stage.

Currently, the second pass of modpost is always invoked. By checking the
timestamp of modules.order, we can avoid the unneeded modpost.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile               | 14 +++++++++++---
 scripts/Makefile.build | 21 +++++++++++++--------
 scripts/Makefile.lib   | 27 ++++++++++++++-------------
 3 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/Makefile b/Makefile
index 0416760aeb28..b40420a0b991 100644
--- a/Makefile
+++ b/Makefile
@@ -1066,6 +1066,10 @@ vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation \
 		     $(patsubst %/,%,$(filter %/, $(core-) \
 			$(drivers-) $(libs-))))
 
+subdir-modorder := $(addsuffix modules.order,$(filter %/, \
+			$(core-y) $(core-m) $(libs-y) $(libs-m) \
+			$(drivers-y) $(drivers-m)))
+
 build-dirs	:= $(vmlinux-dirs)
 clean-dirs	:= $(vmlinux-alldirs)
 
@@ -1124,7 +1128,7 @@ targets := vmlinux
 
 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
-$(sort $(vmlinux-deps)): descend ;
+$(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
 
 filechk_kernel.release = \
 	echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
@@ -1345,8 +1349,12 @@ PHONY += modules_check
 modules_check: modules.order
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
 
-modules.order: descend
-	$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
+cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@
+
+modules.order: $(subdir-modorder) FORCE
+	$(call if_changed,modules_order)
+
+targets += modules.order
 
 # Target to prepare building external modules
 PHONY += modules_prepare
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a1f09bec8c70..2e8810b7e5ed 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -71,7 +71,7 @@ endif
 
 # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
 subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
-subdir-modorder := $(sort $(filter %/modules.order, $(modorder)))
+subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
 
 targets-for-builtin := $(extra-y)
 
@@ -83,8 +83,7 @@ ifdef need-builtin
 targets-for-builtin += $(obj)/built-in.a
 endif
 
-targets-for-modules := $(obj-m)
-targets-for-modules += $(patsubst %.o, %.mod, $(obj-m))
+targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
 
 ifdef need-modorder
 targets-for-modules += $(obj)/modules.order
@@ -361,8 +360,9 @@ endif
 $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
 	$(call if_changed_rule,as_o_S)
 
-targets += $(filter-out $(subdir-builtin), $(real-obj-y)) $(real-obj-m) $(lib-y)
-targets += $(always-y) $(MAKECMDGOALS)
+targets += $(filter-out $(subdir-builtin), $(real-obj-y))
+targets += $(filter-out $(subdir-modorder), $(real-obj-m))
+targets += $(lib-y) $(always-y) $(MAKECMDGOALS)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
@@ -404,11 +404,16 @@ $(obj)/built-in.a: $(real-obj-y) FORCE
 #
 # Create commands to either record .ko file or cat modules.order from
 # a subdirectory
-$(obj)/modules.order: $(subdir-modorder) FORCE
-	$(Q){ $(foreach m, $(modorder), \
-	$(if $(filter $^, $m), cat $m, echo $m);) :; } \
+# Add $(obj-m) as the prerequisite to avoid updating the timestamp of
+# modules.order unless contained modules are updated.
+
+cmd_modules_order = { $(foreach m, $(real-prereqs), \
+	$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
 	| $(AWK) '!x[$$0]++' - > $@
 
+$(obj)/modules.order: $(obj-m) FORCE
+	$(call if_changed,modules_order)
+
 #
 # Rule to compile a set of .o files into one .a file (with symbol table)
 #
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 748e44d5a1e3..e598b07e6de4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -32,27 +32,29 @@ obj-m := $(filter-out $(obj-y),$(obj-m))
 # Filter out objects already built-in
 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
 
-# Determine modorder.
-# Unfortunately, we don't have information about ordering between -y
-# and -m subdirs.  Just put -y's first.
-ifdef need-modorder
-modorder	:= $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
-endif
-
 # Subdirectories we need to descend into
 subdir-ym := $(sort $(subdir-y) $(subdir-m) \
 			$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
 
-# Handle objects in subdirs
-# ---------------------------------------------------------------------------
-# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a
-# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
+# Handle objects in subdirs:
+# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
+#   foo/modules.order
+# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
+#
+# Generate modules.order to determine modorder. Unfortunately, we don't have
+# information about ordering between -y and -m subdirs. Just put -y's first.
+
+ifdef need-modorder
+obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
+else
+obj-m := $(filter-out %/, $(obj-m))
+endif
+
 ifdef need-builtin
 obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
 else
 obj-y		:= $(filter-out %/, $(obj-y))
 endif
-obj-m		:= $(filter-out %/, $(obj-m))
 
 # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))), $(m))))
@@ -81,7 +83,6 @@ endif
 extra-y		:= $(addprefix $(obj)/,$(extra-y))
 always-y	:= $(addprefix $(obj)/,$(always-y))
 targets		:= $(addprefix $(obj)/,$(targets))
-modorder	:= $(addprefix $(obj)/,$(modorder))
 obj-m		:= $(addprefix $(obj)/,$(obj-m))
 lib-y		:= $(addprefix $(obj)/,$(lib-y))
 real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
-- 
2.25.1

  parent reply	other threads:[~2020-06-01  5:57 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-01  5:56 [PATCH 01/37] kbuild: refactor subdir-ym calculation Masahiro Yamada
2020-06-01  5:56 ` [PATCH 02/37] kbuild: refactor tagets caluculation for KBUILD_{BUILTIN,KBUILD_MODULES} Masahiro Yamada
2020-06-01  5:56 ` [PATCH 03/37] kbuild: merge init-y into core-y Masahiro Yamada
2020-06-01  5:56 ` [PATCH 04/37] kbuild: merge net-y and virt-y into drivers-y Masahiro Yamada
2020-06-01  5:56 ` [PATCH 05/37] kbuild: refactor KBUILD_VMLINUX_{OBJS,LIBS} calculation Masahiro Yamada
2020-06-03  4:21   ` Masahiro Yamada
2020-06-01  5:57 ` Masahiro Yamada [this message]
2020-06-01  5:57 ` [PATCH 07/37] modpost: fix -i (--ignore-errors) MAKEFLAGS detection Masahiro Yamada
2020-06-01  5:57 ` [PATCH 08/37] modpost: move -T option close to the modpost command Masahiro Yamada
2020-06-01  5:57 ` [PATCH 09/37] modpost: pass -N option only for modules modpost Masahiro Yamada
2020-06-01  5:57 ` [PATCH 10/37] modpost: load KBUILD_EXTRA_SYMBOLS files in order Masahiro Yamada
2020-06-01  5:57 ` [PATCH 11/37] modpost: track if the symbol origin is a dump file or ELF object Masahiro Yamada
2020-06-01  5:57 ` [PATCH 12/37] modpost: allow to pass -i option multiple times to remove -e option Masahiro Yamada
2020-06-01  5:57 ` [PATCH 13/37] modpost: rename ext_sym_list to dump_list Masahiro Yamada
2020-06-01  5:57 ` [PATCH 14/37] modpost: re-add -e to set external_module flag Masahiro Yamada
2020-06-01  5:57 ` [PATCH 15/37] modpost: print symbol dump file as the build target in short log Masahiro Yamada
2020-06-01  5:57 ` [PATCH 16/37] modpost: refactor -i option calculation Masahiro Yamada
2020-06-01  5:57 ` [PATCH 17/37] modpost: generate vmlinux.symvers and reuse it for the second modpost Masahiro Yamada
2020-06-01  5:57 ` [PATCH 18/37] modpost: invoke modpost only when input files are updated Masahiro Yamada
2020-06-01  5:57 ` [PATCH 19/37] modpost: show warning if vmlinux is not found when processing modules Masahiro Yamada
2020-06-01  5:57 ` [PATCH 20/37] modpost: show warning if any of symbol dump files is missing Masahiro Yamada
2020-06-01  5:57 ` [PATCH 21/37] modpost: drop RCS/CVS $Revision handling in MODULE_VERSION() Masahiro Yamada
2020-06-01  5:57 ` [PATCH 22/37] modpost: do not call get_modinfo() for vmlinux(.o) Masahiro Yamada
2020-06-01  5:57 ` [PATCH 23/37] modpost: add read_text_file() and get_line() helpers Masahiro Yamada
2020-06-01  5:57 ` [PATCH 24/37] modpost: fix potential mmap'ed file overrun in get_src_version() Masahiro Yamada
2020-06-01  5:57 ` [PATCH 25/37] modpost: avoid false-positive file open error Masahiro Yamada
2020-06-01  5:57 ` [PATCH 26/37] modpost: use read_text_file() and get_line() for reading text files Masahiro Yamada
2020-06-01  5:57 ` [PATCH 27/37] modpost: remove get_next_text() and make {grab,release_}file static Masahiro Yamada
2020-06-01  5:57 ` [PATCH 28/37] modpost: remove -s option Masahiro Yamada
2020-06-01  5:57 ` [PATCH 29/37] modpost: move -d option in scripts/Makefile.modpost Masahiro Yamada
2020-06-01  5:57 ` [PATCH 30/37] modpost: remove mod->is_dot_o struct member Masahiro Yamada
2020-06-01  5:57 ` [PATCH 31/37] modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}() Masahiro Yamada
2020-06-01  5:57 ` [PATCH 32/37] modpost: add mod->is_vmlinux struct member Masahiro Yamada
2020-06-01  5:57 ` [PATCH 33/37] modpost: remove mod->skip " Masahiro Yamada
2020-06-01  5:57 ` [PATCH 34/37] modpost: set have_vmlinux in new_module() Masahiro Yamada
2020-06-01  5:57 ` [PATCH 35/37] modpost: strip .o from modname before calling new_module() Masahiro Yamada
2020-06-01  5:57 ` [PATCH 36/37] modpost: remove is_vmlinux() helper Masahiro Yamada
2020-06-01  5:57 ` [PATCH 37/37] modpost: change elf_info->size to size_t Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200601055731.3006266-6-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.