[PATCH v1] rust: arch/um: Fix loading Rust modules

FUJITA Tomonori tomo at flapping.org
Sun Oct 4 05:12:30 PDT 2026


From: FUJITA Tomonori <fujita.tomonori at gmail.com>

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.

Reported-by: Zigit Zo <zig at iorw.io>
Link: https://lore.kernel.org/rust-for-linux/62F5EEA0B866E9E0+20240903130606.292935-1-zig@iorw.io/
Assisted-by: LLM
Signed-off-by: FUJITA Tomonori <fujita.tomonori at gmail.com>
---
 arch/um/Makefile | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/um/Makefile b/arch/um/Makefile
index 937639edc295..c4a99073f014 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -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
-- 
2.43.0




More information about the linux-um mailing list