From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Masahiro Yamada <masahiroy@kernel.org>,
Michal Marek <michal.lkml@markovi.net>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH 5/7] kbuild: get rid of duplication in *.mod files
Date: Thu, 7 Apr 2022 00:30:21 +0900 [thread overview]
Message-ID: <20220406153023.500847-6-masahiroy@kernel.org> (raw)
In-Reply-To: <20220406153023.500847-1-masahiroy@kernel.org>
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-objs := 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>
---
scripts/Makefile.build | 3 ++-
scripts/mod/sumversion.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 6ae92d119dfa..f7a30f378e20 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -303,7 +303,8 @@ $(obj)/%.prelink.o: $(obj)/%.o FORCE
$(call if_changed,cc_prelink_modules)
endif
-cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) > $@
+cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
+ $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
$(call if_changed,mod)
diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
index 0125698f2037..79bb9eaa65ac 100644
--- a/scripts/mod/sumversion.c
+++ b/scripts/mod/sumversion.c
@@ -398,7 +398,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen)
buf = read_text_file(filelist);
md4_init(&md);
- while ((fname = strsep(&buf, " \n"))) {
+ while ((fname = strsep(&buf, "\n"))) {
if (!*fname)
continue;
if (!(is_static_library(fname)) &&
--
2.32.0
next prev parent reply other threads:[~2022-04-06 17:27 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-06 15:30 [PATCH 0/7] kbuild: more misc cleanups Masahiro Yamada
2022-04-06 15:30 ` [PATCH 1/7] kbuild: reuse suffix-search to refactor multi_depend Masahiro Yamada
2022-04-06 20:54 ` Nick Desaulniers
2022-04-06 15:30 ` [PATCH 2/7] kbuild: make multi_depend work with targets in subdirectory Masahiro Yamada
2022-04-07 17:34 ` Nick Desaulniers
2022-04-06 15:30 ` [PATCH 3/7] kbuild: reuse real-search to simplify cmd_mod Masahiro Yamada
2022-04-07 17:38 ` Nick Desaulniers
2022-04-06 15:30 ` [PATCH 4/7] kbuild: split the second line of *.mod into *.usyms Masahiro Yamada
2022-04-07 17:47 ` Nick Desaulniers
2022-04-07 23:56 ` Masahiro Yamada
2022-04-06 15:30 ` Masahiro Yamada [this message]
2022-04-07 17:55 ` [PATCH 5/7] kbuild: get rid of duplication in *.mod files Nick Desaulniers
2022-04-08 0:07 ` Masahiro Yamada
2022-04-08 20:42 ` Nick Desaulniers
2022-04-13 8:19 ` Masahiro Yamada
2022-04-06 15:30 ` [PATCH 6/7] kbuild: make *.mod not depend on *.o Masahiro Yamada
2022-04-07 17:59 ` Nick Desaulniers
2022-04-07 21:39 ` David Laight
2022-04-08 0:37 ` Masahiro Yamada
2022-04-08 2:37 ` Masahiro Yamada
2022-04-06 15:30 ` [PATCH 7/7] kbuild: read *.mod to get objects passed to $(LD) or $(AR) Masahiro Yamada
2022-04-06 18:13 ` Jeff Johnson
2022-04-07 3:07 ` Masahiro Yamada
2022-04-07 18:01 ` Nick Desaulniers
2022-04-15 7:20 ` [PATCH 0/7] kbuild: more misc cleanups Masahiro Yamada
2022-04-22 19:07 ` Elliot Berman
2022-04-23 5:02 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220406153023.500847-6-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox