[PATCH v2] x86/rust: avoid duplication of RETPOLINE_RUSTFLAGS in recursive kbuild

From: Thomas Weißschuh

Date: Tue Dec 01 2026 - 16:38:04 EST


Currently the initial modificiation of REPTOLINE_RUSTFLAGS is an append.
There is no initial (re)set of the value.

When kbuild is invoked recursively, for example through a top-level
`make pacman-pkg` invocation, then the inner instance of kbuild will
inherit the value from the outer one and append the same values again.

Switching between recursive and non-recursive invocations of kbuild in
the same build tree changes the Rust compilation command line and Rust
code is rebuilt. While this is harmless, it is slow and unnecessary.

Replace the initial append operation with a regular assignment. This
avoids the duplicated values in a recursive kbuild invocation and
therefore also the spurious rebuilds.

RETPOLINE_CFLAGS is not affected as it is always reset to a fixed value
further up in the Makefile.

Fixes: d7868550d573 ("x86/rust: support MITIGATION_RETHUNK")
Fixes: 1eaa31fa4112 ("x86/rust: use `-Zindirect-branch-cs-prefix` for RETPOLINE builds")
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
Changes in v2:
- Rebase on rust/rust-next.
- Adapt to 1eaa31fa4112 ("x86/rust: use `-Zindirect-branch-cs-prefix` for RETPOLINE builds")
- Link to v1: https://patch.msgid.link/20261013-rust-x86-rethunk-rebuilds-v1-1-d2042a72640b@xxxxxxxxxxxxxx
---
This is the only instance of this problem in my kernel configuration.
---
arch/x86/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 83b07961b850..873ad2f79b93 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -21,7 +21,7 @@ RETPOLINE_CFLAGS := -mretpoline-external-thunk
RETPOLINE_VDSO_CFLAGS := -mretpoline
endif
RETPOLINE_CFLAGS += $(CONFIG_CC_OPT_INDIRECT_BRANCH_CS_PREFIX)
-RETPOLINE_RUSTFLAGS += $(if $(call rustc-min-version,109100),-Zindirect-branch-cs-prefix,-Zllvm_module_flag=indirect_branch_cs_prefix:u32:1:override)
+RETPOLINE_RUSTFLAGS := $(if $(call rustc-min-version,109100),-Zindirect-branch-cs-prefix,-Zllvm_module_flag=indirect_branch_cs_prefix:u32:1:override)

ifdef CONFIG_MITIGATION_RETHUNK
RETHUNK_CFLAGS := -mfunction-return=thunk-extern

---
base-commit: 82d8023ec40420ed61d7a96a173ef862741f1753
change-id: 20261013-rust-x86-rethunk-rebuilds-82c0109356d2

Best regards,
--
Thomas Weißschuh <linux@xxxxxxxxxxxxxx>