* [PATCH V8 0/4] Rust support for powerpc
@ 2026-04-03 14:53 Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error Mukesh Kumar Chaurasiya (IBM)
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-04-03 14:53 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
Cc: Mukesh Kumar Chaurasiya (IBM)
Enable experimental rust support for ppc64le and ppc32be. The patch for
ppc32 has been provided by Link Mauve[1] and ppc64le support[2] has been
merged over it. ppc32 needs some toolchain fixes mentioned in the patch
`rust: Add PowerPC support` and the discussion for that is done here[1].
This has been tested on
- powernv9 hardware
- pseries P11 hardware
- pseries(9, 10) qemu
- powernv(9, 10) qemu
- rustdoc on x86 and powerpc64le
- rusttest on x86 and powerpc64le
We are actively working with our LLVM team to get the target for ppc,
ppc64 and ppc64le in the rust compiler.
[1] https://lore.kernel.org/all/20260204030507.8203-1-linkmauve@linkmauve.fr
[2] https://lore.kernel.org/all/20260204042417.83903-1-mkchauras@gmail.com
Changelog:
V7 -> V8:
- rust/Makefile updated to separate host libraries from target
V7: https://lore.kernel.org/all/20260329160254.2592207-1-mkchauras@gmail.com/
Changelog:
V6 -> V7:
- Documentation removed as powerpc is still under development
- Added a fix for race condition in rust/Makefile
V6: https://lore.kernel.org/all/20260210090023.2587534-1-mkchauras@gmail.com
V5 -> V6:
- Added a missing Tested by from Venkat which got missed since V3
- Support is marked as Maintained instead of experimental
V5: https://lore.kernel.org/all/20260210053756.2088302-1-mkchauras@gmail.com
V4 -> V5:
- Removed a nested ifdef from PPC64 for Little endian toolchain
V4: https://lore.kernel.org/all/20260209105456.1551677-1-mkchauras@gmail.com
V3 -> V4:
- Co-developed-by header added in patch 1
V3: https://lore.kernel.org/all/20260205180429.3280657-1-mkchauras@gmail.com
V2 -> V3:
- Splited HAVE_RUST in 2 lines
- BINDGEN_TARGET_powerpc initialized before assigning the same to
BINDGEN_TARGET
V2: https://lore.kernel.org/all/20260204210125.613350-1-mkchauras@gmail.com
V1 -> V2:
- jump label fix for rust has been moved to a separate patch
- PPC32 support has been taken
- rust support has been marked experimental
- target.json dependency has been removed
- HAVE_RUST now depends on CPU_LITTLE_ENDIAN for PPC64
Link Mauve (1):
rust: Add PowerPC support
Mukesh Kumar Chaurasiya (IBM) (3):
rust: Fix "multiple candidates for rmeta dependency core" error
powerpc/jump_label: adjust inline asm to be consistent
powerpc: Enable Rust for ppc64le
arch/powerpc/Kconfig | 2 +
arch/powerpc/Makefile | 7 +++
arch/powerpc/include/asm/jump_label.h | 23 +++++----
rust/Makefile | 73 ++++++++++++++++++---------
4 files changed, 71 insertions(+), 34 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error
2026-04-03 14:53 [PATCH V8 0/4] Rust support for powerpc Mukesh Kumar Chaurasiya (IBM)
@ 2026-04-03 14:53 ` Mukesh Kumar Chaurasiya (IBM)
2026-04-03 15:09 ` Gary Guo
2026-04-03 14:53 ` [PATCH V8 2/4] powerpc/jump_label: adjust inline asm to be consistent Mukesh Kumar Chaurasiya (IBM)
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-04-03 14:53 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
Cc: Mukesh Kumar Chaurasiya (IBM)
When building Rust code with LLVM=1 with -j1, rustc was encountering
an error:
"multiple candidates for `rmeta` dependency `core` found", with two
candidates:
1. The host's standard library from the rustup toolchain
2. The kernel's custom libcore.rmeta in the rust/ directory
This occurred because the build system was using `-L$(objtree)/rust`
for host library builds (proc_macro2, quote, syn), which caused rustc
to search the rust/ directory. During this search, rustc would find
both the kernel's custom libcore.rmeta and gain access to the host's
standard library, creating a conflict.
The solution is to separate host libraries into a dedicated rust/host/
subdirectory and use `-L$(objtree)/rust/host` for host builds instead
of `-L$(objtree)/rust`. This ensures that:
1. Host library builds (proc_macro2, quote, syn) only search rust/host/
and never encounter the kernel's libcore.rmeta
2. Proc macro builds use `-L$(objtree)/rust/host` to find their
dependencies
3. Test builds use `-L$(objtree)/rust/test` for their dependencies
4. Target builds continue to use `-L$(objtree)/rust` as before
Special handling is added for rustdoc-pin_init, which is a host build
(to access the alloc crate) but depends on proc macros from the main
rust/ directory. It uses explicit `--extern` paths with absolute paths
to reference the proc macros without adding `-L$(objtree)/rust`, which
would reintroduce the conflict.
The rust/host/ directory is added to clean-files to ensure it's removed
during `make clean`.
Changes:
- Add clean-files := host/ to clean the generated directory
- Change host library targets from lib*.rlib to host/lib*.rlib
- Update cmd_rustc_procmacrolibrary to create host/ directory
- Update cmd_rustc_procmacro to use -L$(objtree)/rust/host
- Update cmd_rustdoc to use -L$(objtree)/rust/host for host builds
- Update cmd_rustc_test_library to use -L$(objtree)/rust/test
- Update rustdoc-pin_init to use explicit --extern paths for proc macros
Link: https://github.com/Rust-for-Linux/linux/issues/105
Link: https://github.com/linuxppc/issues/issues/451
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
rust/Makefile | 63 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 23 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 9801af2e1e02..762bddc868e4 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -3,6 +3,9 @@
# Where to place rustdoc generated documentation
rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
+# Clean generated host directory
+clean-files := host/
+
obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
always-$(CONFIG_RUST) += exports_core_generated.h
@@ -27,7 +30,7 @@ endif
obj-$(CONFIG_RUST) += exports.o
-always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
+always-$(CONFIG_RUST) += host/libproc_macro2.rlib host/libquote.rlib host/libsyn.rlib
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
@@ -150,7 +153,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
OBJTREE=$(abspath $(objtree)) \
$(RUSTDOC) $(filter-out $(skip_flags) --remap-path-prefix=% --remap-path-scope=%, \
$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
- $(rustc_target_flags) -L$(objtree)/$(obj) \
+ $(rustc_target_flags) -L$(objtree)/$(obj)$(if $(rustdoc_host),/host) \
-Zunstable-options --generate-link-to-definition \
--output $(rustdoc_output) \
--crate-name $(subst rustdoc-,,$@) \
@@ -193,13 +196,16 @@ rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
+$(call if_changed,rustdoc)
rustdoc-quote: private rustdoc_host = yes
-rustdoc-quote: private rustc_target_flags = $(quote-flags)
+rustdoc-quote: private rustc_target_flags = $(quote-flags) \
+ --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
rustdoc-quote: private skip_flags = $(quote-skip_flags)
rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
+$(call if_changed,rustdoc)
rustdoc-syn: private rustdoc_host = yes
-rustdoc-syn: private rustc_target_flags = $(syn-flags)
+rustdoc-syn: private rustc_target_flags = $(syn-flags) \
+ --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
+ --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
rustdoc-syn: $(src)/syn/lib.rs rustdoc-clean rustdoc-quote FORCE
+$(call if_changed,rustdoc)
@@ -236,7 +242,10 @@ rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \
+$(call if_changed,rustdoc)
rustdoc-pin_init: private rustdoc_host = yes
-rustdoc-pin_init: private rustc_target_flags = $(pin_init-flags) \
+rustdoc-pin_init: private rustc_target_flags = \
+ --extern pin_init_internal=$(abspath $(objtree)/$(obj)/$(libpin_init_internal_name)) \
+ --extern macros=$(abspath $(objtree)/$(obj)/$(libmacros_name)) \
+ $(call cfgs-to-flags,$(pin_init-cfgs)) \
--extern alloc --cfg feature=\"alloc\"
rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
rustdoc-macros FORCE
@@ -369,7 +378,9 @@ rusttest: rusttest-macros
rusttest-macros: private rustc_target_flags = --extern proc_macro \
--extern macros --extern kernel --extern pin_init \
- --extern proc_macro2 --extern quote --extern syn
+ --extern proc_macro2=$(abspath $(objtree)/$(obj)/test/libproc_macro2.rlib) \
+ --extern quote=$(abspath $(objtree)/$(obj)/test/libquote.rlib) \
+ --extern syn=$(abspath $(objtree)/$(obj)/test/libsyn.rlib)
rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
rusttest-macros: $(src)/macros/lib.rs \
rusttestlib-macros rusttestlib-kernel rusttestlib-pin_init FORCE
@@ -525,48 +536,54 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
cmd_rustc_procmacrolibrary = \
+ mkdir -p $(dir $@); \
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
$(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
--emit=dep-info=$(depfile) --emit=link=$@ --crate-type rlib -O \
- --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
--crate-name $(patsubst lib%.rlib,%,$(notdir $@)) $<
-$(obj)/libproc_macro2.rlib: private skip_clippy = 1
-$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
-$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
+$(obj)/host/libproc_macro2.rlib: private skip_clippy = 1
+$(obj)/host/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
+$(obj)/host/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
+$(call if_changed_dep,rustc_procmacrolibrary)
-$(obj)/libquote.rlib: private skip_clippy = 1
-$(obj)/libquote.rlib: private skip_flags = $(quote-skip_flags)
-$(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
-$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
+$(obj)/host/libquote.rlib: private skip_clippy = 1
+$(obj)/host/libquote.rlib: private skip_flags = $(quote-skip_flags)
+$(obj)/host/libquote.rlib: private rustc_target_flags = $(quote-flags) \
+ --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
+$(obj)/host/libquote.rlib: $(src)/quote/lib.rs $(obj)/host/libproc_macro2.rlib FORCE
+$(call if_changed_dep,rustc_procmacrolibrary)
-$(obj)/libsyn.rlib: private skip_clippy = 1
-$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
-$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
+$(obj)/host/libsyn.rlib: private skip_clippy = 1
+$(obj)/host/libsyn.rlib: private rustc_target_flags = $(syn-flags) \
+ --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
+ --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
+$(obj)/host/libsyn.rlib: $(src)/syn/lib.rs $(obj)/host/libquote.rlib FORCE
+$(call if_changed_dep,rustc_procmacrolibrary)
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
cmd_rustc_procmacro = \
- $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
+ $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
- --crate-type proc-macro -L$(objtree)/$(obj) \
+ --crate-type proc-macro \
+ -L$(objtree)/$(obj)/host \
--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
- @$(objtree)/include/generated/rustc_cfg $<
+ @$(objtree)/include/generated/rustc_cfg \
+ $(rustc_target_flags) \
+ $<
# Procedural macros can only be used with the `rustc` that compiled it.
$(obj)/$(libmacros_name): private rustc_target_flags = \
--extern proc_macro2 --extern quote --extern syn
-$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
- $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
+$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/host/libproc_macro2.rlib \
+ $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
+$(call if_changed_dep,rustc_procmacro)
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
$(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
- $(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
+ $(obj)/host/libproc_macro2.rlib $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
+$(call if_changed_dep,rustc_procmacro)
# `rustc` requires `-Zunstable-options` to use custom target specifications
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH V8 2/4] powerpc/jump_label: adjust inline asm to be consistent
2026-04-03 14:53 [PATCH V8 0/4] Rust support for powerpc Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error Mukesh Kumar Chaurasiya (IBM)
@ 2026-04-03 14:53 ` Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 3/4] rust: Add PowerPC support Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 4/4] powerpc: Enable Rust for ppc64le Mukesh Kumar Chaurasiya (IBM)
3 siblings, 0 replies; 8+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-04-03 14:53 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
Cc: Mukesh Kumar Chaurasiya (IBM)
Added support for a new macro ARCH_STATIC_BRANCH_ASM in powerpc
to avoid duplication of inline asm between C and Rust. This is
inline with 'commit aecaf181651c ("jump_label: adjust inline asm to be consistent")'
Co-developed-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://github.com/Rust-for-Linux/linux/issues/105
Link: https://github.com/linuxppc/issues/issues/451
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
arch/powerpc/include/asm/jump_label.h | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/include/asm/jump_label.h
index d4eaba459a0e..3016e9c8d6bc 100644
--- a/arch/powerpc/include/asm/jump_label.h
+++ b/arch/powerpc/include/asm/jump_label.h
@@ -15,14 +15,20 @@
#define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG)
#define JUMP_LABEL_NOP_SIZE 4
+#define JUMP_TABLE_ENTRY(key, label) \
+ ".pushsection __jump_table, \"aw\" \n\t" \
+ ".long 1b - ., " label " - . \n\t" \
+ JUMP_ENTRY_TYPE key " - . \n\t" \
+ ".popsection \n\t"
+
+#define ARCH_STATIC_BRANCH_ASM(key, label) \
+ "1: nop \n\t" \
+ JUMP_TABLE_ENTRY(key, label)
+
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
{
- asm goto("1:\n\t"
- "nop # arch_static_branch\n\t"
- ".pushsection __jump_table, \"aw\"\n\t"
- ".long 1b - ., %l[l_yes] - .\n\t"
- JUMP_ENTRY_TYPE "%c0 - .\n\t"
- ".popsection \n\t"
+ asm goto(
+ ARCH_STATIC_BRANCH_ASM("%c0", "%l[l_yes]")
: : "i" (&((char *)key)[branch]) : : l_yes);
return false;
@@ -34,10 +40,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
{
asm goto("1:\n\t"
"b %l[l_yes] # arch_static_branch_jump\n\t"
- ".pushsection __jump_table, \"aw\"\n\t"
- ".long 1b - ., %l[l_yes] - .\n\t"
- JUMP_ENTRY_TYPE "%c0 - .\n\t"
- ".popsection \n\t"
+ JUMP_TABLE_ENTRY("%c0", "%l[l_yes]")
: : "i" (&((char *)key)[branch]) : : l_yes);
return false;
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH V8 3/4] rust: Add PowerPC support
2026-04-03 14:53 [PATCH V8 0/4] Rust support for powerpc Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 2/4] powerpc/jump_label: adjust inline asm to be consistent Mukesh Kumar Chaurasiya (IBM)
@ 2026-04-03 14:53 ` Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 4/4] powerpc: Enable Rust for ppc64le Mukesh Kumar Chaurasiya (IBM)
3 siblings, 0 replies; 8+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-04-03 14:53 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
Cc: Link Mauve, Mukesh Kumar Chaurasiya (IBM)
From: Link Mauve <linkmauve@linkmauve.fr>
For now only Big Endian 32-bit PowerPC is supported, as that is the only
hardware I have. This has been tested on the Nintendo Wii so far, but I
plan on also using it on the GameCube, Wii U and Apple G4.
These changes aren’t the only ones required to get the kernel to compile
and link on PowerPC, libcore will also have to be changed to not use
integer division to format u64, u128 and core::time::Duration, otherwise
__udivdi3() and __umoddi3() will have to be added. I have tested this
change by replacing the three implementations with unimplemented!() and
it linked just fine.
Signed-off-by: Link Mauve <linkmauve@linkmauve.fr>
Link: https://github.com/Rust-for-Linux/linux/issues/105
Link: https://github.com/linuxppc/issues/issues/451
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/Makefile | 2 ++
rust/Makefile | 4 +++-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 10240cb80904..1246b3add8ff 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -284,6 +284,7 @@ config PPC
select HAVE_REGS_AND_STACK_ACCESS_API
select HAVE_RELIABLE_STACKTRACE
select HAVE_RSEQ
+ select HAVE_RUST if PPC32
select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
select HAVE_SETUP_PER_CPU_AREA if PPC64
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index a58b1029592c..589613eaa5dc 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -61,6 +61,8 @@ else
KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o
endif
+KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu
+
ifdef CONFIG_CPU_LITTLE_ENDIAN
KBUILD_CPPFLAGS += -mlittle-endian
KBUILD_LDFLAGS += -EL
diff --git a/rust/Makefile b/rust/Makefile
index 762bddc868e4..d05e76df15a8 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -413,13 +413,15 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
-fstrict-flex-arrays=% -fmin-function-alignment=% \
-fzero-init-padding-bits=% -mno-fdpic \
-fdiagnostics-show-context -fdiagnostics-show-context=% \
- --param=% --param asan-% -fno-isolate-erroneous-paths-dereference
+ --param=% --param asan-% -fno-isolate-erroneous-paths-dereference \
+ -ffixed-r2 -mmultiple -mno-readonly-in-sdata
# Derived from `scripts/Makefile.clang`.
BINDGEN_TARGET_x86 := x86_64-linux-gnu
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
BINDGEN_TARGET_arm := arm-linux-gnueabi
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
+BINDGEN_TARGET_powerpc := powerpc-linux-gnu
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH V8 4/4] powerpc: Enable Rust for ppc64le
2026-04-03 14:53 [PATCH V8 0/4] Rust support for powerpc Mukesh Kumar Chaurasiya (IBM)
` (2 preceding siblings ...)
2026-04-03 14:53 ` [PATCH V8 3/4] rust: Add PowerPC support Mukesh Kumar Chaurasiya (IBM)
@ 2026-04-03 14:53 ` Mukesh Kumar Chaurasiya (IBM)
3 siblings, 0 replies; 8+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-04-03 14:53 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
Cc: Mukesh Kumar Chaurasiya (IBM), Link Mauve, Venkat Rao Bagalkote
Enabling rust support for ppc64le.
Tested on pseries Power11:
╰─❯ dmesg | grep rust
[ 0.225728] Initialise system trusted keyrings
[ 0.270961] rust_minimal: Rust minimal sample (init)
[ 0.270968] rust_minimal: Am I built-in? true
[ 0.270974] rust_minimal: test_parameter: 1
[ 0.270983] rust_misc_device: Initialising Rust Misc Device Sample
[ 0.271012] rust_print: Rust printing macros sample (init)
[ 0.271019] rust_print: Emergency message (level 0) without args
[ 0.271023] rust_print: Alert message (level 1) without args
[ 0.271026] rust_print: Critical message (level 2) without args
[ 0.271030] rust_print: Error message (level 3) without args
[ 0.271033] rust_print: Warning message (level 4) without args
[ 0.271037] rust_print: Notice message (level 5) without args
[ 0.271040] rust_print: Info message (level 6) without args
[ 0.271043] rust_print: A line that is continued without args
[ 0.271054] rust_print: Emergency message (level 0) with args
[ 0.271064] rust_print: Alert message (level 1) with args
[ 0.271072] rust_print: Critical message (level 2) with args
[ 0.271077] rust_print: Error message (level 3) with args
[ 0.271083] rust_print: Warning message (level 4) with args
[ 0.271091] rust_print: Notice message (level 5) with args
[ 0.271097] rust_print: Info message (level 6) with args
[ 0.271102] rust_print: A line that is continued with args
[ 0.271110] rust_print: 1
[ 0.271113] rust_print: "hello, world"
[ 0.271121] rust_print: [samples/rust/rust_print_main.rs:35:5] c = "hello, world"
[ 0.271129] rust_print: Arc<dyn Display> says 42
[ 0.271130] rust_print: Arc<dyn Display> says hello, world
[ 0.271136] rust_print: "hello, world"
[ 0.271198] usbcore: registered new interface driver rust_driver_usb
[ 0.271207] rust_faux_driver: Initialising Rust Faux Device Sample
[ 0.271227] faux_driver rust-faux-sample-device: Hello from faux device!
[ 0.271297] rust_configfs: Rust configfs sample (init)
Reviewed-by: Link Mauve <linkmauve@linkmauve.fr>
Tested-by: Link Mauve <linkmauve@linkmauve.fr>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Link: https://github.com/Rust-for-Linux/linux/issues/105
Link: https://github.com/linuxppc/issues/issues/451
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/Makefile | 7 ++++++-
rust/Makefile | 6 ++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1246b3add8ff..a5f50434daf3 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -285,6 +285,7 @@ config PPC
select HAVE_RELIABLE_STACKTRACE
select HAVE_RSEQ
select HAVE_RUST if PPC32
+ select HAVE_RUST if PPC64 && CPU_LITTLE_ENDIAN
select HAVE_SAMPLE_FTRACE_DIRECT if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI if HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
select HAVE_SETUP_PER_CPU_AREA if PPC64
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 589613eaa5dc..9385db478c59 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -61,7 +61,12 @@ else
KBUILD_LDFLAGS_MODULE += $(objtree)/arch/powerpc/lib/crtsavres.o
endif
-KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu
+ifdef CONFIG_PPC64
+KBUILD_RUSTFLAGS += --target=powerpc64le-unknown-linux-gnu
+KBUILD_RUSTFLAGS += -Ctarget-feature=-mma,-vsx,-hard-float,-altivec
+else
+KBUILD_RUSTFLAGS += --target=powerpc-unknown-linux-gnu
+endif
ifdef CONFIG_CPU_LITTLE_ENDIAN
KBUILD_CPPFLAGS += -mlittle-endian
diff --git a/rust/Makefile b/rust/Makefile
index d05e76df15a8..321b7d0e15c7 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -421,7 +421,13 @@ BINDGEN_TARGET_x86 := x86_64-linux-gnu
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
BINDGEN_TARGET_arm := arm-linux-gnueabi
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
+
+ifdef CONFIG_PPC64
+BINDGEN_TARGET_powerpc := powerpc64le-linux-gnu
+else
BINDGEN_TARGET_powerpc := powerpc-linux-gnu
+endif
+
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error
2026-04-03 14:53 ` [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error Mukesh Kumar Chaurasiya (IBM)
@ 2026-04-03 15:09 ` Gary Guo
2026-04-04 3:39 ` Mukesh Kumar Chaurasiya
0 siblings, 1 reply; 8+ messages in thread
From: Gary Guo @ 2026-04-03 15:09 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM), maddy, mpe, npiggin, chleroy,
peterz, jpoimboe, jbaron, aliceryhl, rostedt, ardb, ojeda, boqun,
gary, bjorn3_gh, lossin, a.hindborg, tmgross, dakr, nathan,
nick.desaulniers+lkml, morbo, justinstitt, linuxppc-dev,
linux-kernel, rust-for-linux, llvm
On Fri Apr 3, 2026 at 3:53 PM BST, Mukesh Kumar Chaurasiya (IBM) wrote:
> When building Rust code with LLVM=1 with -j1, rustc was encountering
> an error:
> "multiple candidates for `rmeta` dependency `core` found", with two
> candidates:
> 1. The host's standard library from the rustup toolchain
> 2. The kernel's custom libcore.rmeta in the rust/ directory
>
> This occurred because the build system was using `-L$(objtree)/rust`
> for host library builds (proc_macro2, quote, syn), which caused rustc
> to search the rust/ directory. During this search, rustc would find
> both the kernel's custom libcore.rmeta and gain access to the host's
> standard library, creating a conflict.
>
> The solution is to separate host libraries into a dedicated rust/host/
> subdirectory and use `-L$(objtree)/rust/host` for host builds instead
> of `-L$(objtree)/rust`. This ensures that:
>
> 1. Host library builds (proc_macro2, quote, syn) only search rust/host/
> and never encounter the kernel's libcore.rmeta
> 2. Proc macro builds use `-L$(objtree)/rust/host` to find their
> dependencies
> 3. Test builds use `-L$(objtree)/rust/test` for their dependencies
> 4. Target builds continue to use `-L$(objtree)/rust` as before
>
> Special handling is added for rustdoc-pin_init, which is a host build
> (to access the alloc crate) but depends on proc macros from the main
> rust/ directory. It uses explicit `--extern` paths with absolute paths
> to reference the proc macros without adding `-L$(objtree)/rust`, which
> would reintroduce the conflict.
>
> The rust/host/ directory is added to clean-files to ensure it's removed
> during `make clean`.
>
> Changes:
> - Add clean-files := host/ to clean the generated directory
> - Change host library targets from lib*.rlib to host/lib*.rlib
> - Update cmd_rustc_procmacrolibrary to create host/ directory
> - Update cmd_rustc_procmacro to use -L$(objtree)/rust/host
> - Update cmd_rustdoc to use -L$(objtree)/rust/host for host builds
> - Update cmd_rustc_test_library to use -L$(objtree)/rust/test
> - Update rustdoc-pin_init to use explicit --extern paths for proc macros
This should go after the tags and ---, so it's not part of the commit message.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/105
> Link: https://github.com/linuxppc/issues/issues/451
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> rust/Makefile | 63 ++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/rust/Makefile b/rust/Makefile
> index 9801af2e1e02..762bddc868e4 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -3,6 +3,9 @@
> # Where to place rustdoc generated documentation
> rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
>
> +# Clean generated host directory
> +clean-files := host/
> +
> obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
> always-$(CONFIG_RUST) += exports_core_generated.h
>
> @@ -27,7 +30,7 @@ endif
>
> obj-$(CONFIG_RUST) += exports.o
>
> -always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
> +always-$(CONFIG_RUST) += host/libproc_macro2.rlib host/libquote.rlib host/libsyn.rlib
>
> always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
> always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
> @@ -150,7 +153,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
> OBJTREE=$(abspath $(objtree)) \
> $(RUSTDOC) $(filter-out $(skip_flags) --remap-path-prefix=% --remap-path-scope=%, \
> $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
> - $(rustc_target_flags) -L$(objtree)/$(obj) \
> + $(rustc_target_flags) -L$(objtree)/$(obj)$(if $(rustdoc_host),/host) \
> -Zunstable-options --generate-link-to-definition \
> --output $(rustdoc_output) \
> --crate-name $(subst rustdoc-,,$@) \
> @@ -193,13 +196,16 @@ rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
> +$(call if_changed,rustdoc)
>
> rustdoc-quote: private rustdoc_host = yes
> -rustdoc-quote: private rustc_target_flags = $(quote-flags)
> +rustdoc-quote: private rustc_target_flags = $(quote-flags) \
> + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
Why not just add `-L$(objtree)/$(obj)/host`? If we go with the host directory
approach we shouldn't need to explicitly specify the path?
Best,
Gary
> rustdoc-quote: private skip_flags = $(quote-skip_flags)
> rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
> +$(call if_changed,rustdoc)
>
> rustdoc-syn: private rustdoc_host = yes
> -rustdoc-syn: private rustc_target_flags = $(syn-flags)
> +rustdoc-syn: private rustc_target_flags = $(syn-flags) \
> + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
> + --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
> rustdoc-syn: $(src)/syn/lib.rs rustdoc-clean rustdoc-quote FORCE
> +$(call if_changed,rustdoc)
>
> @@ -236,7 +242,10 @@ rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \
> +$(call if_changed,rustdoc)
>
> rustdoc-pin_init: private rustdoc_host = yes
> -rustdoc-pin_init: private rustc_target_flags = $(pin_init-flags) \
> +rustdoc-pin_init: private rustc_target_flags = \
> + --extern pin_init_internal=$(abspath $(objtree)/$(obj)/$(libpin_init_internal_name)) \
> + --extern macros=$(abspath $(objtree)/$(obj)/$(libmacros_name)) \
> + $(call cfgs-to-flags,$(pin_init-cfgs)) \
> --extern alloc --cfg feature=\"alloc\"
> rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
> rustdoc-macros FORCE
> @@ -369,7 +378,9 @@ rusttest: rusttest-macros
>
> rusttest-macros: private rustc_target_flags = --extern proc_macro \
> --extern macros --extern kernel --extern pin_init \
> - --extern proc_macro2 --extern quote --extern syn
> + --extern proc_macro2=$(abspath $(objtree)/$(obj)/test/libproc_macro2.rlib) \
> + --extern quote=$(abspath $(objtree)/$(obj)/test/libquote.rlib) \
> + --extern syn=$(abspath $(objtree)/$(obj)/test/libsyn.rlib)
> rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
> rusttest-macros: $(src)/macros/lib.rs \
> rusttestlib-macros rusttestlib-kernel rusttestlib-pin_init FORCE
> @@ -525,48 +536,54 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
>
> quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
> cmd_rustc_procmacrolibrary = \
> + mkdir -p $(dir $@); \
> $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
> $(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
> --emit=dep-info=$(depfile) --emit=link=$@ --crate-type rlib -O \
> - --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
> --crate-name $(patsubst lib%.rlib,%,$(notdir $@)) $<
>
> -$(obj)/libproc_macro2.rlib: private skip_clippy = 1
> -$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
> -$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
> +$(obj)/host/libproc_macro2.rlib: private skip_clippy = 1
> +$(obj)/host/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
> +$(obj)/host/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
> +$(call if_changed_dep,rustc_procmacrolibrary)
>
> -$(obj)/libquote.rlib: private skip_clippy = 1
> -$(obj)/libquote.rlib: private skip_flags = $(quote-skip_flags)
> -$(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
> -$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
> +$(obj)/host/libquote.rlib: private skip_clippy = 1
> +$(obj)/host/libquote.rlib: private skip_flags = $(quote-skip_flags)
> +$(obj)/host/libquote.rlib: private rustc_target_flags = $(quote-flags) \
> + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
> +$(obj)/host/libquote.rlib: $(src)/quote/lib.rs $(obj)/host/libproc_macro2.rlib FORCE
> +$(call if_changed_dep,rustc_procmacrolibrary)
>
> -$(obj)/libsyn.rlib: private skip_clippy = 1
> -$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
> -$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
> +$(obj)/host/libsyn.rlib: private skip_clippy = 1
> +$(obj)/host/libsyn.rlib: private rustc_target_flags = $(syn-flags) \
> + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
> + --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
> +$(obj)/host/libsyn.rlib: $(src)/syn/lib.rs $(obj)/host/libquote.rlib FORCE
> +$(call if_changed_dep,rustc_procmacrolibrary)
>
> quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
> cmd_rustc_procmacro = \
> - $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
> + $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
> -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
> --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
> - --crate-type proc-macro -L$(objtree)/$(obj) \
> + --crate-type proc-macro \
> + -L$(objtree)/$(obj)/host \
> --crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
> - @$(objtree)/include/generated/rustc_cfg $<
> + @$(objtree)/include/generated/rustc_cfg \
> + $(rustc_target_flags) \
> + $<
>
> # Procedural macros can only be used with the `rustc` that compiled it.
> $(obj)/$(libmacros_name): private rustc_target_flags = \
> --extern proc_macro2 --extern quote --extern syn
> -$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
> - $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
> +$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/host/libproc_macro2.rlib \
> + $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
> +$(call if_changed_dep,rustc_procmacro)
>
> $(obj)/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
> $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
> - $(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
> + $(obj)/host/libproc_macro2.rlib $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
> +$(call if_changed_dep,rustc_procmacro)
>
> # `rustc` requires `-Zunstable-options` to use custom target specifications
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error
2026-04-03 15:09 ` Gary Guo
@ 2026-04-04 3:39 ` Mukesh Kumar Chaurasiya
2026-04-04 20:28 ` Miguel Ojeda
0 siblings, 1 reply; 8+ messages in thread
From: Mukesh Kumar Chaurasiya @ 2026-04-04 3:39 UTC (permalink / raw)
To: Gary Guo
Cc: maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron, aliceryhl,
rostedt, ardb, ojeda, boqun, bjorn3_gh, lossin, a.hindborg,
tmgross, dakr, nathan, nick.desaulniers+lkml, morbo, justinstitt,
linuxppc-dev, linux-kernel, rust-for-linux, llvm
On Fri, Apr 03, 2026 at 04:09:04PM +0100, Gary Guo wrote:
> On Fri Apr 3, 2026 at 3:53 PM BST, Mukesh Kumar Chaurasiya (IBM) wrote:
> > When building Rust code with LLVM=1 with -j1, rustc was encountering
> > an error:
> > "multiple candidates for `rmeta` dependency `core` found", with two
> > candidates:
> > 1. The host's standard library from the rustup toolchain
> > 2. The kernel's custom libcore.rmeta in the rust/ directory
> >
> > This occurred because the build system was using `-L$(objtree)/rust`
> > for host library builds (proc_macro2, quote, syn), which caused rustc
> > to search the rust/ directory. During this search, rustc would find
> > both the kernel's custom libcore.rmeta and gain access to the host's
> > standard library, creating a conflict.
> >
> > The solution is to separate host libraries into a dedicated rust/host/
> > subdirectory and use `-L$(objtree)/rust/host` for host builds instead
> > of `-L$(objtree)/rust`. This ensures that:
> >
> > 1. Host library builds (proc_macro2, quote, syn) only search rust/host/
> > and never encounter the kernel's libcore.rmeta
> > 2. Proc macro builds use `-L$(objtree)/rust/host` to find their
> > dependencies
> > 3. Test builds use `-L$(objtree)/rust/test` for their dependencies
> > 4. Target builds continue to use `-L$(objtree)/rust` as before
> >
> > Special handling is added for rustdoc-pin_init, which is a host build
> > (to access the alloc crate) but depends on proc macros from the main
> > rust/ directory. It uses explicit `--extern` paths with absolute paths
> > to reference the proc macros without adding `-L$(objtree)/rust`, which
> > would reintroduce the conflict.
> >
> > The rust/host/ directory is added to clean-files to ensure it's removed
> > during `make clean`.
> >
> > Changes:
> > - Add clean-files := host/ to clean the generated directory
> > - Change host library targets from lib*.rlib to host/lib*.rlib
> > - Update cmd_rustc_procmacrolibrary to create host/ directory
> > - Update cmd_rustc_procmacro to use -L$(objtree)/rust/host
> > - Update cmd_rustdoc to use -L$(objtree)/rust/host for host builds
> > - Update cmd_rustc_test_library to use -L$(objtree)/rust/test
> > - Update rustdoc-pin_init to use explicit --extern paths for proc macros
>
> This should go after the tags and ---, so it's not part of the commit message.
>
Hey Gary,
I was intending that to be a part of commit message. May be specifying
that as changes is confusing. I'll put it there as a summary.
> >
> > Link: https://github.com/Rust-for-Linux/linux/issues/105
> > Link: https://github.com/linuxppc/issues/issues/451
> > Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> > ---
> > rust/Makefile | 63 ++++++++++++++++++++++++++++++++-------------------
> > 1 file changed, 40 insertions(+), 23 deletions(-)
> >
> > diff --git a/rust/Makefile b/rust/Makefile
> > index 9801af2e1e02..762bddc868e4 100644
> > --- a/rust/Makefile
> > +++ b/rust/Makefile
> > @@ -3,6 +3,9 @@
> > # Where to place rustdoc generated documentation
> > rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
> >
> > +# Clean generated host directory
> > +clean-files := host/
> > +
> > obj-$(CONFIG_RUST) += core.o compiler_builtins.o ffi.o
> > always-$(CONFIG_RUST) += exports_core_generated.h
> >
> > @@ -27,7 +30,7 @@ endif
> >
> > obj-$(CONFIG_RUST) += exports.o
> >
> > -always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib
> > +always-$(CONFIG_RUST) += host/libproc_macro2.rlib host/libquote.rlib host/libsyn.rlib
> >
> > always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
> > always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated_kunit.c
> > @@ -150,7 +153,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
> > OBJTREE=$(abspath $(objtree)) \
> > $(RUSTDOC) $(filter-out $(skip_flags) --remap-path-prefix=% --remap-path-scope=%, \
> > $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
> > - $(rustc_target_flags) -L$(objtree)/$(obj) \
> > + $(rustc_target_flags) -L$(objtree)/$(obj)$(if $(rustdoc_host),/host) \
> > -Zunstable-options --generate-link-to-definition \
> > --output $(rustdoc_output) \
> > --crate-name $(subst rustdoc-,,$@) \
> > @@ -193,13 +196,16 @@ rustdoc-proc_macro2: $(src)/proc-macro2/lib.rs rustdoc-clean FORCE
> > +$(call if_changed,rustdoc)
> >
> > rustdoc-quote: private rustdoc_host = yes
> > -rustdoc-quote: private rustc_target_flags = $(quote-flags)
> > +rustdoc-quote: private rustc_target_flags = $(quote-flags) \
> > + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
>
> Why not just add `-L$(objtree)/$(obj)/host`? If we go with the host directory
> approach we shouldn't need to explicitly specify the path?
>
> Best,
> Gary
>
Yeah makes sense. Will send out new revision.
Regards,
Mukesh
> > rustdoc-quote: private skip_flags = $(quote-skip_flags)
> > rustdoc-quote: $(src)/quote/lib.rs rustdoc-clean rustdoc-proc_macro2 FORCE
> > +$(call if_changed,rustdoc)
> >
> > rustdoc-syn: private rustdoc_host = yes
> > -rustdoc-syn: private rustc_target_flags = $(syn-flags)
> > +rustdoc-syn: private rustc_target_flags = $(syn-flags) \
> > + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
> > + --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
> > rustdoc-syn: $(src)/syn/lib.rs rustdoc-clean rustdoc-quote FORCE
> > +$(call if_changed,rustdoc)
> >
> > @@ -236,7 +242,10 @@ rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs \
> > +$(call if_changed,rustdoc)
> >
> > rustdoc-pin_init: private rustdoc_host = yes
> > -rustdoc-pin_init: private rustc_target_flags = $(pin_init-flags) \
> > +rustdoc-pin_init: private rustc_target_flags = \
> > + --extern pin_init_internal=$(abspath $(objtree)/$(obj)/$(libpin_init_internal_name)) \
> > + --extern macros=$(abspath $(objtree)/$(obj)/$(libmacros_name)) \
> > + $(call cfgs-to-flags,$(pin_init-cfgs)) \
> > --extern alloc --cfg feature=\"alloc\"
> > rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
> > rustdoc-macros FORCE
> > @@ -369,7 +378,9 @@ rusttest: rusttest-macros
> >
> > rusttest-macros: private rustc_target_flags = --extern proc_macro \
> > --extern macros --extern kernel --extern pin_init \
> > - --extern proc_macro2 --extern quote --extern syn
> > + --extern proc_macro2=$(abspath $(objtree)/$(obj)/test/libproc_macro2.rlib) \
> > + --extern quote=$(abspath $(objtree)/$(obj)/test/libquote.rlib) \
> > + --extern syn=$(abspath $(objtree)/$(obj)/test/libsyn.rlib)
> > rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
> > rusttest-macros: $(src)/macros/lib.rs \
> > rusttestlib-macros rusttestlib-kernel rusttestlib-pin_init FORCE
> > @@ -525,48 +536,54 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
> >
> > quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
> > cmd_rustc_procmacrolibrary = \
> > + mkdir -p $(dir $@); \
> > $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
> > $(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
> > --emit=dep-info=$(depfile) --emit=link=$@ --crate-type rlib -O \
> > - --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
> > --crate-name $(patsubst lib%.rlib,%,$(notdir $@)) $<
> >
> > -$(obj)/libproc_macro2.rlib: private skip_clippy = 1
> > -$(obj)/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
> > -$(obj)/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
> > +$(obj)/host/libproc_macro2.rlib: private skip_clippy = 1
> > +$(obj)/host/libproc_macro2.rlib: private rustc_target_flags = $(proc_macro2-flags)
> > +$(obj)/host/libproc_macro2.rlib: $(src)/proc-macro2/lib.rs FORCE
> > +$(call if_changed_dep,rustc_procmacrolibrary)
> >
> > -$(obj)/libquote.rlib: private skip_clippy = 1
> > -$(obj)/libquote.rlib: private skip_flags = $(quote-skip_flags)
> > -$(obj)/libquote.rlib: private rustc_target_flags = $(quote-flags)
> > -$(obj)/libquote.rlib: $(src)/quote/lib.rs $(obj)/libproc_macro2.rlib FORCE
> > +$(obj)/host/libquote.rlib: private skip_clippy = 1
> > +$(obj)/host/libquote.rlib: private skip_flags = $(quote-skip_flags)
> > +$(obj)/host/libquote.rlib: private rustc_target_flags = $(quote-flags) \
> > + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib)
> > +$(obj)/host/libquote.rlib: $(src)/quote/lib.rs $(obj)/host/libproc_macro2.rlib FORCE
> > +$(call if_changed_dep,rustc_procmacrolibrary)
> >
> > -$(obj)/libsyn.rlib: private skip_clippy = 1
> > -$(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
> > -$(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
> > +$(obj)/host/libsyn.rlib: private skip_clippy = 1
> > +$(obj)/host/libsyn.rlib: private rustc_target_flags = $(syn-flags) \
> > + --extern proc_macro2=$(abspath $(objtree)/$(obj)/host/libproc_macro2.rlib) \
> > + --extern quote=$(abspath $(objtree)/$(obj)/host/libquote.rlib)
> > +$(obj)/host/libsyn.rlib: $(src)/syn/lib.rs $(obj)/host/libquote.rlib FORCE
> > +$(call if_changed_dep,rustc_procmacrolibrary)
> >
> > quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
> > cmd_rustc_procmacro = \
> > - $(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
> > + $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
> > -Clinker-flavor=gcc -Clinker=$(HOSTCC) \
> > -Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
> > --emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
> > - --crate-type proc-macro -L$(objtree)/$(obj) \
> > + --crate-type proc-macro \
> > + -L$(objtree)/$(obj)/host \
> > --crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
> > - @$(objtree)/include/generated/rustc_cfg $<
> > + @$(objtree)/include/generated/rustc_cfg \
> > + $(rustc_target_flags) \
> > + $<
> >
> > # Procedural macros can only be used with the `rustc` that compiled it.
> > $(obj)/$(libmacros_name): private rustc_target_flags = \
> > --extern proc_macro2 --extern quote --extern syn
> > -$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/libproc_macro2.rlib \
> > - $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
> > +$(obj)/$(libmacros_name): $(src)/macros/lib.rs $(obj)/host/libproc_macro2.rlib \
> > + $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
> > +$(call if_changed_dep,rustc_procmacro)
> >
> > $(obj)/$(libpin_init_internal_name): private rustc_target_flags = $(pin_init_internal-flags)
> > $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
> > - $(obj)/libproc_macro2.rlib $(obj)/libquote.rlib $(obj)/libsyn.rlib FORCE
> > + $(obj)/host/libproc_macro2.rlib $(obj)/host/libquote.rlib $(obj)/host/libsyn.rlib FORCE
> > +$(call if_changed_dep,rustc_procmacro)
> >
> > # `rustc` requires `-Zunstable-options` to use custom target specifications
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error
2026-04-04 3:39 ` Mukesh Kumar Chaurasiya
@ 2026-04-04 20:28 ` Miguel Ojeda
0 siblings, 0 replies; 8+ messages in thread
From: Miguel Ojeda @ 2026-04-04 20:28 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya
Cc: Gary Guo, maddy, mpe, npiggin, chleroy, peterz, jpoimboe, jbaron,
aliceryhl, rostedt, ardb, ojeda, boqun, bjorn3_gh, lossin,
a.hindborg, tmgross, dakr, nathan, nick.desaulniers+lkml, morbo,
justinstitt, linuxppc-dev, linux-kernel, rust-for-linux, llvm
On Sat, Apr 4, 2026 at 5:39 AM Mukesh Kumar Chaurasiya
<mkchauras@gmail.com> wrote:
>
> Yeah makes sense. Will send out new revision.
In addition to what Gary said, I am not sure if you will need to use
`abspath` anymore in the new one, but in any case, if you do, please
clarify if/why it wouldn't work without an absolute one.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-04 20:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 14:53 [PATCH V8 0/4] Rust support for powerpc Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 1/4] rust: Fix "multiple candidates for rmeta dependency core" error Mukesh Kumar Chaurasiya (IBM)
2026-04-03 15:09 ` Gary Guo
2026-04-04 3:39 ` Mukesh Kumar Chaurasiya
2026-04-04 20:28 ` Miguel Ojeda
2026-04-03 14:53 ` [PATCH V8 2/4] powerpc/jump_label: adjust inline asm to be consistent Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 3/4] rust: Add PowerPC support Mukesh Kumar Chaurasiya (IBM)
2026-04-03 14:53 ` [PATCH V8 4/4] powerpc: Enable Rust for ppc64le Mukesh Kumar Chaurasiya (IBM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox