Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 017c9aa

Browse files
authoredNov 9, 2022
Rollup merge of #103929 - BlackHoleFox:apple-targets-cleanup, r=petrochenkov
Cleanup Apple-related code in rustc_target While working on #103455, the consistency of the `rustc_target` code for Apple's platforms was "kind of bad." There were two "base" files (`apple_base.rs` and `apple_sdk_base.rs`) that the targets each pulled some parts out of, each and all of them were written slightly differently, and sometimes missed comments other implementations had. So to hopefully make future maintenance, like implementing rust-lang/compiler-team#556, easier, this makes all of them use similar patterns and the same target base logic everywhere instead of picking bits from both. This also has some other smaller upsides like less stringly-typed functions.
2 parents 3f11d39 + ae948c6 commit 017c9aa

20 files changed

+218
-221
lines changed
 

‎compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1+
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
12
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
23

34
pub fn target() -> Target {
4-
let arch = "arm64";
5-
let mut base = super::apple_base::opts("macos", arch, "");
5+
let arch = Arch::Arm64;
6+
let mut base = opts("macos", arch);
67
base.cpu = "apple-a14".into();
78
base.max_atomic_width = Some(128);
89

910
// FIXME: The leak sanitizer currently fails the tests, see #88132.
1011
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
1112

12-
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
13-
14-
// Clang automatically chooses a more specific target based on
15-
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
16-
// correctly, we do too.
17-
let llvm_target = super::apple_base::macos_llvm_target(arch);
13+
base.link_env_remove.to_mut().extend(macos_link_env_remove());
1814

1915
Target {
20-
llvm_target: llvm_target.into(),
16+
// Clang automatically chooses a more specific target based on
17+
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
18+
// correctly, we do too.
19+
llvm_target: macos_llvm_target(arch).into(),
2120
pointer_width: 64,
2221
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
23-
arch: "aarch64".into(),
22+
arch: arch.target_arch(),
2423
options: TargetOptions {
2524
mcount: "\u{1}mcount".into(),
2625
frame_pointer: FramePointer::NonLeaf,
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_llvm_target, opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
// Clang automatically chooses a more specific target based on
6-
// IPHONEOS_DEPLOYMENT_TARGET.
7-
// This is required for the target to pick the right
8-
// MACH-O commands, so we do too.
9-
let arch = "arm64";
10-
let llvm_target = super::apple_base::ios_llvm_target(arch);
11-
5+
let arch = Arch::Arm64;
126
Target {
13-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_llvm_target(arch).into(),
1412
pointer_width: 64,
1513
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
16-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1715
options: TargetOptions {
1816
features: "+neon,+fp-armv8,+apple-a7".into(),
1917
max_atomic_width: Some(128),
@@ -30,7 +28,7 @@ pub fn target() -> Target {
3028
darwinpcs\0\
3129
-Os\0"
3230
.into(),
33-
..opts("ios", Arch::Arm64)
31+
..opts("ios", arch)
3432
},
3533
}
3634
}

‎compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let llvm_target = "arm64-apple-ios14.0-macabi";
66

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

1011
Target {
1112
llvm_target: llvm_target.into(),
1213
pointer_width: 64,
1314
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
14-
arch: "aarch64".into(),
15+
arch: arch.target_arch(),
1516
options: TargetOptions {
1617
features: "+neon,+fp-armv8,+apple-a12".into(),
1718
max_atomic_width: Some(128),
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("ios", Arch::Arm64_sim);
6-
7-
// Clang automatically chooses a more specific target based on
8-
// IPHONEOS_DEPLOYMENT_TARGET.
9-
// This is required for the simulator target to pick the right
10-
// MACH-O commands, so we do too.
11-
let arch = "arm64";
12-
let llvm_target = super::apple_base::ios_sim_llvm_target(arch);
13-
5+
let arch = Arch::Arm64_sim;
146
Target {
15-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the simulator target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_sim_llvm_target(arch).into(),
1612
pointer_width: 64,
1713
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
18-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1915
options: TargetOptions {
2016
features: "+neon,+fp-armv8,+apple-a7".into(),
2117
max_atomic_width: Some(128),
@@ -32,7 +28,7 @@ pub fn target() -> Target {
3228
darwinpcs\0\
3329
-Os\0"
3430
.into(),
35-
..base
31+
..opts("ios", arch)
3632
},
3733
}
3834
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let arch = Arch::Arm64;
56
Target {
67
llvm_target: "arm64-apple-tvos".into(),
78
pointer_width: 64,
89
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
9-
arch: "aarch64".into(),
10+
arch: arch.target_arch(),
1011
options: TargetOptions {
1112
features: "+neon,+fp-armv8,+apple-a7".into(),
1213
max_atomic_width: Some(128),
1314
forces_embed_bitcode: true,
1415
frame_pointer: FramePointer::NonLeaf,
15-
..opts("tvos", Arch::Arm64)
16+
..opts("tvos", arch)
1617
},
1718
}
1819
}
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, watchos_sim_llvm_target, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("watchos", Arch::Arm64_sim);
6-
7-
// Clang automatically chooses a more specific target based on
8-
// WATCHOS_DEPLOYMENT_TARGET.
9-
// This is required for the simulator target to pick the right
10-
// MACH-O commands, so we do too.
11-
let arch = "arm64";
12-
let llvm_target = super::apple_base::watchos_sim_llvm_target(arch);
13-
5+
let arch = Arch::Arm64_sim;
146
Target {
15-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// WATCHOS_DEPLOYMENT_TARGET.
9+
// This is required for the simulator target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: watchos_sim_llvm_target(arch).into(),
1612
pointer_width: 64,
1713
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
18-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1915
options: TargetOptions {
2016
features: "+neon,+fp-armv8,+apple-a7".into(),
2117
max_atomic_width: Some(128),
@@ -32,7 +28,7 @@ pub fn target() -> Target {
3228
darwinpcs\0\
3329
-Os\0"
3430
.into(),
35-
..base
31+
..opts("watchos", arch)
3632
},
3733
}
3834
}

‎compiler/rustc_target/src/spec/apple_base.rs

Lines changed: 107 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,88 @@ use std::{borrow::Cow, env};
33
use crate::spec::{cvs, Cc, DebuginfoKind, FramePointer, LinkArgs};
44
use crate::spec::{LinkerFlavor, Lld, SplitDebuginfo, StaticCow, TargetOptions};
55

6-
fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
6+
#[cfg(test)]
7+
#[path = "apple/tests.rs"]
8+
mod tests;
9+
10+
use Arch::*;
11+
#[allow(non_camel_case_types)]
12+
#[derive(Copy, Clone)]
13+
pub enum Arch {
14+
Armv7,
15+
Armv7k,
16+
Armv7s,
17+
Arm64,
18+
Arm64_32,
19+
I386,
20+
I686,
21+
X86_64,
22+
X86_64_sim,
23+
X86_64_macabi,
24+
Arm64_macabi,
25+
Arm64_sim,
26+
}
27+
28+
impl Arch {
29+
pub fn target_name(self) -> &'static str {
30+
match self {
31+
Armv7 => "armv7",
32+
Armv7k => "armv7k",
33+
Armv7s => "armv7s",
34+
Arm64 | Arm64_macabi | Arm64_sim => "arm64",
35+
Arm64_32 => "arm64_32",
36+
I386 => "i386",
37+
I686 => "i686",
38+
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
39+
}
40+
}
41+
42+
pub fn target_arch(self) -> Cow<'static, str> {
43+
Cow::Borrowed(match self {
44+
Armv7 | Armv7k | Armv7s => "arm",
45+
Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
46+
I386 | I686 => "x86",
47+
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
48+
})
49+
}
50+
51+
fn target_abi(self) -> &'static str {
52+
match self {
53+
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 => "",
54+
X86_64_macabi | Arm64_macabi => "macabi",
55+
// x86_64-apple-ios is a simulator target, even though it isn't
56+
// declared that way in the target like the other ones...
57+
Arm64_sim | X86_64_sim => "sim",
58+
}
59+
}
60+
61+
fn target_cpu(self) -> &'static str {
62+
match self {
63+
Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
64+
Armv7k => "cortex-a8",
65+
Armv7s => "cortex-a9",
66+
Arm64 => "apple-a7",
67+
Arm64_32 => "apple-s4",
68+
I386 | I686 => "yonah",
69+
X86_64 | X86_64_sim => "core2",
70+
X86_64_macabi => "core2",
71+
Arm64_macabi => "apple-a12",
72+
Arm64_sim => "apple-a12",
73+
}
74+
}
75+
76+
fn link_env_remove(self) -> StaticCow<[StaticCow<str>]> {
77+
match self {
78+
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
79+
| Arm64_sim => {
80+
cvs!["MACOSX_DEPLOYMENT_TARGET"]
81+
}
82+
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
83+
}
84+
}
85+
}
86+
87+
fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
788
let platform_name: StaticCow<str> = match abi {
889
"sim" => format!("{}-simulator", os).into(),
990
"macabi" => "mac-catalyst".into(),
@@ -19,6 +100,8 @@ fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> Lin
19100
}
20101
.into();
21102

103+
let arch = arch.target_name();
104+
22105
let mut args = TargetOptions::link_args(
23106
LinkerFlavor::Darwin(Cc::No, Lld::No),
24107
&["-arch", arch, "-platform_version"],
@@ -35,24 +118,29 @@ fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> Lin
35118
args
36119
}
37120

38-
pub fn opts(os: &'static str, arch: &'static str, abi: &'static str) -> TargetOptions {
39-
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
121+
pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
122+
// Static TLS is only available in macOS 10.7+. If you try to compile for 10.6
40123
// either the linker will complain if it is used or the binary will end up
41124
// segfaulting at runtime when run on 10.6. Rust by default supports macOS
42125
// 10.7+, but there is a standard environment variable,
43126
// MACOSX_DEPLOYMENT_TARGET, which is used to signal targeting older
44127
// versions of macOS. For example compiling on 10.10 with
45128
// MACOSX_DEPLOYMENT_TARGET set to 10.6 will cause the linker to generate
46-
// warnings about the usage of ELF TLS.
129+
// warnings about the usage of static TLS.
47130
//
48-
// Here we detect what version is being requested, defaulting to 10.7. ELF
131+
// Here we detect what version is being requested, defaulting to 10.7. Static
49132
// TLS is flagged as enabled if it looks to be supported. The architecture
50133
// only matters for default deployment target which is 11.0 for ARM64 and
51134
// 10.7 for everything else.
52-
let has_thread_local = macos_deployment_target("x86_64") >= (10, 7);
135+
let has_thread_local = os == "macos" && macos_deployment_target(Arch::X86_64) >= (10, 7);
136+
137+
let abi = arch.target_abi();
53138

54139
TargetOptions {
140+
abi: abi.into(),
55141
os: os.into(),
142+
cpu: arch.target_cpu().into(),
143+
link_env_remove: arch.link_env_remove(),
56144
vendor: "apple".into(),
57145
linker_flavor: LinkerFlavor::Darwin(Cc::Yes, Lld::No),
58146
// macOS has -dead_strip, which doesn't rely on function_sections
@@ -103,23 +191,24 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
103191
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok())
104192
}
105193

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

110-
fn macos_deployment_target(arch: &str) -> (u32, u32) {
199+
fn macos_deployment_target(arch: Arch) -> (u32, u32) {
111200
deployment_target("MACOSX_DEPLOYMENT_TARGET")
112201
.unwrap_or_else(|| macos_default_deployment_target(arch))
113202
}
114203

115-
fn macos_lld_platform_version(arch: &str) -> String {
204+
fn macos_lld_platform_version(arch: Arch) -> String {
116205
let (major, minor) = macos_deployment_target(arch);
117206
format!("{}.{}", major, minor)
118207
}
119208

120-
pub fn macos_llvm_target(arch: &str) -> String {
209+
pub fn macos_llvm_target(arch: Arch) -> String {
121210
let (major, minor) = macos_deployment_target(arch);
122-
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
211+
format!("{}-apple-macosx{}.{}.0", arch.target_name(), major, minor)
123212
}
124213

125214
pub fn macos_link_env_remove() -> Vec<StaticCow<str>> {
@@ -142,25 +231,25 @@ fn ios_deployment_target() -> (u32, u32) {
142231
deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
143232
}
144233

145-
pub fn ios_llvm_target(arch: &str) -> String {
234+
pub fn ios_llvm_target(arch: Arch) -> String {
146235
// Modern iOS tooling extracts information about deployment target
147236
// from LC_BUILD_VERSION. This load command will only be emitted when
148237
// we build with a version specific `llvm_target`, with the version
149238
// set high enough. Luckily one LC_BUILD_VERSION is enough, for Xcode
150239
// to pick it up (since std and core are still built with the fallback
151240
// of version 7.0 and hence emit the old LC_IPHONE_MIN_VERSION).
152241
let (major, minor) = ios_deployment_target();
153-
format!("{}-apple-ios{}.{}.0", arch, major, minor)
242+
format!("{}-apple-ios{}.{}.0", arch.target_name(), major, minor)
154243
}
155244

156245
fn ios_lld_platform_version() -> String {
157246
let (major, minor) = ios_deployment_target();
158247
format!("{}.{}", major, minor)
159248
}
160249

161-
pub fn ios_sim_llvm_target(arch: &str) -> String {
250+
pub fn ios_sim_llvm_target(arch: Arch) -> String {
162251
let (major, minor) = ios_deployment_target();
163-
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
252+
format!("{}-apple-ios{}.{}.0-simulator", arch.target_name(), major, minor)
164253
}
165254

166255
fn tvos_deployment_target() -> (u32, u32) {
@@ -181,7 +270,7 @@ fn watchos_lld_platform_version() -> String {
181270
format!("{}.{}", major, minor)
182271
}
183272

184-
pub fn watchos_sim_llvm_target(arch: &str) -> String {
273+
pub fn watchos_sim_llvm_target(arch: Arch) -> String {
185274
let (major, minor) = watchos_deployment_target();
186-
format!("{}-apple-watchos{}.{}.0-simulator", arch, major, minor)
275+
format!("{}-apple-watchos{}.{}.0-simulator", arch.target_name(), major, minor)
187276
}

‎compiler/rustc_target/src/spec/apple_sdk_base.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.

‎compiler/rustc_target/src/spec/arm64_32_apple_watchos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_llvm_target, opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let llvm_target = super::apple_base::ios_llvm_target("armv7");
6-
5+
let arch = Arch::Armv7;
76
Target {
8-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_llvm_target(arch).into(),
912
pointer_width: 32,
1013
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
11-
arch: "arm".into(),
14+
arch: arch.target_arch(),
1215
options: TargetOptions {
1316
features: "+v7,+vfp3,+neon".into(),
1417
max_atomic_width: Some(64),
15-
..opts("ios", Arch::Armv7)
18+
..opts("ios", arch)
1619
},
1720
}
1821
}

‎compiler/rustc_target/src/spec/armv7k_apple_watchos.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("watchos", Arch::Armv7k);
5+
let arch = Arch::Armv7k;
66
Target {
77
llvm_target: "armv7k-apple-watchos".into(),
88
pointer_width: 32,
99
data_layout: "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128".into(),
10-
arch: "arm".into(),
10+
arch: arch.target_arch(),
1111
options: TargetOptions {
1212
features: "+v7,+vfp4,+neon".into(),
1313
max_atomic_width: Some(64),
@@ -22,7 +22,7 @@ pub fn target() -> Target {
2222
darwinpcs\0\
2323
-Os\0"
2424
.into(),
25-
..base
25+
..opts("watchos", arch)
2626
},
2727
}
2828
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let arch = Arch::Armv7s;
56
Target {
67
llvm_target: "armv7s-apple-ios".into(),
78
pointer_width: 32,
89
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
9-
arch: "arm".into(),
10+
arch: arch.target_arch(),
1011
options: TargetOptions {
1112
features: "+v7,+vfp4,+neon".into(),
1213
max_atomic_width: Some(64),
13-
..opts("ios", Arch::Armv7s)
14+
..opts("ios", arch)
1415
},
1516
}
1617
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("ios", Arch::I386);
6-
let llvm_target = super::apple_base::ios_sim_llvm_target("i386");
7-
5+
let arch = Arch::I386;
86
Target {
9-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_sim_llvm_target(arch).into(),
1012
pointer_width: 32,
1113
data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
1214
f64:32:64-f80:128-n8:16:32-S128"
1315
.into(),
14-
arch: "x86".into(),
16+
arch: arch.target_arch(),
1517
options: TargetOptions {
1618
max_atomic_width: Some(64),
1719
stack_probes: StackProbeType::X86,
18-
..base
20+
..opts("ios", arch)
1921
},
2022
}
2123
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1+
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
12
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions};
23

34
pub fn target() -> Target {
4-
// ld64 only understand i386 and not i686
5-
let mut base = super::apple_base::opts("macos", "i386", "");
6-
base.cpu = "yonah".into();
5+
// ld64 only understands i386 and not i686
6+
let arch = Arch::I386;
7+
let mut base = opts("macos", arch);
78
base.max_atomic_width = Some(64);
89
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
9-
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
10+
base.link_env_remove.to_mut().extend(macos_link_env_remove());
1011
base.stack_probes = StackProbeType::X86;
1112
base.frame_pointer = FramePointer::Always;
1213

13-
// Clang automatically chooses a more specific target based on
14-
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
15-
// correctly, we do too.
16-
let arch = "i686";
17-
let llvm_target = super::apple_base::macos_llvm_target(&arch);
18-
1914
Target {
20-
llvm_target: llvm_target.into(),
15+
// Clang automatically chooses a more specific target based on
16+
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
17+
// correctly, we do too.
18+
//
19+
// While ld64 doesn't understand i686, LLVM does.
20+
llvm_target: macos_llvm_target(Arch::I686).into(),
2121
pointer_width: 32,
2222
data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
2323
f64:32:64-f80:128-n8:16:32-S128"
2424
.into(),
25-
arch: "x86".into(),
25+
arch: arch.target_arch(),
2626
options: TargetOptions { mcount: "\u{1}mcount".into(), ..base },
2727
}
2828
}

‎compiler/rustc_target/src/spec/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub mod crt_objects;
5959

6060
mod android_base;
6161
mod apple_base;
62-
mod apple_sdk_base;
6362
mod avr_gnu_base;
6463
mod bpf_base;
6564
mod dragonfly_base;
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1+
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
12
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet};
23
use crate::spec::{StackProbeType, Target, TargetOptions};
34

45
pub fn target() -> Target {
5-
let arch = "x86_64";
6-
let mut base = super::apple_base::opts("macos", arch, "");
7-
base.cpu = "core2".into();
8-
base.max_atomic_width = Some(128); // core2 support cmpxchg16b
6+
let arch = Arch::X86_64;
7+
let mut base = opts("macos", arch);
8+
base.max_atomic_width = Some(128); // core2 supports cmpxchg16b
99
base.frame_pointer = FramePointer::Always;
1010
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
11-
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
11+
base.link_env_remove.to_mut().extend(macos_link_env_remove());
1212
base.stack_probes = StackProbeType::X86;
1313
base.supported_sanitizers =
1414
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;
1515

16-
// Clang automatically chooses a more specific target based on
17-
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
18-
// correctly, we do too.
19-
let llvm_target = super::apple_base::macos_llvm_target(&arch);
20-
2116
Target {
22-
llvm_target: llvm_target.into(),
17+
// Clang automatically chooses a more specific target based on
18+
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
19+
// correctly, we do too.
20+
llvm_target: macos_llvm_target(arch).into(),
2321
pointer_width: 64,
2422
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2523
.into(),
26-
arch: arch.into(),
24+
arch: arch.target_arch(),
2725
options: TargetOptions { mcount: "\u{1}mcount".into(), ..base },
2826
}
2927
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("ios", Arch::X86_64_sim);
6-
let llvm_target = super::apple_base::ios_sim_llvm_target("x86_64");
7-
5+
let arch = Arch::X86_64_sim;
86
Target {
9-
llvm_target: llvm_target.into(),
7+
llvm_target: ios_sim_llvm_target(arch).into(),
108
pointer_width: 64,
119
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1210
.into(),
13-
arch: "x86_64".into(),
11+
arch: arch.target_arch(),
1412
options: TargetOptions {
1513
max_atomic_width: Some(64),
1614
stack_probes: StackProbeType::X86,
17-
..base
15+
..opts("ios", arch)
1816
},
1917
}
2018
}

‎compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let llvm_target = "x86_64-apple-ios13.0-macabi";
66

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

1011
Target {
1112
llvm_target: llvm_target.into(),
1213
pointer_width: 64,
1314
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1415
.into(),
15-
arch: "x86_64".into(),
16+
arch: arch.target_arch(),
1617
options: TargetOptions {
1718
max_atomic_width: Some(64),
1819
stack_probes: StackProbeType::X86,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("tvos", Arch::X86_64_sim);
5+
let arch = Arch::X86_64_sim;
66
Target {
77
llvm_target: "x86_64-apple-tvos".into(),
88
pointer_width: 64,
99
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(),
10-
arch: "x86_64".into(),
10+
arch: arch.target_arch(),
1111
options: TargetOptions {
1212
max_atomic_width: Some(64),
1313
stack_probes: StackProbeType::X86,
14-
..base
14+
..opts("tvos", arch)
1515
},
1616
}
1717
}
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, watchos_sim_llvm_target, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("watchos", Arch::X86_64_sim);
6-
7-
let arch = "x86_64";
8-
let llvm_target = super::apple_base::watchos_sim_llvm_target(arch);
9-
5+
let arch = Arch::X86_64_sim;
106
Target {
11-
llvm_target: llvm_target.into(),
7+
llvm_target: watchos_sim_llvm_target(arch).into(),
128
pointer_width: 64,
139
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1410
.into(),
15-
arch: "x86_64".into(),
11+
arch: arch.target_arch(),
1612
options: TargetOptions {
1713
max_atomic_width: Some(64),
1814
stack_probes: StackProbeType::X86,
@@ -28,7 +24,7 @@ pub fn target() -> Target {
2824
darwinpcs\0\
2925
-Os\0"
3026
.into(),
31-
..base
27+
..opts("watchos", arch)
3228
},
3329
}
3430
}

0 commit comments

Comments
 (0)
Please sign in to comment.