Skip to content

Commit ac7f423

Browse files
Rollup merge of #145840 - a4lg:riscv-elf-flags-for-internal-objs, r=WaffleLapkin
rustc_codegen_ssa: More comprehensive RISC-V ELF flags This change implements more conformant, more comprehensive RISC-V ELF flags handling when generating certain object files directly from rustc. * Use `"zca"` instead of `"c"` The "Zca" extension (a subset of "C") is the minimal configuration for compressed instructions to set `EF_RISCV_RVC` flag. * Set TSO flag from `"ztso"` The "Ztso" extension denotes that the program depends on the RVTSO (Total Store Ordering) memory consistency model, which is stronger than the standard RVWMO (Weak Memory Ordering) consistency model and on ELF targets, we need to set `EF_RISCV_TSO` flag.
2 parents fbf247d + cb8c905 commit ac7f423

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,18 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
329329
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
330330
let mut e_flags: u32 = 0x0;
331331

332-
// Check if compressed is enabled
333-
// `unstable_target_features` is used here because "c" is gated behind riscv_target_feature.
334-
if sess.unstable_target_features.contains(&sym::c) {
332+
// Check if compression is enabled
333+
// `unstable_target_features` is used here because "zca" is gated behind riscv_target_feature.
334+
if sess.unstable_target_features.contains(&sym::zca) {
335335
e_flags |= elf::EF_RISCV_RVC;
336336
}
337337

338+
// Check if RVTSO is enabled
339+
// `unstable_target_features` is used here because "ztso" is gated behind riscv_target_feature.
340+
if sess.unstable_target_features.contains(&sym::ztso) {
341+
e_flags |= elf::EF_RISCV_TSO;
342+
}
343+
338344
// Set the appropriate flag based on ABI
339345
// This needs to match LLVM `RISCVELFStreamer.cpp`
340346
match &*sess.target.llvm_abiname {

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,9 +2419,11 @@ symbols! {
24192419
yield_expr,
24202420
ymm_reg,
24212421
yreg,
2422+
zca,
24222423
zfh,
24232424
zfhmin,
24242425
zmm_reg,
2426+
ztso,
24252427
// tidy-alphabetical-end
24262428
}
24272429
}

0 commit comments

Comments
 (0)