Skip to content

Commit 9e2e575

Browse files
author
Jethro Beekman
committed
Add x86_64-fortanix-unknown-sgx target to the compiler
1 parent a44e446 commit 9e2e575

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/librustc_target/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ supported_targets! {
412412
("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
413413

414414
("aarch64-unknown-none", aarch64_unknown_none),
415+
416+
("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx),
415417
}
416418

417419
/// Everything `rustc` knows about how to compile for a specific target.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::iter;
12+
13+
use super::{LinkerFlavor, Target, TargetOptions, PanicStrategy};
14+
15+
pub fn target() -> Result<Target, String> {
16+
const PRE_LINK_ARGS: &[&str] = &[
17+
"-Wl,--as-needed",
18+
"-Wl,-z,noexecstack",
19+
"-m64",
20+
"-fuse-ld=gold",
21+
"-nostdlib",
22+
"-shared",
23+
"-Wl,-e,sgx_entry",
24+
"-Wl,-Bstatic",
25+
"-Wl,--gc-sections",
26+
"-Wl,-z,text",
27+
"-Wl,-z,norelro",
28+
"-Wl,--rosegment",
29+
"-Wl,--no-undefined",
30+
"-Wl,--error-unresolved-symbols",
31+
"-Wl,--no-undefined-version",
32+
"-Wl,-Bsymbolic",
33+
"-Wl,--export-dynamic",
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+
];
45+
let opts = TargetOptions {
46+
dynamic_linking: false,
47+
executables: true,
48+
linker_is_gnu: true,
49+
max_atomic_width: Some(64),
50+
panic_strategy: PanicStrategy::Abort,
51+
cpu: "x86-64".into(),
52+
position_independent_executables: true,
53+
pre_link_args: iter::once(
54+
(LinkerFlavor::Gcc, PRE_LINK_ARGS.iter().cloned().map(String::from).collect())
55+
).collect(),
56+
override_export_symbols: Some(EXPORT_SYMBOLS.iter().cloned().map(String::from).collect()),
57+
..Default::default()
58+
};
59+
Ok(Target {
60+
llvm_target: "x86_64-unknown-linux-gnu".into(),
61+
target_endian: "little".into(),
62+
target_pointer_width: "64".into(),
63+
target_c_int_width: "32".into(),
64+
target_os: "unknown".into(),
65+
target_env: "sgx".into(),
66+
target_vendor: "fortanix".into(),
67+
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".into(),
68+
arch: "x86_64".into(),
69+
linker_flavor: LinkerFlavor::Gcc,
70+
options: opts,
71+
})
72+
}

0 commit comments

Comments
 (0)