Skip to content

Commit 740e70b

Browse files
author
Jethro Beekman
committed
Add x86_64-fortanix-unknown-sgx target to libstd and dependencies
The files src/libstd/sys/sgx/*.rs are mostly copied/adapted from the wasm target. This also updates the dlmalloc submodule to the very latest version.
1 parent 27e17a9 commit 740e70b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2888
-42
lines changed

src/Cargo.lock

+11-25
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ dependencies = [
185185
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
186186
"core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
187187
"crates-io 0.21.0",
188-
"crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
188+
"crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
189189
"crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
190190
"curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
191191
"curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
192-
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
192+
"env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
193193
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
194194
"filetime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
195195
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -539,14 +539,6 @@ name = "crossbeam-utils"
539539
version = "0.5.0"
540540
source = "registry+https://github.com/rust-lang/crates.io-index"
541541

542-
[[package]]
543-
name = "crossbeam-utils"
544-
version = "0.6.1"
545-
source = "registry+https://github.com/rust-lang/crates.io-index"
546-
dependencies = [
547-
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
548-
]
549-
550542
[[package]]
551543
name = "crypto-hash"
552544
version = "0.3.1"
@@ -670,18 +662,6 @@ dependencies = [
670662
"termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
671663
]
672664

673-
[[package]]
674-
name = "env_logger"
675-
version = "0.6.0"
676-
source = "registry+https://github.com/rust-lang/crates.io-index"
677-
dependencies = [
678-
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
679-
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
680-
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
681-
"regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
682-
"termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
683-
]
684-
685665
[[package]]
686666
name = "environment"
687667
version = "0.1.1"
@@ -751,7 +731,6 @@ version = "1.0.3"
751731
source = "registry+https://github.com/rust-lang/crates.io-index"
752732
dependencies = [
753733
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
754-
"libz-sys 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
755734
"miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
756735
]
757736

@@ -777,6 +756,14 @@ name = "foreign-types-shared"
777756
version = "0.1.1"
778757
source = "registry+https://github.com/rust-lang/crates.io-index"
779758

759+
[[package]]
760+
name = "fortanix-sgx-abi"
761+
version = "0.0.0"
762+
dependencies = [
763+
"compiler_builtins 0.0.0",
764+
"core 0.0.0",
765+
]
766+
780767
[[package]]
781768
name = "fs2"
782769
version = "0.4.3"
@@ -2705,6 +2692,7 @@ dependencies = [
27052692
"compiler_builtins 0.0.0",
27062693
"core 0.0.0",
27072694
"dlmalloc 0.0.0",
2695+
"fortanix-sgx-abi 0.0.0",
27082696
"libc 0.0.0",
27092697
"panic_abort 0.0.0",
27102698
"panic_unwind 0.0.0",
@@ -3232,7 +3220,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32323220
"checksum crossbeam-epoch 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c90f1474584f38e270b5b613e898c8c328aa4f3dea85e0a27ac2e642f009416"
32333221
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
32343222
"checksum crossbeam-utils 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "677d453a17e8bd2b913fa38e8b9cf04bcdbb5be790aa294f2389661d72036015"
3235-
"checksum crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c55913cc2799171a550e307918c0a360e8c16004820291bf3b638969b4a01816"
32363223
"checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
32373224
"checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16"
32383225
"checksum curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "721c204978be2143fab0a84b708c49d79d1f6100b8785610f456043a90708870"
@@ -3245,7 +3232,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32453232
"checksum elasticlunr-rs 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4837d77a1e157489a3933b743fd774ae75074e0e390b2b7f071530048a0d87ee"
32463233
"checksum ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dc8393b3c7352f94092497f6b52019643e493b6b890eb417cdb7c46117e621"
32473234
"checksum env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f4d7e69c283751083d53d01eac767407343b8b69c4bd70058e08adc2637cb257"
3248-
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
32493235
"checksum environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee"
32503236
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
32513237
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"

src/liblibc

src/libpanic_abort/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
6666
unsafe fn abort() -> ! {
6767
core::intrinsics::abort();
6868
}
69+
70+
#[cfg(target_env="sgx")]
71+
unsafe fn abort() -> ! {
72+
extern "C" { pub fn panic_exit() -> !; }
73+
panic_exit();
74+
}
6975
}
7076

7177
// This... is a bit of an oddity. The tl;dr; is that this is required to link

src/libpanic_unwind/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cfg_if! {
6262
if #[cfg(target_os = "emscripten")] {
6363
#[path = "emcc.rs"]
6464
mod imp;
65-
} else if #[cfg(target_arch = "wasm32")] {
65+
} else if #[cfg(any(target_arch = "wasm32", target_env = "sgx"))] {
6666
#[path = "dummy.rs"]
6767
mod imp;
6868
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {

src/libstd/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ panic_unwind = { path = "../libpanic_unwind", optional = true }
1818
panic_abort = { path = "../libpanic_abort" }
1919
core = { path = "../libcore" }
2020
libc = { path = "../rustc/libc_shim" }
21-
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
21+
compiler_builtins = { path = "../rustc/compiler_builtins_shim", features = ["mem"] }
2222
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
2323
unwind = { path = "../libunwind" }
2424

@@ -35,9 +35,12 @@ rustc_lsan = { path = "../librustc_lsan" }
3535
rustc_msan = { path = "../librustc_msan" }
3636
rustc_tsan = { path = "../librustc_tsan" }
3737

38-
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
38+
[target.'cfg(any(all(target_arch = "wasm32", not(target_os = "emscripten")), target_env = "sgx"))'.dependencies]
3939
dlmalloc = { path = '../rustc/dlmalloc_shim' }
4040

41+
[target.x86_64-fortanix-unknown-sgx.dependencies]
42+
fortanix-sgx-abi = { path = "../rustc/fortanix-sgx-abi_shim" }
43+
4144
[build-dependencies]
4245
cc = "1.0"
4346
build_helper = { path = "../build_helper" }

src/libstd/io/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub enum ErrorKind {
184184
}
185185

186186
impl ErrorKind {
187-
fn as_str(&self) -> &'static str {
187+
pub(crate) fn as_str(&self) -> &'static str {
188188
match *self {
189189
ErrorKind::NotFound => "entity not found",
190190
ErrorKind::PermissionDenied => "permission denied",

src/libstd/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
#![feature(panic_info_message)]
311311
#![feature(non_exhaustive)]
312312
#![feature(alloc_layout_extra)]
313+
#![cfg_attr(target_env = "sgx", feature(global_asm, range_contains))]
313314

314315
#![default_lib_allocator]
315316

@@ -352,6 +353,11 @@ extern crate unwind;
352353
// testing gives test-std access to real-std lang items and globals. See #2912
353354
#[cfg(test)] extern crate std as realstd;
354355

356+
#[cfg(target_env = "sgx")]
357+
#[macro_use]
358+
#[allow(unused_imports)] // FIXME: without `#[macro_use]`, get error: “cannot determine resolution for the macro `usercalls_asm`”
359+
extern crate fortanix_sgx_abi;
360+
355361
// The standard macros that are not built-in to the compiler.
356362
#[macro_use]
357363
mod macros;
@@ -483,6 +489,12 @@ pub mod future;
483489
mod sys_common;
484490
mod sys;
485491

492+
#[unstable(feature = "perma_unstable", issue = "0")]
493+
#[cfg(target_env = "sgx")]
494+
#[doc(hidden)]
495+
// see comment at definition site for why this is necessary
496+
pub use sys::abi::asm_exports;
497+
486498
pub mod alloc;
487499

488500
// Private support modules

src/libstd/panicking.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ use thread;
3737

3838
#[derive(Clone, Copy)]
3939
#[allow(dead_code)]
40-
pub enum PanicOutput {
40+
pub enum PanicOutput<W: Write = ::io::Sink> {
4141
StdErr,
42+
Custom(fn() -> Option<W>)
4243
}
4344

44-
impl PanicOutput {
45+
impl<W: Write> PanicOutput<W> {
4546
pub(crate) fn write<T, F: FnOnce(&mut Write) -> T>(self, write: F) {
4647
match self {
4748
PanicOutput::StdErr => Stderr::new().ok().map(|mut w| write(&mut w)),
49+
PanicOutput::Custom(f) => f().map(|mut w| write(&mut w)),
4850
};
4951
}
5052
}

src/libstd/sys/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ cfg_if! {
4848
} else if #[cfg(target_arch = "wasm32")] {
4949
mod wasm;
5050
pub use self::wasm::*;
51+
} else if #[cfg(target_env = "sgx")] {
52+
mod sgx;
53+
pub use self::sgx::*;
5154
} else {
5255
compile_error!("libstd doesn't compile for this platform yet");
5356
}

0 commit comments

Comments
 (0)