Re: [PATCH] kbuild: rust: disable function merging unconditionally
From: Alice Ryhl
Date: Wed Nov 18 2026 - 15:12:05 EST
On Wed, Nov 18, 2026 at 7:48 PM Nick Desaulniers
<ndesaulniers@xxxxxxxxxx> wrote:
>
> On Wed, Nov 18, 2026 at 5:09 AM 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.
>
> Do you have a link to a bug filed against llvm?
https://github.com/llvm/llvm-project/issues/217629
> > * 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,
>
> I've never heard of function merging (in clang). I've heard of
> -Wl,--icf={none,safe,all), a linker flag. Is rustc setting that by
> default, implicitly?
> https://github.com/ClangBuiltLinux/linux/issues/1598
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.
Alice