Rollup merge of #136565 - workingjubilee:fixup-abi-in-target, r=compiler-errors

compiler: Clean up weird `rustc_abi` reexports

Just general cleanup in `rustc_target` and `rustc_abi`. I was originally going to make a PR with a larger change that also fixed the last few crates and in doing so removed some clutter from `rustc_abi`, but wound up slightly stuck on it, then figured out how to fix it, and then got distracted by other things... so now I'm trying to figure out what I had figured out earlier.
This commit is contained in:
Matthias Krüger
2025-02-07 12:01:58 +01:00
committed by GitHub
27 changed files with 221 additions and 199 deletions

View File

@@ -42,6 +42,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fmt, io};
use rustc_abi::{Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
use rustc_data_structures::fx::FxHashSet;
use rustc_fs_util::try_canonicalize;
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
@@ -51,9 +52,7 @@ use serde_json::Value;
use tracing::debug;
use crate::abi::call::Conv;
use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
use crate::json::{Json, ToJson};
use crate::spec::abi::Abi;
use crate::spec::crt_objects::CrtObjects;
pub mod crt_objects;
@@ -2845,44 +2844,40 @@ impl DerefMut for Target {
impl Target {
/// Given a function ABI, turn it into the correct ABI for this target.
pub fn adjust_abi(&self, abi: Abi, c_variadic: bool) -> Abi {
pub fn adjust_abi(&self, abi: ExternAbi, c_variadic: bool) -> ExternAbi {
use ExternAbi::*;
match abi {
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
// `__stdcall` only applies on x86 and on non-variadic functions:
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
Abi::System { unwind } if self.is_like_windows && self.arch == "x86" && !c_variadic => {
Abi::Stdcall { unwind }
System { unwind } if self.is_like_windows && self.arch == "x86" && !c_variadic => {
Stdcall { unwind }
}
Abi::System { unwind } => Abi::C { unwind },
Abi::EfiApi if self.arch == "arm" => Abi::Aapcs { unwind: false },
Abi::EfiApi if self.arch == "x86_64" => Abi::Win64 { unwind: false },
Abi::EfiApi => Abi::C { unwind: false },
System { unwind } => C { unwind },
EfiApi if self.arch == "arm" => Aapcs { unwind: false },
EfiApi if self.arch == "x86_64" => Win64 { unwind: false },
EfiApi => C { unwind: false },
// See commentary in `is_abi_supported`: we map these ABIs to "C" when they do not make sense.
Abi::Stdcall { .. } | Abi::Thiscall { .. } | Abi::Fastcall { .. }
if self.arch == "x86" =>
{
abi
}
Abi::Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => abi,
Abi::Stdcall { unwind }
| Abi::Thiscall { unwind }
| Abi::Fastcall { unwind }
| Abi::Vectorcall { unwind } => Abi::C { unwind },
// See commentary in `is_abi_supported`.
Stdcall { .. } | Thiscall { .. } if self.arch == "x86" => abi,
Stdcall { unwind } | Thiscall { unwind } => C { unwind },
Fastcall { .. } if self.arch == "x86" => abi,
Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => abi,
Fastcall { unwind } | Vectorcall { unwind } => C { unwind },
// The Windows x64 calling convention we use for `extern "Rust"`
// <https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions#register-volatility-and-preservation>
// expects the callee to save `xmm6` through `xmm15`, but `PreserveMost`
// (that we use by default for `extern "rust-cold"`) doesn't save any of those.
// So to avoid bloating callers, just use the Rust convention here.
Abi::RustCold if self.is_like_windows && self.arch == "x86_64" => Abi::Rust,
RustCold if self.is_like_windows && self.arch == "x86_64" => Rust,
abi => abi,
}
}
pub fn is_abi_supported(&self, abi: Abi) -> bool {
use Abi::*;
pub fn is_abi_supported(&self, abi: ExternAbi) -> bool {
use ExternAbi::*;
match abi {
Rust
| C { .. }