Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-language LTO is broken for riscv64 lp64d #121924

Closed
kxxt opened this issue Mar 3, 2024 · 0 comments · Fixed by #123612
Closed

Cross-language LTO is broken for riscv64 lp64d #121924

kxxt opened this issue Mar 3, 2024 · 0 comments · Fixed by #123612
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.

Comments

@kxxt
Copy link
Contributor

kxxt commented Mar 3, 2024

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

make

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 in llvm.module.flags makes lld think that the rust generated bitcode is a soft float object file, contrary to the fact that riscv64gc-unknown-linux-gnu is lp64d.

$ llvm-dis main.o
$ grep target-abi main.o.ll
!1 = !{i32 1, !"target-abi", !"lp64d"}
$ ar x libreproducer.rlib
$ llvm-dis reproducer.reproducer.*.rcgu.o
$ grep target-abi reproducer.reproducer.*.rcgu.o.ll
(no output)

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:

rustc 1.78.0-nightly (878c8a2a6 2024-02-29)
binary: rustc
commit-hash: 878c8a2a62d49ca5c454547ad67290a1df746cb5
commit-date: 2024-02-29
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
@kxxt kxxt added the C-bug Category: This is a bug. label Mar 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-riscv Target: RISC-V architecture A-LTO Area: Link-time optimization (LTO) labels Mar 3, 2024
@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 14, 2024
kxxt added a commit to kxxt/rust that referenced this issue Apr 8, 2024
Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
@jieyouxu jieyouxu added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Apr 8, 2024
kxxt added a commit to kxxt/rust that referenced this issue Apr 8, 2024
Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
kxxt added a commit to kxxt/rust that referenced this issue Apr 8, 2024
Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
kxxt added a commit to kxxt/rust that referenced this issue Apr 8, 2024
Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 10, 2024
…nikic,DianQK

Set target-abi module flag for RISC-V targets

Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
@bors bors closed this as completed in f19c48e Apr 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 10, 2024
Rollup merge of rust-lang#123612 - kxxt:riscv-target-abi, r=jieyouxu,nikic,DianQK

Set target-abi module flag for RISC-V targets

Fixes cross-language LTO on RISC-V targets (Fixes rust-lang#121924)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants