about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back
diff options
context:
space:
mode:
authorWANG Rui <wangrui@loongson.cn>2023-06-12 19:38:56 +0800
committerWANG Rui <wangrui@loongson.cn>2023-06-12 19:50:47 +0800
commitaa8e8642d955e2184e5c14513e083c970dbd5f25 (patch)
tree247e6b881f22a3a48d33ba25ff302e0537947d7b /compiler/rustc_codegen_ssa/src/back
parentfd0a3313f7a64cb16533030e49a271db449368c3 (diff)
downloadrust-aa8e8642d955e2184e5c14513e083c970dbd5f25.tar.gz
rust-aa8e8642d955e2184e5c14513e083c970dbd5f25.zip
loongarch: Fix ELF header flags
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/metadata.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index b198e35e0c1..28af2a92eaf 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -284,8 +284,19 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
             e_flags
         }
         Architecture::LoongArch64 => {
-            // Source: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version
-            elf::EF_LARCH_OBJABI_V1 | elf::EF_LARCH_ABI_DOUBLE_FLOAT
+            // Source: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#e_flags-identifies-abi-type-and-version
+            let mut e_flags: u32 = elf::EF_LARCH_OBJABI_V1;
+            let features = &sess.target.options.features;
+
+            // Select the appropriate floating-point ABI
+            if features.contains("+d") {
+                e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT;
+            } else if features.contains("+f") {
+                e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT;
+            } else {
+                e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT;
+            }
+            e_flags
         }
         _ => 0,
     };