Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: get rid of duplication in *.mod files

It is allowed to add the same objects multiple times to obj-y / obj-m:

obj-y += foo.o foo.o foo.o
obj-m += bar.o bar.o bar.o

It is also allowed to add the same objects multiple times to a composite
module:

obj-m += foo.o
foo-y := foo1.o foo2.o foo2.o foo1.o

This flexibility is useful because the same object might be selected by
different CONFIG options, like this:

obj-m += foo.o
foo-y := foo1.o
foo-$(CONFIG_FOO_X) += foo2.o
foo-$(CONFIG_FOO_Y) += foo2.o

The duplicated objects are omitted at link time. It works naturally in
Makefiles because GNU Make removes duplication in $^ without changing
the order.

It is working well, almost...

A small flaw I notice is, *.mod contains duplication in such a case.

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 multiple
times.

I am fixing this because I plan to reuse *.mod for other purposes,
where the duplication can be problematic.

The code change is quite simple. We already use awk to drop duplicated
lines in modules.order (see cmd_modules_order in the same file).
I copied the code, but changed RS to use spaces as record separators.

I also changed the file format to list one object per line.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+3 -2
+2 -1
scripts/Makefile.build
··· 303 303 $(call if_changed,cc_prelink_modules) 304 304 endif 305 305 306 - cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) > $@ 306 + cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \ 307 + $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@ 307 308 308 309 $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE 309 310 $(call if_changed,mod)
+1 -1
scripts/mod/sumversion.c
··· 398 398 buf = read_text_file(filelist); 399 399 400 400 md4_init(&md); 401 - while ((fname = strsep(&buf, " \n"))) { 401 + while ((fname = strsep(&buf, "\n"))) { 402 402 if (!*fname) 403 403 continue; 404 404 if (!(is_static_library(fname)) &&