about summary refs log tree commit diff
path: root/compiler/rustc_target
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-12-30 19:08:03 +0100
committerRalf Jung <post@ralfj.de>2024-12-30 21:59:05 +0100
commita0dbb37ebd7919df4b698deb356e024a741283ec (patch)
tree44f86eee8f6ccca604db1afc1541c1a39f3eacfc /compiler/rustc_target
parentfff026c8e572809cfce7202ec1ad63897b72c5b0 (diff)
downloadrust-a0dbb37ebd7919df4b698deb356e024a741283ec.tar.gz
rust-a0dbb37ebd7919df4b698deb356e024a741283ec.zip
add llvm_floatabi field to target spec that controls FloatABIType
Diffstat (limited to 'compiler/rustc_target')
-rw-r--r--compiler/rustc_target/src/spec/json.rs14
-rw-r--r--compiler/rustc_target/src/spec/mod.rs41
2 files changed, 55 insertions, 0 deletions
diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs
index 206766325aa..9cdc0801b1f 100644
--- a/compiler/rustc_target/src/spec/json.rs
+++ b/compiler/rustc_target/src/spec/json.rs
@@ -116,6 +116,18 @@ impl Target {
                     Some(Ok(()))
                 })).unwrap_or(Ok(()))
             } );
+            ($key_name:ident, FloatAbi) => ( {
+                let name = (stringify!($key_name)).replace("_", "-");
+                obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
+                    match s.parse::<super::FloatAbi>() {
+                        Ok(float_abi) => base.$key_name = Some(float_abi),
+                        _ => return Some(Err(format!("'{}' is not a valid value for \
+                                                      llvm-floatabi. Use 'soft' or 'hard'.",
+                                                      s))),
+                    }
+                    Some(Ok(()))
+                })).unwrap_or(Ok(()))
+            } );
             ($key_name:ident, RelocModel) => ( {
                 let name = (stringify!($key_name)).replace("_", "-");
                 obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
@@ -598,6 +610,7 @@ impl Target {
         key!(mcount = "target-mcount");
         key!(llvm_mcount_intrinsic, optional);
         key!(llvm_abiname);
+        key!(llvm_floatabi, FloatAbi)?;
         key!(relax_elf_relocations, bool);
         key!(llvm_args, list);
         key!(use_ctors_section, bool);
@@ -772,6 +785,7 @@ impl ToJson for Target {
         target_option_val!(mcount, "target-mcount");
         target_option_val!(llvm_mcount_intrinsic);
         target_option_val!(llvm_abiname);
+        target_option_val!(llvm_floatabi);
         target_option_val!(relax_elf_relocations);
         target_option_val!(llvm_args);
         target_option_val!(use_ctors_section);
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index ad746d3f26b..c25788b97e5 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1085,6 +1085,35 @@ impl ToJson for CodeModel {
     }
 }
 
+/// The float ABI setting to be configured in the LLVM target machine.
+#[derive(Clone, Copy, PartialEq, Hash, Debug)]
+pub enum FloatAbi {
+    Soft,
+    Hard,
+}
+
+impl FromStr for FloatAbi {
+    type Err = ();
+
+    fn from_str(s: &str) -> Result<FloatAbi, ()> {
+        Ok(match s {
+            "soft" => FloatAbi::Soft,
+            "hard" => FloatAbi::Hard,
+            _ => return Err(()),
+        })
+    }
+}
+
+impl ToJson for FloatAbi {
+    fn to_json(&self) -> Json {
+        match *self {
+            FloatAbi::Soft => "soft",
+            FloatAbi::Hard => "hard",
+        }
+        .to_json()
+    }
+}
+
 #[derive(Clone, Copy, PartialEq, Hash, Debug)]
 pub enum TlsModel {
     GeneralDynamic,
@@ -2150,6 +2179,8 @@ pub struct TargetOptions {
     pub env: StaticCow<str>,
     /// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
     /// or `"eabihf"`. Defaults to "".
+    /// This field is *not* forwarded directly to LLVM; its primary purpose is `cfg(target_abi)`.
+    /// However, parts of the backend do check this field for specific values to enable special behavior.
     pub abi: StaticCow<str>,
     /// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
     pub vendor: StaticCow<str>,
@@ -2446,8 +2477,17 @@ pub struct TargetOptions {
     pub llvm_mcount_intrinsic: Option<StaticCow<str>>,
 
     /// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
+    /// and the `-target-abi` flag in llc. In the LLVM API this is `MCOptions.ABIName`.
     pub llvm_abiname: StaticCow<str>,
 
+    /// Control the float ABI to use, for architectures that support it. The only architecture we
+    /// currently use this for is ARM. Corresponds to the `-float-abi` flag in llc. In the LLVM API
+    /// this is `FloatABIType`. (clang's `-mfloat-abi` is similar but more complicated since it
+    /// can also affect the `soft-float` target feature.)
+    ///
+    /// If not provided, LLVM will infer the float ABI from the target triple (`llvm_target`).
+    pub llvm_floatabi: Option<FloatAbi>,
+
     /// Whether or not RelaxElfRelocation flag will be passed to the linker
     pub relax_elf_relocations: bool,
 
@@ -2719,6 +2759,7 @@ impl Default for TargetOptions {
             mcount: "mcount".into(),
             llvm_mcount_intrinsic: None,
             llvm_abiname: "".into(),
+            llvm_floatabi: None,
             relax_elf_relocations: false,
             llvm_args: cvs![],
             use_ctors_section: false,