Cross-language LTO is broken for riscv64 lp64d #121924
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
A-LTO
Area: Link-time optimization (LTO)
C-bug
Category: This is a bug.
O-riscv
Target: RISC-V architecture
S-has-mcve
Status: A Minimal Complete and Verifiable Example has been found for this issue
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Cross-language LTO is broken for riscv64 lp64d (e.g. riscv64gc-unknown-linux-gnu).
I tried this code:
A minimal reproduction is available at https://github.com/kxxt/riscv-rust-cross-language-lto-reproducer
I expected to see this happen: code compiles and links successfully
Instead, this happened:
ld.lld: error: lto.tmp: cannot link object files with different floating-point ABI from /usr/riscv64-linux-gnu/usr/lib/Scrt1.o
This is because the lack of
target-abi
inllvm.module.flags
makes lld think that the rust generated bitcode is a soft float object file, contrary to the fact thatriscv64gc-unknown-linux-gnu
islp64d
.Relevant discussions:
I think rustc should encode the target-abi into LLVM bitcode as clang already does.
The real world use case for this feature is cross-compiling electron/chromium for riscv64. I attempted to fix this problem by myself but due to my unfamiliarity with llvm and the rustc code base, I only came up with this workaround: embed riscv64 target abi in bc when plugin-lto is used · kxxt/rust@a599284 · GitHub . A rust toolchain including that commit can be found at https://github.com/riscv-forks/electron/releases/tag/rustc-cd6d8f2a04528f827ad3d399581c0f3502b15a72-1-llvmorg-18-init-17730-gf670112a . I believe someone from rust team could fix this problem in a better way than my patch.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: