Skip to content

Commit a8a92f5

Browse files
committed
Fix ABI flags in RISC-V/LoongArch ELF file generated by rustc
1 parent 0f7f6b7 commit a8a92f5

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_metadata::fs::METADATA_FILENAME;
1616
use rustc_metadata::EncodedMetadata;
1717
use rustc_session::cstore::MetadataLoader;
1818
use rustc_session::Session;
19+
use rustc_span::sym;
1920
use rustc_target::abi::Endian;
2021
use rustc_target::spec::{ef_avr_arch, RelocModel, Target};
2122

@@ -272,35 +273,37 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
272273
Architecture::Riscv32 | Architecture::Riscv64 => {
273274
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
274275
let mut e_flags: u32 = 0x0;
275-
let features = &sess.target.options.features;
276+
276277
// Check if compressed is enabled
277-
if features.contains("+c") {
278+
if sess.unstable_target_features.contains(&sym::c) {
278279
e_flags |= elf::EF_RISCV_RVC;
279280
}
280281

281-
// Select the appropriate floating-point ABI
282-
if features.contains("+d") {
283-
e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE;
284-
} else if features.contains("+f") {
285-
e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE;
286-
} else {
287-
e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT;
282+
// Set the appropriate flag based on ABI
283+
// This needs to match LLVM `RISCVELFStreamer.cpp`
284+
match &*sess.target.llvm_abiname {
285+
"ilp32" | "lp64" => (),
286+
"ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
287+
"ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
288+
"ilp32e" => e_flags |= elf::EF_RISCV_RVE,
289+
_ => bug!("unknown RISC-V ABI name"),
288290
}
291+
289292
e_flags
290293
}
291294
Architecture::LoongArch64 => {
292295
// Source: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#e_flags-identifies-abi-type-and-version
293296
let mut e_flags: u32 = elf::EF_LARCH_OBJABI_V1;
294-
let features = &sess.target.options.features;
295297

296-
// Select the appropriate floating-point ABI
297-
if features.contains("+d") {
298-
e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT;
299-
} else if features.contains("+f") {
300-
e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT;
301-
} else {
302-
e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT;
298+
// Set the appropriate flag based on ABI
299+
// This needs to match LLVM `LoongArchELFStreamer.cpp`
300+
match &*sess.target.llvm_abiname {
301+
"ilp32s" | "lp64s" => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT,
302+
"ilp32f" | "lp64f" => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT,
303+
"ilp32d" | "lp64d" => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT,
304+
_ => bug!("unknown RISC-V ABI name"),
303305
}
306+
304307
e_flags
305308
}
306309
Architecture::Avr => {

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ symbols! {
445445
bridge,
446446
bswap,
447447
builtin_syntax,
448+
c,
448449
c_str,
449450
c_str_literals,
450451
c_unwind,

0 commit comments

Comments
 (0)