Skip to content

Commit 51c9355

Browse files
committed
Test that TLS access works outside of the dylib it's defined in
1 parent cdbbce0 commit 51c9355

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Diff for: tests/ui/thread-local/auxiliary/tls-export.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![crate_type = "dylib"]
2+
#![feature(thread_local)]
3+
#![feature(cfg_target_thread_local)]
4+
#![cfg(target_thread_local)]
5+
6+
extern crate tls_rlib;
7+
8+
pub use tls_rlib::*;
9+
10+
#[thread_local]
11+
pub static FOO: bool = true;
12+
13+
#[inline(never)]
14+
pub fn foo_addr() -> usize {
15+
&FOO as *const bool as usize
16+
}

Diff for: tests/ui/thread-local/auxiliary/tls-rlib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// no-prefer-dynamic
2+
3+
#![crate_type = "rlib"]
4+
#![feature(thread_local)]
5+
#![feature(cfg_target_thread_local)]
6+
#![cfg(target_thread_local)]
7+
8+
#[thread_local]
9+
pub static BAR: bool = true;
10+
11+
#[inline(never)]
12+
pub fn bar_addr() -> usize {
13+
&BAR as *const bool as usize
14+
}

Diff for: tests/ui/thread-local/tls-dylib-access.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// aux-build: tls-rlib.rs
2+
// aux-build: tls-export.rs
3+
// run-pass
4+
5+
#![feature(cfg_target_thread_local)]
6+
7+
#[cfg(target_thread_local)]
8+
extern crate tls_export;
9+
10+
fn main() {
11+
#[cfg(target_thread_local)]
12+
{
13+
// Check that we get the real address of the `FOO` TLS in the dylib
14+
assert_eq!(&tls_export::FOO as *const bool as usize, tls_export::foo_addr());
15+
16+
// Check that we get the real address of the `BAR` TLS in the rlib linked into the dylib
17+
assert_eq!(&tls_export::BAR as *const bool as usize, tls_export::bar_addr());
18+
}
19+
}

0 commit comments

Comments
 (0)