rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.02k stars 12.68k forks source link

Allow building for hard-float targets in RISC-V #65024

Closed archshift closed 2 years ago

archshift commented 5 years ago

Currently Rust does not support compiling/linking with LLVM's -target-abi=lp64d option, which enables the hard-float ABI in riscv64.

This feature is necessary for Rust interop with C code on hard-float targets.

songdongsheng commented 5 years ago

+1 for general-purpose binary Linux distributions has been agreed use lp64d as the Hardware baseline and ABI choice.

https://wiki.debian.org/RISC-V#Hardware_baseline_and_ABI_choice

archshift commented 4 years ago

Now that #65953 is in, we can add new target specifications to close this issue.

We might want to add a d or f after the 32 or 64 in the target triple, like so:

The alternative is to append hf to the end of the triple, although the fact that not every RV distribution has hard doubles might complicate this. But we might assume that any target has float widths corresponding to the pointer width.

That way, we can specify:

Or even:

lenary commented 4 years ago

It is very unlikely that rustc is doing the correct ABI lowering of calls etc for the C psABI, especially when hard-floats are considered. Just switching on ilp32d/ilp32f/lp64d/lp64f will not be enough.

It has been on my list for a while to check the ABI lowering in rustc so that it matches the psABI, which will potentially require backwards-incompatible changes. I hope to get to this soon (there's other RISC-V LLVM work on my plate first).

lenary commented 4 years ago

Rustc should now be doing the correct ABI lowering of calls in the C psABI, including hard-float support (since #68452).

A target spec for rv64gc + lp64d (targetting linux) has been added in the form of riscv64gc-unknown-linux-gnu which should be exactly what's needed for linux platform support.

archshift commented 4 years ago

I suppose this can be closed now?

sanxiyn commented 2 years ago

riscv64gc-unknown-linux-gnu target is hard-float with lp64d ABI. Closing.