-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Add s390x-unknown-none-softfloat with RustcAbi::Softfloat
#151154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b1dc31
51affa0
7c3d096
83dba5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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::Softfloat), | ||
| 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, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]), | ||
|
|
@@ -1098,7 +1098,7 @@ impl Target { | |
| incompatible: &["soft-float"], | ||
| } | ||
| } | ||
| Some(RustcAbi::X86Softfloat) => { | ||
| Some(RustcAbi::Softfloat) => { | ||
| // Softfloat ABI, requires corresponding target feature. That feature trumps | ||
| // `x87` and all other FPU features so those do not matter. | ||
| // Note that this one requirement is the entire implementation of the ABI! | ||
|
|
@@ -1118,7 +1118,7 @@ impl Target { | |
| incompatible: &["soft-float"], | ||
| } | ||
| } | ||
| Some(RustcAbi::X86Softfloat) => { | ||
| Some(RustcAbi::Softfloat) => { | ||
| // Softfloat ABI, requires corresponding target feature. That feature trumps | ||
| // `x87` and all other FPU features so those do not matter. | ||
| // Note that this one requirement is the entire implementation of the ABI! | ||
|
|
@@ -1218,11 +1218,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::Softfloat) => { | ||
| // Softfloat ABI, requires corresponding target feature. | ||
| // llvm will switch to soft-float ABI just based on this feature. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also explain why "vector" is forbidden (given in particular that e.g. for x86 we do not forbid vector features here) |
||
| FeatureConstraints { required: &["soft-float"], incompatible: &["vector"] } | ||
| } | ||
| Some(r) => { | ||
| panic!("invalid Rust ABI for s390x: {r:?}"); | ||
| } | ||
| } | ||
| } | ||
| _ => NOTHING, | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # `s390x-unknown-none-softfloat` | ||
|
|
||
| **Tier: 2** | ||
|
|
||
| IBM z/Architecture (s390x) code in ELF format for kernels, etc. | ||
|
|
||
| ## Target maintainers | ||
|
|
||
| [@uweigand](https://github.com/uweigand) | ||
| [@cuviper](https://github.com/cuviper) | ||
|
Comment on lines
+9
to
+10
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is fine with me, thanks!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can be a backup, since I'll need to support this as a distro maintainer, but uweigand is definitely the expert here. :) |
||
|
|
||
| ## Requirements | ||
|
|
||
| This target is intended for kernel development on s390x only. This target is | ||
| cross-compiled. There is no support for `std`.There is no default allocator, | ||
| but it's possible to use `alloc` by supplying an allocator. | ||
|
|
||
| The target does not assume existence of a FPU and does not make use of any | ||
| non-GPR register. This allows the generated code to run in environments, such | ||
| as kernels, which may need to avoid the use of such registers or which may have | ||
| special considerations about the use of such registers (e.g. saving and | ||
| restoring them to avoid breaking userspace code using the same registers). You | ||
| can change code generation to use additional CPU features via the | ||
| `-C target-feature=` codegen options to rustc, or via the `#[target_feature]` | ||
| mechanism within Rust code. | ||
|
|
||
| By default, code generated with the soft-float target should run on any Z System | ||
| starting at [Z10][s390x-isa]. Enabling additional target features or changing the | ||
| `-Ctarget-cpu` may raise the ISA required from the `z10` baseline. | ||
|
|
||
| `extern "C"` does not use a stable ABI and is subject to change between compiler | ||
| or codegen backend versions. | ||
|
|
||
| The target only generates object files in the ELF format. Any alternate formats | ||
| or special considerations for binary layout will require linker options or linker | ||
| scripts. | ||
workingjubilee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * [z/Architecture Principles of Operation][s390x-isa] | ||
|
|
||
| [s390x-isa]: https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf | ||
| [s390x-abi]: https://github.com/IBM/s390x-abi | ||
|
|
||
| ## Building the target | ||
|
|
||
| You can build Rust with support for the target by adding it to the `target` | ||
| list in `bootstrap.toml`: | ||
|
|
||
| ```toml | ||
| [build] | ||
| target = ["s390x-unknown-none-softfloat"] | ||
| ``` | ||
|
|
||
| ## Building Rust programs | ||
|
|
||
| This target is not intended to build stand-alone binaries. You should only use | ||
| it in conjunction with the kernel build toolchain. | ||
|
|
||
| ## Testing | ||
|
|
||
| As code generated by this target is intended to always be part of the kernel, | ||
| there are no additional requirements for testing. | ||
|
|
||
| If you want to do native testing but do not have your own s390x | ||
| machine, there are several options how to get access to one: | ||
|
|
||
| * The [IBM LinuxONE Community Cloud][cloud-community] provides a | ||
| self-service portal where you can create s390x virtual machine | ||
| instances. These are intended for temporary use (limited to 120 days). | ||
|
|
||
| * The [IBM LinuxONE Open Source Cloud][cloud-opensource] provides | ||
| permanent access to s390x machines. This requires approval by IBM, | ||
| which will normally be granted if you're planning to use the machine | ||
| to work on an open-source project that is relevant to the IBM Z | ||
| ecosystem - the Rust compiler would certainly qualify. | ||
|
|
||
| [cloud-community]: https://linuxone.cloud.marist.edu/ | ||
| [cloud-opensource]: https://community.ibm.com/zsystems/form/l1cc-oss-vm-request/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| //@ add-minicore | ||
| //@ revisions: enable-softfloat disable-softfloat | ||
| //@ assembly-output: emit-asm | ||
| //@ compile-flags: -Copt-level=3 --crate-type=lib | ||
| //@[enable-softfloat] compile-flags: --target=s390x-unknown-none-softfloat | ||
| //@[enable-softfloat] needs-llvm-components: systemz | ||
| //@[disable-softfloat] compile-flags: --target=s390x-unknown-linux-gnu | ||
| //@[disable-softfloat] needs-llvm-components: systemz | ||
| //@ ignore-backends: gcc | ||
|
|
||
| #![feature(no_core, lang_items)] | ||
| #![no_std] | ||
| #![no_core] | ||
|
|
||
| extern crate minicore; | ||
| use minicore::*; | ||
|
|
||
| extern "C" { | ||
| fn extern_func(value: f64) -> f64; | ||
| } | ||
|
|
||
| // CHECK-LABEL: test_softfloat | ||
| #[no_mangle] | ||
| extern "C" fn test_softfloat() -> f64 { | ||
| let value = 3.141_f64; | ||
|
|
||
| // without softfloat we load the value direct to the first float register | ||
| // we do NOT construct a softfloat in r2 (first non-float arg register) | ||
| // disable-softfloat: ld %f{{.*}}, 0(%r{{.*}}) | ||
| // disable-softfloat-NOT: llihf %r{{.*}}, 1074340036 | ||
| // disable-softfloat-NOT: oilf %r{{.*}}, 2611340116 | ||
|
|
||
| // with softfloat we construct the softfloat arg in r2 | ||
| // we do NOT pass anything by f0 (first float arg register) | ||
| // float registers can not be accessed | ||
| // enable-softfloat: llihf %r{{.*}}, 1074340036 | ||
| // enable-softfloat-NEXT: oilf %r{{.*}}, 2611340116 | ||
| // enable-softfloat-NOT: ld %f{{.*}}, 0(%r{{.*}}) | ||
|
|
||
| unsafe { extern_func(value) }; | ||
| // disable-softfloat-NEXT: brasl %r{{.*}}, extern_func@PLT | ||
| // enable-softfloat-NEXT: brasl %r{{.*}}, extern_func@PLT | ||
|
|
||
| // for return we check that without softfloat we write to float register | ||
| // disable-softfloat: ld %f{{.*}}, 0(%r{{.*}}) | ||
| // disable-softfloat-NOT: llihf %r{{.*}}, 1072841097 | ||
| // disable-softfloat-NOT: oilf %r{{.*}}, 927712936 | ||
|
|
||
| #[cfg(not(target_feature = "soft-float"))] | ||
| { | ||
| 1.141_f64 | ||
| } | ||
|
|
||
| // for return we check that WITH softfloat we write to genral purpose register | ||
| // enable-softfloat: llihf %r{{.*}}, 1072841097 | ||
| // enable-softfloat-NEXT: oilf %r{{.*}}, 927712936 | ||
| // enable-softfloat-NOT: ld %f{{.*}}, 0(%r{{.*}}) | ||
| #[cfg(target_feature = "soft-float")] | ||
| { | ||
| 2.718_f64 | ||
| } | ||
| // enable-softfloat: br %r{{.*}} | ||
| // disable-softfloat: br %r{{.*}} | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.