Skip to contentSkip to conversation

Kbuild: lto: fix module versionings mismatch in GNU make 3.X

PATCH In review Lecopzer Chen 2 participants 2 messages Jul 15, 2021 – Jul 18, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 Kbuild: lto: fix module versionings mismatch in GNU make 3.X

When building modules(CONFIG_...=m), I found some of module versions are incorrect and set to 0.
This can be found in build log for first clean build which shows

WARNING: EXPORT symbol "XXXX" [drivers/XXX/XXX.ko] version generation failed, symbol will not be versioned.

But in second build(incremental build), the WARNING disappeared and the module version becomes valid CRC and make someone who want to change modules without updating kernel image can't insert their modules.

The problematic code is
+ $(foreach n, $(filter-out FORCE,$^), \
+ $(if $(wildcard $(n).symversions), \
+ ; cat $(n).symversions >> [email protected]))

For example:
rm -f fs/notify/built-in.a.symversions ; rm -f fs/notify/built-in.a; \
llvm-ar cDPrST fs/notify/built-in.a fs/notify/fsnotify.o \
fs/notify/notification.o fs/notify/group.o ...

foreach n shows nothing to cat into $(n).symversions because if $(wildcard $(n).symversions) return nothing, but actually they do exist during this line was executed.

-rw-r--r-- 1 root root 168580 Jun 13 19:10 fs/notify/fsnotify.o
-rw-r--r-- 1 root root 111 Jun 13 19:10 fs/notify/fsnotify.o.symversions

The reason is the $(n).symversions are generated at runtime, but Makefile wildcard function expends and checks the file exist or not during parsing the Makefile.

Thus fix this by use test shell command to check the file existence in runtime.

Rebase from both:
1. [https://lore.kernel.org/lkml/[email protected]/]
2. [https://lore.kernel.org/lkml/[email protected]/]

Fixes 38e89184900385 ("kbuild: lto: fix module versioning")
---
 scripts/Makefile.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.build +1 -1
index 10b2f2380d6f..02197cb8e3a7 100644
@@ -386,7 +386,7 @@ ifeq ($(CONFIG_LTO_CLANG) $(CONFIG_MODVERSIONS),y y)
       cmd_update_lto_symversions =					\
 	rm -f [email protected]						\
 	$(foreach n, $(filter-out FORCE,$^),				\
-		$(if $(wildcard $(n).symversions),			\
+		$(if $(shell test -s $(n).symversions && echo y),	\
 			; cat $(n).symversions >> [email protected]))
 else
       cmd_update_lto_symversions = echo >/dev/null
Signature · 1 line
2.18.0
#1 lore raw
Quoted 36 lines · Lecopzer Chen

When building modules(CONFIG_...=m), I found some of module versions are incorrect and set to 0.
This can be found in build log for first clean build which shows

WARNING: EXPORT symbol "XXXX" [drivers/XXX/XXX.ko] version generation failed, symbol will not be versioned.

But in second build(incremental build), the WARNING disappeared and the module version becomes valid CRC and make someone who want to change modules without updating kernel image can't insert their modules.

The problematic code is

(quoted diff) +3 -0
+       $(foreach n, $(filter-out FORCE,$^),                            \
+               $(if $(wildcard $(n).symversions),                      \
+                       ; cat $(n).symversions >> [email protected]))

For example:
rm -f fs/notify/built-in.a.symversions ; rm -f fs/notify/built-in.a; \
llvm-ar cDPrST fs/notify/built-in.a fs/notify/fsnotify.o \
fs/notify/notification.o fs/notify/group.o ...

foreach n shows nothing to cat into $(n).symversions because if $(wildcard $(n).symversions) return nothing, but actually they do exist during this line was executed.

(quoted diff) +0 -2
-rw-r--r-- 1 root root 168580 Jun 13 19:10 fs/notify/fsnotify.o
-rw-r--r-- 1 root root    111 Jun 13 19:10 fs/notify/fsnotify.o.symversions

The reason is the $(n).symversions are generated at runtime, but Makefile wildcard function expends and checks the file exist or not during parsing the Makefile.

Thus fix this by use test shell command to check the file existence in runtime.

Quoted 6 lines

Rebase from both:
1. [https://lore.kernel.org/lkml/[email protected]/]
2. [https://lore.kernel.org/lkml/[email protected]/]

Fixes 38e89184900385 ("kbuild: lto: fix module versioning")

Sign-off-byed: Sami Tolvanen <[email protected]>

This Signed-off-by is not correct usage, I think.

I replaced it with Co-developed-by.

I usually use 'for ... do ... done' instead of $(foreach ...), and 'if ... then ... fi' instead of $(if ...).

But, this is the minimal change without causing
too long command line.

Applied to linux-kbuild. Thanks.

Quoted 21 lines
---
 scripts/Makefile.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.build +1 -2
index 10b2f2380d6f..02197cb8e3a7 100644
@@ -386,7 +386,7 @@ ifeq ($(CONFIG_LTO_CLANG) $(CONFIG_MODVERSIONS),y y)
       cmd_update_lto_symversions =                                     \
        rm -f [email protected]                                            \
        $(foreach n, $(filter-out FORCE,$^),                            \
-               $(if $(wildcard $(n).symversions),                      \
+               $(if $(shell test -s $(n).symversions && echo y),       \
                        ; cat $(n).symversions >> [email protected]))
 else
       cmd_update_lto_symversions = echo >/dev/null
--

2.18.0

Signature · 2 lines
Best Regards
Masahiro Yamada