Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c344a1c

Browse files
authoredOct 22, 2024··
Unrolled build for rust-lang#131807
Rollup merge of rust-lang#131807 - beetrees:riscv-target-abi, r=workingjubilee Always specify `llvm_abiname` for RISC-V targets For RISC-V targets, when `llvm_abiname` is not specified LLVM will infer the ABI from the target features, causing rust-lang#116344 to occur. This PR adds the correct `llvm_abiname` to all RISC-V targets where it is missing (which are all soft-float targets), and adds a test to prevent future RISC-V targets from accidentally omitting `llvm_abiname`. The only affect of this PR is that `-Ctarget-feature=+f` (or similar) will no longer affect the ABI on the modified targets. <!-- homu-ignore:start --> r? `@RalfJung` <!--- homu-ignore:end -->
2 parents 1de57a5 + 3ea91c0 commit c344a1c

16 files changed

+71
-1
lines changed
 

‎compiler/rustc_target/src/spec/targets/riscv32i_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn target() -> Target {
2020
max_atomic_width: Some(32),
2121
atomic_cas: false,
2222
features: "+forced-atomics".into(),
23+
llvm_abiname: "ilp32".into(),
2324
panic_strategy: PanicStrategy::Abort,
2425
relocation_model: RelocModel::Static,
2526
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32im_risc0_zkvm_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub(crate) fn target() -> Target {
2929
atomic_cas: true,
3030

3131
features: "+m".into(),
32+
llvm_abiname: "ilp32".into(),
3233
executables: true,
3334
panic_strategy: PanicStrategy::Abort,
3435
relocation_model: RelocModel::Static,

‎compiler/rustc_target/src/spec/targets/riscv32im_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn target() -> Target {
2020
max_atomic_width: Some(32),
2121
atomic_cas: false,
2222
features: "+m,+forced-atomics".into(),
23+
llvm_abiname: "ilp32".into(),
2324
panic_strategy: PanicStrategy::Abort,
2425
relocation_model: RelocModel::Static,
2526
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32ima_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) fn target() -> Target {
1919
cpu: "generic-rv32".into(),
2020
max_atomic_width: Some(32),
2121
features: "+m,+a".into(),
22+
llvm_abiname: "ilp32".into(),
2223
panic_strategy: PanicStrategy::Abort,
2324
relocation_model: RelocModel::Static,
2425
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32imac_esp_espidf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn target() -> Target {
2727
atomic_cas: true,
2828

2929
features: "+m,+a,+c".into(),
30+
llvm_abiname: "ilp32".into(),
3031
panic_strategy: PanicStrategy::Abort,
3132
relocation_model: RelocModel::Static,
3233
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32imac_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) fn target() -> Target {
1919
cpu: "generic-rv32".into(),
2020
max_atomic_width: Some(32),
2121
features: "+m,+a,+c".into(),
22+
llvm_abiname: "ilp32".into(),
2223
panic_strategy: PanicStrategy::Abort,
2324
relocation_model: RelocModel::Static,
2425
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32imac_unknown_nuttx_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) fn target() -> Target {
2121
cpu: "generic-rv32".into(),
2222
max_atomic_width: Some(32),
2323
features: "+m,+a,+c".into(),
24+
llvm_abiname: "ilp32".into(),
2425
panic_strategy: PanicStrategy::Unwind,
2526
relocation_model: RelocModel::Static,
2627
..Default::default()

‎compiler/rustc_target/src/spec/targets/riscv32imac_unknown_xous_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn target() -> Target {
2020
cpu: "generic-rv32".into(),
2121
max_atomic_width: Some(32),
2222
features: "+m,+a,+c".into(),
23+
llvm_abiname: "ilp32".into(),
2324
panic_strategy: PanicStrategy::Unwind,
2425
relocation_model: RelocModel::Static,
2526
..Default::default()

‎compiler/rustc_target/src/spec/targets/riscv32imc_esp_espidf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn target() -> Target {
3030
atomic_cas: true,
3131

3232
features: "+m,+c".into(),
33+
llvm_abiname: "ilp32".into(),
3334
panic_strategy: PanicStrategy::Abort,
3435
relocation_model: RelocModel::Static,
3536
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32imc_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn target() -> Target {
2020
max_atomic_width: Some(32),
2121
atomic_cas: false,
2222
features: "+m,+c,+forced-atomics".into(),
23+
llvm_abiname: "ilp32".into(),
2324
panic_strategy: PanicStrategy::Abort,
2425
relocation_model: RelocModel::Static,
2526
emit_debug_gdb_scripts: false,

‎compiler/rustc_target/src/spec/targets/riscv32imc_unknown_nuttx_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) fn target() -> Target {
2121
cpu: "generic-rv32".into(),
2222
max_atomic_width: Some(32),
2323
features: "+m,+c".into(),
24+
llvm_abiname: "ilp32".into(),
2425
panic_strategy: PanicStrategy::Unwind,
2526
relocation_model: RelocModel::Static,
2627
..Default::default()

‎compiler/rustc_target/src/spec/targets/riscv64imac_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub(crate) fn target() -> Target {
2222
cpu: "generic-rv64".into(),
2323
max_atomic_width: Some(64),
2424
features: "+m,+a,+c".into(),
25+
llvm_abiname: "lp64".into(),
2526
panic_strategy: PanicStrategy::Abort,
2627
relocation_model: RelocModel::Static,
2728
code_model: Some(CodeModel::Medium),

‎compiler/rustc_target/src/spec/targets/riscv64imac_unknown_nuttx_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
cpu: "generic-rv64".into(),
2525
max_atomic_width: Some(64),
2626
features: "+m,+a,+c".into(),
27+
llvm_abiname: "lp64".into(),
2728
panic_strategy: PanicStrategy::Abort,
2829
relocation_model: RelocModel::Static,
2930
code_model: Some(CodeModel::Medium),

‎compiler/rustc_target/src/spec/tests/tests_impl.rs

+11
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ impl Target {
152152
if self.crt_static_default || self.crt_static_allows_dylibs {
153153
assert!(self.crt_static_respected);
154154
}
155+
156+
// Check that RISC-V targets always specify which ABI they use.
157+
match &*self.arch {
158+
"riscv32" => {
159+
assert_matches!(&*self.llvm_abiname, "ilp32" | "ilp32f" | "ilp32d" | "ilp32e")
160+
}
161+
"riscv64" => {
162+
assert_matches!(&*self.llvm_abiname, "lp64" | "lp64f" | "lp64d" | "lp64q")
163+
}
164+
_ => {}
165+
}
155166
}
156167

157168
// Add your target to the whitelist if it has `std` library
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target riscv64imac-unknown-none-elf -Ctarget-feature=+f,+d
3+
//@ needs-llvm-components: riscv
4+
5+
#![feature(no_core, lang_items, f16)]
6+
#![crate_type = "lib"]
7+
#![no_core]
8+
9+
#[lang = "sized"]
10+
trait Sized {}
11+
12+
#[lang = "copy"]
13+
trait Copy {}
14+
15+
impl Copy for f16 {}
16+
impl Copy for f32 {}
17+
impl Copy for f64 {}
18+
19+
// This test checks that the floats are all returned in `a0` as required by the `lp64` ABI.
20+
21+
// CHECK-LABEL: read_f16
22+
#[no_mangle]
23+
pub extern "C" fn read_f16(x: &f16) -> f16 {
24+
// CHECK: lh a0, 0(a0)
25+
// CHECK-NEXT: lui a1, 1048560
26+
// CHECK-NEXT: or a0, a0, a1
27+
// CHECK-NEXT: ret
28+
*x
29+
}
30+
31+
// CHECK-LABEL: read_f32
32+
#[no_mangle]
33+
pub extern "C" fn read_f32(x: &f32) -> f32 {
34+
// CHECK: flw fa5, 0(a0)
35+
// CHECK-NEXT: fmv.x.w a0, fa5
36+
// CHECK-NEXT: ret
37+
*x
38+
}
39+
40+
// CHECK-LABEL: read_f64
41+
#[no_mangle]
42+
pub extern "C" fn read_f64(x: &f64) -> f64 {
43+
// CHECK: ld a0, 0(a0)
44+
// CHECK-NEXT: ret
45+
*x
46+
}

‎tests/codegen/riscv-target-abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//@[riscv32imac] compile-flags: --target=riscv32imac-unknown-none-elf
1212
//@[riscv32imac] needs-llvm-components: riscv
13-
// riscv32imac-NOT: !"target-abi"
13+
// riscv32imac: !{i32 1, !"target-abi", !"ilp32"}
1414

1515
#![feature(no_core, lang_items)]
1616
#![crate_type = "lib"]

0 commit comments

Comments
 (0)
Please sign in to comment.