Auto merge of #136146 - RalfJung:x86-abi, r=workingjubilee
Explicitly choose x86 softfloat/hardfloat ABI Part of https://github.com/rust-lang/rust/pull/135408: Instead of choosing this based on the target features listed in the target spec, make that choice explicit. All built-in targets are being updated here; custom (JSON-defined) x86 (32bit and 64bit) softfloat targets need to explicitly set `rustc-abi` to `x86-softfloat`.
This commit is contained in:
@@ -1114,6 +1114,33 @@ impl ToJson for FloatAbi {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Rustc-specific variant of the ABI used for this target.
|
||||
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||
pub enum RustcAbi {
|
||||
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
|
||||
X86Softfloat,
|
||||
}
|
||||
|
||||
impl FromStr for RustcAbi {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<RustcAbi, ()> {
|
||||
Ok(match s {
|
||||
"x86-softfloat" => RustcAbi::X86Softfloat,
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJson for RustcAbi {
|
||||
fn to_json(&self) -> Json {
|
||||
match *self {
|
||||
RustcAbi::X86Softfloat => "x86-softfloat",
|
||||
}
|
||||
.to_json()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||
pub enum TlsModel {
|
||||
GeneralDynamic,
|
||||
@@ -2505,6 +2532,12 @@ pub struct TargetOptions {
|
||||
/// If not provided, LLVM will infer the float ABI from the target triple (`llvm_target`).
|
||||
pub llvm_floatabi: Option<FloatAbi>,
|
||||
|
||||
/// Picks a specific ABI for this target. This is *not* just for "Rust" ABI functions,
|
||||
/// it can also affect "C" ABI functions; the point is that this flag is interpreted by
|
||||
/// rustc and not forwarded to LLVM.
|
||||
/// So far, this is only used on x86.
|
||||
pub rustc_abi: Option<RustcAbi>,
|
||||
|
||||
/// Whether or not RelaxElfRelocation flag will be passed to the linker
|
||||
pub relax_elf_relocations: bool,
|
||||
|
||||
@@ -2664,10 +2697,6 @@ impl TargetOptions {
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn has_feature(&self, search_feature: &str) -> bool {
|
||||
self.features.split(',').any(|f| f.strip_prefix('+').is_some_and(|f| f == search_feature))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TargetOptions {
|
||||
@@ -2774,6 +2803,7 @@ impl Default for TargetOptions {
|
||||
llvm_mcount_intrinsic: None,
|
||||
llvm_abiname: "".into(),
|
||||
llvm_floatabi: None,
|
||||
rustc_abi: None,
|
||||
relax_elf_relocations: false,
|
||||
llvm_args: cvs![],
|
||||
use_ctors_section: false,
|
||||
@@ -3240,6 +3270,17 @@ impl Target {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Check consistency of Rust ABI declaration.
|
||||
if let Some(rust_abi) = self.rustc_abi {
|
||||
match rust_abi {
|
||||
RustcAbi::X86Softfloat => check_matches!(
|
||||
&*self.arch,
|
||||
"x86" | "x86_64",
|
||||
"`x86-softfloat` ABI is only valid for x86 targets"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the given target-features string makes some basic sense.
|
||||
if !self.features.is_empty() {
|
||||
let mut features_enabled = FxHashSet::default();
|
||||
|
||||
Reference in New Issue
Block a user