aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.build
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2019-07-17 02:17:57 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2019-07-17 13:19:31 -0400
commitb7dca6dd1e591ad19a9aae716f3898be8063f880 (patch)
tree34d1ad73abe2f2c3a9f359927718e1604cf8ff58 /scripts/Makefile.build
parent7deb55f57159f9de696ef8d5e93b201a6aba871c (diff)
kbuild: create *.mod with full directory path and remove MODVERDIR
While descending directories, Kbuild produces objects for modules, but do not link final *.ko files; it is done in the modpost. To keep track of modules, Kbuild creates a *.mod file in $(MODVERDIR) for every module it is building. Some post-processing steps read the necessary information from *.mod files. This avoids descending into directories again. This mechanism was introduced in 2003 or so. Later, commit 551559e13af1 ("kbuild: implement modules.order") added modules.order. So, we can simply read it out to know all the modules with directory paths. This is easier than parsing the first line of *.mod files. $(MODVERDIR) has a flat directory structure, that is, *.mod files are named only with base names. This is based on the assumption that the module name is unique across the tree. This assumption is really fragile. Stephen Rothwell reported a race condition caused by a module name conflict: https://lkml.org/lkml/2019/5/13/991 In parallel building, two different threads could write to the same $(MODVERDIR)/*.mod simultaneously. Non-unique module names are the source of all kind of troubles, hence commit 3a48a91901c5 ("kbuild: check uniqueness of module names") introduced a new checker script. However, it is still fragile in the build system point of view because this race happens before scripts/modules-check.sh is invoked. If it happens again, the modpost will emit unclear error messages. To fix this issue completely, create *.mod with full directory path so that two threads never attempt to write to the same file. $(MODVERDIR) is no longer needed. Since modules with directory paths are listed in modules.order, Kbuild is still able to find *.mod files without additional descending. I also killed cmd_secanalysis; scripts/mod/sumversion.c computes MD4 hash for modules with MODULE_VERSION(). When CONFIG_DEBUG_SECTION_MISMATCH=y, it occurs not only in the modpost stage, but also during directory descending, where sumversion.c may parse stale *.mod files. It would emit 'No such file or directory' warning when an object consisting a module is renamed, or when a single-obj module is turned into a multi-obj module or vice versa. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-by: Nicolas Pitre <nico@fluxnic.net>
Diffstat (limited to 'scripts/Makefile.build')
-rw-r--r--scripts/Makefile.build15
1 files changed, 3 insertions, 12 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index be32a3752de4..c6dfcc028f56 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -67,8 +67,6 @@ ifeq ($(CONFIG_MODULES)$(need-modorder),y1)
67modorder-target := $(obj)/modules.order 67modorder-target := $(obj)/modules.order
68endif 68endif
69 69
70# We keep a list of all modules in $(MODVERDIR)
71
72__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ 70__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
73 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ 71 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
74 $(subdir-ym) $(always) 72 $(subdir-ym) $(always)
@@ -87,11 +85,6 @@ ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
87 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< 85 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
88endif 86endif
89 87
90# Do section mismatch analysis for each module/built-in.a
91ifdef CONFIG_DEBUG_SECTION_MISMATCH
92 cmd_secanalysis = ; scripts/mod/modpost $@
93endif
94
95# Compile C sources (.c) 88# Compile C sources (.c)
96# --------------------------------------------------------------------------- 89# ---------------------------------------------------------------------------
97 90
@@ -278,13 +271,11 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
278 $(call cmd,force_checksrc) 271 $(call cmd,force_checksrc)
279 $(call if_changed_rule,cc_o_c) 272 $(call if_changed_rule,cc_o_c)
280 273
281# Single-part modules are special since we need to mark them in $(MODVERDIR)
282
283$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE 274$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
284 $(call cmd,force_checksrc) 275 $(call cmd,force_checksrc)
285 $(call if_changed_rule,cc_o_c) 276 $(call if_changed_rule,cc_o_c)
286 @{ echo $(@:.o=.ko); echo $@; \ 277 @{ echo $(@:.o=.ko); echo $@; \
287 $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) 278 $(cmd_undef_syms); } > $(patsubst %.o,%.mod,$@)
288 279
289quiet_cmd_cc_lst_c = MKLST $@ 280quiet_cmd_cc_lst_c = MKLST $@
290 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ 281 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -461,12 +452,12 @@ endif
461# module is turned into a multi object module, $^ will contain header file 452# module is turned into a multi object module, $^ will contain header file
462# dependencies recorded in the .*.cmd file. 453# dependencies recorded in the .*.cmd file.
463quiet_cmd_link_multi-m = LD [M] $@ 454quiet_cmd_link_multi-m = LD [M] $@
464cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) $(cmd_secanalysis) 455 cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^)
465 456
466$(multi-used-m): FORCE 457$(multi-used-m): FORCE
467 $(call if_changed,link_multi-m) 458 $(call if_changed,link_multi-m)
468 @{ echo $(@:.o=.ko); echo $(filter %.o,$^); \ 459 @{ echo $(@:.o=.ko); echo $(filter %.o,$^); \
469 $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) 460 $(cmd_undef_syms); } > $(patsubst %.o,%.mod,$@)
470$(call multi_depend, $(multi-used-m), .o, -objs -y -m) 461$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
471 462
472targets += $(multi-used-m) 463targets += $(multi-used-m)