rustc_target/spec/targets/
x86_64h_apple_darwin.rs

1use crate::spec::base::apple::{Arch, TargetAbi, base};
2use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
3
4pub(crate) fn target() -> Target {
5    let (mut opts, llvm_target, arch) = base("macos", Arch::X86_64h, TargetAbi::Normal);
6    opts.max_atomic_width = Some(128);
7    opts.frame_pointer = FramePointer::Always;
8    opts.supported_sanitizers =
9        SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;
10
11    // x86_64h is core2-avx without a few of the features which would otherwise
12    // be guaranteed, so we need to disable those. This imitates clang's logic:
13    // - https://github.com/llvm/llvm-project/blob/bd1f7c417/clang/lib/Driver/ToolChains/Arch/X86.cpp#L77-L78
14    // - https://github.com/llvm/llvm-project/blob/bd1f7c417/clang/lib/Driver/ToolChains/Arch/X86.cpp#L133-L141
15    //
16    // FIXME: Sadly, turning these off here disables them in such a way that they
17    // aren't re-enabled by `-Ctarget-cpu=native` (on a machine that has them).
18    // It would be nice if this were not the case, but fixing it seems tricky
19    // (and given that the main use-case for this target is for use in universal
20    // binaries, probably not that important).
21    opts.features = "-rdrnd,-aes,-pclmul,-rtm,-fsgsbase".into();
22    // Double-check that the `cpu` is what we expect (if it's not the list above
23    // may need updating).
24    assert_eq!(
25        opts.cpu, "core-avx2",
26        "you need to adjust the feature list in x86_64h-apple-darwin if you change this",
27    );
28
29    Target {
30        llvm_target,
31        metadata: crate::spec::TargetMetadata {
32            description: Some("x86_64 Apple macOS with Intel Haswell+".into()),
33            tier: Some(3),
34            host_tools: Some(true),
35            std: Some(true),
36        },
37        pointer_width: 64,
38        data_layout:
39            "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
40        arch,
41        options: TargetOptions { mcount: "\u{1}mcount".into(), ..opts },
42    }
43}