Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -2089,6 +2091,7 @@ crate::target_spec_enum! {
VecDefault = "vec-default",
VecExtAbi = "vec-extabi",
X32 = "x32",
V8Plus = "v8plus",

@RalfJung RalfJung Aug 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need any kind of process for a new cfg value here?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unspecified = "",
}
other_variant = Other;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,13 +18,15 @@ 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(
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-mcpu=v9", "-m32"],
),
max_atomic_width: Some(32),
cfg_abi: CfgAbi::V8Plus,
..base::linux_gnu::opts()
},
}
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Comment thread
bjorn3 marked this conversation as resolved.
// 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,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/sparcv8plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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

7 changes: 6 additions & 1 deletion tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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

2 changes: 1 addition & 1 deletion tests/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
Expand Down
Loading