Use of RiscV "+forced-atomics" target feature triggers hard-float ABI for symbols.o #114153
Closed
Description
opened on Jul 28, 2023
When building for RiscV-32, adding the "+forced-atomics" target feature (in this case, adding it to a custom target .json file) causes the symbols.o file to be built with the single-float ABI rather than the soft-float ABI used for the all .rcgu.o files, which causes the link to fail due to incompatible float ABIs.
It appears to be due to this code in compiler/rustc_codegen_ssa/src/back/metadata.rs:
Architecture::Riscv32 | Architecture::Riscv64 => {
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
let mut e_flags: u32 = 0x0;
let features = &sess.target.options.features;
// Check if compressed is enabled
if features.contains("+c") {
e_flags |= elf::EF_RISCV_RVC;
}
// Select the appropriate floating-point ABI
if features.contains("+d") {
e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE;
} else if features.contains("+f") {
e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE;
} else {
e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT;
}
e_flags
}
which assumes that any feature beginning with "+f" is in fact exactly "+f", so the addition of "+forced-atomics" triggers the single-float ABI.
Should this check (and most other feature checks) actually be something like: features.split(",").any(|f| f == "+f")
(probably useful as a TargetOptions::has_feature() helper method)?
Activity