* [PATCH v1] rust: arch/um: Fix loading Rust modules
@ 2026-10-04 12:12 FUJITA Tomonori
0 siblings, 0 replies; only message in thread
From: FUJITA Tomonori @ 2026-10-04 12:12 UTC (permalink / raw)
To: anton.ivanov, johannes, ojeda, richard
Cc: a.hindborg, acourbot, aliceryhl, bjorn3_gh, boqun, dakr,
daniel.almeida, david, gary, linux-um, lossin, tamird, tmgross,
work, rust-for-linux, FUJITA Tomonori
From: FUJITA Tomonori <fujita.tomonori@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@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@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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-04 12:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-04 12:12 [PATCH v1] rust: arch/um: Fix loading Rust modules FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox