Skip to content

Commit

Permalink
Cleanup Apple target specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHoleFox committed Nov 5, 2022
1 parent de0ab1c commit ae948c6
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 109 deletions.
12 changes: 5 additions & 7 deletions compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ pub fn target() -> Target {

base.link_env_remove.to_mut().extend(macos_link_env_remove());

// Clang automatically chooses a more specific target based on
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
// correctly, we do too.
let llvm_target = macos_llvm_target(arch.target_name());

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
// correctly, we do too.
llvm_target: macos_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
mcount: "\u{1}mcount".into(),
frame_pointer: FramePointer::NonLeaf,
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_target/src/spec/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ use super::apple_base::{ios_llvm_target, opts, Arch};
use crate::spec::{FramePointer, Target, TargetOptions};

pub fn target() -> Target {
// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the target to pick the right
// MACH-O commands, so we do too.
let arch = Arch::Arm64;
let llvm_target = ios_llvm_target(arch);

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the target to pick the right
// MACH-O commands, so we do too.
llvm_target: ios_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".into(),
max_atomic_width: Some(128),
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions};
pub fn target() -> Target {
let llvm_target = "arm64-apple-ios14.0-macabi";

let mut base = opts("ios", Arch::Arm64_macabi);
let arch = Arch::Arm64_macabi;
let mut base = opts("ios", arch);
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-target", llvm_target]);

Target {
llvm_target: llvm_target.into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a12".into(),
max_atomic_width: Some(128),
Expand Down
18 changes: 7 additions & 11 deletions compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ use crate::spec::{FramePointer, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64_sim;
let base = opts("ios", arch);

// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the simulator target to pick the right
// MACH-O commands, so we do too.
let llvm_target = ios_sim_llvm_target(arch);

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the simulator target to pick the right
// MACH-O commands, so we do too.
llvm_target: ios_sim_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".into(),
max_atomic_width: Some(128),
Expand All @@ -32,7 +28,7 @@ pub fn target() -> Target {
darwinpcs\0\
-Os\0"
.into(),
..base
..opts("ios", arch)
},
}
}
5 changes: 3 additions & 2 deletions compiler/rustc_target/src/spec/aarch64_apple_tvos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use super::apple_base::{opts, Arch};
use crate::spec::{FramePointer, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64;
Target {
llvm_target: "arm64-apple-tvos".into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".into(),
max_atomic_width: Some(128),
forces_embed_bitcode: true,
frame_pointer: FramePointer::NonLeaf,
..opts("tvos", Arch::Arm64)
..opts("tvos", arch)
},
}
}
18 changes: 7 additions & 11 deletions compiler/rustc_target/src/spec/aarch64_apple_watchos_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ use crate::spec::{FramePointer, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64_sim;
let base = opts("watchos", arch);

// Clang automatically chooses a more specific target based on
// WATCHOS_DEPLOYMENT_TARGET.
// This is required for the simulator target to pick the right
// MACH-O commands, so we do too.
let llvm_target = watchos_sim_llvm_target(arch);

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// WATCHOS_DEPLOYMENT_TARGET.
// This is required for the simulator target to pick the right
// MACH-O commands, so we do too.
llvm_target: watchos_sim_llvm_target(arch).into(),
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: "aarch64".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a7".into(),
max_atomic_width: Some(128),
Expand All @@ -32,7 +28,7 @@ pub fn target() -> Target {
darwinpcs\0\
-Os\0"
.into(),
..base
..opts("watchos", arch)
},
}
}
39 changes: 27 additions & 12 deletions compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Arch {
Arm64,
Arm64_32,
I386,
I686,
X86_64,
X86_64_sim,
X86_64_macabi,
Expand All @@ -33,13 +34,23 @@ impl Arch {
Arm64 | Arm64_macabi | Arm64_sim => "arm64",
Arm64_32 => "arm64_32",
I386 => "i386",
I686 => "i686",
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
}
}

pub fn target_arch(self) -> Cow<'static, str> {
Cow::Borrowed(match self {
Armv7 | Armv7k | Armv7s => "arm",
Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
I386 | I686 => "x86",
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
})
}

fn target_abi(self) -> &'static str {
match self {
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 => "",
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 => "",
X86_64_macabi | Arm64_macabi => "macabi",
// x86_64-apple-ios is a simulator target, even though it isn't
// declared that way in the target like the other ones...
Expand All @@ -54,7 +65,7 @@ impl Arch {
Armv7s => "cortex-a9",
Arm64 => "apple-a7",
Arm64_32 => "apple-s4",
I386 => "yonah",
I386 | I686 => "yonah",
X86_64 | X86_64_sim => "core2",
X86_64_macabi => "core2",
Arm64_macabi => "apple-a12",
Expand All @@ -64,15 +75,16 @@ impl Arch {

fn link_env_remove(self) -> StaticCow<[StaticCow<str>]> {
match self {
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | X86_64_sim | Arm64_sim => {
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
| Arm64_sim => {
cvs!["MACOSX_DEPLOYMENT_TARGET"]
}
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
}
}
}

fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
let platform_name: StaticCow<str> = match abi {
"sim" => format!("{}-simulator", os).into(),
"macabi" => "mac-catalyst".into(),
Expand All @@ -88,6 +100,8 @@ fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> Lin
}
.into();

let arch = arch.target_name();

let mut args = TargetOptions::link_args(
LinkerFlavor::Darwin(Cc::No, Lld::No),
&["-arch", arch, "-platform_version"],
Expand Down Expand Up @@ -118,7 +132,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
// TLS is flagged as enabled if it looks to be supported. The architecture
// only matters for default deployment target which is 11.0 for ARM64 and
// 10.7 for everything else.
let has_thread_local = os == "macos" && macos_deployment_target("x86_64") >= (10, 7);
let has_thread_local = os == "macos" && macos_deployment_target(Arch::X86_64) >= (10, 7);

let abi = arch.target_abi();

Expand All @@ -132,7 +146,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
// macOS has -dead_strip, which doesn't rely on function_sections
function_sections: false,
dynamic_linking: true,
pre_link_args: pre_link_args(os, arch.target_name(), abi),
pre_link_args: pre_link_args(os, arch, abi),
families: cvs!["unix"],
is_like_osx: true,
default_dwarf_version: 2,
Expand Down Expand Up @@ -177,23 +191,24 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok())
}

fn macos_default_deployment_target(arch: &str) -> (u32, u32) {
if arch == "arm64" { (11, 0) } else { (10, 7) }
fn macos_default_deployment_target(arch: Arch) -> (u32, u32) {
// Note: Arm64_sim is not included since macOS has no simulator.
if matches!(arch, Arm64 | Arm64_macabi) { (11, 0) } else { (10, 7) }
}

fn macos_deployment_target(arch: &str) -> (u32, u32) {
fn macos_deployment_target(arch: Arch) -> (u32, u32) {
deployment_target("MACOSX_DEPLOYMENT_TARGET")
.unwrap_or_else(|| macos_default_deployment_target(arch))
}

fn macos_lld_platform_version(arch: &str) -> String {
fn macos_lld_platform_version(arch: Arch) -> String {
let (major, minor) = macos_deployment_target(arch);
format!("{}.{}", major, minor)
}

pub fn macos_llvm_target(arch: &str) -> String {
pub fn macos_llvm_target(arch: Arch) -> String {
let (major, minor) = macos_deployment_target(arch);
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
format!("{}-apple-macosx{}.{}.0", arch.target_name(), major, minor)
}

pub fn macos_link_env_remove() -> Vec<StaticCow<str>> {
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_target/src/spec/armv7_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use super::apple_base::{opts, Arch};
use super::apple_base::{ios_llvm_target, opts, Arch};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Armv7;
let llvm_target = super::apple_base::ios_llvm_target(arch);

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the target to pick the right
// MACH-O commands, so we do too.
llvm_target: ios_llvm_target(arch).into(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
arch: "arm".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+v7,+vfp3,+neon".into(),
max_atomic_width: Some(64),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/spec/armv7k_apple_watchos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use super::apple_base::{opts, Arch};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let base = opts("watchos", Arch::Armv7k);
let arch = Arch::Armv7k;
Target {
llvm_target: "armv7k-apple-watchos".into(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128".into(),
arch: "arm".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+v7,+vfp4,+neon".into(),
max_atomic_width: Some(64),
Expand All @@ -22,7 +22,7 @@ pub fn target() -> Target {
darwinpcs\0\
-Os\0"
.into(),
..base
..opts("watchos", arch)
},
}
}
5 changes: 3 additions & 2 deletions compiler/rustc_target/src/spec/armv7s_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use super::apple_base::{opts, Arch};
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Armv7s;
Target {
llvm_target: "armv7s-apple-ios".into(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
arch: "arm".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+v7,+vfp4,+neon".into(),
max_atomic_width: Some(64),
..opts("ios", Arch::Armv7s)
..opts("ios", arch)
},
}
}
15 changes: 8 additions & 7 deletions compiler/rustc_target/src/spec/i386_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use super::apple_base::{opts, Arch};
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
use crate::spec::{StackProbeType, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::I386;
let base = opts("ios", arch);
let llvm_target = super::apple_base::ios_sim_llvm_target(arch);

Target {
llvm_target: llvm_target.into(),
// Clang automatically chooses a more specific target based on
// IPHONEOS_DEPLOYMENT_TARGET.
// This is required for the target to pick the right
// MACH-O commands, so we do too.
llvm_target: ios_sim_llvm_target(arch).into(),
pointer_width: 32,
data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
f64:32:64-f80:128-n8:16:32-S128"
.into(),
arch: "x86".into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
stack_probes: StackProbeType::X86,
..base
..opts("ios", arch)
},
}
}
Loading

0 comments on commit ae948c6

Please sign in to comment.