Skip to content

Commit c66597e

Browse files
committed
prefer actual ABI-controling fields over target.abi when making ABI decisions
1 parent 99246f4 commit c66597e

7 files changed

Lines changed: 37 additions & 28 deletions

File tree

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_codegen_ssa::traits::{
88
use rustc_middle::bug;
99
use rustc_middle::ty::Ty;
1010
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
11-
use rustc_target::spec::{Abi, Arch, Env};
11+
use rustc_target::spec::{Arch, Env, RustcAbi};
1212

1313
use crate::builder::Builder;
1414
use crate::llvm::{Type, Value};
@@ -272,7 +272,7 @@ fn emit_powerpc_va_arg<'ll, 'tcx>(
272272

273273
// Rust does not currently support any powerpc softfloat targets.
274274
let target = &bx.cx.tcx.sess.target;
275-
let is_soft_float_abi = target.abi == Abi::SoftFloat;
275+
let is_soft_float_abi = target.rustc_abi == Some(RustcAbi::Softfloat);
276276
assert!(!is_soft_float_abi);
277277

278278
// All instances of VaArgSafe are passed directly.
@@ -1077,7 +1077,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
10771077
AllowHigherAlign::Yes,
10781078
ForceRightAdjust::Yes,
10791079
),
1080-
Arch::RiscV32 if target.abi == Abi::Ilp32e => {
1080+
Arch::RiscV32 if target.llvm_abiname == "ilp32e" => {
10811081
// FIXME: clang manually adjusts the alignment for this ABI. It notes:
10821082
//
10831083
// > To be compatible with GCC's behaviors, we force arguments with

compiler/rustc_target/src/callconv/aarch64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::iter;
33
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface};
44

55
use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
6-
use crate::spec::{Abi, HasTargetSpec, Target};
6+
use crate::spec::{HasTargetSpec, RustcAbi, Target};
77

88
/// Indicates the variant of the AArch64 ABI we are compiling for.
99
/// Used to accommodate Apple and Microsoft's deviations from the usual AAPCS ABI.
@@ -34,7 +34,7 @@ where
3434
RegKind::Integer => false,
3535
// The softfloat ABI treats floats like integers, so they
3636
// do not get homogeneous aggregate treatment.
37-
RegKind::Float => cx.target_spec().abi != Abi::SoftFloat,
37+
RegKind::Float => cx.target_spec().rustc_abi != Some(RustcAbi::Softfloat),
3838
RegKind::Vector => size.bits() == 64 || size.bits() == 128,
3939
};
4040

@@ -43,7 +43,7 @@ where
4343
}
4444

4545
fn softfloat_float_abi<Ty>(target: &Target, arg: &mut ArgAbi<'_, Ty>) {
46-
if target.abi != Abi::SoftFloat {
46+
if target.rustc_abi != Some(RustcAbi::Softfloat) {
4747
return;
4848
}
4949
// Do *not* use the float registers for passing arguments, as that would make LLVM pick the ABI

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,10 @@ pub struct TargetOptions {
22102210
pub env: Env,
22112211
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
22122212
/// or `"eabihf"`. Defaults to [`Abi::Unspecified`].
2213-
/// This field is *not* forwarded directly to LLVM; its primary purpose is `cfg(target_abi)`.
2214-
/// However, parts of the backend do check this field for specific values to enable special behavior.
2213+
/// This field is *not* forwarded directly to LLVM and therefore does not control which ABI (in
2214+
/// the sense of function calling convention) is actually used; its primary purpose is
2215+
/// `cfg(target_abi)`. The actual calling convention is controlled by `llvm_abiname`,
2216+
/// `llvm_floatabi`, and `rustc_abi`.
22152217
pub abi: Abi,
22162218
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
22172219
#[rustc_lint_opt_deny_field_access(
@@ -3207,8 +3209,8 @@ impl Target {
32073209
),
32083210
RustcAbi::Softfloat => check_matches!(
32093211
self.arch,
3210-
Arch::X86 | Arch::X86_64 | Arch::S390x,
3211-
"`softfloat` ABI is only valid for x86 and s390x targets"
3212+
Arch::X86 | Arch::X86_64 | Arch::S390x | Arch::AArch64,
3213+
"`softfloat` ABI is only valid for x86, s390x, and aarch64 targets"
32123214
),
32133215
}
32143216
}

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_none_softfloat.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
use rustc_abi::Endian;
99

1010
use crate::spec::{
11-
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
12-
Target, TargetMetadata, TargetOptions,
11+
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
12+
StackProbeType, Target, TargetMetadata, TargetOptions,
1313
};
1414

1515
pub(crate) fn target() -> Target {
1616
let opts = TargetOptions {
1717
abi: Abi::SoftFloat,
18+
rustc_abi: Some(RustcAbi::Softfloat),
1819
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
1920
linker: Some("rust-lld".into()),
2021
features: "+v8a,+strict-align,-neon".into(),

compiler/rustc_target/src/spec/targets/aarch64_unknown_none_softfloat.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
// For example, `-C target-cpu=cortex-a53`.
88

99
use crate::spec::{
10-
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
11-
Target, TargetMetadata, TargetOptions,
10+
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
11+
StackProbeType, Target, TargetMetadata, TargetOptions,
1212
};
1313

1414
pub(crate) fn target() -> Target {
1515
let opts = TargetOptions {
1616
abi: Abi::SoftFloat,
17+
rustc_abi: Some(RustcAbi::Softfloat),
1718
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
1819
linker: Some("rust-lld".into()),
1920
features: "+v8a,+strict-align,-neon".into(),

compiler/rustc_target/src/spec/targets/aarch64v8r_unknown_none_softfloat.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use crate::spec::{
2-
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
3-
Target, TargetMetadata, TargetOptions,
2+
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
3+
StackProbeType, Target, TargetMetadata, TargetOptions,
44
};
55

66
pub(crate) fn target() -> Target {
77
let opts = TargetOptions {
88
abi: Abi::SoftFloat,
9+
rustc_abi: Some(RustcAbi::Softfloat),
910
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
1011
linker: Some("rust-lld".into()),
1112
relocation_model: RelocModel::Static,

compiler/rustc_target/src/target_features.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
66
use rustc_span::{Symbol, sym};
77

8-
use crate::spec::{Abi, Arch, FloatAbi, RustcAbi, Target};
8+
use crate::spec::{Arch, FloatAbi, RustcAbi, Target};
99

1010
/// Features that control behaviour of rustc, rather than the codegen.
1111
/// These exist globally and are not in the target-specific lists below.
@@ -1170,17 +1170,21 @@ impl Target {
11701170
Arch::AArch64 | Arch::Arm64EC => {
11711171
// Aarch64 has no sane ABI specifier, and LLVM doesn't even have a way to force
11721172
// the use of soft-float, so all we can do here is some crude hacks.
1173-
if self.abi == Abi::SoftFloat {
1174-
// LLVM will use float registers when `fp-armv8` is available, e.g. for
1175-
// calls to built-ins. The only way to ensure a consistent softfloat ABI
1176-
// on aarch64 is to never enable `fp-armv8`, so we enforce that.
1177-
// In Rust we tie `neon` and `fp-armv8` together, therefore `neon` is the
1178-
// feature we have to mark as incompatible.
1179-
FeatureConstraints { required: &[], incompatible: &["neon"] }
1180-
} else {
1181-
// Everything else is assumed to use a hardfloat ABI. neon and fp-armv8 must be enabled.
1182-
// `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
1183-
FeatureConstraints { required: &["neon"], incompatible: &[] }
1173+
match self.rustc_abi {
1174+
Some(RustcAbi::Softfloat) => {
1175+
// LLVM will use float registers when `fp-armv8` is available, e.g. for
1176+
// calls to built-ins. The only way to ensure a consistent softfloat ABI
1177+
// on aarch64 is to never enable `fp-armv8`, so we enforce that.
1178+
// In Rust we tie `neon` and `fp-armv8` together, therefore `neon` is the
1179+
// feature we have to mark as incompatible.
1180+
FeatureConstraints { required: &[], incompatible: &["neon"] }
1181+
}
1182+
None => {
1183+
// Everything else is assumed to use a hardfloat ABI. neon and fp-armv8 must be enabled.
1184+
// `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
1185+
FeatureConstraints { required: &["neon"], incompatible: &[] }
1186+
}
1187+
Some(r) => panic!("invalid Rust ABI for aarch64: {r:?}"),
11841188
}
11851189
}
11861190
Arch::RiscV32 | Arch::RiscV64 => {

0 commit comments

Comments
 (0)