| Message ID | 20261004121230.373216-1-tomo@flapping.org |
|---|---|
| State | Accepted |
| Headers | show |
| Series | [v1] rust: arch/um: Fix loading Rust modules | expand |
On Sun, Oct 4, 2026 at 2:13 PM FUJITA Tomonori <tomo@flapping.org> wrote: > > arch/um/Makefile adds -Crelocation-model=pie to KBUILD_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
On Mon, 12 Oct 2026 16:40:50 +0200 Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > On Sun, Oct 4, 2026 at 2:13 PM FUJITA Tomonori <tomo@flapping.org> wrote: >> >> arch/um/Makefile adds -Crelocation-model=pie to KBUILD_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 (?). 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, On Sun, 4 Oct 2026 21:12:30 +0900 FUJITA Tomonori <tomo@flapping.org> wrote: > 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 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?
On Tue, 2026-11-03 at 18:02 +0900, FUJITA Tomonori wrote: > > > > 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 > > 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. johannes
On Tue, Nov 3, 2026 at 10:39 AM Johannes Berg <johannes@sipsolutions.net> wrote: > > 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
On Tue, 03 Nov 2026 10:39:11 +0100 Johannes Berg <johannes@sipsolutions.net> wrote: > On Tue, 2026-11-03 at 18:02 +0900, FUJITA Tomonori wrote: [...] >> 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/54FC087D02C52990+20240903130606.292935-3-zig@iorw.io/
On Thu, 2026-11-05 at 10:09 +0900, FUJITA Tomonori wrote: > > 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? 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
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))) \