kbuild: get rid of duplication in the first line of *.mod files
PATCH v2 1/2 kbuild: get rid of duplication in the first line of *.mod files
The first line of *.mod lists the object files that consist of the module. This may contain duplication if the same object is added multiple times, like this:
obj-m := foo.o foo-$(CONFIG_FOO1_X) += foo1.o foo-$(CONFIG_FOO1_Y) += foo1.o foo-$(CONFIG_FOO2_X) += foo2.o foo-$(CONFIG_FOO2_Y) += foo2.o
This is probably not a big deal. As far as I know, the only small problem is scripts/mod/sumversion.c parses the same file over again. This can be avoided by adding $(sort ...). It has a side-effect that sorts the objects alphabetically, but it is not a big deal, either.
---
Changes in v2:
- new patch
scripts/Makefile.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/Makefile.build +3 -1
@@ -265,8 +265,10 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE $(call cmd,force_checksrc) $(call if_changed_rule,cc_o_c) +multi-m-prereqs = $(sort $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m))) + cmd_mod = { \ - echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \ + echo $(if $(multi-m-prereqs), $(multi-m-prereqs), $(@:.mod=.o)); \ $(cmd_undef_syms); \ } > $@
Signature · 1 line
2.17.1
PATCH v2 2/2 kbuild: allow modules to link *.a archives
Since commit 69ea912fda74 ("kbuild: remove unneeded link_multi_deps"), modules cannot link *.a archives.
I do not see such a usecase in the upstream code, but multiple people reported this issue, so it seems to be a desired feature for external modules.
For example, libfoo.a is not linked in the following test case:
obj-m := foo.o
foo-objs := foo1.o libfoo.a
I used $(filter $(multi-m-prereqs), $^) to avoid linking the same object multiple times in case Makefile is written as follows:
obj-m := foo.o
foo-$(CONFIG_FOO1_X) += foo1.o
foo-$(CONFIG_FOO1_Y) += foo1.o
foo-y += libfoo.a---
Changes in v2:
- add $(filter ..., $^) to avoid build errors caused by multiple linking
scripts/Makefile.build | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
scripts/Makefile.build +5 -5
@@ -429,13 +429,13 @@ targets += $(obj)/lib-ksyms.o endif # 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 -# dependencies recorded in the .*.cmd file. +# Do not replace $(filter $(multi-m-prereqs), $^) with $(real-prereqs). +# When a single object module is turned into a multi object module, +# $^ will contain header file dependencies recorded in the .*.cmd file. quiet_cmd_link_multi-m = LD [M] $@ - cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) + cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter $(multi-m-prereqs), $^) -$(multi-used-m): FORCE +$(multi-used-m): $(obj)/%.o: FORCE $(call if_changed,link_multi-m) $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
Signature · 1 line
2.17.1