]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs
Auto merge of #68414 - michaelwoerister:share-drop-glue, r=alexcrichton
[rust.git] / src / librustc_target / 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() -> Result<Target, String> {
6     const PRE_LINK_ARGS: &[&str] = &[
7         "--as-needed",
8         "--eh-frame-hdr",
9         "-z",
10         "noexecstack",
11         "-e",
12         "elf_entry",
13         "-Bstatic",
14         "--gc-sections",
15         "-z",
16         "text",
17         "-z",
18         "norelro",
19         "--no-undefined",
20         "--error-unresolved-symbols",
21         "--no-undefined-version",
22         "-Bsymbolic",
23         "--export-dynamic",
24         // The following symbols are needed by libunwind, which is linked after
25         // libstd. Make sure they're included in the link.
26         "-u",
27         "__rust_abort",
28         "-u",
29         "__rust_c_alloc",
30         "-u",
31         "__rust_c_dealloc",
32         "-u",
33         "__rust_print_err",
34         "-u",
35         "__rust_rwlock_rdlock",
36         "-u",
37         "__rust_rwlock_unlock",
38         "-u",
39         "__rust_rwlock_wrlock",
40     ];
41
42     const EXPORT_SYMBOLS: &[&str] = &[
43         "sgx_entry",
44         "HEAP_BASE",
45         "HEAP_SIZE",
46         "RELA",
47         "RELACOUNT",
48         "ENCLAVE_SIZE",
49         "CFGDATA_BASE",
50         "DEBUG",
51         "EH_FRM_HDR_BASE",
52         "EH_FRM_HDR_SIZE",
53         "TEXT_BASE",
54         "TEXT_SIZE",
55     ];
56     let opts = TargetOptions {
57         dynamic_linking: false,
58         executables: true,
59         linker_is_gnu: true,
60         linker: Some("rust-lld".to_owned()),
61         max_atomic_width: Some(64),
62         panic_strategy: PanicStrategy::Unwind,
63         cpu: "x86-64".into(),
64         features: "+rdrnd,+rdseed".into(),
65         position_independent_executables: true,
66         pre_link_args: iter::once((
67             LinkerFlavor::Lld(LldFlavor::Ld),
68             PRE_LINK_ARGS.iter().cloned().map(String::from).collect(),
69         ))
70         .collect(),
71         post_link_objects: vec!["libunwind.a".into()],
72         override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()),
73         relax_elf_relocations: true,
74         ..Default::default()
75     };
76     Ok(Target {
77         llvm_target: "x86_64-elf".into(),
78         target_endian: "little".into(),
79         target_pointer_width: "64".into(),
80         target_c_int_width: "32".into(),
81         target_os: "unknown".into(),
82         target_env: "sgx".into(),
83         target_vendor: "fortanix".into(),
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         linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
88         options: opts,
89     })
90 }