rustc_target: hide TargetOptions::vendor

This commit is contained in:
Tamir Duberstein 2025-11-09 12:39:18 -05:00
parent 86b95ebc24
commit c5f2eb61a1
No known key found for this signature in database
18 changed files with 93 additions and 69 deletions

View file

@ -916,8 +916,8 @@ pub(crate) fn codegen_call_with_unwind_action(
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
let param = AbiParam::new(ty);
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() {
match (&tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) {
(Arch::X86_64, _) | (Arch::AArch64, "apple") => match (ty, is_signed) {
match (&tcx.sess.target.arch, tcx.sess.target.is_like_darwin) {
(Arch::X86_64, _) | (Arch::AArch64, true) => match (ty, is_signed) {
(types::I8 | types::I16, true) => param.sext(),
(types::I8 | types::I16, false) => param.uext(),
_ => param,

View file

@ -5,7 +5,7 @@ use crate::prelude::*;
pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
let (value, arg_ty) =
if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64 {
if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
(
fx.bcx.ins().bitcast(types::I16, MemFlags::new(), value),
lib_call_arg_param(fx.tcx, types::I16, false),
@ -22,8 +22,7 @@ fn f16_to_f64(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
}
pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64
{
let ret_ty = if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
types::I16
} else {
types::F16
@ -38,8 +37,7 @@ pub(crate) fn f32_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value
}
fn f64_to_f16(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value {
let ret_ty = if fx.tcx.sess.target.vendor == "apple" && fx.tcx.sess.target.arch == Arch::X86_64
{
let ret_ty = if fx.tcx.sess.target.is_like_darwin && fx.tcx.sess.target.arch == Arch::X86_64 {
types::I16
} else {
types::F16

View file

@ -1819,7 +1819,7 @@ fn self_contained_components(
LinkSelfContainedDefault::InferredForMusl => sess.crt_static(Some(crate_type)),
LinkSelfContainedDefault::InferredForMingw => {
sess.host == sess.target
&& sess.target.vendor != "uwp"
&& sess.target.abi != "uwp"
&& detect_self_contained_mingw(sess, linker)
}
}

View file

@ -83,7 +83,7 @@ pub(crate) fn get_linker<'a>(
// To comply with the Windows App Certification Kit,
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
let t = &sess.target;
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.vendor == "uwp" {
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.abi == "uwp" {
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
@ -134,7 +134,7 @@ pub(crate) fn get_linker<'a>(
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
// to the linker args construction.
assert!(cmd.get_args().is_empty() || sess.target.vendor == "uwp");
assert!(cmd.get_args().is_empty() || sess.target.abi == "uwp");
match flavor {
LinkerFlavor::Unix(Cc::No) if sess.target.os == "l4re" => {
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>

View file

@ -171,7 +171,7 @@ pub fn asm_const_to_str<'tcx>(
}
pub fn is_mingw_gnu_toolchain(target: &Target) -> bool {
target.vendor == "pc" && target.os == "windows" && target.env == "gnu" && target.abi.is_empty()
target.os == "windows" && target.env == "gnu" && target.abi.is_empty()
}
pub fn i686_decorated_name(

View file

@ -67,7 +67,7 @@ pub fn walk_native_lib_search_dirs<R>(
// FIXME: On AIX this also has the side-effect of making the list of library search paths
// non-empty, which is needed or the linker may decide to record the LIBPATH env, if
// defined, as the search path instead of appending the default search paths.
if sess.target.vendor == "fortanix"
if sess.target.abi == "fortanix"
|| sess.target.os == "linux"
|| sess.target.os == "fuchsia"
|| sess.target.is_like_aix

View file

@ -298,7 +298,7 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
ins_none!(sym::target_thread_local);
}
ins_str!(sym::target_vendor, &sess.target.vendor);
ins_sym!(sym::target_vendor, sess.target.vendor_symbol());
// If the user wants a test runner, then add the test cfg.
if sess.is_test_crate() {
@ -456,7 +456,7 @@ impl CheckCfg {
);
values_target_os.insert(Symbol::intern(&target.options.os));
values_target_pointer_width.insert(sym::integer(target.pointer_width));
values_target_vendor.insert(Symbol::intern(&target.options.vendor));
values_target_vendor.insert(target.vendor_symbol());
}
}
}

View file

@ -9,7 +9,9 @@
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
#![expect(internal_features)]
#![feature(iter_intersperse)]
#![feature(rustc_attrs)]
// tidy-alphabetical-end
use std::path::{Path, PathBuf};

View file

@ -1,10 +1,9 @@
use crate::spec::{LinkerFlavor, Lld, TargetOptions, base};
pub(crate) fn opts() -> TargetOptions {
let mut opts = base::windows_msvc::opts();
let mut opts =
TargetOptions { abi: "uwp".into(), vendor: "uwp".into(), ..base::windows_msvc::opts() };
opts.abi = "uwp".into();
opts.vendor = "uwp".into();
opts.add_pre_link_args(LinkerFlavor::Msvc(Lld::No), &["/APPCONTAINER", "mincore.lib"]);
opts

View file

@ -261,6 +261,7 @@ impl ToJson for Target {
($attr:ident) => {{ target_option_val!($attr, (stringify!($attr)).replace("_", "-")) }};
($attr:ident, $json_name:expr) => {{
let name = $json_name;
#[allow(rustc::bad_opt_access)]
if default.$attr != target.$attr {
d.insert(name.into(), target.$attr.to_json());
}

View file

@ -2045,6 +2045,7 @@ type StaticCow<T> = Cow<'static, T>;
/// construction, all its fields logically belong to `Target` and available from `Target`
/// through `Deref` impls.
#[derive(PartialEq, Clone, Debug)]
#[rustc_lint_opt_ty]
pub struct TargetOptions {
/// Used as the `target_endian` `cfg` variable. Defaults to little endian.
pub endian: Endian,
@ -2063,7 +2064,10 @@ pub struct TargetOptions {
/// However, parts of the backend do check this field for specific values to enable special behavior.
pub abi: StaticCow<str>,
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
pub vendor: StaticCow<str>,
#[rustc_lint_opt_deny_field_access(
"use `Target::is_like_*` instead of this field; see https://github.com/rust-lang/rust/issues/100343 for rationale"
)]
vendor: StaticCow<str>,
/// Linker to invoke
pub linker: Option<StaticCow<str>>,
@ -3323,6 +3327,10 @@ impl Target {
Align::MAX
}
}
pub fn vendor_symbol(&self) -> Symbol {
Symbol::intern(&self.vendor)
}
}
/// Either a target tuple string or a path to a JSON file.

View file

@ -1,15 +1,18 @@
use crate::spec::{
Arch, Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, TargetMetadata, base,
Arch, Cc, FramePointer, LinkerFlavor, Lld, RustcAbi, Target, TargetMetadata, TargetOptions,
base,
};
pub(crate) fn target() -> Target {
let mut base = base::windows_gnu::opts();
base.vendor = "win7".into();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
base.linker = Some("i686-w64-mingw32-gcc".into());
let mut base = TargetOptions {
vendor: "win7".into(),
rustc_abi: Some(RustcAbi::X86Sse2),
cpu: "pentium4".into(),
max_atomic_width: Some(64),
frame_pointer: FramePointer::Always, // Required for backtraces
linker: Some("i686-w64-mingw32-gcc".into()),
..base::windows_gnu::opts()
};
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.

View file

@ -1,18 +1,22 @@
use crate::spec::{Arch, LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, TargetMetadata, base};
use crate::spec::{
Arch, LinkerFlavor, Lld, RustcAbi, SanitizerSet, Target, TargetMetadata, TargetOptions, base,
};
pub(crate) fn target() -> Target {
let mut base = base::windows_msvc::opts();
base.vendor = "win7".into();
base.rustc_abi = Some(RustcAbi::X86Sse2);
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
// On Windows 7 32-bit, the alignment characteristic of the TLS Directory
// don't appear to be respected by the PE Loader, leading to crashes. As
// a result, let's disable has_thread_local to make sure TLS goes through
// the emulation layer.
// See https://github.com/rust-lang/rust/issues/138903
base.has_thread_local = false;
let mut base = TargetOptions {
vendor: "win7".into(),
rustc_abi: Some(RustcAbi::X86Sse2),
cpu: "pentium4".into(),
max_atomic_width: Some(64),
supported_sanitizers: SanitizerSet::ADDRESS,
// On Windows 7 32-bit, the alignment characteristic of the TLS Directory
// don't appear to be respected by the PE Loader, leading to crashes. As
// a result, let's disable has_thread_local to make sure TLS goes through
// the emulation layer.
// See https://github.com/rust-lang/rust/issues/138903
has_thread_local: false,
..base::windows_msvc::opts()
};
base.add_pre_link_args(
LinkerFlavor::Msvc(Lld::No),

View file

@ -1,15 +1,17 @@
use rustc_abi::Endian;
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, base};
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, TargetOptions, base};
pub(crate) fn target() -> Target {
let mut base = base::solaris::opts();
base.endian = Endian::Big;
let mut base = TargetOptions {
endian: Endian::Big,
// llvm calls this "v9"
cpu: "v9".into(),
vendor: "sun".into(),
max_atomic_width: Some(64),
..base::solaris::opts()
};
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64"]);
// llvm calls this "v9"
base.cpu = "v9".into();
base.vendor = "sun".into();
base.max_atomic_width = Some(64);
Target {
llvm_target: "sparcv9-sun-solaris".into(),

View file

@ -1,16 +1,19 @@
use crate::spec::{
Arch, Cc, LinkerFlavor, SanitizerSet, StackProbeType, Target, TargetMetadata, base,
Arch, Cc, LinkerFlavor, SanitizerSet, StackProbeType, Target, TargetMetadata, TargetOptions,
base,
};
pub(crate) fn target() -> Target {
let mut base = base::solaris::opts();
let mut base = TargetOptions {
cpu: "x86-64".into(),
plt_by_default: false,
vendor: "pc".into(),
max_atomic_width: Some(64),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD,
..base::solaris::opts()
};
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64"]);
base.cpu = "x86-64".into();
base.plt_by_default = false;
base.vendor = "pc".into();
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
Target {
llvm_target: "x86_64-pc-solaris".into(),

View file

@ -1,18 +1,20 @@
use crate::spec::{Arch, Cc, LinkerFlavor, Lld, Target, TargetMetadata, base};
use crate::spec::{Arch, Cc, LinkerFlavor, Lld, Target, TargetMetadata, TargetOptions, base};
pub(crate) fn target() -> Target {
let mut base = base::windows_gnu::opts();
base.vendor = "win7".into();
base.cpu = "x86-64".into();
base.plt_by_default = false;
let mut base = TargetOptions {
vendor: "win7".into(),
cpu: "x86-64".into(),
plt_by_default: false,
max_atomic_width: Some(64),
linker: Some("x86_64-w64-mingw32-gcc".into()),
..base::windows_gnu::opts()
};
// Use high-entropy 64 bit address space for ASLR
base.add_pre_link_args(
LinkerFlavor::Gnu(Cc::No, Lld::No),
&["-m", "i386pep", "--high-entropy-va"],
);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64", "-Wl,--high-entropy-va"]);
base.max_atomic_width = Some(64);
base.linker = Some("x86_64-w64-mingw32-gcc".into());
Target {
llvm_target: "x86_64-pc-windows-gnu".into(),

View file

@ -1,12 +1,14 @@
use crate::spec::{Arch, SanitizerSet, Target, TargetMetadata, base};
use crate::spec::{Arch, SanitizerSet, Target, TargetMetadata, TargetOptions, base};
pub(crate) fn target() -> Target {
let mut base = base::windows_msvc::opts();
base.vendor = "win7".into();
base.cpu = "x86-64".into();
base.plt_by_default = false;
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
let base = TargetOptions {
vendor: "win7".into(),
cpu: "x86-64".into(),
plt_by_default: false,
max_atomic_width: Some(64),
supported_sanitizers: SanitizerSet::ADDRESS,
..base::windows_msvc::opts()
};
Target {
llvm_target: "x86_64-pc-windows-msvc".into(),

View file

@ -715,7 +715,7 @@ impl<'tcx> MiriMachine<'tcx> {
match target.arch {
Arch::Wasm32 | Arch::Wasm64 => 64 * 1024, // https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
Arch::AArch64 => {
if target.options.vendor.as_ref() == "apple" {
if target.is_like_darwin {
// No "definitive" source, but see:
// https://www.wwdcnotes.com/notes/wwdc20/10214/
// https://github.com/ziglang/zig/issues/11308 etc.