]> git.lizzy.rs Git - rust.git/commitdiff
SGX target: Use linker option to avoid code CGU assignment kludge
authorJethro Beekman <jethro@fortanix.com>
Tue, 2 Apr 2019 00:41:37 +0000 (17:41 -0700)
committerJethro Beekman <jethro@fortanix.com>
Tue, 2 Apr 2019 00:41:37 +0000 (17:41 -0700)
src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs
src/libstd/sys/sgx/alloc.rs
src/libstd/sys/sgx/mod.rs
src/libstd/sys/sgx/rwlock.rs
src/libstd/sys/sgx/stdio.rs

index 7c369daa2a8f6e966cad3be1f220037f2a7631db..46cf4cd8ae3530dd9ac6c0e68588be969b4d4b46 100644 (file)
@@ -21,6 +21,15 @@ pub fn target() -> Result<Target, String> {
         "-Wl,--no-undefined-version",
         "-Wl,-Bsymbolic",
         "-Wl,--export-dynamic",
+        // The following symbols are needed by libunwind, which is linked after
+        // libstd. Make sure they're included in the link.
+        "-Wl,-u,__rust_abort",
+        "-Wl,-u,__rust_c_alloc",
+        "-Wl,-u,__rust_c_dealloc",
+        "-Wl,-u,__rust_print_err",
+        "-Wl,-u,__rust_rwlock_rdlock",
+        "-Wl,-u,__rust_rwlock_unlock",
+        "-Wl,-u,__rust_rwlock_wrlock",
     ];
 
     const EXPORT_SYMBOLS: &[&str] = &[
index 98eb8397436bfeb98b06852cea90c6e541c5e5ed..b385d567dd8c4324fc9bc8ed7a1e941baa36dee0 100644 (file)
@@ -1,4 +1,4 @@
-use crate::alloc::{GlobalAlloc, Layout, System};
+use crate::alloc::{self, GlobalAlloc, Layout, System};
 
 use super::waitqueue::SpinMutex;
 
@@ -30,3 +30,17 @@ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut
         DLMALLOC.lock().realloc(ptr, layout.size(), layout.align(), new_size)
     }
 }
+
+// The following functions are needed by libunwind. These symbols are named
+// in pre-link args for the target specification, so keep that in sync.
+#[cfg(not(test))]
+#[no_mangle]
+pub unsafe extern "C" fn __rust_c_alloc(size: usize, align: usize) -> *mut u8 {
+    alloc::alloc(Layout::from_size_align_unchecked(size, align))
+}
+
+#[cfg(not(test))]
+#[no_mangle]
+pub unsafe extern "C" fn __rust_c_dealloc(ptr: *mut u8, size: usize, align: usize) {
+    alloc::dealloc(ptr, Layout::from_size_align_unchecked(size, align))
+}
index dc51a932c616c40fbe87beb5366e2b5464ae3f14..67fffe98a8654d7e1cc384d4d9a84f9dfe3f4d19 100644 (file)
@@ -130,6 +130,15 @@ pub unsafe fn abort_internal() -> ! {
     abi::usercalls::exit(true)
 }
 
+// This function is needed by the panic runtime. The symbol is named in
+// pre-link args for the target specification, so keep that in sync.
+#[cfg(not(test))]
+#[no_mangle]
+// NB. used by both libunwind and libpanic_abort
+pub unsafe extern "C" fn __rust_abort() {
+    abort_internal();
+}
+
 pub fn hashmap_random_keys() -> (u64, u64) {
     fn rdrand64() -> u64 {
         unsafe {
index 4cba36aa64dd53992605d567ca892d1c99b7961e..5d328221b4dc89ff9b14c838d489e1d64928829b 100644 (file)
@@ -1,10 +1,4 @@
-#[cfg(not(test))]
-use crate::alloc::{self, Layout};
 use crate::num::NonZeroUsize;
-#[cfg(not(test))]
-use crate::slice;
-#[cfg(not(test))]
-use crate::str;
 
 use super::waitqueue::{
     try_lock_or_false, NotifiedTcs, SpinMutex, SpinMutexGuard, WaitQueue, WaitVariable,
@@ -165,10 +159,11 @@ unsafe fn unlock(&self) {
     pub unsafe fn destroy(&self) {}
 }
 
+// The following functions are needed by libunwind. These symbols are named
+// in pre-link args for the target specification, so keep that in sync.
 #[cfg(not(test))]
 const EINVAL: i32 = 22;
 
-// used by libunwind port
 #[cfg(not(test))]
 #[no_mangle]
 pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RWLock) -> i32 {
@@ -198,39 +193,6 @@ pub unsafe fn destroy(&self) {}
     return 0;
 }
 
-// the following functions are also used by the libunwind port. They're
-// included here to make sure parallel codegen and LTO don't mess things up.
-#[cfg(not(test))]
-#[no_mangle]
-pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
-    if s < 0 {
-        return;
-    }
-    let buf = slice::from_raw_parts(m as *const u8, s as _);
-    if let Ok(s) = str::from_utf8(&buf[..buf.iter().position(|&b| b == 0).unwrap_or(buf.len())]) {
-        eprint!("{}", s);
-    }
-}
-
-#[cfg(not(test))]
-#[no_mangle]
-// NB. used by both libunwind and libpanic_abort
-pub unsafe extern "C" fn __rust_abort() {
-    crate::sys::abort_internal();
-}
-
-#[cfg(not(test))]
-#[no_mangle]
-pub unsafe extern "C" fn __rust_c_alloc(size: usize, align: usize) -> *mut u8 {
-    alloc::alloc(Layout::from_size_align_unchecked(size, align))
-}
-
-#[cfg(not(test))]
-#[no_mangle]
-pub unsafe extern "C" fn __rust_c_dealloc(ptr: *mut u8, size: usize, align: usize) {
-    alloc::dealloc(ptr, Layout::from_size_align_unchecked(size, align))
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
index f2c6892bfb7fde6f773ea8613b0ba927745063cd..a575401f5f60dc28fba903ebf0e6d8bc7a764c67 100644 (file)
@@ -2,6 +2,10 @@
 
 use crate::io;
 use crate::sys::fd::FileDesc;
+#[cfg(not(test))]
+use crate::slice;
+#[cfg(not(test))]
+use crate::str;
 
 pub struct Stdin(());
 pub struct Stdout(());
@@ -62,3 +66,17 @@ pub fn is_ebadf(err: &io::Error) -> bool {
 pub fn panic_output() -> Option<impl io::Write> {
     super::abi::panic::SgxPanicOutput::new()
 }
+
+// This function is needed by libunwind. The symbol is named in pre-link args
+// for the target specification, so keep that in sync.
+#[cfg(not(test))]
+#[no_mangle]
+pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
+    if s < 0 {
+        return;
+    }
+    let buf = slice::from_raw_parts(m as *const u8, s as _);
+    if let Ok(s) = str::from_utf8(&buf[..buf.iter().position(|&b| b == 0).unwrap_or(buf.len())]) {
+        eprint!("{}", s);
+    }
+}