]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
Auto merge of #83774 - richkadel:zero-based-counters, r=tmandry
[rust.git] / compiler / rustc_target / src / spec / x86_64_fortanix_unknown_sgx.rs
1 use std::iter;
2
3 use super::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions};
4
5 pub fn target() -> Target {
6     const PRE_LINK_ARGS: &[&str] = &[
7         "-e",
8         "elf_entry",
9         "-Bstatic",
10         "--gc-sections",
11         "-z",
12         "text",
13         "-z",
14         "norelro",
15         "--no-undefined",
16         "--error-unresolved-symbols",
17         "--no-undefined-version",
18         "-Bsymbolic",
19         "--export-dynamic",
20         // The following symbols are needed by libunwind, which is linked after
21         // libstd. Make sure they're included in the link.
22         "-u",
23         "__rust_abort",
24         "-u",
25         "__rust_c_alloc",
26         "-u",
27         "__rust_c_dealloc",
28         "-u",
29         "__rust_print_err",
30         "-u",
31         "__rust_rwlock_rdlock",
32         "-u",
33         "__rust_rwlock_unlock",
34         "-u",
35         "__rust_rwlock_wrlock",
36     ];
37
38     const EXPORT_SYMBOLS: &[&str] = &[
39         "sgx_entry",
40         "HEAP_BASE",
41         "HEAP_SIZE",
42         "RELA",
43         "RELACOUNT",
44         "ENCLAVE_SIZE",
45         "CFGDATA_BASE",
46         "DEBUG",
47         "EH_FRM_HDR_OFFSET",
48         "EH_FRM_HDR_LEN",
49         "EH_FRM_OFFSET",
50         "EH_FRM_LEN",
51         "TEXT_BASE",
52         "TEXT_SIZE",
53     ];
54     let opts = TargetOptions {
55         os: "unknown".into(),
56         env: "sgx".into(),
57         vendor: "fortanix".into(),
58         linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
59         dynamic_linking: false,
60         executables: true,
61         linker_is_gnu: true,
62         linker: Some("rust-lld".to_owned()),
63         max_atomic_width: Some(64),
64         panic_strategy: PanicStrategy::Unwind,
65         cpu: "x86-64".into(),
66         features: "+rdrnd,+rdseed,+lvi-cfi,+lvi-load-hardening".into(),
67         llvm_args: vec!["--x86-experimental-lvi-inline-asm-hardening".into()],
68         position_independent_executables: true,
69         pre_link_args: iter::once((
70             LinkerFlavor::Lld(LldFlavor::Ld),
71             PRE_LINK_ARGS.iter().cloned().map(String::from).collect(),
72         ))
73         .collect(),
74         override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()),
75         relax_elf_relocations: true,
76         ..Default::default()
77     };
78     Target {
79         llvm_target: "x86_64-elf".into(),
80         pointer_width: 64,
81         data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
82             .into(),
83         arch: "x86_64".into(),
84         options: opts,
85     }
86 }