Skip to content

Commit 809c35f

Browse files
authored
Rollup merge of rust-lang#139795 - jethrogb:jb/sgx-linkage-comments, r=joboet
Clarify why SGX code specifies linkage/symbol names for certain statics Specifying linkage/symbol name is solely to ensure a single instance between the `std` crate and its unit tests. Also update the symbol names as items have moved around a bit. The actual name isn't that important, it just needs to be unique. But for debugging it can be useful for it to point to the right place.
2 parents b6fae47 + e45b238 commit 809c35f

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

std/src/sys/alloc/sgx.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use crate::sys::pal::waitqueue::SpinMutex;
1010
// The current allocator here is the `dlmalloc` crate which we've got included
1111
// in the rust-lang/rust repository as a submodule. The crate is a port of
1212
// dlmalloc.c from C to Rust.
13+
//
14+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1315
#[cfg_attr(test, linkage = "available_externally")]
14-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE")]
16+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys5alloc3sgx8DLMALLOCE")]
1517
static DLMALLOC: SpinMutex<dlmalloc::Dlmalloc<Sgx>> =
1618
SpinMutex::new(dlmalloc::Dlmalloc::new_with_allocator(Sgx {}));
1719

std/src/sys/args/sgx.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
88
use crate::sys_common::FromInner;
99
use crate::{fmt, slice};
1010

11+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1112
#[cfg_attr(test, linkage = "available_externally")]
1213
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx4args4ARGSE")]
1314
static ARGS: AtomicUsize = AtomicUsize::new(0);

std/src/sys/pal/sgx/abi/tls/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ const USIZE_BITS: usize = 64;
1111
const TLS_KEYS: usize = 128; // Same as POSIX minimum
1212
const TLS_KEYS_BITSET_SIZE: usize = (TLS_KEYS + (USIZE_BITS - 1)) / USIZE_BITS;
1313

14+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
1415
#[cfg_attr(test, linkage = "available_externally")]
15-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_KEY_IN_USEE")]
16+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_KEY_IN_USEE")]
1617
static TLS_KEY_IN_USE: SyncBitset = SYNC_BITSET_INIT;
1718
macro_rules! dup {
1819
((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
1920
(() $($val:tt)*) => ([$($val),*])
2021
}
22+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
2123
#[cfg_attr(test, linkage = "available_externally")]
22-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_DESTRUCTORE")]
24+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx3abi3tls14TLS_DESTRUCTORE")]
2325
static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) (AtomicUsize::new(0)));
2426

2527
unsafe extern "C" {

std/src/sys/pal/sgx/os.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
7373
unsupported()
7474
}
7575

76+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
7677
#[cfg_attr(test, linkage = "available_externally")]
77-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os3ENVE")]
78+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os3ENVE")]
7879
static ENV: AtomicUsize = AtomicUsize::new(0);
80+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
7981
#[cfg_attr(test, linkage = "available_externally")]
80-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os8ENV_INITE")]
82+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx2os8ENV_INITE")]
8183
static ENV_INIT: Once = Once::new();
8284
type EnvStore = Mutex<HashMap<OsString, OsString>>;
8385

std/src/sys/pal/sgx/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ mod task_queue {
4545
}
4646
}
4747

48+
// Specifying linkage/symbol name is solely to ensure a single instance between this crate and its unit tests
4849
#[cfg_attr(test, linkage = "available_externally")]
49-
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx6thread10TASK_QUEUEE")]
50+
#[unsafe(export_name = "_ZN16__rust_internals3std3sys3pal3sgx6thread10TASK_QUEUEE")]
5051
static TASK_QUEUE: Mutex<Vec<Task>> = Mutex::new(Vec::new());
5152

5253
pub(super) fn lock() -> MutexGuard<'static, Vec<Task>> {

0 commit comments

Comments
 (0)