Re: [PATCH] kbuild: rust: disable function merging unconditionally
From: Miguel Ojeda
Date: Thu Nov 19 2026 - 05:36:11 EST
On Wed, Nov 18, 2026 at 2:09 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> Function merging causes various different issues:
>
> * For CONFIG_CFI there's an LLVM bug causing functions with different
> CFI hashes to get merged. This can lead to crashes at runtime.
> * For gendwarfksyms it causes functions with different CRCs to get
> merged. This leads to broken MODVERSIONS information if the function
> changes in the future so that it can no longer be merged.
> * Wrong backtraces when a crash occurs in a merged function.
> * Possibly also issues with pahole/BTF as the merged function's debug
> info is lost.
>
> These issues are new to Rust because in clang, function merging is off
> by default, so these things have never come up before. Because of this,
> turn this option off for all configurations.
>
> Link: https://lore.kernel.org/all/avy_9SPRaPSKD8b4@xxxxxxxxxx/
> Fixes: ac61506bf2d1 ("rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS")
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Applied to `rust-fixes` -- thanks everyone!
I also added Cc: stable@
[ The LLVM bug is tracked at [1]. Nick asked what function merging
refers to here, and Alice writes [2]:
No, this isn't linker ICF. rustc doesn't pass --icf, and in any case
kbuild invokes rustc with --emit=obj and does the final link itself, so
rustc's linker arguments never come into play.
What I'm referring to is LLVM's MergeFunctions IR pass
(llvm/lib/Transforms/IPO/MergeFunctions.cpp). It runs as part of the
optimization pipeline, within a single codegen unit, before any object
file is emitted. Clang only enables it with the cc1-only flag
-fmerge-functions, which the kernel never passes, so C code in the
kernel never sees it.
rustc, however, enables it by default whenever optimizing for speed or
size (opt-level 2, 3, s or z), which covers both kernel configurations.
It uses the "aliases" mode: when two functions have identical bodies,
one is deleted and its symbol becomes a GlobalAlias to the other. You
can turn it off with -Zmerge-functions=disabled.
- Miguel ]
Cheers,
Miguel