]> git.proxmox.com Git - rustc.git/blob - src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs
New upstream version 1.41.1+dfsg1
[rustc.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" , "noexecstack",
10 "-e","elf_entry",
11 "-Bstatic",
12 "--gc-sections",
13 "-z","text",
14 "-z","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","__rust_abort",
23 "-u","__rust_c_alloc",
24 "-u","__rust_c_dealloc",
25 "-u","__rust_print_err",
26 "-u","__rust_rwlock_rdlock",
27 "-u","__rust_rwlock_unlock",
28 "-u","__rust_rwlock_wrlock"
29 ];
30
31 const EXPORT_SYMBOLS: &[&str] = &[
32 "sgx_entry",
33 "HEAP_BASE",
34 "HEAP_SIZE",
35 "RELA",
36 "RELACOUNT",
37 "ENCLAVE_SIZE",
38 "CFGDATA_BASE",
39 "DEBUG",
40 "EH_FRM_HDR_BASE",
41 "EH_FRM_HDR_SIZE",
42 "TEXT_BASE",
43 "TEXT_SIZE",
44 ];
45 let opts = TargetOptions {
46 dynamic_linking: false,
47 executables: true,
48 linker_is_gnu: true,
49 linker: Some("rust-lld".to_owned()),
50 max_atomic_width: Some(64),
51 panic_strategy: PanicStrategy::Unwind,
52 cpu: "x86-64".into(),
53 features: "+rdrnd,+rdseed".into(),
54 position_independent_executables: true,
55 pre_link_args: iter::once((
56 LinkerFlavor::Lld(LldFlavor::Ld),
57 PRE_LINK_ARGS.iter().cloned().map(String::from).collect(),
58 ))
59 .collect(),
60 post_link_objects: vec!["libunwind.a".into()],
61 override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()),
62 relax_elf_relocations: true,
63 ..Default::default()
64 };
65 Ok(Target {
66 llvm_target: "x86_64-elf".into(),
67 target_endian: "little".into(),
68 target_pointer_width: "64".into(),
69 target_c_int_width: "32".into(),
70 target_os: "unknown".into(),
71 target_env: "sgx".into(),
72 target_vendor: "fortanix".into(),
73 data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".into(),
74 arch: "x86_64".into(),
75 linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
76 options: opts,
77 })
78 }