diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index a747b0aec7b28..d52481d72665f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -987,12 +987,14 @@ crate::target_spec_enum! { crate::target_spec_enum! { /// The Rustc-specific variant of the ABI used for this target. pub enum RustcAbi { + /// On x86-32/64, aarch64, and S390x: do not use any FPU or SIMD registers for the ABI. + Softfloat = "softfloat", /// On x86-32 only: make use of SSE and SSE2 for ABI purposes. X86Sse2 = "x86-sse2", /// On PowerPC only: build for SPE. PowerPcSpe = "powerpc-spe", - /// On x86-32/64, aarch64, and S390x: do not use any FPU or SIMD registers for the ABI. - Softfloat = "softfloat", + /// On SPARC-32: use the V8+ ABI. + SparcV8Plus = "sparc-v8plus", } parse_error_type = "rustc abi"; @@ -2089,6 +2091,7 @@ crate::target_spec_enum! { VecDefault = "vec-default", VecExtAbi = "vec-extabi", X32 = "x32", + V8Plus = "v8plus", Unspecified = "", } other_variant = Other; @@ -3596,6 +3599,36 @@ impl Target { self.cfg_abi, ); } + Arch::Sparc => { + check!( + self.llvm_abiname == LlvmAbi::Unspecified, + "`llvm_abiname` is unused on SPARC" + ); + check!(self.llvm_floatabi.is_none(), "`llvm_floatabi` is unused on SPARC"); + check_matches!( + (&self.rustc_abi, &self.cfg_abi), + (Some(RustcAbi::SparcV8Plus), CfgAbi::V8Plus) + | (None, CfgAbi::Unspecified | CfgAbi::Other(_)), + "invalid SPARC Rust-specific ABI and `cfg(target_abi)` combination:\n\ + Rust-specific ABI: {:?}\n\ + cfg(target_abi): {}", + self.rustc_abi, + self.cfg_abi, + ); + } + Arch::Sparc64 => { + check!( + self.llvm_abiname == LlvmAbi::Unspecified, + "`llvm_abiname` is unused on SPARC-64" + ); + check!(self.llvm_floatabi.is_none(), "`llvm_floatabi` is unused on SPARC-64"); + check!(self.rustc_abi.is_none(), "`rustc_abi` is unused on SPARC-64"); + check_matches!( + self.cfg_abi, + CfgAbi::Unspecified | CfgAbi::Other(_), + "invalid `target_abi` for SPARC-64" + ); + } Arch::CSky => { check!( self.llvm_abiname == LlvmAbi::Unspecified, diff --git a/compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs index f110acf63d876..cd478dd16dcf8 100644 --- a/compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/sparc_unknown_linux_gnu.rs @@ -1,6 +1,8 @@ use rustc_abi::Endian; -use crate::spec::{Arch, Cc, LinkerFlavor, Lld, Target, TargetMetadata, TargetOptions, base}; +use crate::spec::{ + Arch, Cc, CfgAbi, LinkerFlavor, Lld, RustcAbi, Target, TargetMetadata, TargetOptions, base, +}; pub(crate) fn target() -> Target { Target { @@ -16,6 +18,7 @@ pub(crate) fn target() -> Target { arch: Arch::Sparc, options: TargetOptions { features: "+v8plus".into(), + rustc_abi: Some(RustcAbi::SparcV8Plus), cpu: "v9".into(), endian: Endian::Big, late_link_args: TargetOptions::link_args( @@ -23,6 +26,7 @@ pub(crate) fn target() -> Target { &["-mcpu=v9", "-m32"], ), max_atomic_width: Some(32), + cfg_abi: CfgAbi::V8Plus, ..base::linux_gnu::opts() }, } diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index ce09972396e56..3abdd73bf145e 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -937,6 +937,11 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ const SPARC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // tidy-alphabetical-start ("leoncasa", Unstable(sym::sparc_target_feature), &[]), + ( + "soft-float", + Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, + &[], + ), ("v8plus", Unstable(sym::sparc_target_feature), &[]), ("v9", Unstable(sym::sparc_target_feature), &[]), // tidy-alphabetical-end @@ -1414,6 +1419,26 @@ impl Target { // to other targets above.) FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] } } + Arch::Sparc => { + // We currently don't have a soft-float target for SPARC. + // We need to pin down v8plus as it is a separate ABI (indicated in object files so + // things cannot be linked across ABI boundaries). + match self.rustc_abi { + None => FeatureConstraints { + required: &[], + incompatible: &["soft-float", "v8plus"], + }, + Some(RustcAbi::SparcV8Plus) => { + FeatureConstraints { required: &["v8plus"], incompatible: &["soft-float"] } + } + _ => unreachable!(), + } + } + Arch::Sparc64 => { + // We currently don't have a soft-float target for SPARC64. + // v8plus is for 32bit SPARC only. + FeatureConstraints { required: &[], incompatible: &["soft-float", "v8plus"] } + } Arch::Avr => { // We only support one ABI on AVR at the moment. // SRAM is minimum requirement for C/C++ in both avr-gcc and Clang, diff --git a/tests/ui/abi/sparcv8plus.rs b/tests/ui/abi/sparcv8plus.rs index 8b7d7dd78ad31..93e8871c642ee 100644 --- a/tests/ui/abi/sparcv8plus.rs +++ b/tests/ui/abi/sparcv8plus.rs @@ -13,7 +13,7 @@ //@ ignore-backends: gcc //[sparc_feature_v8plus,sparc_cpu_v9_feature_v8plus]~? WARN unstable feature specified for `-Ctarget-feature` -//[sparc_feature_v8plus,sparc_cpu_v9_feature_v8plus]~? NOTE this feature is not stably supported; its behavior can change in the future +//[sparc_feature_v8plus,sparc_cpu_v9_feature_v8plus]~? WARN `v8plus` must be disabled #![crate_type = "rlib"] #![feature(no_core, rustc_attrs, lang_items)] diff --git a/tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr b/tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr index 0de9cf69fbfbc..50ad31f1105ae 100644 --- a/tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr +++ b/tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr @@ -2,11 +2,16 @@ warning: unstable feature specified for `-Ctarget-feature`: `v8plus` | = note: this feature is not stably supported; its behavior can change in the future +warning: target feature `v8plus` must be disabled to ensure that the ABI of the current target can be implemented correctly + | + = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #116344 + error: +v8plus,+v9 --> $DIR/sparcv8plus.rs:35:1 | LL | compile_error!("+v8plus,+v9"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 1 previous error; 2 warnings emitted diff --git a/tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr b/tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr index 4ed66d503274c..0d9ea421a8c52 100644 --- a/tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr +++ b/tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr @@ -2,11 +2,16 @@ warning: unstable feature specified for `-Ctarget-feature`: `v8plus` | = note: this feature is not stably supported; its behavior can change in the future +warning: target feature `v8plus` must be disabled to ensure that the ABI of the current target can be implemented correctly + | + = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #116344 + error: +v8plus,-v9 (FIXME) --> $DIR/sparcv8plus.rs:40:1 | LL | compile_error!("+v8plus,-v9 (FIXME)"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 1 previous error; 2 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 693833decc971..6055b12798e65 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -129,7 +129,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_abi = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elfv1`, `elfv2`, `fortanix`, `ilp32`, `ilp32e`, `llvm`, `macabi`, `pauthtest`, `sim`, `softfloat`, `spe`, `uwp`, `vec-extabi`, and `x32` + = note: expected values for `target_abi` are: ``, `abi64`, `abiv2`, `abiv2hf`, `eabi`, `eabihf`, `elfv1`, `elfv2`, `fortanix`, `ilp32`, `ilp32e`, `llvm`, `macabi`, `pauthtest`, `sim`, `softfloat`, `spe`, `uwp`, `v8plus`, `vec-extabi`, and `x32` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`