kbuild: update modules.order only when contained modules are updated

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>
This commit is contained in:
Masahiro Yamada 2020-06-01 14:57:00 +09:00
parent f0d50ca045
commit b2c8855491
3 changed files with 38 additions and 24 deletions

View File

@ -1066,6 +1066,10 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \
$(patsubst %/,%,$(filter %/, $(core-) \ $(patsubst %/,%,$(filter %/, $(core-) \
$(drivers-) $(libs-)))) $(drivers-) $(libs-))))
subdir-modorder := $(addsuffix modules.order,$(filter %/, \
$(core-y) $(core-m) $(libs-y) $(libs-m) \
$(drivers-y) $(drivers-m)))
build-dirs := $(vmlinux-dirs) build-dirs := $(vmlinux-dirs)
clean-dirs := $(vmlinux-alldirs) clean-dirs := $(vmlinux-alldirs)
@ -1124,7 +1128,7 @@ targets := vmlinux
# The actual objects are generated when descending, # The actual objects are generated when descending,
# make sure no implicit rule kicks in # make sure no implicit rule kicks in
$(sort $(vmlinux-deps)): descend ; $(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
filechk_kernel.release = \ filechk_kernel.release = \
echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
@ -1345,8 +1349,12 @@ PHONY += modules_check
modules_check: modules.order modules_check: modules.order
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
modules.order: descend cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
modules.order: $(subdir-modorder) FORCE
$(call if_changed,modules_order)
targets += modules.order
# Target to prepare building external modules # Target to prepare building external modules
PHONY += modules_prepare PHONY += modules_prepare

View File

@ -71,7 +71,7 @@ endif
# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) 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) targets-for-builtin := $(extra-y)
@ -83,8 +83,7 @@ ifdef need-builtin
targets-for-builtin += $(obj)/built-in.a targets-for-builtin += $(obj)/built-in.a
endif endif
targets-for-modules := $(obj-m) targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m)))
targets-for-modules += $(patsubst %.o, %.mod, $(obj-m))
ifdef need-modorder ifdef need-modorder
targets-for-modules += $(obj)/modules.order targets-for-modules += $(obj)/modules.order
@ -361,8 +360,9 @@ endif
$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
$(call if_changed_rule,as_o_S) $(call if_changed_rule,as_o_S)
targets += $(filter-out $(subdir-builtin), $(real-obj-y)) $(real-obj-m) $(lib-y) targets += $(filter-out $(subdir-builtin), $(real-obj-y))
targets += $(always-y) $(MAKECMDGOALS) targets += $(filter-out $(subdir-modorder), $(real-obj-m))
targets += $(lib-y) $(always-y) $(MAKECMDGOALS)
# Linker scripts preprocessor (.lds.S -> .lds) # 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 # Create commands to either record .ko file or cat modules.order from
# a subdirectory # a subdirectory
$(obj)/modules.order: $(subdir-modorder) FORCE # Add $(obj-m) as the prerequisite to avoid updating the timestamp of
$(Q){ $(foreach m, $(modorder), \ # modules.order unless contained modules are updated.
$(if $(filter $^, $m), cat $m, echo $m);) :; } \
cmd_modules_order = { $(foreach m, $(real-prereqs), \
$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
| $(AWK) '!x[$$0]++' - > $@ | $(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) # Rule to compile a set of .o files into one .a file (with symbol table)
# #

View File

@ -32,27 +32,29 @@ obj-m := $(filter-out $(obj-y),$(obj-m))
# Filter out objects already built-in # Filter out objects already built-in
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 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 # Subdirectories we need to descend into
subdir-ym := $(sort $(subdir-y) $(subdir-m) \ subdir-ym := $(sort $(subdir-y) $(subdir-m) \
$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
# Handle objects in subdirs # Handle objects in subdirs:
# --------------------------------------------------------------------------- # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a # foo/modules.order
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) # - 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 ifdef need-builtin
obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
else else
obj-y := $(filter-out %/, $(obj-y)) obj-y := $(filter-out %/, $(obj-y))
endif endif
obj-m := $(filter-out %/, $(obj-m))
# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object # 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)))) 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)) extra-y := $(addprefix $(obj)/,$(extra-y))
always-y := $(addprefix $(obj)/,$(always-y)) always-y := $(addprefix $(obj)/,$(always-y))
targets := $(addprefix $(obj)/,$(targets)) targets := $(addprefix $(obj)/,$(targets))
modorder := $(addprefix $(obj)/,$(modorder))
obj-m := $(addprefix $(obj)/,$(obj-m)) obj-m := $(addprefix $(obj)/,$(obj-m))
lib-y := $(addprefix $(obj)/,$(lib-y)) lib-y := $(addprefix $(obj)/,$(lib-y))
real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y))