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
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_codegen_ssa::traits::{
use rustc_middle::bug;
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
use rustc_target::spec::{Abi, Arch, Env};
use rustc_target::spec::{Arch, Env, RustcAbi};

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

// Rust does not currently support any powerpc softfloat targets.
let target = &bx.cx.tcx.sess.target;
let is_soft_float_abi = target.abi == Abi::SoftFloat;
let is_soft_float_abi = target.rustc_abi == Some(RustcAbi::Softfloat);
Copy link
Member Author

@RalfJung RalfJung Feb 24, 2026

Choose a reason for hiding this comment

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

We don't actually use RustcAbi::Softfloat on powerpc currently.
@Gelbpunkt Do we even have a powerpc softfloat target and how does it work? @folkertdev which target was this check supposed to deal with?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have softfloat powerpc targets at the moment, but I'm pretty sure the RfL people will want to add one? Not sure what the plans are for that...

assert!(!is_soft_float_abi);

// All instances of VaArgSafe are passed directly.
Expand Down Expand Up @@ -1077,7 +1077,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
AllowHigherAlign::Yes,
ForceRightAdjust::Yes,
),
Arch::RiscV32 if target.abi == Abi::Ilp32e => {
Arch::RiscV32 if target.llvm_abiname == "ilp32e" => {
// FIXME: clang manually adjusts the alignment for this ABI. It notes:
//
// > To be compatible with GCC's behaviors, we force arguments with
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/callconv/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::iter;
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface};

use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::spec::{Abi, HasTargetSpec, Target};
use crate::spec::{HasTargetSpec, RustcAbi, Target};

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

Expand All @@ -43,7 +43,7 @@ where
}

fn softfloat_float_abi<Ty>(target: &Target, arg: &mut ArgAbi<'_, Ty>) {
if target.abi != Abi::SoftFloat {
if target.rustc_abi != Some(RustcAbi::Softfloat) {
return;
}
// Do *not* use the float registers for passing arguments, as that would make LLVM pick the ABI
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,10 @@ pub struct TargetOptions {
pub env: Env,
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
/// or `"eabihf"`. Defaults to [`Abi::Unspecified`].
/// This field is *not* forwarded directly to LLVM; its primary purpose is `cfg(target_abi)`.
/// However, parts of the backend do check this field for specific values to enable special behavior.
/// This field is *not* forwarded directly to LLVM and therefore does not control which ABI (in
/// the sense of function calling convention) is actually used; its primary purpose is
/// `cfg(target_abi)`. The actual calling convention is controlled by `llvm_abiname`,
/// `llvm_floatabi`, and `rustc_abi`.
pub abi: Abi,
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
#[rustc_lint_opt_deny_field_access(
Expand Down Expand Up @@ -3207,8 +3209,8 @@ impl Target {
),
RustcAbi::Softfloat => check_matches!(
self.arch,
Arch::X86 | Arch::X86_64 | Arch::S390x,
"`softfloat` ABI is only valid for x86 and s390x targets"
Arch::X86 | Arch::X86_64 | Arch::S390x | Arch::AArch64,
"`softfloat` ABI is only valid for x86, s390x, and aarch64 targets"
),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
use rustc_abi::Endian;

use crate::spec::{
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
Target, TargetMetadata, TargetOptions,
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
StackProbeType, Target, TargetMetadata, TargetOptions,
};

pub(crate) fn target() -> Target {
let opts = TargetOptions {
abi: Abi::SoftFloat,
rustc_abi: Some(RustcAbi::Softfloat),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
features: "+v8a,+strict-align,-neon".into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
// For example, `-C target-cpu=cortex-a53`.

use crate::spec::{
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
Target, TargetMetadata, TargetOptions,
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
StackProbeType, Target, TargetMetadata, TargetOptions,
};

pub(crate) fn target() -> Target {
let opts = TargetOptions {
abi: Abi::SoftFloat,
rustc_abi: Some(RustcAbi::Softfloat),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
features: "+v8a,+strict-align,-neon".into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::spec::{
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, StackProbeType,
Target, TargetMetadata, TargetOptions,
Abi, Arch, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, RustcAbi, SanitizerSet,
StackProbeType, Target, TargetMetadata, TargetOptions,
};

pub(crate) fn target() -> Target {
let opts = TargetOptions {
abi: Abi::SoftFloat,
rustc_abi: Some(RustcAbi::Softfloat),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("rust-lld".into()),
relocation_model: RelocModel::Static,
Expand Down
28 changes: 16 additions & 12 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_span::{Symbol, sym};

use crate::spec::{Abi, Arch, FloatAbi, RustcAbi, Target};
use crate::spec::{Arch, FloatAbi, RustcAbi, Target};

/// Features that control behaviour of rustc, rather than the codegen.
/// These exist globally and are not in the target-specific lists below.
Expand Down Expand Up @@ -1170,17 +1170,21 @@ impl Target {
Arch::AArch64 | Arch::Arm64EC => {
// Aarch64 has no sane ABI specifier, and LLVM doesn't even have a way to force
// the use of soft-float, so all we can do here is some crude hacks.
if self.abi == Abi::SoftFloat {
// LLVM will use float registers when `fp-armv8` is available, e.g. for
// calls to built-ins. The only way to ensure a consistent softfloat ABI
// on aarch64 is to never enable `fp-armv8`, so we enforce that.
// In Rust we tie `neon` and `fp-armv8` together, therefore `neon` is the
// feature we have to mark as incompatible.
FeatureConstraints { required: &[], incompatible: &["neon"] }
} else {
// Everything else is assumed to use a hardfloat ABI. neon and fp-armv8 must be enabled.
// `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
FeatureConstraints { required: &["neon"], incompatible: &[] }
match self.rustc_abi {
Copy link
Member Author

Choose a reason for hiding this comment

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

This actually seems like a great improvement in consistency; every other match in this function is about rustc_abi / llvm_abiname / llvm_floatabi.

Some(RustcAbi::Softfloat) => {
// LLVM will use float registers when `fp-armv8` is available, e.g. for
// calls to built-ins. The only way to ensure a consistent softfloat ABI
// on aarch64 is to never enable `fp-armv8`, so we enforce that.
// In Rust we tie `neon` and `fp-armv8` together, therefore `neon` is the
// feature we have to mark as incompatible.
FeatureConstraints { required: &[], incompatible: &["neon"] }
}
None => {
// Everything else is assumed to use a hardfloat ABI. neon and fp-armv8 must be enabled.
// `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
FeatureConstraints { required: &["neon"], incompatible: &[] }
}
Some(r) => panic!("invalid Rust ABI for aarch64: {r:?}"),
}
}
Arch::RiscV32 | Arch::RiscV64 => {
Expand Down
Loading