Re: [PATCH] kbuild: rust: disable function merging unconditionally
From: Nick Desaulniers
Date: Wed Nov 18 2026 - 13:49:05 EST
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?
> * 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
> 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>
> ---
> Makefile | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 5aac6f1b011e..17b7ac3afbc4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -622,6 +622,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \
> -Csymbol-mangling-version=v0 \
> -Crelocation-model=static \
> -Zfunction-sections=n \
> + -Zmerge-functions=disabled \
> -Wclippy::float_arithmetic
> KBUILD_RUSTFLAGS_OPTION_CHKS :=
>
> @@ -1136,8 +1137,7 @@ endif
> ifdef CONFIG_RUST
> # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
> # CONFIG_CFI_ICALL_NORMALIZE_INTEGERS.
> - # Disable function merging as LLVM incorrectly merges functions with different KCFI types.
> - RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zmerge-functions=disabled
> + RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
> KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI)
> export RUSTC_FLAGS_CFI
> endif
>
> ---
> base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
> change-id: 20261117-rust-merge-functions-9ccbc0516df5
>
> Best regards,
> --
> Alice Ryhl <aliceryhl@xxxxxxxxxx>
>
--
Thanks,
~Nick Desaulniers