Skip to content

Commit

Permalink
Rollup merge of rust-lang#57803 - jethrogb:jb/sgx-unwind-version, r=a…
Browse files Browse the repository at this point in the history
…lexcrichton

Several changes to libunwind for SGX target

Two fixes:
* rust-lang#34978 bites again!
* __rust_alloc are actually private symbols. Add new public versions. Also, these ones are `extern "C"`.

Upstream changes (fortanix/llvm-project#2, fortanix/llvm-project#3):
* b7357de Avoid too new relocation types being emitted
* 0feefe5 Use new symbol names to call Rust allocator

Fixes fortanix/rust-sgx#65
  • Loading branch information
Centril authored Jan 24, 2019
2 parents 8348f83 + 6abba95 commit bea8321
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ci/docker/dist-various-2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc
COPY dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/
# We pass the commit id of the port of LLVM's libunwind to the build script.
# Any update to the commit id here, should cause the container image to be re-built from this point on.
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "bbe23902411be88d7388f381becefadd6e3ef819"
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "13fad13f8ea83a8da58d04a5faa45943151b3398"

COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
Expand Down
15 changes: 15 additions & 0 deletions src/libstd/sys/sgx/rwlock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::{self, Layout};
use num::NonZeroUsize;
use slice;
use str;
Expand Down Expand Up @@ -147,6 +148,7 @@ impl RWLock {
self.__write_unlock(rguard, wguard);
}

// only used by __rust_rwlock_unlock below
#[inline]
unsafe fn unlock(&self) {
let rguard = self.readers.lock();
Expand All @@ -164,6 +166,7 @@ impl RWLock {

const EINVAL: i32 = 22;

// used by libunwind port
#[no_mangle]
pub unsafe extern "C" fn __rust_rwlock_rdlock(p: *mut RWLock) -> i32 {
if p.is_null() {
Expand All @@ -190,6 +193,8 @@ pub unsafe extern "C" fn __rust_rwlock_unlock(p: *mut RWLock) -> i32 {
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.
#[no_mangle]
pub unsafe extern "C" fn __rust_print_err(m: *mut u8, s: i32) {
if s < 0 {
Expand All @@ -206,6 +211,16 @@ pub unsafe extern "C" fn __rust_abort() {
::sys::abort_internal();
}

#[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))
}

#[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 {

Expand Down

0 comments on commit bea8321

Please sign in to comment.