History

kbuild: unify two modpost invocations

Currently, modpost is executed twice; first for vmlinux, second for modules. This commit merges them. Current build flow ================== 1) build obj-y and obj-m objects 2) link vmlinux.o 3) modpost for vmlinux 4) link vmlinux 5) modpost for modules 6) link modules (*.ko) The build steps 1) through 6) are serialized, that is, modules are built after vmlinux. You do not get benefits of parallel builds when scripts/link-vmlinux.sh is being run. New build flow ============== 1) build obj-y and obj-m objects 2) link vmlinux.o 3) modpost for vmlinux and modules 4a) link vmlinux 4b) link modules (*.ko) In the new build flow, modpost is invoked just once. vmlinux and modules are built in parallel. One exception is CONFIG_DEBUG_INFO_BTF_MODULES=y, where modules depend on vmlinux.

Masahiro Yamada committed 4 years ago

Commit f73edc81 parent 9c5a0ac4 files · +54 −76Browse files

Unified · Split

4 files
  1. Makefile +25 −7
  2. scripts/Makefile.modfinal +1 −1
  3. scripts/Makefile.modpost +28 −65
  4. scripts/link-vmlinux.sh +0 −3
Makefile+25−7
@@ -1150,7 +1150,7 @@ cmd_link-vmlinux = \ · 1149 unmodified lines
1150 $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \1150 $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \
1151 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)1151 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
1152 1152
1153vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE1153vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) modpost FORCE
1154 +$(call if_changed_dep,link-vmlinux)1154 +$(call if_changed_dep,link-vmlinux)
1155 1155
1156targets := vmlinux1156targets := vmlinux
@@ -1426,7 +1426,13 @@ endif · 269 unmodified lines
1426# Build modules1426# Build modules
1427#1427#
1428 1428
1429modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_prepare1429# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFOBTF_MODULES
1430# is an exception.
1431ifdef CONFIG_DEBUG_INFO_BTF_MODULES
1432modules: vmlinux
1433endif
1434
1435modules: modules_prepare
1430 1436
1431# Target to prepare building external modules1437# Target to prepare building external modules
1432modules_prepare: prepare1438modules_prepare: prepare
@@ -1739,8 +1745,12 @@ ifdef CONFIG_MODULES · 306 unmodified lines
1739$(MODORDER): $(build-dir)1745$(MODORDER): $(build-dir)
1740 @:1746 @:
1741 1747
1742modules: modules_check1748# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
1743 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost1749# This is solely useful to speed up test compiles.
1750modules: modpost
1751ifneq ($(KBUILD_MODPOST_NOFINAL),1)
1752 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1753endif
1744 1754
1745PHONY += modules_check1755PHONY += modules_check
1746modules_check: $(MODORDER)1756modules_check: $(MODORDER)
@@ -1771,6 +1781,11 @@ KBUILD_MODULES := · 24 unmodified lines
1771 1781
1772endif # CONFIG_MODULES1782endif # CONFIG_MODULES
1773 1783
1784PHONY += modpost
1785modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
1786 $(if $(KBUILD_MODULES), modules_check)
1787 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1788
1774# Single targets1789# Single targets
1775# ---------------------------------------------------------------------------1790# ---------------------------------------------------------------------------
1776# To build individual files in subdirectories, you can do like this:1791# To build individual files in subdirectories, you can do like this:
@@ -1790,16 +1805,19 @@ single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) · 13 unmodified lines
1790single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \1805single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
1791 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))1806 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
1792 1807
1793$(single-ko): single_modpost1808$(single-ko): single_modules
1794 @:1809 @:
1795$(single-no-ko): $(build-dir)1810$(single-no-ko): $(build-dir)
1796 @:1811 @:
1797 1812
1798# Remove MODORDER when done because it is not the real one.1813# Remove MODORDER when done because it is not the real one.
1799PHONY += single_modpost1814PHONY += single_modules
1800single_modpost: $(single-no-ko) modules_prepare1815single_modules: $(single-no-ko) modules_prepare
1801 $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$m;) } > $(MODORDER)1816 $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$m;) } > $(MODORDER)
1802 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost1817 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1818ifneq ($(KBUILD_MODPOST_NOFINAL),1)
1819 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1820endif
1803 $(Q)rm -f $(MODORDER)1821 $(Q)rm -f $(MODORDER)
1804 1822
1805single-goals := $(addprefix $(build-dir)/, $(single-no-ko))1823single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
scripts/Makefile.modfinal+1−1
@@ -55,7 +55,7 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ · 54 unmodified lines
55 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)55 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
56 56
57# Re-generate module BTFs if either module's .ko or vmlinux changed57# Re-generate module BTFs if either module's .ko or vmlinux changed
58$(modules): %.ko: %.o %.mod.o scripts/module.lds $(if $(KBUILD_BUILTIN),vmlinux) FORCE58$(modules): %.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE
59 +$(call if_changed_except,ld_ko_o,vmlinux)59 +$(call if_changed_except,ld_ko_o,vmlinux)
60ifdef CONFIG_DEBUG_INFO_BTF_MODULES60ifdef CONFIG_DEBUG_INFO_BTF_MODULES
61 +$(if $(newer-prereqs),$(call cmd,btf_ko))61 +$(if $(newer-prereqs),$(call cmd,btf_ko))
scripts/Makefile.modpost+28−65
@@ -32,9 +32,6 @@ · 31 unmodified lines
32# Step 4 is solely used to allow module versioning in external modules,32# Step 4 is solely used to allow module versioning in external modules,
33# where the CRC of each module is retrieved from the Module.symvers file.33# where the CRC of each module is retrieved from the Module.symvers file.
34 34
35# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
36# This is solely useful to speed up test compiles
37
38PHONY := __modpost35PHONY := __modpost
39__modpost:36__modpost:
40 37
@@ -45,24 +42,23 @@ MODPOST = scripts/mod/modpost \ · 4 unmodified lines
45 $(if $(CONFIG_MODVERSIONS),-m) \42 $(if $(CONFIG_MODVERSIONS),-m) \
46 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \43 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \
47 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \44 $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
45 $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
46 $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \
48 -o $@47 -o $@
49 48
50ifdef MODPOST_VMLINUX49# 'make -i -k' ignores compile errors, and builds as many modules as possible.
51 50ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
52quiet_cmd_modpost = MODPOST $@51MODPOST += -n
53 cmd_modpost = $(MODPOST) $<52endif
54
55vmlinux.symvers: vmlinux.o
56 $(call cmd,modpost)
57 53
58__modpost: vmlinux.symvers54ifeq ($(KBUILD_EXTMOD),)
59 55
60# Generate the list of in-tree objects in vmlinux56# Generate the list of in-tree objects in vmlinux
61# ---------------------------------------------------------------------------57# ---------------------------------------------------------------------------
62 58
63# This is used to retrieve symbol versions generated by genksyms.59# This is used to retrieve symbol versions generated by genksyms.
64ifdef CONFIG_MODVERSIONS60ifdef CONFIG_MODVERSIONS
65vmlinux.symvers: .vmlinux.objs61vmlinux.symvers Module.symvers: .vmlinux.objs
66endif62endif
67 63
68# Ignore libgcc.a64# Ignore libgcc.a
@@ -83,24 +79,12 @@ targets += .vmlinux.objs · 14 unmodified lines
83.vmlinux.objs: $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE79.vmlinux.objs: $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
84 $(call if_changed,vmlinux_objs)80 $(call if_changed,vmlinux_objs)
85 81
86else82vmlinux.o-if-present := $(wildcard vmlinux.o)
87 83output-symdump := vmlinux.symvers
88ifeq ($(KBUILD_EXTMOD),)
89
90input-symdump := vmlinux.symvers
91output-symdump := modules-only.symvers
92
93quiet_cmd_cat = GEN $@
94 cmd_cat = cat $(real-prereqs) > $@
95
96ifneq ($(wildcard vmlinux.symvers),)
97
98__modpost: Module.symvers
99Module.symvers: vmlinux.symvers modules-only.symvers FORCE
100 $(call if_changed,cat)
101
102targets += Module.symvers
103 84
85ifdef KBUILD_MODULES
86output-symdump := $(if $(vmlinux.o-if-present), Module.symvers, modules-only.symvers)
87missing-input := $(filter-out $(vmlinux.o-if-present),vmlinux.o)
104endif88endif
105 89
106else90else
@@ -112,56 +96,35 @@ src := $(obj) · 5 unmodified lines
112# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS96# Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
113include $(or $(wildcard $(src)/Kbuild), $(src)/Makefile)97include $(or $(wildcard $(src)/Kbuild), $(src)/Makefile)
114 98
115# modpost option for external modules99module.symvers-if-present := $(wildcard Module.symvers)
116MODPOST += -e
117
118input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS)
119output-symdump := $(KBUILD_EXTMOD)/Module.symvers100output-symdump := $(KBUILD_EXTMOD)/Module.symvers
101missing-input := $(filter-out $(module.symvers-if-present), Module.symvers)
120 102
121endif103MODPOST += -e $(addprefix -i ,$(module.symvers-if-present) $(KBUILD_EXTRA_SYMBOLS))
122
123existing-input-symdump := $(wildcard $(input-symdump))
124
125# modpost options for modules (both in-kernel and external)
126MODPOST += \
127 $(addprefix -i ,$(existing-input-symdump)) \
128 $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \
129 $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N)
130
131# 'make -i -k' ignores compile errors, and builds as many modules as possible.
132ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
133MODPOST += -n
134endif
135 104
136# Clear VPATH to not search for *.symvers in $(srctree). Check only $(objtree).105endif # ($(KBUILD_EXTMOD),)
137VPATH :=
138$(input-symdump):
139 @echo >&2 'WARNING: Symbol version dump "$@" is missing.'
140 @echo >&2 ' Modules may not have dependencies or modversions.'
141 @echo >&2 ' You may get many unresolved symbol warnings.'
142 106
143# KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols107ifneq ($(KBUILD_MODPOST_WARN)$(missing-input),)
144ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),)
145MODPOST += -w108MODPOST += -w
146endif109endif
147 110
111modorder-if-needed := $(if $(KBUILD_MODULES), $(MODORDER))
112
148# Read out modules.order to pass in modpost.113# Read out modules.order to pass in modpost.
149# Otherwise, allmodconfig would fail with "Argument list too long".114# Otherwise, allmodconfig would fail with "Argument list too long".
150quiet_cmd_modpost = MODPOST $@115quiet_cmd_modpost = MODPOST $@
151 cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T -116 cmd_modpost = \
152 117 $(if $(missing-input), \
153$(output-symdump): $(MODORDER) $(input-symdump) FORCE118 echo >&2 "WARNING: $(missing-input) is missing."; \
154 $(call if_changed,modpost)119 echo >&2 " Modules may not have dependencies or modversions."; \
120 echo >&2 " You may get many unresolved symbol warnings.";) \
121 sed 's/ko$$/o/' $(or $(modorder-if-needed), /dev/null) | $(MODPOST) $(vmlinux.o-if-present) -T -
155 122
156targets += $(output-symdump)123targets += $(output-symdump)
124$(output-symdump): $(modorder-if-needed) $(vmlinux.o-if-present) $(moudle.symvers-if-present) FORCE
125 $(call if_changed,modpost)
157 126
158__modpost: $(output-symdump)127__modpost: $(output-symdump)
159ifneq ($(KBUILD_MODPOST_NOFINAL),1)
160 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
161endif
162
163endif
164
165PHONY += FORCE128PHONY += FORCE
166FORCE:129FORCE:
167 130
scripts/link-vmlinux.sh+0−3
@@ -214,9 +214,6 @@ if [ "$1" = "clean" ]; then · 213 unmodified lines
214 exit 0214 exit 0
215fi215fi
216 216
217# modpost vmlinux.o to check for section mismatches
218${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
219
220info MODINFO modules.builtin.modinfo217info MODINFO modules.builtin.modinfo
221${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo218${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo
222info GEN modules.builtin219info GEN modules.builtin