kbuild: modpost: do not parse unnecessary rules for vmlinux modpost

Since commit ff9b45c55b ("kbuild: modpost: read modules.order instead
of $(MODVERDIR)/*.mod"), 'make vmlinux' emits a warning, like this:

$ make defconfig vmlinux
  [ snip ]
  LD      vmlinux.o
cat: modules.order: No such file or directory
  MODPOST vmlinux.o
  MODINFO modules.builtin.modinfo
  KSYM    .tmp_kallsyms1.o
  KSYM    .tmp_kallsyms2.o
  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map

When building only vmlinux, KBUILD_MODULES is not set. Hence, the
modules.order is not generated. For the vmlinux modpost, it is not
necessary at all.

Separate scripts/Makefile.modpost for the vmlinux/modules stages.
This works more efficiently because the vmlinux modpost does not
need to include .*.cmd files.

Fixes: ff9b45c55b ("kbuild: modpost: read modules.order instead of $(MODVERDIR)/*.mod")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2019-07-31 00:59:02 +09:00
parent acf2a1397a
commit a721588d94
2 changed files with 41 additions and 35 deletions

View File

@ -38,12 +38,39 @@
# symbols in the final module linking stage # symbols in the final module linking stage
# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
# This is solely useful to speed up test compiles # This is solely useful to speed up test compiles
PHONY := _modpost
_modpost: __modpost PHONY := __modpost
__modpost:
include include/config/auto.conf include include/config/auto.conf
include scripts/Kbuild.include include scripts/Kbuild.include
kernelsymfile := $(objtree)/Module.symvers
modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
MODPOST = scripts/mod/modpost \
$(if $(CONFIG_MODVERSIONS),-m) \
$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
$(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
$(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
$(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
$(if $(KBUILD_MODPOST_WARN),-w)
ifdef MODPOST_VMLINUX
__modpost: vmlinux.o
quiet_cmd_modpost = MODPOST $@
cmd_modpost = $(MODPOST) $@
PHONY += vmlinux.o
vmlinux.o:
$(call cmd,modpost)
else
# When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info # When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info
ifneq ($(KBUILD_EXTMOD),) ifneq ($(KBUILD_EXTMOD),)
@ -58,50 +85,27 @@ endif
include scripts/Makefile.lib include scripts/Makefile.lib
kernelsymfile := $(objtree)/Module.symvers
modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
modorder := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order modorder := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order
# Step 1), find all modules listed in modules.order # find all modules listed in modules.order
ifdef CONFIG_MODULES
modules := $(sort $(shell cat $(modorder))) modules := $(sort $(shell cat $(modorder)))
endif
# Stop after building .o files if NOFINAL is set. Makes compile tests quicker # Stop after building .o files if NOFINAL is set. Makes compile tests quicker
_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules)) __modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
@:
# Step 2), invoke modpost MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - $(wildcard vmlinux)
# Includes step 3,4
modpost = scripts/mod/modpost \
$(if $(CONFIG_MODVERSIONS),-m) \
$(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \
$(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
$(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
$(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
$(if $(KBUILD_MODPOST_WARN),-w)
MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))
# We can go over command line length here, so be careful. # We can go over command line length here, so be careful.
quiet_cmd_modpost = MODPOST $(words $(modules)) modules quiet_cmd_modpost = MODPOST $(words $(modules)) modules
cmd_modpost = sed 's/ko$$/o/' $(modorder) | $(modpost) $(MODPOST_OPT) -s -T - cmd_modpost = sed 's/ko$$/o/' $(modorder) | $(MODPOST)
PHONY += __modpost PHONY += modules-modpost
__modpost: modules-modpost:
$(call cmd,modpost) $(wildcard vmlinux) $(call cmd,modpost)
quiet_cmd_kernel-mod = MODPOST $@
cmd_kernel-mod = $(modpost) $@
vmlinux.o: FORCE
$(call cmd,kernel-mod)
# Declare generated files as targets for modpost # Declare generated files as targets for modpost
$(modules:.ko=.mod.c): __modpost ; $(modules:.ko=.mod.c): modules-modpost
# Step 5), compile all *.mod.c files # Step 5), compile all *.mod.c files
@ -149,4 +153,6 @@ existing-targets := $(wildcard $(sort $(targets)))
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
endif
.PHONY: $(PHONY) .PHONY: $(PHONY)

View File

@ -210,7 +210,7 @@ info LD vmlinux.o
modpost_link vmlinux.o modpost_link vmlinux.o
# modpost vmlinux.o to check for section mismatches # modpost vmlinux.o to check for section mismatches
${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
info MODINFO modules.builtin.modinfo info MODINFO modules.builtin.modinfo
${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo ${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo