Skip to content

Commit 9684c38

Browse files
committed
Add support for the x86_64h-apple-darwin target
1 parent 73c8d2d commit 9684c38

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

compiler/rustc_target/src/spec/apple_base.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum Arch {
1919
I386,
2020
I686,
2121
X86_64,
22+
X86_64h,
2223
X86_64_sim,
2324
X86_64_macabi,
2425
Arm64_macabi,
@@ -36,6 +37,7 @@ impl Arch {
3637
I386 => "i386",
3738
I686 => "i686",
3839
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
40+
X86_64h => "x86_64h",
3941
}
4042
}
4143

@@ -44,13 +46,13 @@ impl Arch {
4446
Armv7 | Armv7k | Armv7s => "arm",
4547
Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
4648
I386 | I686 => "x86",
47-
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
49+
X86_64 | X86_64_sim | X86_64_macabi | X86_64h => "x86_64",
4850
})
4951
}
5052

5153
fn target_abi(self) -> &'static str {
5254
match self {
53-
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 => "",
55+
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64h => "",
5456
X86_64_macabi | Arm64_macabi => "macabi",
5557
// x86_64-apple-ios is a simulator target, even though it isn't
5658
// declared that way in the target like the other ones...
@@ -67,6 +69,10 @@ impl Arch {
6769
Arm64_32 => "apple-s4",
6870
I386 | I686 => "yonah",
6971
X86_64 | X86_64_sim => "core2",
72+
// Note: `core-avx2` is slightly more advanced than `x86_64h`, see
73+
// comments (and disabled features) in `x86_64h_apple_darwin` for
74+
// details.
75+
X86_64h => "core-avx2",
7076
X86_64_macabi => "core2",
7177
Arm64_macabi => "apple-a12",
7278
Arm64_sim => "apple-a12",
@@ -182,8 +188,13 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
182188
}
183189

184190
fn macos_default_deployment_target(arch: Arch) -> (u32, u32) {
185-
// Note: Arm64_sim is not included since macOS has no simulator.
186-
if matches!(arch, Arm64 | Arm64_macabi) { (11, 0) } else { (10, 7) }
191+
match arch {
192+
// Note: Arm64_sim is not included since macOS has no simulator.
193+
Arm64 | Arm64_macabi => (11, 0),
194+
// x86_64h-apple-darwin only supports macOS 10.8 and later
195+
X86_64h => (10, 8),
196+
_ => (10, 7),
197+
}
187198
}
188199

189200
fn macos_deployment_target(arch: Arch) -> (u32, u32) {
@@ -227,7 +238,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
227238
// of the linking environment that's wrong and reversed.
228239
match arch {
229240
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
230-
| Arm64_sim => {
241+
| X86_64h | Arm64_sim => {
231242
cvs!["MACOSX_DEPLOYMENT_TARGET"]
232243
}
233244
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ supported_targets! {
11101110

11111111
("aarch64-apple-darwin", aarch64_apple_darwin),
11121112
("x86_64-apple-darwin", x86_64_apple_darwin),
1113+
("x86_64h-apple-darwin", x86_64h_apple_darwin),
11131114
("i686-apple-darwin", i686_apple_darwin),
11141115

11151116
// FIXME(#106649): Remove aarch64-fuchsia in favor of aarch64-unknown-fuchsia
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use super::apple_base::{macos_llvm_target, opts, Arch};
2+
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet};
3+
use crate::spec::{StackProbeType, Target, TargetOptions};
4+
5+
pub fn target() -> Target {
6+
let arch = Arch::X86_64h;
7+
let mut base = opts("macos", arch);
8+
base.max_atomic_width = Some(128);
9+
base.frame_pointer = FramePointer::Always;
10+
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
11+
base.stack_probes = StackProbeType::X86;
12+
base.supported_sanitizers =
13+
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;
14+
15+
// x86_64h is core2-avx without a few of the features which would otherwise
16+
// be guaranteed, so we need to disable those. This imitates clang's logic:
17+
// - https://github.com/llvm/llvm-project/blob/bd1f7c417/clang/lib/Driver/ToolChains/Arch/X86.cpp#L77-L78
18+
// - https://github.com/llvm/llvm-project/blob/bd1f7c417/clang/lib/Driver/ToolChains/Arch/X86.cpp#L133-L141
19+
//
20+
// FIXME: Sadly, turning these off here disables them in such a way that they
21+
// aren't re-enabled by `-Ctarget-cpu=native` (on a machine that has them).
22+
// It would be nice if this were not the case, but fixing it seems tricky
23+
// (and given that the main use-case for this target is for use in universal
24+
// binaries, probably not that important).
25+
base.features = "-rdrnd,-aes,-pclmul,-rtm,-fsgsbase".into();
26+
// Double-check that the `cpu` is what we expect (if it's not the list above
27+
// may need updating).
28+
assert_eq!(
29+
base.cpu, "core-avx2",
30+
"you need to adjust the feature list in x86_64h-apple-darwin if you change this",
31+
);
32+
33+
Target {
34+
// Clang automatically chooses a more specific target based on
35+
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
36+
// correctly, we do too.
37+
llvm_target: macos_llvm_target(arch).into(),
38+
pointer_width: 64,
39+
data_layout: "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
40+
.into(),
41+
arch: arch.target_arch(),
42+
options: TargetOptions { mcount: "\u{1}mcount".into(), ..base },
43+
}
44+
}

0 commit comments

Comments
 (0)