rust: kbuild: generate a symbol version for rust_build_error
PATCH 1/1 rust: kbuild: generate a symbol version for rust_build_error
CONFIG_RUST_BUILD_ASSERT_ALLOW exports rust_build_error to modules. When CONFIG_MODVERSIONS is also enabled, modpost warns that the export has no symbol version and records a zero CRC because the build_error.o rule skips gendwarfksyms.
Generate the checksum from build_error.o with the existing Rust library rule. Make build_error.o depend on rust/Makefile when module versioning is enabled so incremental builds pick up the change. Kbuild's saved rustc command does not include the gendwarfksyms step.
---
An incremental x86-64 build with LLVM=1 CLIPPY=1 clears the modpost warning. The kernel export and a Rust module that references it both record the same nonzero CRC.
OpenAI Codex assisted with coding and testing.
--- rust/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
rust/Makefile +3 -2
@@ -773,8 +773,9 @@ $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ # treated as such so that we pass the same flags. Otherwise, for instance, # `rustc` will complain about missing sanitizer flags causing an ABI mismatch. $(obj)/build_error.o: private is-kernel-object := y -$(obj)/build_error.o: private skip_gendwarfksyms = 1 -$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +# Rebuild when the symbol version generation rule changes. +$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o \ + $(if $(CONFIG_MODVERSIONS),$(src)/Makefile) FORCE +$(call if_changed_rule,rustc_library) $(obj)/ffi.o: private skip_gendwarfksyms = 1
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261118-fix-rust-build-error-modversions-4af535edc9b2
Best regards,
Signature · 1 line
Peder Bergan <[email protected]>
Quoted 22 lines · On Wed, Nov 18, 2026 at 1:08 AM Peder Bergan via B4 Relay…
From: Peder Bergan <[email protected]>
CONFIG_RUST_BUILD_ASSERT_ALLOWexportsrust_build_errorto modules. WhenCONFIG_MODVERSIONSis also enabled, modpost warns that the export has no symbol version and records a zero CRC because the build_error.o rule skips gendwarfksyms.Generate the checksum from build_error.o with the existing Rust library rule. Make build_error.o depend on
rust/Makefilewhen module versioning is enabled so incremental builds pick up the change. Kbuild's saved rustc command does not include the gendwarfksyms step.Fixes ac61506bf2d1 ("rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS")Reported-by Gwan-gyeong Mun <[email protected]>Signed-off-by Peder Bergan <[email protected]>---
An incremental x86-64 build with LLVM=1 CLIPPY=1 clears the modpost warning. The kernel export and a Rust module that references it both record the same nonzero CRC.
Quoted 4 lines
OpenAI Codex assisted with coding and testing.
--- rust/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Sami
Gary Guo
reviewerQuoted 31 lines · On Wed Nov 18, 2026 at 9:08 AM GMT, Peder Bergan via B4 Relay wrote:
From: Peder Bergan <[email protected]>
CONFIG_RUST_BUILD_ASSERT_ALLOWexportsrust_build_errorto modules. WhenCONFIG_MODVERSIONSis also enabled, modpost warns that the export has no symbol version and records a zero CRC because the build_error.o rule skips gendwarfksyms.Generate the checksum from build_error.o with the existing Rust library rule. Make build_error.o depend on
rust/Makefilewhen module versioning is enabled so incremental builds pick up the change. Kbuild's saved rustc command does not include the gendwarfksyms step.Fixes ac61506bf2d1 ("rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS")Reported-by Gwan-gyeong Mun <[email protected]>Signed-off-by Peder Bergan <[email protected]>---
An incremental x86-64 build with LLVM=1 CLIPPY=1 clears the modpost warning. The kernel export and a Rust module that references it both record the same nonzero CRC.OpenAI Codex assisted with coding and testing.
--- rust/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)rust/Makefile +0
-0
rust/Makefile $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ · line 778
Quoted 8 lines
rust/Makefile +3
-2@@ -773,8 +773,9 @@ $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ # treated as such so that we pass the same flags. Otherwise, for instance, # `rustc` will complain about missing sanitizer flags causing an ABI mismatch. $(obj)/build_error.o: private is-kernel-object := y -$(obj)/build_error.o: private skip_gendwarfksyms = 1 -$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +# Rebuild when the symbol version generation rule changes. +$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o \ + $(if $(CONFIG_MODVERSIONS),$(src)/Makefile) FORCE
Dependency on Makefile is just wrong in so many ways.
Best,
Gary
Quoted 11 lines
rust/Makefile +0
-1+$(call if_changed_rule,rustc_library) $(obj)/ffi.o: private skip_gendwarfksyms = 1 ---base-commit:
aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261118-fix-rust-build-error-modversions-4af535edc9b2Best regards,
Signature · 1 line
Peder Bergan <[email protected]>
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] rust: kbuild: wrong $(src)/Makefile dependency on $(obj)/build_error.o --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] rust: kbuild: wrong $(src)/Makefile dependency on $(obj)/build_error.o
--
commit 9e904760dafd3ce72fdc411a11382bf2076cfd36
Author: Peder Bergan <[email protected]>
rust: kbuild: generate a symbol version for rust_build_error
This commit enables gendwarfksyms for build_error.o so rust_build_error gets a symbol version when CONFIG_MODVERSIONS is enabled, and adds a conditional dependency on rust/Makefile for incremental builds.
Quoted 5 lines
rust/Makefile +0
-0
rust/Makefile $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ · line 779
Quoted 9 lines
rust/Makefile +3
-2@@ -773,8 +773,9 @@ $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ # treated as such so that we pass the same flags. Otherwise, for instance, # `rustc` will complain about missing sanitizer flags causing an ABI mismatch. $(obj)/build_error.o: private is-kernel-object := y -$(obj)/build_error.o: private skip_gendwarfksyms = 1 -$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +# Rebuild when the symbol version generation rule changes. +$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o \ + $(if $(CONFIG_MODVERSIONS),$(src)/Makefile) FORCE +$(call if_changed_rule,rustc_library)
[Severity: Low]
Does adding $(src)/Makefile here rebuild $(obj)/build_error.o when CONFIG_MODVERSIONS is enabled in an existing build tree?
if_changed_rule checks $(newer-prereqs), which uses $? and only triggers when a prerequisite's mtime is newer than the target. Toggling CONFIG_MODVERSIONS from n to y in Kconfig does not touch $(src)/Makefile, so its mtime stays older than an existing $(obj)/build_error.o and the object is not rebuilt to generate the symbol version.
Conversely, once CONFIG_MODVERSIONS is enabled, any edit to rust/Makefile updates its mtime and forces a rebuild of $(obj)/build_error.o, $(obj)/kernel.o and all downstream Rust targets. Tracking config changes that do not alter the saved command is normally done via
$(wildcard $(objtree)/include/config/MODVERSIONS).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-fix-rust-build-error-modversions-v1-1-7c1023764f30@gmail.com?part=1