Rust for Linux List
 help / color / mirror / Atom feed
From: FUJITA Tomonori <tomo@flapping.org>
To: anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net,
	ojeda@kernel.org, richard@nod.at
Cc: a.hindborg@kernel.org, acourbot@nvidia.com, aliceryhl@google.com,
	bjorn3_gh@protonmail.com, boqun@kernel.org, dakr@kernel.org,
	daniel.almeida@collabora.com, david@davidgow.net,
	gary@garyguo.net, linux-um@lists.infradead.org,
	lossin@kernel.org, tamird@kernel.org, tmgross@umich.edu,
	work@onurozkan.dev, rust-for-linux@vger.kernel.org,
	FUJITA Tomonori <fujita.tomonori@gmail.com>
Subject: [PATCH v1] rust: arch/um: Fix loading Rust modules
Date: Sun,  4 Oct 2026 21:12:30 +0900	[thread overview]
Message-ID: <20261004121230.373216-1-tomo@flapping.org> (raw)

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


                 reply	other threads:[~2026-10-04 12:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261004121230.373216-1-tomo@flapping.org \
    --to=tomo@flapping.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=david@davidgow.net \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=johannes@sipsolutions.net \
    --cc=linux-um@lists.infradead.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=richard@nod.at \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox