Skip to content

Commit 6861049

Browse files
committed
arm: use target.abi over soft-float target feature
1 parent 5c6ed53 commit 6861049

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3168,14 +3168,22 @@ impl Target {
31683168
self.llvm_abiname,
31693169
);
31703170
}
3171-
"aarch64" => {
3171+
"aarch64" | "arm64ec" => {
31723172
check_matches!(
31733173
&*self.abi,
31743174
"softfloat" | "uwp" | "llvm" | "macabi" | "sim" | "ilp32" | "",
31753175
"invalid aarch64 ABI name: {}",
31763176
self.abi,
31773177
)
31783178
}
3179+
"arm" => {
3180+
check_matches!(
3181+
&*self.abi,
3182+
"eabi" | "eabihf" | "uwp" | "macabi" | "sim" | "",
3183+
"invalid aarch64 ABI name: {}",
3184+
self.abi,
3185+
)
3186+
}
31793187
_ => {}
31803188
}
31813189

compiler/rustc_target/src/target_features.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ const AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
204204
("flagm", Stable, &[]),
205205
// FEAT_FLAGM2
206206
("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]),
207+
// We forbid directly toggling just `fp-armv8`; it must be toggled with `neon`.
207208
("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]),
208209
// FEAT_FP16
209210
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
@@ -758,6 +759,7 @@ impl Target {
758759
match &*self.arch {
759760
"x86" => {
760761
// We support 2 ABIs, hardfloat (default) and softfloat.
762+
// x86 has no sane ABI indicator so we have to use the target feature.
761763
if self.has_feature("soft-float") {
762764
NOTHING
763765
} else {
@@ -767,6 +769,7 @@ impl Target {
767769
}
768770
"x86_64" => {
769771
// We support 2 ABIs, hardfloat (default) and softfloat.
772+
// x86 has no sane ABI indicator so we have to use the target feature.
770773
if self.has_feature("soft-float") {
771774
NOTHING
772775
} else {
@@ -775,20 +778,20 @@ impl Target {
775778
}
776779
}
777780
"arm" => {
778-
// We support 2 ABIs, hardfloat (default) and softfloat.
779-
if self.has_feature("soft-float") {
780-
NOTHING
781-
} else {
782-
// Hardfloat ABI. x87 must be enabled.
783-
(&["fpregs"], &[])
781+
// It's unclear how the `abi` and the `soft-float` target feature interact.
782+
// We use the `abi` as our primary signal, and force `soft-float` to match.
783+
match &*self.abi {
784+
"eabi" => (&["soft-float"], &[]),
785+
"eabihf" | "uwp" | "macabi" | "sim" | "" => (&["fpregs"], &["soft-float"]),
786+
_ => unreachable!(),
784787
}
785788
}
786789
"aarch64" | "arm64ec" => {
787790
match &*self.abi {
788791
"softfloat" => {
789792
// This is not fully correct, LLVM actually doesn't let us enforce the softfloat
790793
// ABI properly... see <https://github.com/rust-lang/rust/issues/134375>.
791-
// FIXME: should be forbid "neon" here? But that would be a breaking change.
794+
// FIXME: should we forbid "neon" here? But that would be a breaking change.
792795
NOTHING
793796
}
794797
"uwp" | "llvm" | "macabi" | "sim" | "ilp32" | "" => {

tests/codegen/tied-features-strength.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-linelength
2-
//@ revisions: ENABLE_SVE DISABLE_SVE ENABLE_NEON
2+
//@ revisions: ENABLE_SVE DISABLE_SVE DISABLE_NEON ENABLE_NEON
33
//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
44
//@ needs-llvm-components: aarch64
55

@@ -13,9 +13,9 @@
1313
//@ [DISABLE_SVE] compile-flags: -C target-feature=-sve -Copt-level=0
1414
// DISABLE_SVE: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(-sve,?)|(\+neon,?)|(\+fp-armv8,?))*}}" }
1515

16-
// The DISABLE_NEON is disabled since neon is a required target feature for this targt, it cannot be disabled.
17-
// it would have: compile-flags: -C target-feature=-neon -Copt-level=0
18-
// DISABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(-fp-armv8,?)|(-neon,?))*}}" }
16+
//@ [DISABLE_NEON] compile-flags: -C target-feature=-neon -Copt-level=0
17+
// `neon` and `fp-armv8` get enabled as target base features, but then disabled again at the end of the list.
18+
// DISABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(\+fp-armv8,?)|(\+neon,?))*}},-neon,-fp-armv8" }
1919

2020
//@ [ENABLE_NEON] compile-flags: -C target-feature=+neon -Copt-level=0
2121
// ENABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(\+fp-armv8,?)|(\+neon,?))*}}" }

tests/run-make/simd-ffi/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn main() {
5656
.target(&target)
5757
.emit("llvm-ir,asm")
5858
.input("simd.rs")
59-
.arg("-Ctarget-feature=+neon,+sse")
59+
.arg("-Ctarget-feature=-soft-float,+neon,+sse")
6060
.arg(&format!("-Cextra-filename=-{target}"))
6161
.run();
6262
}

0 commit comments

Comments
 (0)