Skip to content

Commit cb8c905

Browse files
committed
rustc_codegen_ssa: More comprehensive RISC-V ELF flags
This commit 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.
1 parent 6912064 commit cb8c905

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,17 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
330330
let mut e_flags: u32 = 0x0;
331331

332332
// Check if compression 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) {
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)