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