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

From: Miguel Ojeda

Date: Thu Dec 03 2026 - 05:52:55 EST


On Tue, Dec 1, 2026 at 10:38 PM Thomas Weißschuh <linux@xxxxxxxxxxxxxx> wrote:
>
> 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>

Applied to `rust-fixes` -- thanks everyone!

[ Since commit 1eaa31fa4112 ("x86/rust: use `-Zindirect-branch-cs-prefix`
for RETPOLINE builds"), this is not harmless anymore: for Rust < 1.91.0,
the duplicated flag is `-Zllvm_module_flag`, which breaks recursive
builds with `CONFIG_RUST_INLINE_HELPERS=y`.

For reference, the error looks like:

module flag identifiers must be unique (or of 'require' type)
!"indirect_branch_cs_prefix"
llvm-link: error: linked module is broken!
make[2]: *** [rust/Makefile:806: rust/kernel.o] Error 1

- Miguel ]

[ Reworded for typos. - Miguel ]

(I reworded for typos because one was in the identifier name; though a
Git grep would have found the other one).

Cheers,
Miguel