History

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

Since commit ff9b45c55b26 ("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.

Masahiro Yamada committed 7 years ago

Commit a7215881 parent acf2a132 files · +42 −36Browse files

Showing the changes to scripts (2 of 2 files). Show all

Unified · Split

2 files
  1. scripts/Makefile.modpost +41 −35
  2. scripts/link-vmlinux.sh +1 −1
scripts/Makefile.modpost+41−35
@@ -38,12 +38,39 @@ · 37 unmodified lines
3838 # symbols in the final module linking stage
3939 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
4040 # This is solely useful to speed up test compiles
41−PHONY := _modpost
42−_modpost: __modpost
41+
42+PHONY := __modpost
43+__modpost:
4344
4445 include include/config/auto.conf
4546 include scripts/Kbuild.include
4647
48+kernelsymfile := $(objtree)/Module.symvers
49+modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
50+
51+MODPOST = scripts/mod/modpost \
52+ $(if $(CONFIG_MODVERSIONS),-m) \
53+ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
54+ $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
55+ $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
56+ $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
57+ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
58+ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
59+ $(if $(KBUILD_MODPOST_WARN),-w)
60+
61+ifdef MODPOST_VMLINUX
62+
63+__modpost: vmlinux.o
64+
65+quiet_cmd_modpost = MODPOST $@
66+ cmd_modpost = $(MODPOST) $@
67+
68+PHONY += vmlinux.o
69+vmlinux.o:
70+ $(call cmd,modpost)
71+
72+else
73+
4774 # When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info
4875 ifneq ($(KBUILD_EXTMOD),)
4976
@@ -58,50 +85,27 @@ endif · 8 unmodified lines
5885
5986 include scripts/Makefile.lib
6087
61−kernelsymfile := $(objtree)/Module.symvers
62−modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
63−
6488 modorder := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order
6589
66−# Step 1), find all modules listed in modules.order
67−ifdef CONFIG_MODULES
90+# find all modules listed in modules.order
6891 modules := $(sort $(shell cat $(modorder)))
69−endif
7092
7193 # Stop after building .o files if NOFINAL is set. Makes compile tests quicker
72−_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
73−
74−# Step 2), invoke modpost
75−# Includes step 3,4
76−modpost = scripts/mod/modpost \
77− $(if $(CONFIG_MODVERSIONS),-m) \
78− $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \
79− $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
80− $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
81− $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \
82− $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
83− $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
84− $(if $(KBUILD_MODPOST_WARN),-w)
85−
86−MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))
94+__modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
95+ @:
96+
97+MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - $(wildcard vmlinux)
8798
8899 # We can go over command line length here, so be careful.
89100 quiet_cmd_modpost = MODPOST $(words $(modules)) modules
90− cmd_modpost = sed 's/ko$$/o/' $(modorder) | $(modpost) $(MODPOST_OPT) -s -T -
101+ cmd_modpost = sed 's/ko$$/o/' $(modorder) | $(MODPOST)
91102
92−PHONY += __modpost
93−__modpost:
94− $(call cmd,modpost) $(wildcard vmlinux)
95−
96−quiet_cmd_kernel-mod = MODPOST $@
97− cmd_kernel-mod = $(modpost) $@
98−
99−vmlinux.o: FORCE
100− $(call cmd,kernel-mod)
103+PHONY += modules-modpost
104+modules-modpost:
105+ $(call cmd,modpost)
101106
102107 # Declare generated files as targets for modpost
103−$(modules:.ko=.mod.c): __modpost ;
104−
108+$(modules:.ko=.mod.c): modules-modpost
105109
106110 # Step 5), compile all *.mod.c files
107111
@@ -149,4 +153,6 @@ existing-targets := $(wildcard $(sort $(targets))) · 41 unmodified lines
149153
150154 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
151155
156+endif
157+
152158 .PHONY: $(PHONY)
scripts/link-vmlinux.sh+1−1
@@ -210,7 +210,7 @@ info LD vmlinux.o · 209 unmodified lines
210210 modpost_link vmlinux.o
211211
212212 # modpost vmlinux.o to check for section mismatches
213−${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
213+${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
214214
215215 info MODINFO modules.builtin.modinfo
216216 ${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo