rust: arch/um: use 'static' relocation model for uml modules
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/2 rust: arch/um: use 'static' relocation model for uml modules
In the x86_64 UML, kernel modules compiled with Rust will currently generate some R_X86_64_GOTPCREL relocations, which will then be rejected by the kernel.
And because of the kernel modules of UML are only got handled by the UML itself, relocation model 'static' can work as expected other than 'pie'.
--- arch/um/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/Makefile +1 -1
@@ -63,7 +63,7 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Din6addr_loopback=kernel_in6addr_loopback \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr -KBUILD_RUSTFLAGS += -Crelocation-model=pie +KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie KBUILD_AFLAGS += $(ARCH_INCLUDE)
Signature · 1 line
2.46.0
Quoted 13 lines · Zigit Zo
In the
x86_64UML, kernel modules compiled with Rust will currently generate someR_X86_64_GOTPCRELrelocations, which will then be rejected by the kernel.And because of the kernel modules of UML are only got handled by the UML itself, relocation model 'static' can work as expected other than 'pie'.
---arch/um/Makefile +0
-0
arch/um/Makefile KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ · line 69
Quoted 8 lines
arch/um/Makefile +1
-1@@ -63,7 +63,7 @@ KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \ -Din6addr_loopback=kernel_in6addr_loopback \ -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr -KBUILD_RUSTFLAGS += -Crelocation-model=pie +KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie KBUILD_AFLAGS += $(ARCH_INCLUDE)
I failed to match the actual change with the commit message. Consider that ignorance on my side.
I see a problem in just renaming a variable, might be my problem. Thing is that removal of 'KBUILD_RUSTFLAG += ' feels wrong, hence this posting.
Groeten
Geert Stappers
Signature · 1 line
Silence is hard to parse
Quoted 2 lines · Geert Stappers
I failed to match the actual change with the commit message. Consider that ignorance on my side.
FYI, I'm using the master branch of the upstream, but yes it's in the 'rust-next' or other branches as well, so maybe not a big deal IMO.
Of what 'https://rust-for-linux.com/branches' says, maybe I'll use the 'rust-next' branch for the next time, thanks for pointing out!
Quoted 2 lines
I see a problem in just renaming a variable, might be my problem. Thing is that removal of '
KBUILD_RUSTFLAG+= ' feels wrong, hence this posting.
I think this is fine, the 'KBUILD_RUSTFLAG' controls the 'PIE' flag for both the kernel itself and the loadable modules. And yes, that's the only way I can make the 'PIE' flag out of the modules while keeping the UML kernel itself works, and the 'scripts/Makefile.lib' I tought has placed those flags correctly.
What about adding a 'static' flag to the 'arch/um/Makefile' explicitly,
---KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie KBUILD_RUSTFLAGS_MODULE += -Crelocation-model=static
---
but that's just a redundant of the already defined 'KBUILD_RUSTFLAGS'. Have no more ideas what can this flag goes wrong :(
PATCH 2/2 rust: arch/um: use 'large' code model for uml
In reply to a message not in the archiveThe Rust modules compiled against UML should be 'large', without this the compiler will generate some R_X86_64_32S relocations, but UML is running at userspace with signed-address larger than zero, therefore makes '__write_relocate_add' treating the relocation as overflowed.
--- arch/um/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/um/Makefile +1 -0
@@ -32,6 +32,7 @@ endif ifdef CONFIG_64BIT KBUILD_CFLAGS += -mcmodel=large + KBUILD_RUSTFLAGS += -Ccode-model=large endif HOST_DIR := arch/$(HEADER_ARCH)
Signature · 1 line
2.46.0