rust: arch/um: Fix loading Rust modules
Subsystems (2)
PATCH 1/1 rust: arch/um: Fix loading Rust modules
From: FUJITA Tomonori <[email protected]>
Rust modules fail to load on x86_64 UML:
# insmod rnull_mod.ko subarch: rnull_mod: Unknown rela relocation: 9 insmod: can't insert 'rnull_mod.ko': invalid module format
arch/um/Makefile adds -Crelocation-model=pie to KBUILD_RUSTFLAGS. This comes after -Crelocation-model=static in the top-level Makefile, so all Rust code on UML, both built-in code and modules, is built as PIE. In PIE mode, rustc accesses statics in other crates through the GOT and emits R_X86_64_GOTPCREL (9) relocations. UML uses the x86 module loader, and it does not handle them.
Remove the flag. Rust code, both built-in code and modules, then uses the static relocation model, the same as C code.
Modules still fail to load with a larger mem=, such as mem=512M, because Rust code uses the small code model while C code uses -mcmodel=large. This is a separate problem.
Tested with clang 20 and rustc 1.90: vmlinux builds and boots, and rnull_mod.ko loads with mem=32M.
--- arch/um/Makefile | 2 -- 1 file changed, 2 deletions(-)
arch/um/Makefile +0 -2
@@ -62,8 +62,6 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \ -D__close_range=kernel__close_range -KBUILD_RUSTFLAGS += -Crelocation-model=pie - KBUILD_AFLAGS += $(ARCH_INCLUDE) USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
base-commit: 2dee3d3adcadcc57d62ba6608cd02f50b0c10264
Signature · 1 line
2.43.0
Quoted 2 lines · FUJITA Tomonori
arch/um/Makefileadds -Crelocation-model=pie toKBUILD_RUSTFLAGS. This
Hmm... That was intentionally added by David back in commit 905a77077573 ("rust: arch/um: Use 'pie' relocation mode under UML"):
UML expects a position independent executable for some reason, so tell rustc to generate pie objects. Otherwise we get a bunch of relocations we can't deal with in libcore.
So it seems David faced other relocation errors (?).
Cheers,
Miguel
Quoted 4 lines · On Mon, 12 Oct 2026 16:40:50 +0200 Miguel Ojeda…
Quoted 2 lines · FUJITA Tomonori
arch/um/Makefileadds -Crelocation-model=pie toKBUILD_RUSTFLAGS. This
Quoted 8 lines
Hmm... That was intentionally added by David back in commit
905a77077573("rust:arch/um: Use 'pie' relocation mode under UML"):UML expects a position independent executable for some reason, so tell rustc to generate pie objects. Otherwise we get a bunch of relocations we can't deal with in libcore.
So it seems David faced other relocation errors (?).
I think that at that time, vmlinux was linked as PIE with clang, because -no-pie was not passed to clang. A static libcore cannot be linked into a PIE, so the errors probably came from that.
Since commit 846cfbeed09b ("um: Fix adding '-no-pie' for clang"), vmlinux is linked with -no-pie with clang too. So pie is no longer needed for Rust code, and it breaks modules.
Hi, UML maintainers,
Quoted 47 lines · On Sun, 4 Oct 2026 21:12:30 +0900 FUJITA Tomonori <[email protected]> wrote:
From: FUJITA Tomonori <[email protected]>
Rust modules fail to load on
x86_64UML:# insmod rnull_mod.ko subarch: rnull_mod: Unknown rela relocation: 9 insmod: can't insert 'rnull_mod.ko': invalid module format
arch/um/Makefileadds -Crelocation-model=pie toKBUILD_RUSTFLAGS. This comes after -Crelocation-model=static in the top-levelMakefile, so all Rust code on UML, both built-in code and modules, is built as PIE. In PIE mode, rustc accesses statics in other crates through the GOT and emitsR_X86_64_GOTPCREL(9) relocations. UML uses the x86 module loader, and it does not handle them.Remove the flag. Rust code, both built-in code and modules, then uses the static relocation model, the same as C code.
Modules still fail to load with a larger mem=, such as mem=512M, because Rust code uses the small code model while C code uses -mcmodel=large. This is a separate problem.
Tested with clang 20 and rustc 1.90: vmlinux builds and boots, and rnull_mod.ko loads with mem=32M.
Reported-by Zigit Zo <[email protected]>Assisted-by LLMSigned-off-by FUJITA Tomonori <[email protected]>--- arch/um/Makefile | 2 -- 1 file changed, 2 deletions(-)arch/um/Makefile +0
-2@@ -62,8 +62,6 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \ -D__close_range=kernel__close_range -KBUILD_RUSTFLAGS += -Crelocation-model=pie - KBUILD_AFLAGS += $(ARCH_INCLUDE) USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
Quoted 1 line
base-commit:
2dee3d3adcadcc57d62ba6608cd02f50b0c10264
Gentle ping. The patch still applies cleanly on top of v7.4-rc1. If it looks fine, could you take it through the UML tree?
Johannes Berg
maintainerQuoted 15 lines · FUJITA Tomonori
Quoted 15 lines
arch/um/Makefile +0
-0@@ -62,8 +62,6 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr \-D__close_range=kernel__close_range
arch/um/Makefile +0
-2-KBUILD_RUSTFLAGS += -Crelocation-model=pie -
KBUILD_AFLAGS+= $(ARCH_INCLUDE)
USER_CFLAGS= $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
Quoted 4 lines
Quoted 1 line
base-commit:
2dee3d3adcadcc57d62ba6608cd02f50b0c10264Gentle ping. The patch still applies cleanly on top of v7.4-rc1. If it looks fine, could you take it through the UML tree?
I guess I figured with the "rust:" prefix it'd go through their tree, but either way during the merge window and all I wasn't really paying attention to UML.
I'll pick it up now.
johannes
Quoted 6 lines · Johannes Berg
I guess I figured with the "rust:" prefix it'd go through their tree, but either way during the merge window and all I wasn't really paying attention to UML.
I'll pick it up now.
Thanks!
(Yeah, I think the title should have been um: or um: rust: or similar. Personally, I check the list of files and the kind of change more than anything else for deciding trees, rather than the titles; maybe I should check those more).
Cheers,
Miguel
Quoted 1 line · On Tue, 03 Nov 2026 10:39:11 +0100 Johannes Berg <[email protected]>…
On Tue, 2026-11-03 at 18:02 +0900, FUJITA Tomonori wrote:
[...]
Quoted 8 lines
Quoted 2 lines
Gentle ping. The patch still applies cleanly on top of v7.4-rc1. If it looks fine, could you take it through the UML tree?
I guess I figured with the "rust:" prefix it'd go through their tree, but either way during the merge window and all I wasn't really paying attention to UML.
I'll pick it up now.
Thanks!
As the commit message says, Rust modules still fail to load with a larger mem=, because Rust code uses the small code model. Zigit Zo posted a fix for this in 2024 [1]. It is the same change as the one I would send:
KBUILD_RUSTFLAGS += -Ccode-model=large
It was not merged. Was it because the patch has no Signed-off-by?
[1] https://lore.kernel.org/rust-for-linux/[email protected]/
Johannes Berg
maintainerQuoted 9 lines · FUJITA Tomonori
As the commit message says, Rust modules still fail to load with a larger mem=, because Rust code uses the small code model. Zigit Zo posted a fix for this in 2024 [1]. It is the same change as the one I would send:
KBUILD_RUSTFLAGS += -Ccode-model=largeIt was not merged. Was it because the patch has no Signed-off-by?
I have no idea, but I process enough patches (mostly in wireless though) that I almost certainly wouldn't remember one that just gets dropped on the floor because it doesn't have a Signed-off-by (or similar mechanical issues).
johannes