add a new s390x-unknown-none-softfloat target

This target is intended to be used for kernel development. Becasue on s390x
float and vector registers overlap we have to disable the vector extension.

The default s390x-unknown-gnu-linux target will not allow use of
softfloat.

Co-authored-by: Jubilee <workingjubilee@gmail.com>
This commit is contained in:
Eddy (Eduard) Stefes 2026-01-14 13:08:10 +01:00
parent a3ceeeb26c
commit 2b1dc3144b
8 changed files with 153 additions and 6 deletions

View file

@ -1007,6 +1007,8 @@ crate::target_spec_enum! {
X86Sse2 = "x86-sse2",
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
X86Softfloat = "x86-softfloat",
// On S390x only: do not use any FPU or Vector registers for the ABI.
S390xSoftFloat = "s390x-softfloat",
}
parse_error_type = "rustc abi";
@ -1460,6 +1462,7 @@ supported_targets! {
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
("s390x-unknown-none-softfloat", s390x_unknown_none_softfloat),
("s390x-unknown-linux-musl", s390x_unknown_linux_musl),
("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
@ -3209,6 +3212,11 @@ impl Target {
Arch::X86 | Arch::X86_64,
"`x86-softfloat` ABI is only valid for x86 targets"
),
RustcAbi::S390xSoftFloat => check_matches!(
self.arch,
Arch::S390x,
"`s390x-softfloat` ABI is only valid for s390x targets"
),
}
}

View file

@ -0,0 +1,39 @@
use rustc_abi::{Align, Endian};
use crate::spec::{
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
StackProbeType, Target, TargetMetadata, TargetOptions,
};
pub(crate) fn target() -> Target {
let opts = TargetOptions {
abi: Abi::SoftFloat,
cpu: "z10".into(),
endian: Endian::Big,
features: "+soft-float,-vector".into(),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
max_atomic_width: Some(128),
min_global_align: Some(Align::from_bits(16).unwrap()),
panic_strategy: PanicStrategy::Abort,
relocation_model: RelocModel::Static,
rustc_abi: Some(RustcAbi::S390xSoftFloat),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::KERNELADDRESS,
..Default::default()
};
Target {
llvm_target: "s390x-unknown-linux-gnu".into(),
metadata: TargetMetadata {
description: Some("S390x Linux".into()),
host_tools: Some(false),
std: Some(false),
tier: Some(2),
},
arch: Arch::S390x,
data_layout: "E-S64-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64".into(),
options: opts,
pointer_width: 64,
}
}

View file

@ -863,7 +863,7 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("miscellaneous-extensions-3", Stable, &[]),
("miscellaneous-extensions-4", Stable, &[]),
("nnp-assist", Stable, &["vector"]),
("soft-float", Forbidden { reason: "currently unsupported ABI-configuration feature" }, &[]),
("soft-float", Forbidden { reason: "unsupported ABI-configuration feature" }, &[]),
("transactional-execution", Unstable(sym::s390x_target_feature), &[]),
("vector", Stable, &[]),
("vector-enhancements-1", Stable, &["vector"]),
@ -1105,6 +1105,7 @@ impl Target {
// LLVM handles the rest.
FeatureConstraints { required: &["soft-float"], incompatible: &[] }
}
Some(r) => panic!("invalid Rust ABI for x86: {r:?}"),
}
}
Arch::X86_64 => {
@ -1218,11 +1219,27 @@ impl Target {
}
}
Arch::S390x => {
// We don't currently support a softfloat target on this architecture.
// As usual, we have to reject swapping the `soft-float` target feature.
// The "vector" target feature does not affect the ABI for floats
// because the vector and float registers overlap.
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
// Same as x86, We use our own ABI indicator here;
// LLVM does not have anything native and will switch ABI based
// on the soft-float target feature.
// Every case should require or forbid `soft-float`!
// The "vector" target feature may only be used without soft-float
// because the float and vector registers overlap and the
// standard s390x C ABI may pass vectors via these registers.
match self.rustc_abi {
None => {
// Default hardfloat ABI.
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
}
Some(RustcAbi::S390xSoftFloat) => {
// Softfloat ABI, requires corresponding target feature.
// llvm will switch to soft-float ABI just based on this feature.
FeatureConstraints { required: &["soft-float"], incompatible: &["vector"] }
}
Some(r) => {
panic!("invalid Rust ABI for s390x: {r:?}");
}
}
}
_ => NOTHING,
}