kbuild: refactor subdir-ym calculation
Subsystems (2)
PATCH 1/37 kbuild: refactor subdir-ym calculation
Remove the unneeded variables, __subdir-y and __subdir-m.
---
scripts/Makefile.lib | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
scripts/Makefile.lib +4 -9
@@ -39,16 +39,14 @@ ifdef need-modorder modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) endif +# Subdirectories we need to descend into +subdir-ym := $(sort $(subdir-y) $(subdir-m) \ + $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) + # Handle objects in subdirs # --------------------------------------------------------------------------- # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a -# and add the directory to the list of dirs to descend into: $(subdir-y) # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) -# and add the directory to the list of dirs to descend into: $(subdir-m) -__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) -subdir-y += $(__subdir-y) -__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) -subdir-m += $(__subdir-m) ifdef need-builtin obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) else
@@ -56,9 +54,6 @@ obj-y := $(filter-out %/, $(obj-y)) endif obj-m := $(filter-out %/, $(obj-m)) -# Subdirectories we need to descend into -subdir-ym := $(sort $(subdir-y) $(subdir-m)) - # 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-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))), $(m))))
Signature · 1 line
2.25.1
PATCH 2/37 kbuild: refactor tagets caluculation for KBUILD_{BUILTIN,KBUILD_MODULES}
Remove lib-target, builtin-target, modorder-target, and modtargets.
Instead, add targets-for-builtin and targets-for-modules.
---
scripts/Makefile.build | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
scripts/Makefile.build +12 -13
@@ -73,19 +73,24 @@ endif subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) subdir-modorder := $(sort $(filter %/modules.order, $(modorder))) +targets-for-builtin := $(extra-y) + ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) -lib-target := $(obj)/lib.a +targets-for-builtin += $(obj)/lib.a endif ifdef need-builtin -builtin-target := $(obj)/built-in.a +targets-for-builtin += $(obj)/built-in.a endif +targets-for-modules := $(obj-m) +targets-for-modules += $(patsubst %.o, %.mod, $(obj-m)) + ifdef need-modorder -modorder-target := $(obj)/modules.order +targets-for-modules += $(obj)/modules.order endif -mod-targets := $(patsubst %.o, %.mod, $(obj-m)) +targets += $(targets-for-builtin) $(targets-for-modules) # Linus' kernel sanity checking tool ifeq ($(KBUILD_CHECKSRC),1)
@@ -284,8 +289,6 @@ cmd_mod = { \ $(obj)/%.mod: $(obj)/%.o FORCE $(call if_changed,mod) -targets += $(mod-targets) - quiet_cmd_cc_lst_c = MKLST $@ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
@@ -359,7 +362,7 @@ $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE $(call if_changed_rule,as_o_S) targets += $(filter-out $(subdir-builtin), $(real-obj-y)) $(real-obj-m) $(lib-y) -targets += $(extra-y) $(always-y) $(MAKECMDGOALS) +targets += $(always-y) $(MAKECMDGOALS) # Linker scripts preprocessor (.lds.S -> .lds) # ---------------------------------------------------------------------------
@@ -396,8 +399,6 @@ quiet_cmd_ar_builtin = AR $@ $(obj)/built-in.a: $(real-obj-y) FORCE $(call if_changed,ar_builtin) -targets += $(builtin-target) - # # Rule to create modules.order file #
@@ -414,8 +415,6 @@ $(obj)/modules.order: $(subdir-modorder) FORCE $(obj)/lib.a: $(lib-y) FORCE $(call if_changed,ar) -targets += $(lib-target) - # NOTE: # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object # module is turned into a multi object module, $^ will contain header file
@@ -478,8 +477,8 @@ endif else -__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ - $(if $(KBUILD_MODULES),$(obj-m) $(mod-targets) $(modorder-target)) \ +__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ + $(if $(KBUILD_MODULES), $(targets-for-modules)) \ $(subdir-ym) $(always-y) @:
Signature · 1 line
2.25.1
PATCH 3/37 kbuild: merge init-y into core-y
In reply to Masahiro YamadaNo arch Makefile specifies init-y.
Merge init-y into core-y. This does not change the link order.
---
Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Makefile +4 -6
@@ -643,12 +643,11 @@ endif ifeq ($(KBUILD_EXTMOD),) # Objects we will link into vmlinux / subdirs we need to visit -init-y := init/ +core-y := init/ usr/ drivers-y := drivers/ sound/ drivers-$(CONFIG_SAMPLES) += samples/ net-y := net/ libs-y := lib/ -core-y := usr/ virt-y := virt/ endif # KBUILD_EXTMOD
@@ -1060,18 +1059,17 @@ export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps ifeq ($(KBUILD_EXTMOD),) core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ -vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ +vmlinux-dirs := $(patsubst %/,%,$(filter %/, \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y))) vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ - $(patsubst %/,%,$(filter %/, $(init-) $(core-) \ + $(patsubst %/,%,$(filter %/, $(core-) \ $(drivers-) $(net-) $(libs-) $(virt-)))) build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs) -init-y := $(patsubst %/, %/built-in.a, $(init-y)) core-y := $(patsubst %/, %/built-in.a, $(core-y)) drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) net-y := $(patsubst %/, %/built-in.a, $(net-y))
@@ -1085,7 +1083,7 @@ endif virt-y := $(patsubst %/, %/built-in.a, $(virt-y)) # Externally visible symbols (used by link-vmlinux.sh) -export KBUILD_VMLINUX_OBJS := $(head-y) $(init-y) $(core-y) $(libs-y2) \ +export KBUILD_VMLINUX_OBJS := $(head-y) $(core-y) $(libs-y2) \ $(drivers-y) $(net-y) $(virt-y) export KBUILD_VMLINUX_LIBS := $(libs-y1) export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
Signature · 1 line
2.25.1
PATCH 4/37 kbuild: merge net-y and virt-y into drivers-y
In reply to Masahiro YamadaThis will slightly change the link order; drivers-y from arch Makefile will be linked after virt/built-in.a, but I guess this is not a big deal.
---
Makefile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
Makefile +4 -8
@@ -646,9 +646,8 @@ ifeq ($(KBUILD_EXTMOD),) core-y := init/ usr/ drivers-y := drivers/ sound/ drivers-$(CONFIG_SAMPLES) += samples/ -net-y := net/ +drivers-y += net/ virt/ libs-y := lib/ -virt-y := virt/ endif # KBUILD_EXTMOD # The all: target is the default when no target is given on the
@@ -1061,18 +1060,17 @@ core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ vmlinux-dirs := $(patsubst %/,%,$(filter %/, \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ - $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y))) + $(libs-y) $(libs-m))) vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ $(patsubst %/,%,$(filter %/, $(core-) \ - $(drivers-) $(net-) $(libs-) $(virt-)))) + $(drivers-) $(libs-)))) build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs) core-y := $(patsubst %/, %/built-in.a, $(core-y)) drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) -net-y := $(patsubst %/, %/built-in.a, $(net-y)) libs-y2 := $(patsubst %/, %/built-in.a, $(filter %/, $(libs-y))) ifdef CONFIG_MODULES libs-y1 := $(filter-out %/, $(libs-y))
@@ -1080,11 +1078,9 @@ libs-y2 += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) else libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) endif -virt-y := $(patsubst %/, %/built-in.a, $(virt-y)) # Externally visible symbols (used by link-vmlinux.sh) -export KBUILD_VMLINUX_OBJS := $(head-y) $(core-y) $(libs-y2) \ - $(drivers-y) $(net-y) $(virt-y) +export KBUILD_VMLINUX_OBJS := $(head-y) $(core-y) $(libs-y2) $(drivers-y) export KBUILD_VMLINUX_LIBS := $(libs-y1) export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds export LDFLAGS_vmlinux
Signature · 1 line
2.25.1
PATCH 5/37 kbuild: refactor KBUILD_VMLINUX_{OBJS,LIBS} calculation
In reply to Masahiro YamadaDo not overwrite core-y or drivers-y. Remove libs-y1 and libs-y2.
---
Makefile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
Makefile +8 -9
@@ -1069,19 +1069,18 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs) -core-y := $(patsubst %/, %/built-in.a, $(core-y)) -drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) -libs-y2 := $(patsubst %/, %/built-in.a, $(filter %/, $(libs-y))) +# Externally visible symbols (used by link-vmlinux.sh) +KBUILD_VMLINUX_OBJS := $(head-y) $(addsuffix built-in.a, $(core-y)) +KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y))) ifdef CONFIG_MODULES -libs-y1 := $(filter-out %/, $(libs-y)) -libs-y2 += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) +KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) +KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) else -libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) +KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) endif +KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(drivers-y)) -# Externally visible symbols (used by link-vmlinux.sh) -export KBUILD_VMLINUX_OBJS := $(head-y) $(core-y) $(libs-y2) $(drivers-y) -export KBUILD_VMLINUX_LIBS := $(libs-y1) +export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds export LDFLAGS_vmlinux # used by scripts/Makefile.package
Signature · 1 line
2.25.1
Re: [PATCH 05/37] kbuild: refactor KBUILD_VMLINUX_{OBJS,LIBS} calculation
Quoted 5 lines · Masahiro Yamada
Do not overwrite core-y or drivers-y. Remove libs-y1 and libs-y2.
Signed-off-by Masahiro Yamada <[email protected]>---
To mend ARCH=arm64 build error,
I will fix up as follows.
Makefile +2 -2
@@ -1070,7 +1070,7 @@ build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs) # Externally visible symbols (used by link-vmlinux.sh) -KBUILD_VMLINUX_OBJS := $(head-y) $(addsuffix built-in.a, $(core-y)) +KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y)) KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y))) ifdef CONFIG_MODULES KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
@@ -1078,7 +1078,7 @@ KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) else KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) endif -KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(drivers-y)) +KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
Quoted 39 lines
Makefile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)Makefile +8
-10@@ -1069,19 +1069,18 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs) -core-y := $(patsubst %/, %/built-in.a, $(core-y)) -drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) -libs-y2 := $(patsubst %/, %/built-in.a, $(filter %/, $(libs-y))) +# Externally visible symbols (used by link-vmlinux.sh) +KBUILD_VMLINUX_OBJS := $(head-y) $(addsuffix built-in.a, $(core-y)) +KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y))) ifdef CONFIG_MODULES -libs-y1 := $(filter-out %/, $(libs-y)) -libs-y2 += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) +KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) +KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) else -libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) +KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) endif +KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(drivers-y)) -# Externally visible symbols (used by link-vmlinux.sh) -export KBUILD_VMLINUX_OBJS := $(head-y) $(core-y) $(libs-y2) $(drivers-y) -export KBUILD_VMLINUX_LIBS := $(libs-y1) +export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds export LDFLAGS_vmlinux # used by scripts/Makefile.package --2.25.1
Signature · 2 lines
Best Regards Masahiro Yamada
PATCH 6/37 kbuild: update modules.order only when contained modules are updated
In reply to Masahiro YamadaMake 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.
---
Makefile | 14 +++++++++++--- scripts/Makefile.build | 21 +++++++++++++-------- scripts/Makefile.lib | 27 ++++++++++++++------------- 3 files changed, 38 insertions(+), 24 deletions(-)
Makefile +11 -3
@@ -1066,6 +1066,10 @@ vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \ $(patsubst %/,%,$(filter %/, $(core-) \ $(drivers-) $(libs-)))) +subdir-modorder := $(addsuffix modules.order,$(filter %/, \ + $(core-y) $(core-m) $(libs-y) $(libs-m) \ + $(drivers-y) $(drivers-m))) + build-dirs := $(vmlinux-dirs) clean-dirs := $(vmlinux-alldirs)
@@ -1124,7 +1128,7 @@ targets := vmlinux # The actual objects are generated when descending, # make sure no implicit rule kicks in -$(sort $(vmlinux-deps)): descend ; +$(sort $(vmlinux-deps) $(subdir-modorder)): descend ; filechk_kernel.release = \ echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
@@ -1345,8 +1349,12 @@ PHONY += modules_check modules_check: modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< -modules.order: descend - $(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@ +cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@ + +modules.order: $(subdir-modorder) FORCE + $(call if_changed,modules_order) + +targets += modules.order # Target to prepare building external modules PHONY += modules_prepare
scripts/Makefile.build +13 -8
@@ -71,7 +71,7 @@ endif # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) 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)
@@ -83,8 +83,7 @@ ifdef need-builtin targets-for-builtin += $(obj)/built-in.a endif -targets-for-modules := $(obj-m) -targets-for-modules += $(patsubst %.o, %.mod, $(obj-m)) +targets-for-modules := $(patsubst %.o, %.mod, $(filter %.o, $(obj-m))) ifdef need-modorder targets-for-modules += $(obj)/modules.order
@@ -361,8 +360,9 @@ endif $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE $(call if_changed_rule,as_o_S) -targets += $(filter-out $(subdir-builtin), $(real-obj-y)) $(real-obj-m) $(lib-y) -targets += $(always-y) $(MAKECMDGOALS) +targets += $(filter-out $(subdir-builtin), $(real-obj-y)) +targets += $(filter-out $(subdir-modorder), $(real-obj-m)) +targets += $(lib-y) $(always-y) $(MAKECMDGOALS) # 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 # a subdirectory -$(obj)/modules.order: $(subdir-modorder) FORCE - $(Q){ $(foreach m, $(modorder), \ - $(if $(filter $^, $m), cat $m, echo $m);) :; } \ +# Add $(obj-m) as the prerequisite to avoid updating the timestamp of +# modules.order unless contained modules are updated. + +cmd_modules_order = { $(foreach m, $(real-prereqs), \ + $(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \ | $(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) #
scripts/Makefile.lib +14 -13
@@ -32,27 +32,29 @@ obj-m := $(filter-out $(obj-y),$(obj-m)) # Filter out objects already built-in 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 subdir-ym := $(sort $(subdir-y) $(subdir-m) \ $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) -# Handle objects in subdirs -# --------------------------------------------------------------------------- -# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a -# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) +# Handle objects in subdirs: +# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and +# foo/modules.order +# - 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 obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) else obj-y := $(filter-out %/, $(obj-y)) endif -obj-m := $(filter-out %/, $(obj-m)) # 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))))
@@ -81,7 +83,6 @@ endif extra-y := $(addprefix $(obj)/,$(extra-y)) always-y := $(addprefix $(obj)/,$(always-y)) targets := $(addprefix $(obj)/,$(targets)) -modorder := $(addprefix $(obj)/,$(modorder)) obj-m := $(addprefix $(obj)/,$(obj-m)) lib-y := $(addprefix $(obj)/,$(lib-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
Signature · 1 line
2.25.1
PATCH 7/37 modpost: fix -i (--ignore-errors) MAKEFLAGS detection
In reply to Masahiro Yamada$(filter -i,$(MAKEFLAGS)) works only for some cases.
The representation of $(MAKEFLAGS) depends on various factors:
- GNU Make version (version 3.8x or version 4.x)
- The context where $(MAKEFLAGS) is expanded (parse stage or recipe)
- The presence of other flags like -j
In my experiments, $(MAKEFLAGS) is expanded as follows:
* GNU Make 3.8x:
* without -j option:
--no-print-directory -Rri
* with -j option
* parse stage
--no-print-directory -Rri
* recipe line
--no-print-directory -Rr --jobserver-fds=3,4 -j -i
* GNU Make 4.x:
* without -j option
irR --no-print-directory
* with -j option
* parse stage
irR --no-print-directory
* recipe line
irR -j --jobserver-fds=3,4 --no-print-directory
If you use GNU Make 4.x, the flags are grouped together like 'irR', which does not work.
For the single thread build with GNU Make 3.8x, the flags are grouped like '-Rri', which does not work either.
To make it work for all cases, do likewise as commit 6f0fa58e4596 ("kbuild: simplify silent build (-s) detection").
BTW, since commit ff9b45c55b26 ("kbuild: modpost: read modules.order instead of $(MODVERDIR)/*.mod"), you also need to pass -k option to build final *.ko files. 'make -i -k' ignores compile errors in modules, and build as many remaining *.ko as possible.
Please note this feature is kind of dangerous because a module may depend on another module. If the prerequisite module fails to build, other modules may lack the correct module dependency or CRC. Honestly, I am not a big fan of it, but I am keeping this feature.
---
scripts/Makefile.modpost | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/Makefile.modpost +5 -1
@@ -66,7 +66,7 @@ __modpost: else -MODPOST += $(subst -i,-n,$(filter -i,$(MAKEFLAGS))) -s -T - \ +MODPOST += -s -T - \ $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) ifeq ($(KBUILD_EXTMOD),)
@@ -82,6 +82,10 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) endif +ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) +MODPOST += -n +endif + # find all modules listed in modules.order modules := $(sort $(shell cat $(MODORDER)))
Signature · 1 line
2.25.1
PATCH 8/37 modpost: move -T option close to the modpost command
In reply to Masahiro YamadaThe '-T -' option reads the file list from stdin.
It is clearer to put it close to the piped command.
---
scripts/Makefile.modpost | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/Makefile.modpost +2 -2
@@ -66,7 +66,7 @@ __modpost: else -MODPOST += -s -T - \ +MODPOST += -s \ $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) ifeq ($(KBUILD_EXTMOD),)
@@ -92,7 +92,7 @@ modules := $(sort $(shell cat $(MODORDER))) # Read out modules.order instead of expanding $(modules) to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". quiet_cmd_modpost = MODPOST $(words $(modules)) modules - cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) + cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T - __modpost: $(call cmd,modpost)
Signature · 1 line
2.25.1
PATCH 9/37 modpost: pass -N option only for modules modpost
In reply to Masahiro YamadaThe built-in only code is not required to have MODULE_IMPORT_NS() to use symbols. So, the namespace is not checked for vmlinux(.o).
Do not pass the meaningless -N option to the first pass of modpost.
---
scripts/Makefile.modpost | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/Makefile.modpost +4 -1
@@ -53,7 +53,6 @@ MODPOST = scripts/mod/modpost \ $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ - $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) \ $(if $(KBUILD_MODPOST_WARN),-w) ifdef MODPOST_VMLINUX
@@ -82,6 +81,10 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) endif +# modpost options for modules (both in-kernel and external) +MODPOST += \ + $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) + ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) MODPOST += -n endif
Signature · 1 line
2.25.1
PATCH 10/37 modpost: load KBUILD_EXTRA_SYMBOLS files in order
In reply to Masahiro YamadaCurrently, modpost reads extra symbol dump files in the reverse order. If '-e foo -e bar' is given, modpost reads bar, foo, in this order.
This is probably not a big deal, but there is no good reason to reverse the order. Read files in the given order.
---
scripts/mod/modpost.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
scripts/mod/modpost.c +8 -8
@@ -2555,8 +2555,8 @@ int main(int argc, char **argv)int opt;int err;int n; -struct ext_sym_list *extsym_iter;struct ext_sym_list *extsym_start =NULL ; +struct ext_sym_list **extsym_iter = &extsym_start;while ((opt =getopt (argc, argv,"i:e:mnsT:o:awENd:" )) !=-1 ) {switch (opt) {
@@ -2566,11 +2566,9 @@ int main(int argc, char **argv)break ;case 'e' : external_module =1 ; - extsym_iter = -NOFAIL (malloc (sizeof (*extsym_iter))); - extsym_iter->next = extsym_start; - extsym_iter->file = optarg; - extsym_start = extsym_iter; + *extsym_iter =NOFAIL (calloc (1 ,sizeof (**extsym_iter))); + (*extsym_iter)->file = optarg; + extsym_iter = &(*extsym_iter)->next;break ;case 'm' : modversions =1 ;
@@ -2610,10 +2608,12 @@ int main(int argc, char **argv)if (kernel_read)read_dump (kernel_read,1 );while (extsym_start) { +struct ext_sym_list *tmp; +read_dump (extsym_start->file,0 ); - extsym_iter = extsym_start->next; + tmp = extsym_start->next;free (extsym_start); - extsym_start = extsym_iter; + extsym_start = tmp; }while (optind < argc)
Signature · 1 line
2.25.1
PATCH 11/37 modpost: track if the symbol origin is a dump file or ELF object
In reply to Masahiro YamadaThe meaning of sym->kernel is obscure; it is set for in-kernel symbols loaded from Modules.symver. This happens only when we are building external modules, and it is used to determine whether to dump symbols to $(KBUILD_EXTMOD)/Modules.symver
It is clearer to remember whether the symbol or module came from a dump file or ELF object.
This changes the KBUILD_EXTRA_SYMBOLS behavior. Previously, symbols loaded from KBUILD_EXTRA_SYMBOLS are accumulated into the current $(KBUILD_EXTMOD)/Modules.symver
Going forward, they will be only used to check symbol references, but not dumped into the current $(KBUILD_EXTMOD)/Modules.symver. I believe this makes more sense.
sym->vmlinux will have no user. Remove it too.
---
scripts/mod/modpost.c | 15 +++++---------- scripts/mod/modpost.h | 1 + 2 files changed, 6 insertions(+), 10 deletions(-)
scripts/mod/modpost.c +5 -10
@@ -161,9 +161,6 @@ struct symbol {int crc_valid;char *namespace; unsigned int weak:1; - unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ - unsigned int kernel:1; /* 1 if symbol is from kernel -* (only for external modules) **/ unsigned int is_static:1; /* 1 if symbol is not global */enum export export;/* Type of export */ char name[];
@@ -398,8 +395,6 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, } s->module = mod; - s->vmlinux =is_vmlinux (mod->name); - s->kernel =0 ; s->export = export;return s; }
@@ -2427,7 +2422,7 @@ static void write_if_changed(struct buffer *b, const char *fname)/* parse Module.symvers file. line format: * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace **/ -static void read_dump (const char *fname,unsigned int kernel) +static void read_dump (const char *fname) {unsigned long size, pos =0 ;void *file =grab_file (fname, &size);
@@ -2465,9 +2460,9 @@ static void read_dump(const char *fname, unsigned int kernel) have_vmlinux =1 ; mod =new_module (modname); mod->skip =1 ; + mod->from_dump =1 ; } s =sym_add_exported (symname, mod,export_no (export)); - s->kernel = kernel; s->is_static =0 ;sym_set_crc (symname, crc);sym_update_namespace (symname, namespace);
@@ -2487,7 +2482,7 @@ static int dump_sym(struct symbol *sym) {if (!external_module)return 1 ; -if (sym->vmlinux || sym->kernel) +if (sym->module->from_dump)return 0 ;return 1 ; }
@@ -2606,11 +2601,11 @@ int main(int argc, char **argv) }if (kernel_read) -read_dump (kernel_read,1 ); +read_dump (kernel_read);while (extsym_start) {struct ext_sym_list *tmp; -read_dump (extsym_start->file,0 ); +read_dump (extsym_start->file); tmp = extsym_start->next;free (extsym_start); extsym_start = tmp;
scripts/mod/modpost.h +1 -0
@@ -119,6 +119,7 @@ struct module {const char *name;int gpl_compatible;struct symbol *unres; +int from_dump;/* 1 if module was loaded from *.symver */ int seen;int skip;int has_init;
Signature · 1 line
2.25.1
PATCH 12/37 modpost: allow to pass -i option multiple times to remove -e option
In reply to Masahiro YamadaNow that there is no difference between -i and -e, they can be unified.
Make modpost accept the -i option multiple times, then remove -e.
I will reuse -e for a different purpose.
---
scripts/Makefile.modpost | 2 +- scripts/mod/modpost.c | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-)
scripts/Makefile.modpost +1 -1
@@ -50,7 +50,7 @@ MODPOST = scripts/mod/modpost \ $(if $(CONFIG_MODVERSIONS),-m) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ - $(if $(KBUILD_EXTMOD),$(addprefix -e ,$(KBUILD_EXTRA_SYMBOLS))) \ + $(if $(KBUILD_EXTMOD),$(addprefix -i ,$(KBUILD_EXTRA_SYMBOLS))) \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_MODPOST_WARN),-w)
scripts/mod/modpost.c +1 -8
@@ -2544,7 +2544,6 @@ int main(int argc, char **argv) {struct module *mod;struct buffer buf = { }; -char *kernel_read =NULL ;char *missing_namespace_deps =NULL ;char *dump_write =NULL , *files_source =NULL ;int opt;
@@ -2553,13 +2552,9 @@ int main(int argc, char **argv)struct ext_sym_list *extsym_start =NULL ;struct ext_sym_list **extsym_iter = &extsym_start; -while ((opt =getopt (argc, argv,"i:e:mnsT:o:awENd:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"i:mnsT:o:awENd:" )) !=-1 ) {switch (opt) {case 'i' : - kernel_read = optarg; - external_module =1 ; -break ; -case 'e' : external_module =1 ; *extsym_iter =NOFAIL (calloc (1 ,sizeof (**extsym_iter))); (*extsym_iter)->file = optarg;
@@ -2600,8 +2595,6 @@ int main(int argc, char **argv) } } -if (kernel_read) -read_dump (kernel_read);while (extsym_start) {struct ext_sym_list *tmp;
Signature · 1 line
2.25.1
PATCH 13/37 modpost: rename ext_sym_list to dump_list
In reply to Masahiro YamadaThe -i option is used to include Modules.symver as well as files from $(KBUILD_EXTRA_SYMBOLS).
Make the struct and variable names more generic.
---
scripts/mod/modpost.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
scripts/mod/modpost.c +14 -13
@@ -2535,8 +2535,8 @@ static void write_namespace_deps_files(const char *fname)free (ns_deps_buf.p); } -struct ext_sym_list { -struct ext_sym_list *next; +struct dump_list { +struct dump_list *next;const char *file; };
@@ -2549,16 +2549,17 @@ int main(int argc, char **argv)int opt;int err;int n; -struct ext_sym_list *extsym_start =NULL ; -struct ext_sym_list **extsym_iter = &extsym_start; +struct dump_list *dump_read_start =NULL ; +struct dump_list **dump_read_iter = &dump_read_start;while ((opt =getopt (argc, argv,"i:mnsT:o:awENd:" )) !=-1 ) {switch (opt) {case 'i' : external_module =1 ; - *extsym_iter =NOFAIL (calloc (1 ,sizeof (**extsym_iter))); - (*extsym_iter)->file = optarg; - extsym_iter = &(*extsym_iter)->next; + *dump_read_iter = +NOFAIL (calloc (1 ,sizeof (**dump_read_iter))); + (*dump_read_iter)->file = optarg; + dump_read_iter = &(*dump_read_iter)->next;break ;case 'm' : modversions =1 ;
@@ -2595,13 +2596,13 @@ int main(int argc, char **argv) } } -while (extsym_start) { -struct ext_sym_list *tmp; +while (dump_read_start) { +struct dump_list *tmp; -read_dump (extsym_start->file); - tmp = extsym_start->next; -free (extsym_start); - extsym_start = tmp; +read_dump (dump_read_start->file); + tmp = dump_read_start->next; +free (dump_read_start); + dump_read_start = tmp; }while (optind < argc)
Signature · 1 line
2.25.1
PATCH 14/37 modpost: re-add -e to set external_module flag
In reply to Masahiro YamadaPreviously, the -i option had two functions; load a symbol dump file, and set the external_module flag.
I want to assign a dedicate option for each of them.
Going forward, the -i is used to load a symbol dump file, and the -e to set the external_module flag.
With this, we will be able to use -i for loading in-kernel symbols.
---
scripts/Makefile.modpost | 4 ++++ scripts/mod/modpost.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
scripts/Makefile.modpost +4 -0
@@ -79,6 +79,10 @@ src := $(obj) # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) + +# modpost option for external modules +MODPOST += -e + endif # modpost options for modules (both in-kernel and external)
scripts/mod/modpost.c +4 -2
@@ -2552,10 +2552,12 @@ int main(int argc, char **argv)struct dump_list *dump_read_start =NULL ;struct dump_list **dump_read_iter = &dump_read_start; -while ((opt =getopt (argc, argv,"i:mnsT:o:awENd:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ei:mnsT:o:awENd:" )) !=-1 ) {switch (opt) { -case 'i' : +case 'e' : external_module =1 ; +break ; +case 'i' : *dump_read_iter =NOFAIL (calloc (1 ,sizeof (**dump_read_iter))); (*dump_read_iter)->file = optarg;
Signature · 1 line
2.25.1
PATCH 15/37 modpost: print symbol dump file as the build target in short log
In reply to Masahiro YamadaThe symbol dump *.symvers is the output of modpost. Print it in the short log.
---
scripts/Makefile.modpost | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
scripts/Makefile.modpost +20 -13
@@ -44,25 +44,26 @@ include include/config/auto.conf include scripts/Kbuild.include kernelsymfile := $(objtree)/Module.symvers -modulesymfile := $(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 $(kernelsymfile)) \ $(if $(KBUILD_EXTMOD),$(addprefix -i ,$(KBUILD_EXTRA_SYMBOLS))) \ - $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ - $(if $(KBUILD_MODPOST_WARN),-w) + $(if $(KBUILD_MODPOST_WARN),-w) \ + -o $@ ifdef MODPOST_VMLINUX -quiet_cmd_modpost = MODPOST vmlinux.o - cmd_modpost = $(MODPOST) vmlinux.o +quiet_cmd_modpost = MODPOST $@ + cmd_modpost = $(MODPOST) $< -__modpost: +Module.symvers: vmlinux.o $(call cmd,modpost) +__modpost: Module.symvers + else MODPOST += -s \
@@ -70,6 +71,8 @@ MODPOST += -s \ ifeq ($(KBUILD_EXTMOD),) MODPOST += $(wildcard vmlinux) +output-symdump := Module.symvers + else # set src + obj - they may be used in the modules's Makefile
@@ -83,6 +86,8 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ # modpost option for external modules MODPOST += -e +output-symdump := $(KBUILD_EXTMOD)/Module.symvers + endif # modpost options for modules (both in-kernel and external)
@@ -93,20 +98,22 @@ ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) MODPOST += -n endif -# find all modules listed in modules.order -modules := $(sort $(shell cat $(MODORDER))) - -# Read out modules.order instead of expanding $(modules) to pass in modpost. +# Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". -quiet_cmd_modpost = MODPOST $(words $(modules)) modules +quiet_cmd_modpost = MODPOST $@ cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T - -__modpost: +$(output-symdump): FORCE $(call cmd,modpost) + +__modpost: $(output-symdump) ifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal endif +PHONY += FORCE +FORCE: + endif .PHONY: $(PHONY)
Signature · 1 line
2.25.1
PATCH 16/37 modpost: refactor -i option calculation
In reply to Masahiro YamadaPrepare to use -i for in-tree modpost as well.
---
scripts/Makefile.modpost | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/Makefile.modpost +2 -4
@@ -43,13 +43,9 @@ __modpost: include include/config/auto.conf include scripts/Kbuild.include -kernelsymfile := $(objtree)/Module.symvers - MODPOST = scripts/mod/modpost \ $(if $(CONFIG_MODVERSIONS),-m) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ - $(if $(KBUILD_EXTMOD),-i $(kernelsymfile)) \ - $(if $(KBUILD_EXTMOD),$(addprefix -i ,$(KBUILD_EXTRA_SYMBOLS))) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ $(if $(KBUILD_MODPOST_WARN),-w) \ -o $@
@@ -86,12 +82,14 @@ include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ # modpost option for external modules MODPOST += -e +input-symdump := Module.symvers $(KBUILD_EXTRA_SYMBOLS) output-symdump := $(KBUILD_EXTMOD)/Module.symvers endif # modpost options for modules (both in-kernel and external) MODPOST += \ + $(addprefix -i ,$(input-symdump)) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
Signature · 1 line
2.25.1
PATCH 17/37 modpost: generate vmlinux.symvers and reuse it for the second modpost
In reply to Masahiro YamadaThe full build runs modpost twice, first for vmlinux.o and second for modules.
The first pass dumps all the vmlinux symbols into Module.symvers, but the second pass parses vmlinux again instead of reusing the dump file, presumably because it needs to avoid accumulating stale symbols.
Loading symbol info from a dump file is faster than parsing an ELF object. Besides, modpost deals with various issues to parse vmlinux in the second pass.
A solution is to make the first pass dumps symbols into a separate file, vmlinux.symvers. The second pass reads it, and parses module .o files. The merged symbol information is dumped into Module.symvers in the same way as before.
This makes further modpost cleanups possible.
Also, it fixes the problem of 'make vmlinux', which previously overwrote Module.symvers, throwing away module symbols.
I slightly touched scripts/link-vmlinux.sh so that vmlinux is re-linked when you cross this commit. Otherwise, vmlinux.symvers would not be generated.
---
.gitignore | 1 + Documentation/dontdiff | 1 + Makefile | 2 +- scripts/Makefile.modpost | 7 ++++--- scripts/link-vmlinux.sh | 2 -- 5 files changed, 7 insertions(+), 6 deletions(-)
.gitignore +1 -0
@@ -56,6 +56,7 @@ modules.order /linux /vmlinux /vmlinux.32 +/vmlinux.symvers /vmlinux-gdb.py /vmlinuz /System.map
Documentation/dontdiff +1 -0
@@ -251,6 +251,7 @@ vmlinux-* vmlinux.aout vmlinux.bin.all vmlinux.lds +vmlinux.symvers vmlinuz voffset.h vsyscall.lds
Makefile +1 -1
@@ -1416,7 +1416,7 @@ endif # CONFIG_MODULES # make distclean Remove editor backup files, patch leftover files and the like # Directories & files removed with 'make clean' -CLEAN_FILES += include/ksym \ +CLEAN_FILES += include/ksym vmlinux.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps # Directories & files removed with 'make mrproper'
scripts/Makefile.modpost +4 -3
@@ -55,10 +55,10 @@ ifdef MODPOST_VMLINUX quiet_cmd_modpost = MODPOST $@ cmd_modpost = $(MODPOST) $< -Module.symvers: vmlinux.o +vmlinux.symvers: vmlinux.o $(call cmd,modpost) -__modpost: Module.symvers +__modpost: vmlinux.symvers else
@@ -66,7 +66,8 @@ MODPOST += -s \ $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) ifeq ($(KBUILD_EXTMOD),) -MODPOST += $(wildcard vmlinux) + +input-symdump := vmlinux.symvers output-symdump := Module.symvers else
scripts/link-vmlinux.sh +0 -2
@@ -218,8 +218,6 @@ on_signals() } trap on_signals HUP INT QUIT TERM -# -# # Use "make V=1" to debug this script case "${KBUILD_VERBOSE}" in *1*)
Signature · 1 line
2.25.1
PATCH 18/37 modpost: invoke modpost only when input files are updated
In reply to Masahiro YamadaCurrently, the second pass of modpost is always invoked when you run 'make' or 'make modules' even if none of modules is changed.
Use if_changed to invoke it only when it is necessary.
---
scripts/Makefile.modpost | 20 ++++++++++++++++---- scripts/mod/modpost.c | 32 +++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 15 deletions(-)
scripts/Makefile.modpost +16 -4
@@ -90,20 +90,25 @@ endif # modpost options for modules (both in-kernel and external) MODPOST += \ - $(addprefix -i ,$(input-symdump)) \ + $(addprefix -i ,$(wildcard $(input-symdump))) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) MODPOST += -n endif +$(input-symdump): + @: + # Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". quiet_cmd_modpost = MODPOST $@ - cmd_modpost = sed 's/ko$$/o/' $(MODORDER) | $(MODPOST) -T - + cmd_modpost = sed 's/ko$$/o/' $< | $(MODPOST) -T - -$(output-symdump): FORCE - $(call cmd,modpost) +$(output-symdump): $(MODORDER) $(input-symdump) FORCE + $(call if_changed,modpost) + +targets += $(output-symdump) __modpost: $(output-symdump) ifneq ($(KBUILD_MODPOST_NOFINAL),1)
@@ -113,6 +118,13 @@ endif PHONY += FORCE FORCE: +existing-targets := $(wildcard $(sort $(targets))) + +-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) + +PHONY += FORCE +FORCE: + endif .PHONY: $(PHONY)
scripts/mod/modpost.c +21 -11
@@ -2375,6 +2375,25 @@ static void add_srcversion(struct buffer *b, struct module *mod) } } +static void write_buf (struct buffer *b,const char *fname) +{ +FILE *file; + + file =fopen (fname,"w" ); +if (!file) { +perror (fname); +exit (1 ); + } +if (fwrite (b->p,1 , b->pos, file) != b->pos) { +perror (fname); +exit (1 ); + } +if (fclose (file) !=0 ) { +perror (fname); +exit (1 ); + } +} +static void write_if_changed (struct buffer *b,const char *fname) {char *tmp;
@@ -2407,16 +2426,7 @@ static void write_if_changed(struct buffer *b, const char *fname) close_write:fclose (file); write: - file =fopen (fname,"w" ); -if (!file) { -perror (fname); -exit (1 ); - } -if (fwrite (b->p,1 , b->pos, file) != b->pos) { -perror (fname); -exit (1 ); - } -fclose (file); +write_buf (b, fname); }/* parse Module.symvers file. line format:
@@ -2508,7 +2518,7 @@ static void write_dump(const char *fname) symbol = symbol->next; } } -write_if_changed (&buf, fname); +write_buf (&buf, fname);free (buf.p); }
Signature · 1 line
2.25.1
PATCH 19/37 modpost: show warning if vmlinux is not found when processing modules
In reply to Masahiro Yamadacheck_exports() does not print warnings about unresolved symbols if vmlinux is missing because there would be too many.
This situation happens when you do 'make modules' from the clean tree, or compile external modules against a kernel tree that has not been completely built.
It is dangerous to not check unresolved symbols because you might be building useless modules. At least it should be warned.
---
scripts/mod/modpost.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +7 -2
@@ -2001,8 +2001,6 @@ static void read_symbols(const char *modname) mod =new_module (modname); -/* When there's no vmlinux, don't print warnings about -* unresolved symbols (since there'll be too many ;) */ if (is_vmlinux (modname)) { have_vmlinux =1 ; mod->skip =1 ;
@@ -2623,6 +2621,13 @@ int main(int argc, char **argv)if (files_source)read_symbols_from_files (files_source); +/* +* When there's no vmlinux, don't print warnings about +* unresolved symbols (since there'll be too many ;) +*/ +if (!have_vmlinux) +warn ("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n" ); + err =0 ;for (mod = modules; mod; mod = mod->next) {
Signature · 1 line
2.25.1
PATCH 20/37 modpost: show warning if any of symbol dump files is missing
In reply to Masahiro YamadaIf modpost fails to load a symbol dump file, it cannot check unresolved symbols, hence module dependency will not be added. Nor CRCs can be added.
Currently, external module builds check only $(objtree)/Module.symvers, but it should check files specified by KBUILD_EXTRA_SYMBOLS as well.
Move the warning message from the top Makefile to scripts/Makefile.modpost and print the warning if any dump file is missing.
---
Makefile | 10 +--------- scripts/Makefile.modpost | 5 ++++- 2 files changed, 5 insertions(+), 10 deletions(-)
Makefile +1 -9
@@ -1649,17 +1649,9 @@ else # KBUILD_EXTMOD # We are always building modules KBUILD_MODULES := 1 -PHONY += $(objtree)/Module.symvers -$(objtree)/Module.symvers: - @test -e $(objtree)/Module.symvers || ( \ - echo; \ - echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \ - echo " is missing; modules will have no dependencies and modversions."; \ - echo ) - build-dirs := $(KBUILD_EXTMOD) PHONY += modules -modules: descend $(objtree)/Module.symvers +modules: descend $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost PHONY += modules_install
scripts/Makefile.modpost +4 -1
@@ -97,8 +97,11 @@ ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),) MODPOST += -n endif +# Clear VPATH to not search for *.symvers in $(srctree). Check only $(objtree). +VPATH := $(input-symdump): - @: + @echo >&2 'WARNING: Symbol version dump "$@" is missing.' + @echo >&2 ' Modules may not have dependencies or modversions.' # Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long".
Signature · 1 line
2.25.1
PATCH 21/37 modpost: drop RCS/CVS $Revision handling in MODULE_VERSION()
In reply to Masahiro YamadaAs far as I understood, this code gets rid of '$Revision$' or '$Revision:' of CVS, RCS or whatever in MODULE_VERSION() tags.
Remove the primeval code.
---
scripts/mod/modpost.c | 3 -- scripts/mod/modpost.h | 4 --- scripts/mod/sumversion.c | 66 ---------------------------------------- 3 files changed, 73 deletions(-)
scripts/mod/modpost.c +0 -3
@@ -2066,9 +2066,6 @@ static void read_symbols(const char *modname)check_sec_ref (mod, modname, &info); version =get_modinfo (&info,"version" ); -if (version) -maybe_frob_rcs_version (modname, version, info.modinfo, - version - (char *)info.hdr);if (version || (all_versions && !is_vmlinux (modname)))get_src_version (modname, mod->srcversion,sizeof (mod->srcversion)-1 );
scripts/mod/modpost.h +0 -4
@@ -188,10 +188,6 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,void add_moddevtable (struct buffer *buf,struct module *mod);/* sumversion.c */ -void maybe_frob_rcs_version (const char *modfilename, -char *version, -void *modinfo, -unsigned long modinfo_offset);void get_src_version (const char *modname,char sum[],unsigned sumlen);/* from modpost.c */
scripts/mod/sumversion.c +0 -66
69 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 22/37 modpost: do not call get_modinfo() for vmlinux(.o)
In reply to Masahiro YamadaThe three calls of get_modinfo() ("license", "import_ns", "version") always return NULL for vmlinux(.o) because the built-in module info is prefixed with __MODULE_INFO_PREFIX.
It is harmless to call get_modinfo(), but there is no point to search for what apparently does not exist.
---
scripts/mod/modpost.c | 45 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
scripts/mod/modpost.c +24 -21
@@ -2006,25 +2006,26 @@ static void read_symbols(const char *modname) mod->skip =1 ; } - license =get_modinfo (&info,"license" ); -if (!license && !is_vmlinux (modname)) -warn ("missing MODULE_LICENSE() in %s\n" -"see include/linux/module.h for " -"more information\n" , modname); -while (license) { -if (license_is_gpl_compatible (license)) - mod->gpl_compatible =1 ; -else { - mod->gpl_compatible =0 ; -break ; +if (!is_vmlinux (modname)) { + license =get_modinfo (&info,"license" ); +if (!license) +warn ("missing MODULE_LICENSE() in %s\n" , modname); +while (license) { +if (license_is_gpl_compatible (license)) + mod->gpl_compatible =1 ; +else { + mod->gpl_compatible =0 ; +break ; + } + license =get_next_modinfo (&info,"license" , license); } - license =get_next_modinfo (&info,"license" , license); - } - namespace =get_modinfo (&info,"import_ns" ); -while (namespace) { -add_namespace (&mod->imported_namespaces, namespace); - namespace =get_next_modinfo (&info,"import_ns" , namespace); + namespace =get_modinfo (&info,"import_ns" ); +while (namespace) { +add_namespace (&mod->imported_namespaces, namespace); + namespace =get_next_modinfo (&info,"import_ns" , + namespace); + } }for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
@@ -2065,10 +2066,12 @@ static void read_symbols(const char *modname)if (!is_vmlinux (modname) || vmlinux_section_warnings)check_sec_ref (mod, modname, &info); - version =get_modinfo (&info,"version" ); -if (version || (all_versions && !is_vmlinux (modname))) -get_src_version (modname, mod->srcversion, -sizeof (mod->srcversion)-1 ); +if (!is_vmlinux (modname)) { + version =get_modinfo (&info,"version" ); +if (version || all_versions) +get_src_version (modname, mod->srcversion, +sizeof (mod->srcversion) -1 ); + }parse_elf_finish (&info);
Signature · 1 line
2.25.1
PATCH 23/37 modpost: add read_text_file() and get_line() helpers
In reply to Masahiro Yamadamodpost uses grab_file() to open a file, but it is not suitable for a text file because the mmap'ed file is not terminated by null byte. Actually, I see some issues for the use of grab_file().
The new helper, read_text_file() loads the whole file content into a malloc'ed buffer, and appends a null byte. Then, get_line() reads each line.
To handle text files, I intend to replace as follows:
grab_file() -> read_text_file()
get_new_line() -> get_line()
---
scripts/mod/modpost.c | 49 +++++++++++++++++++++++++++++++++++++++++++ scripts/mod/modpost.h | 2 ++ 2 files changed, 51 insertions(+)
scripts/mod/modpost.c +49 -0
@@ -112,6 +112,55 @@ void *do_nofail(void *ptr, const char *expr)return ptr; } +char *read_text_file (const char *filename) +{ +struct stat st; +size_t nbytes; +int fd; +char *buf; + + fd =open (filename,O_RDONLY ); +if (fd <0 ) { +perror (filename); +exit (1 ); + } + +if (fstat (fd, &st) <0 ) { +perror (filename); +exit (1 ); + } + + buf =NOFAIL (malloc (st.st_size +1 )); + + nbytes = st.st_size; + +while (nbytes) { +ssize_t bytes_read; + + bytes_read =read (fd, buf, nbytes); +if (bytes_read <0 ) { +perror (filename); +exit (1 ); + } + + nbytes -= bytes_read; + } + buf[st.st_size] ='\0' ; + +close (fd); + +return buf; +} + +char *get_line (char **stringp) +{ +/* do not return the unwanted extra line at EOF */ +if (*stringp && **stringp =='\0' ) +return NULL ; + +return strsep (stringp,"\n" ); +} +/* A list of all modules we processed */ static struct module *modules;
scripts/mod/modpost.h +2 -0
@@ -191,6 +191,8 @@ void add_moddevtable(struct buffer *buf, struct module *mod);void get_src_version (const char *modname,char sum[],unsigned sumlen);/* from modpost.c */ +char *read_text_file (const char *filename); +char *get_line (char **stringp);void *grab_file (const char *filename,unsigned long *size);char *get_next_line (unsigned long *pos,void *file,unsigned long size);void release_file (void *file,unsigned long size);
Signature · 1 line
2.25.1
PATCH 24/37 modpost: fix potential mmap'ed file overrun in get_src_version()
In reply to Masahiro YamadaI do not know how reliably this function works, but it looks dangerous to me.
strchr(sources, '\n');
... continues searching until it finds '\n' or it reaches the '\0' terminator. In other words, 'sources' should be a null-terminated string.
However, grab_file() just mmaps a file, so 'sources' is not terminated with null byte. If the file does not contain '\n' at all, strchr() will go beyond the mmap'ed memory.
Use read_text_file(), which loads the file content into a malloc'ed buffer, appending null byte.
Here we are interested only in the first line of *.mod files. Use get_line() helper to get the first line.
This also makes missing *.mod file a fatal error.
Commit 4be40e22233c ("kbuild: do not emit src version warning for non-modules") ignored missing *.mod files.
I do not fully understand what that commit addressed, but commit 91341d4b2c19 ("kbuild: introduce new option to enhance section mismatch analysis") introduced partial section checks by using modpost. built-in.o was parsed by modpost. Even modules had a problem because *.mod files were created after the modpost check.
Commit b7dca6dd1e59 ("kbuild: create *.mod with full directory path and remove MODVERDIR") stopped doing that. Now that modpost is only invoked after the directory descend, *.mod files should always exist at the modpost stage.
---
scripts/mod/sumversion.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
scripts/mod/sumversion.c +11 -17
@@ -392,40 +392,34 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)/* Calc and record src checksum. */ void get_src_version (const char *modname,char sum[],unsigned sumlen) { -void *file; -unsigned long len; +char *buf, *pos, *firstline;struct md4_ctx md; -char *sources, *end, *fname; +char *fname;char filelist[PATH_MAX +1 ];/* objects for a module are listed in the first line of *.mod file. */ snprintf (filelist,sizeof (filelist),"%.*smod" , (int )strlen (modname) -1 , modname); - file =grab_file (filelist, &len); -if (!file) -/* not a module or .mod file missing - ignore */ -return ; + buf =read_text_file (filelist); - sources = file; - - end =strchr (sources,'\n' ); -if (!end) { + pos = buf; + firstline =get_line (&pos); +if (!firstline) {warn ("bad ending versions file for %s\n" , modname); - goto release; + goto free; } - *end ='\0' ;md4_init (&md); -while ((fname =strsep (&sources," " )) !=NULL ) { +while ((fname =strsep (&firstline," " ))) {if (!*fname)continue ;if (!(is_static_library (fname)) && !parse_source_files (fname, &md)) - goto release; + goto free; }md4_final_ascii (&md, sum, sumlen); -release: -release_file (file, len); +free: +free (buf); }
Signature · 1 line
2.25.1
PATCH 25/37 modpost: avoid false-positive file open error
In reply to Masahiro YamadaOne problem of grab_file() is that it cannot distinguish the following two cases:
- It cannot read the file (the file does not exist, or read permission is not set)
- It can read the file, but the file size is zero
This is because grab_file() calls mmap(), which requires the mapped length is greater than 0. Hence, grab_file() fails for both cases.
If an empty header file were included for checksum calculation, the following warning would be printed:
WARNING: modpost: could not open ...: Invalid argument
An empty file is a valid source file, so it should not fail.
Use read_text_file() instead. It can read a zero-length file. Then, parse_file() will succeed with doing nothing.
Going forward, the first case (it cannot read the file) is a fatal error. If the source file from which an object was compiled is missing, something went wrong.
---
scripts/mod/sumversion.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
scripts/mod/sumversion.c +3 -4
@@ -258,9 +258,8 @@ static int parse_file(const char *fname, struct md4_ctx *md)char *file;unsigned long i, len; - file =grab_file (fname, &len); -if (!file) -return 0 ; + file =read_text_file (fname); + len =strlen (file);for (i =0 ; i < len; i++) {/* Collapse and ignore \ and CR. */
@@ -287,7 +286,7 @@ static int parse_file(const char *fname, struct md4_ctx *md)add_char (file[i], md); } -release_file (file, len); +free (file);return 1 ; }/* Check whether the file is a static library or not */
Signature · 1 line
2.25.1
PATCH 26/37 modpost: use read_text_file() and get_line() for reading text files
In reply to Masahiro Yamadagrab_file() mmaps a file, but it is not so efficient here because get_next_line() copies every line to the temporary buffer anyway.
read_text_file() and get_line() are simpler. get_line() exploits the library function strchr().
Going forward, the missing *.symvers or *.cmd is a fatal error. This should not happen because scripts/Makefile.modpost guards the -i option files with $(wildcard $(input-symdump)).
---
scripts/mod/modpost.c | 15 ++++++++------- scripts/mod/sumversion.c | 16 ++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-)
scripts/mod/modpost.c +8 -7
@@ -2481,15 +2481,16 @@ static void write_if_changed(struct buffer *b, const char *fname)**/ static void read_dump (const char *fname) { -unsigned long size, pos =0 ; -void *file =grab_file (fname, &size); -char *line; +char *buf, *pos, *line; -if (!file) + buf =read_text_file (fname); +if (!buf)/* No symbol versions, silently ignore */ return ; -while ((line =get_next_line (&pos, file, size))) { + pos = buf; + +while ((line =get_line (&pos))) {char *symname, *namespace, *modname, *d, *export;unsigned int crc;struct module *mod;
@@ -2524,10 +2525,10 @@ static void read_dump(const char *fname)sym_set_crc (symname, crc);sym_update_namespace (symname, namespace); } -release_file (file, size); +free (buf);return ; fail: -release_file (file, size); +free (buf);fatal ("parse error in symbol dump file\n" ); }
scripts/mod/sumversion.c +6 -10
@@ -303,9 +303,8 @@ static int is_static_library(const char *objfile)* to figure out source files. */ static int parse_source_files (const char *objfile,struct md4_ctx *md) { -char *cmd, *file, *line, *dir; +char *cmd, *file, *line, *dir, *pos;const char *base; -unsigned long flen, pos =0 ;int dirlen, ret =0 , check_files =0 ; cmd =NOFAIL (malloc (strlen (objfile) +sizeof ("..cmd" )));
@@ -323,14 +322,12 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)strncpy (dir, objfile, dirlen); dir[dirlen] ='\0' ; - file =grab_file (cmd, &flen); -if (!file) { -warn ("could not find %s for %s\n" , cmd, objfile); - goto out; - } + file =read_text_file (cmd); + + pos = file;/* Sum all files in the same dir or subdirs. */ -while ((line =get_next_line (&pos, file, flen)) !=NULL ) { +while ((line =get_line (&pos))) {char * p = line;if (strncmp (line,"source_" ,sizeof ("source_" )-1 ) ==0 ) {
@@ -381,8 +378,7 @@ static int parse_source_files(const char *objfile, struct md4_ctx *md)/* Everyone parsed OK */ ret =1 ; out_file: -release_file (file, flen); -out: +free (file);free (dir);free (cmd);return ret;
Signature · 1 line
2.25.1
PATCH 27/37 modpost: remove get_next_text() and make {grab,release_}file static
In reply to Masahiro Yamadaget_next_line() is no longer used. Remove.
grab_file() and release_file() are only used in modpost.c. Make them static.
---
scripts/mod/modpost.c | 38 ++------------------------------------ scripts/mod/modpost.h | 3 --- 2 files changed, 2 insertions(+), 39 deletions(-)
scripts/mod/modpost.c +2 -36
@@ -463,7 +463,7 @@ static void sym_set_crc(const char *name, unsigned int crc) s->crc_valid =1 ; } -void *grab_file (const char *filename,unsigned long *size) +static void *grab_file (const char *filename,unsigned long *size) {struct stat st;void *map =MAP_FAILED ;
@@ -485,41 +485,7 @@ void *grab_file(const char *filename, unsigned long *size)return map; } -/** -* Return a copy of the next line in a mmap'ed file. -* spaces in the beginning of the line is trimmed away. -* Return a pointer to a static buffer. -**/ -char *get_next_line (unsigned long *pos,void *file,unsigned long size) -{ -static char line[4096 ]; -int skip =1 ; -size_t len =0 ; -signed char *p = (signed char *)file + *pos; -char *s = line; - -for (; *pos < size ; (*pos)++) { -if (skip &&isspace (*p)) { - p++; -continue ; - } - skip =0 ; -if (*p !='\n' && (*pos < size)) { - len++; - *s++ = *p++; -if (len >4095 ) -break ;/* Too long, stop */ - }else { -/* End of string */ - *s ='\0' ; -return line; - } - } -/* End of buffer */ -return NULL ; -} - -void release_file (void *file,unsigned long size) +static void release_file (void *file,unsigned long size) {munmap (file, size); }
scripts/mod/modpost.h +0 -3
@@ -193,9 +193,6 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen);/* from modpost.c */ char *read_text_file (const char *filename);char *get_line (char **stringp); -void *grab_file (const char *filename,unsigned long *size); -char *get_next_line (unsigned long *pos,void *file,unsigned long size); -void release_file (void *file,unsigned long size);enum loglevel {LOG_WARN ,
Signature · 1 line
2.25.1
PATCH 28/37 modpost: remove -s option
In reply to Masahiro YamadaThe -s option was added by commit 8d8d8289df65 ("kbuild: do not do section mismatch checks on vmlinux in 2nd pass").
Now that the second pass does not parse vmlinux, this option is unneeded.
---
scripts/Makefile.modpost | 2 +- scripts/mod/modpost.c | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-)
scripts/Makefile.modpost +1 -1
@@ -62,7 +62,7 @@ __modpost: vmlinux.symvers else -MODPOST += -s \ +MODPOST += \ $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) ifeq ($(KBUILD_EXTMOD),)
scripts/mod/modpost.c +2 -8
@@ -30,8 +30,6 @@ static int have_vmlinux = 0;static int all_versions =0 ;/* If we are modposting external module set to 1 */ static int external_module =0 ; -/* Warn about section mismatch in vmlinux if set to 1 */ -static int vmlinux_section_warnings =1 ;/* Only warn about unresolved symbols */ static int warn_unresolved =0 ;/* How a symbol is exported */
@@ -2078,8 +2076,7 @@ static void read_symbols(const char *modname) } } -if (!is_vmlinux (modname) || vmlinux_section_warnings) -check_sec_ref (mod, modname, &info); +check_sec_ref (mod, modname, &info);if (!is_vmlinux (modname)) { version =get_modinfo (&info,"version" );
@@ -2576,7 +2573,7 @@ int main(int argc, char **argv)struct dump_list *dump_read_start =NULL ;struct dump_list **dump_read_iter = &dump_read_start; -while ((opt =getopt (argc, argv,"ei:mnsT:o:awENd:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ei:mnT:o:awENd:" )) !=-1 ) {switch (opt) {case 'e' : external_module =1 ;
@@ -2599,9 +2596,6 @@ int main(int argc, char **argv)case 'a' : all_versions =1 ;break ; -case 's' : - vmlinux_section_warnings =0 ; -break ;case 'T' : files_source = optarg;break ;
Signature · 1 line
2.25.1
PATCH 29/37 modpost: move -d option in scripts/Makefile.modpost
In reply to Masahiro YamadaCollect options for modules into a single place.
---
scripts/Makefile.modpost | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
scripts/Makefile.modpost +1 -3
@@ -62,9 +62,6 @@ __modpost: vmlinux.symvers else -MODPOST += \ - $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) - ifeq ($(KBUILD_EXTMOD),) input-symdump := vmlinux.symvers
@@ -91,6 +88,7 @@ endif # modpost options for modules (both in-kernel and external) MODPOST += \ $(addprefix -i ,$(wildcard $(input-symdump))) \ + $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) ifneq ($(findstring i,$(filter-out --%,$(MAKEFLAGS))),)
Signature · 1 line
2.25.1
PATCH 30/37 modpost: remove mod->is_dot_o struct member
In reply to Masahiro YamadaPreviously, there were two cases where mod->is_dot_o is unset:
[1] the executable 'vmlinux' in the second pass of modpost
[2] modules loaded by read_dump()
I think [1] was intended usage to distinguish 'vmlinux.o' and 'vmlinux'. Now that modpost does not parse the executable 'vmlinux', this case does not happen.
[2] is obscure, maybe a bug. Module.symver stores module paths without extension. So, none of modules loaded by read_dump() has the .o suffix, and new_module() unsets ->is_dot_o. Anyway, it is not a big deal because handle_symbol() is not called for the case.
To sum up, all the parsed ELF files are .o files.
mod->is_dot_o is unneeded.
---
scripts/mod/modpost.c | 14 ++------------ scripts/mod/modpost.h | 1 - 2 files changed, 2 insertions(+), 13 deletions(-)
scripts/mod/modpost.c +2 -12
@@ -182,10 +182,8 @@ static struct module *new_module(const char *modname) p =NOFAIL (strdup (modname));/* strip trailing .o */ -if (strends (p,".o" )) { +if (strends (p,".o" )) p[strlen (p) -2 ] ='\0' ; - mod->is_dot_o =1 ; - }/* add to list */ mod->name = p;
@@ -716,8 +714,7 @@ static void handle_symbol(struct module *mod, struct elf_info *info,enum export export;const char *name; -if ((!is_vmlinux (mod->name) || mod->is_dot_o) && -strstarts (symname,"__ksymtab" )) +if (strstarts (symname,"__ksymtab" )) export =export_from_secname (info,get_secindex (info, sym));else export =export_from_sec (info,get_secindex (info, sym));
@@ -2676,13 +2673,6 @@ int main(int argc, char **argv)struct symbol *s;for (s = symbolhash[n]; s; s = s->next) { -/* -* Do not check "vmlinux". This avoids the same warnings -* shown twice, and false-positives for ARCH=um. -*/ -if (is_vmlinux (s->module->name) && !s->module->is_dot_o) -continue ; -if (s->is_static) warn("\"%s\" [%s] is a static %s\n", s->name, s->module->name,
scripts/mod/modpost.h +0 -1
@@ -126,7 +126,6 @@ struct module {int has_cleanup;struct buffer dev_table_buf;char srcversion[25 ]; -int is_dot_o;// Missing namespace dependencies struct namespace_list *missing_namespaces;// Actual imported namespaces
Signature · 1 line
2.25.1
PATCH 31/37 modpost: remove is_vmlinux() call in check_for_{gpl_usage,unused}()
In reply to Masahiro Yamadacheck_exports() is never called for vmlinux because mod->skip is set for vmlinux.
Hence, check_for_gpl_usage() and check_for_unused() are not called for vmlinux, either. is_vmlinux() is always false here.
Remove the is_vmlinux() calls, and hard-code the ".ko" suffix.
---
scripts/mod/modpost.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
scripts/mod/modpost.c +8 -12
@@ -2144,20 +2144,18 @@ void buf_write(struct buffer *buf, const char *s, int len)static void check_for_gpl_usage (enum export exp,const char *m,const char *s) { -const char *e =is_vmlinux (m) ?"" :".ko" ; -switch (exp) {case export_gpl: -fatal ("GPL-incompatible module %s%s " -"uses GPL-only symbol '%s'\n" , m, e, s); +fatal ("GPL-incompatible module %s.ko uses GPL-only symbol '%s'\n" , + m, s);break ;case export_unused_gpl: -fatal ("GPL-incompatible module %s%s " -"uses GPL-only symbol marked UNUSED '%s'\n" , m, e, s); +fatal ("GPL-incompatible module %s.ko uses GPL-only symbol marked UNUSED '%s'\n" , + m, s);break ;case export_gpl_future: -warn ("GPL-incompatible module %s%s " -"uses future GPL-only symbol '%s'\n" , m, e, s); +warn ("GPL-incompatible module %s.ko uses future GPL-only symbol '%s'\n" , + m, s);break ;case export_plain:case export_unused:
@@ -2169,13 +2167,11 @@ static void check_for_gpl_usage(enum export exp, const char *m, const char *s)static void check_for_unused (enum export exp,const char *m,const char *s) { -const char *e =is_vmlinux (m) ?"" :".ko" ; -switch (exp) {case export_unused:case export_unused_gpl: -warn ("module %s%s " -"uses symbol '%s' marked UNUSED\n" , m, e, s); +warn ("module %s.ko uses symbol '%s' marked UNUSED\n" , + m, s);break ;default :/* ignore */
Signature · 1 line
2.25.1
PATCH 32/37 modpost: add mod->is_vmlinux struct member
In reply to Masahiro Yamadais_vmlinux() is called in several places to check whether the current module is vmlinux or not.
It is faster and clearer to check mod->is_vmlinux flag.
---
scripts/mod/modpost.c | 19 ++++++++++--------- scripts/mod/modpost.h | 1 + 2 files changed, 11 insertions(+), 9 deletions(-)
scripts/mod/modpost.c +10 -9
@@ -187,6 +187,7 @@ static struct module *new_module(const char *modname)/* add to list */ mod->name = p; + mod->is_vmlinux =is_vmlinux (modname); mod->gpl_compatible =-1 ; mod->next = modules; modules = mod;
@@ -431,11 +432,11 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,if (!s) { s =new_symbol (name, mod, export); - }else if (!external_module ||is_vmlinux (s->module->name) || + }else if (!external_module || s->module->is_vmlinux || s->module == mod) {warn ("%s: '%s' exported twice. Previous export was in %s%s\n" , mod->name, name, s->module->name, -is_vmlinux (s->module->name) ?"" :".ko" ); + s->module->is_vmlinux ?"" :".ko" );return s; }
@@ -692,7 +693,7 @@ static void handle_modversion(const struct module *mod,if (sym->st_shndx ==SHN_UNDEF ) {warn ("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n" , - symname, mod->name,is_vmlinux (mod->name) ?"" :".ko" ); + symname, mod->name, mod->is_vmlinux ?"" :".ko" );return ; }
@@ -2011,12 +2012,12 @@ static void read_symbols(const char *modname) mod =new_module (modname); -if (is_vmlinux (modname)) { +if (mod->is_vmlinux) { have_vmlinux =1 ; mod->skip =1 ; } -if (!is_vmlinux (modname)) { +if (!mod->is_vmlinux) { license =get_modinfo (&info,"license" );if (!license)warn ("missing MODULE_LICENSE() in %s\n" , modname);
@@ -2075,7 +2076,7 @@ static void read_symbols(const char *modname)check_sec_ref (mod, modname, &info); -if (!is_vmlinux (modname)) { +if (!mod->is_vmlinux) { version =get_modinfo (&info,"version" );if (version || all_versions) get_src_version(modname, mod->srcversion,
@@ -2345,7 +2346,7 @@ static void add_depends(struct buffer *b, struct module *mod)/* Clear ->seen flag of modules that own symbols needed by this. */ for (s = mod->unres; s; s = s->next)if (s->module) - s->module->seen =is_vmlinux (s->module->name); + s->module->seen = s->module->is_vmlinux;buf_printf (b,"\n" );buf_printf (b,"MODULE_INFO(depends, \"" );
@@ -2470,9 +2471,9 @@ static void read_dump(const char *fname) goto fail; mod =find_module (modname);if (!mod) { -if (is_vmlinux (modname)) - have_vmlinux =1 ; mod =new_module (modname); +if (mod->is_vmlinux) + have_vmlinux =1 ; mod->skip =1 ; mod->from_dump =1 ; }
scripts/mod/modpost.h +1 -0
@@ -120,6 +120,7 @@ struct module {int gpl_compatible;struct symbol *unres;int from_dump;/* 1 if module was loaded from *.symver */ +int is_vmlinux;int seen;int skip;int has_init;
Signature · 1 line
2.25.1
PATCH 33/37 modpost: remove mod->skip struct member
In reply to Masahiro YamadaThe meaning of 'skip' is obscure since it does not explain "what to skip".
mod->skip is set when it is vmlinux or the module info came from a dump file.
So, mod->skip is equivalent to (mod->is_vmlinux || mod->from_dump).
For the check in write_namespace_deps_files(), mod->is_vmlinux is unneeded because the -d option is not passed in the first pass of modpost.
---
scripts/mod/modpost.c | 9 +++------ scripts/mod/modpost.h | 1 - 2 files changed, 3 insertions(+), 7 deletions(-)
scripts/mod/modpost.c +3 -6
@@ -2012,10 +2012,8 @@ static void read_symbols(const char *modname) mod =new_module (modname); -if (mod->is_vmlinux) { +if (mod->is_vmlinux) have_vmlinux =1 ; - mod->skip =1 ; - }if (!mod->is_vmlinux) { license =get_modinfo (&info,"license" );
@@ -2474,7 +2472,6 @@ static void read_dump(const char *fname) mod =new_module (modname);if (mod->is_vmlinux) have_vmlinux =1 ; - mod->skip =1 ; mod->from_dump =1 ; } s =sym_add_exported (symname, mod,export_no (export));
@@ -2535,7 +2532,7 @@ static void write_namespace_deps_files(const char *fname)for (mod = modules; mod; mod = mod->next) { -if (mod->skip || !mod->missing_namespaces) +if (mod->from_dump || !mod->missing_namespaces)continue ;buf_printf (&ns_deps_buf,"%s.ko:" , mod->name);
@@ -2637,7 +2634,7 @@ int main(int argc, char **argv)for (mod = modules; mod; mod = mod->next) {char fname[PATH_MAX ]; -if (mod->skip) +if (mod->is_vmlinux || mod->from_dump)continue ; buf.pos =0 ;
scripts/mod/modpost.h +0 -1
@@ -122,7 +122,6 @@ struct module {int from_dump;/* 1 if module was loaded from *.symver */ int is_vmlinux;int seen; -int skip;int has_init;int has_cleanup;struct buffer dev_table_buf;
Signature · 1 line
2.25.1
PATCH 34/37 modpost: set have_vmlinux in new_module()
In reply to Masahiro YamadaSet have_vmlinux flag in a single place.
---
scripts/mod/modpost.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/mod/modpost.c +3 -5
@@ -192,6 +192,9 @@ static struct module *new_module(const char *modname) mod->next = modules; modules = mod; +if (mod->is_vmlinux) + have_vmlinux =1 ; +return mod; }
@@ -2012,9 +2015,6 @@ static void read_symbols(const char *modname) mod =new_module (modname); -if (mod->is_vmlinux) - have_vmlinux =1 ; -if (!mod->is_vmlinux) { license =get_modinfo (&info,"license" );if (!license)
@@ -2470,8 +2470,6 @@ static void read_dump(const char *fname) mod =find_module (modname);if (!mod) { mod =new_module (modname); -if (mod->is_vmlinux) - have_vmlinux =1 ; mod->from_dump =1 ; } s =sym_add_exported (symname, mod,export_no (export));
Signature · 1 line
2.25.1
PATCH 35/37 modpost: strip .o from modname before calling new_module()
In reply to Masahiro Yamadanew_module() conditionally strips the .o because the modname has .o suffix when it is called from read_symbols(), but no .o when it is called from read_dump().
It is clearer to strip .o in read_symbols().
I also used flexible-array for mod->name.
---
scripts/mod/modpost.c | 20 +++++++++++--------- scripts/mod/modpost.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-)
scripts/mod/modpost.c +11 -9
@@ -175,18 +175,12 @@ static struct module *find_module(const char *modname)static struct module *new_module (const char *modname) {struct module *mod; -char *p; - mod =NOFAIL (malloc (sizeof (*mod))); + mod =NOFAIL (malloc (sizeof (*mod) +strlen (modname) +1 ));memset (mod,0 ,sizeof (*mod)); - p =NOFAIL (strdup (modname)); - -/* strip trailing .o */ -if (strends (p,".o" )) - p[strlen (p) -2 ] ='\0' ;/* add to list */ - mod->name = p; +strcpy (mod->name, modname); mod->is_vmlinux =is_vmlinux (modname); mod->gpl_compatible =-1 ; mod->next = modules;
@@ -2013,7 +2007,15 @@ static void read_symbols(const char *modname)if (!parse_elf (&info, modname))return ; - mod =new_module (modname); + { +char *tmp; + +/* strip trailing .o */ + tmp =NOFAIL (strdup (modname)); + tmp[strlen (tmp) -2 ] ='\0' ; + mod =new_module (tmp); +free (tmp); + }if (!mod->is_vmlinux) { license =get_modinfo (&info,"license" );
scripts/mod/modpost.h +1 -1
@@ -116,7 +116,6 @@ struct namespace_list {struct module {struct module *next; -const char *name;int gpl_compatible;struct symbol *unres;int from_dump;/* 1 if module was loaded from *.symver */
@@ -130,6 +129,7 @@ struct module {struct namespace_list *missing_namespaces;// Actual imported namespaces struct namespace_list *imported_namespaces; +char name[]; };struct elf_info {
Signature · 1 line
2.25.1
PATCH 36/37 modpost: remove is_vmlinux() helper
In reply to Masahiro YamadaNow that is_vmlinux() is called only in new_module(), we can inline the function call.
modname is the basename with '.o' is stripped. No need to compare it with 'vmlinux.o'.
vmlinux is always located at the current working directory. No need to strip the directory path.
---
scripts/mod/modpost.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
scripts/mod/modpost.c +1 -15
@@ -88,20 +88,6 @@ static inline bool strends(const char *str, const char *postfix)return strcmp (str +strlen (str) -strlen (postfix), postfix) ==0 ; } -static int is_vmlinux (const char *modname) -{ -const char *myname; - - myname =strrchr (modname,'/' ); -if (myname) - myname++; -else - myname = modname; - -return (strcmp (myname,"vmlinux" ) ==0 ) || - (strcmp (myname,"vmlinux.o" ) ==0 ); -} -void *do_nofail (void *ptr,const char *expr) {if (!ptr)
@@ -181,7 +167,7 @@ static struct module *new_module(const char *modname)/* add to list */ strcpy (mod->name, modname); - mod->is_vmlinux =is_vmlinux (modname); + mod->is_vmlinux = (strcmp (modname,"vmlinux" ) ==0 ); mod->gpl_compatible =-1 ; mod->next = modules; modules = mod;
Signature · 1 line
2.25.1
PATCH 37/37 modpost: change elf_info->size to size_t
In reply to Masahiro YamadaAlign with the mmap / munmap APIs.
---
scripts/mod/modpost.c | 9 ++++----- scripts/mod/modpost.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-)
scripts/mod/modpost.c +4 -5
@@ -443,7 +443,7 @@ static void sym_set_crc(const char *name, unsigned int crc) s->crc_valid =1 ; } -static void *grab_file (const char *filename,unsigned long *size) +static void *grab_file (const char *filename,size_t *size) {struct stat st;void *map =MAP_FAILED ;
@@ -465,7 +465,7 @@ static void *grab_file(const char *filename, unsigned long *size)return map; } -static void release_file (void *file,unsigned long size) +static void release_file (void *file,size_t size) {munmap (file, size); }
@@ -521,9 +521,8 @@ static int parse_elf(struct elf_info *info, const char *filename)/* Check if file offset is correct */ if (hdr->e_shoff > info->size) { -fatal ("section header offset=%lu in file '%s' is bigger than " -"filesize=%lu\n" , (unsigned long )hdr->e_shoff, - filename, info->size); +fatal ("section header offset=%lu in file '%s' is bigger than filesize=%zu\n" , + (unsigned long )hdr->e_shoff, filename, info->size);return 0 ; }
scripts/mod/modpost.h +1 -1
@@ -133,7 +133,7 @@ struct module { };struct elf_info { -unsigned long size; +size_t size;Elf_Ehdr *hdr;Elf_Shdr *sechdrs;Elf_Sym *symtab_start;
Signature · 1 line
2.25.1