about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTsukasa OI <floss_rust@irq.a4lg.com>2025-08-25 08:48:39 +0000
committerTsukasa OI <floss_rust@irq.a4lg.com>2025-08-26 03:42:37 +0000
commitcb8c905c47aea018d8bef7b68ab885ce99d984da (patch)
treeb296a0ebc4e015e8506b191380ad8ec382717744
parent691206470b0a48fa89a8742bba21bf1034a44b54 (diff)
downloadrust-cb8c905c47aea018d8bef7b68ab885ce99d984da.tar.gz
rust-cb8c905c47aea018d8bef7b68ab885ce99d984da.zip
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.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/metadata.rs10
-rw-r--r--compiler/rustc_span/src/symbol.rs2
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index 55cbf81a8bb..10aaadd5688 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -330,11 +330,17 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
             let mut e_flags: u32 = 0x0;
 
             // Check if compression is enabled
-            // `unstable_target_features` is used here because "c" is gated behind riscv_target_feature.
-            if sess.unstable_target_features.contains(&sym::c) {
+            // `unstable_target_features` is used here because "zca" is gated behind riscv_target_feature.
+            if sess.unstable_target_features.contains(&sym::zca) {
                 e_flags |= elf::EF_RISCV_RVC;
             }
 
+            // Check if RVTSO is enabled
+            // `unstable_target_features` is used here because "ztso" is gated behind riscv_target_feature.
+            if sess.unstable_target_features.contains(&sym::ztso) {
+                e_flags |= elf::EF_RISCV_TSO;
+            }
+
             // Set the appropriate flag based on ABI
             // This needs to match LLVM `RISCVELFStreamer.cpp`
             match &*sess.target.llvm_abiname {
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 5d140cc6117..585968044bf 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -2419,9 +2419,11 @@ symbols! {
         yield_expr,
         ymm_reg,
         yreg,
+        zca,
         zfh,
         zfhmin,
         zmm_reg,
+        ztso,
         // tidy-alphabetical-end
     }
 }