diff options
| author | Alice Ryhl <aliceryhl@google.com> | 2026-11-18 13:09:18 +0000 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2026-11-19 11:28:42 +0100 |
| commit | 73bdf8773de4af2c2b7f49370191ae6d5aeddea5 (patch) | |
| tree | 97646a60fddce9ddb2e07a7cd90368263090a7b4 /kernel/cpu | |
| parent | cf2212fd3053857f800cc22d903118d522131ca8 (diff) | |
kbuild: rust: disable function merging unconditionally
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.
[ 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 ]
Link: https://lore.kernel.org/all/avy_9SPRaPSKD8b4@google.com/
Fixes: ac61506bf2d1 ("rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS")
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Cc: stable@vger.kernel.org
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Link: https://github.com/llvm/llvm-project/issues/217629 [1]
Link: https://lore.kernel.org/rust-for-linux/CAH5fLgidhnPbP=xXQ3162w6q0U6rWHPZ9Mu6-E5va4_CXyanOg@mail.gmail.com/ [2]
Link: https://patch.msgid.link/20261118-rust-merge-functions-v1-1-fe86126522b9@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'kernel/cpu')
0 files changed, 0 insertions, 0 deletions
