]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs
46cf4cd8ae3530dd9ac6c0e68588be969b4d4b46
[rust.git] / src / librustc_target / spec / x86_64_fortanix_unknown_sgx.rs
1 use std::iter;
2
3 use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions};
4
5 pub fn target() -> Result<Target, String> {
6     const PRE_LINK_ARGS: &[&str] = &[
7         "-Wl,--as-needed",
8         "-Wl,-z,noexecstack",
9         "-m64",
10         "-fuse-ld=gold",
11         "-nostdlib",
12         "-shared",
13         "-Wl,-e,sgx_entry",
14         "-Wl,-Bstatic",
15         "-Wl,--gc-sections",
16         "-Wl,-z,text",
17         "-Wl,-z,norelro",
18         "-Wl,--rosegment",
19         "-Wl,--no-undefined",
20         "-Wl,--error-unresolved-symbols",
21         "-Wl,--no-undefined-version",
22         "-Wl,-Bsymbolic",
23         "-Wl,--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         "-Wl,-u,__rust_abort",
27         "-Wl,-u,__rust_c_alloc",
28         "-Wl,-u,__rust_c_dealloc",
29         "-Wl,-u,__rust_print_err",
30         "-Wl,-u,__rust_rwlock_rdlock",
31         "-Wl,-u,__rust_rwlock_unlock",
32         "-Wl,-u,__rust_rwlock_wrlock",
33     ];
34
35     const EXPORT_SYMBOLS: &[&str] = &[
36         "sgx_entry",
37         "HEAP_BASE",
38         "HEAP_SIZE",
39         "RELA",
40         "RELACOUNT",
41         "ENCLAVE_SIZE",
42         "CFGDATA_BASE",
43         "DEBUG",
44         "EH_FRM_HDR_BASE",
45         "EH_FRM_HDR_SIZE",
46         "TEXT_BASE",
47         "TEXT_SIZE",
48     ];
49     let opts = TargetOptions {
50         dynamic_linking: false,
51         executables: true,
52         linker_is_gnu: true,
53         max_atomic_width: Some(64),
54         panic_strategy: PanicStrategy::Unwind,
55         cpu: "x86-64".into(),
56         features: "+rdrnd,+rdseed".into(),
57         position_independent_executables: true,
58         pre_link_args: iter::once((
59             LinkerFlavor::Gcc,
60             PRE_LINK_ARGS.iter().cloned().map(String::from).collect(),
61         ))
62         .collect(),
63         post_link_objects: vec!["libunwind.a".into()],
64         override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()),
65         ..Default::default()
66     };
67     Ok(Target {
68         llvm_target: "x86_64-unknown-linux-gnu".into(),
69         target_endian: "little".into(),
70         target_pointer_width: "64".into(),
71         target_c_int_width: "32".into(),
72         target_os: "unknown".into(),
73         target_env: "sgx".into(),
74         target_vendor: "fortanix".into(),
75         data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".into(),
76         arch: "x86_64".into(),
77         linker_flavor: LinkerFlavor::Gcc,
78         options: opts,
79     })
80 }