diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-02-03 08:05:59 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-03-29 05:56:11 +0200 |
| commit | 51c93553d4344472f2e291b3a4f110f884062a37 (patch) | |
| tree | 9208fde9195a20d1aa035e29f15afbb4ad11cc2b | |
| parent | cdbbce0a9e5c839295cf9a8714798af45d541e20 (diff) | |
| download | rust-51c93553d4344472f2e291b3a4f110f884062a37.tar.gz rust-51c93553d4344472f2e291b3a4f110f884062a37.zip | |
Test that TLS access works outside of the dylib it's defined in
| -rw-r--r-- | tests/ui/thread-local/auxiliary/tls-export.rs | 16 | ||||
| -rw-r--r-- | tests/ui/thread-local/auxiliary/tls-rlib.rs | 14 | ||||
| -rw-r--r-- | tests/ui/thread-local/tls-dylib-access.rs | 19 |
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/ui/thread-local/auxiliary/tls-export.rs b/tests/ui/thread-local/auxiliary/tls-export.rs new file mode 100644 index 00000000000..aab48f871c9 --- /dev/null +++ b/tests/ui/thread-local/auxiliary/tls-export.rs @@ -0,0 +1,16 @@ +#![crate_type = "dylib"] +#![feature(thread_local)] +#![feature(cfg_target_thread_local)] +#![cfg(target_thread_local)] + +extern crate tls_rlib; + +pub use tls_rlib::*; + +#[thread_local] +pub static FOO: bool = true; + +#[inline(never)] +pub fn foo_addr() -> usize { + &FOO as *const bool as usize +} diff --git a/tests/ui/thread-local/auxiliary/tls-rlib.rs b/tests/ui/thread-local/auxiliary/tls-rlib.rs new file mode 100644 index 00000000000..0fbcf387b5f --- /dev/null +++ b/tests/ui/thread-local/auxiliary/tls-rlib.rs @@ -0,0 +1,14 @@ +// no-prefer-dynamic + +#![crate_type = "rlib"] +#![feature(thread_local)] +#![feature(cfg_target_thread_local)] +#![cfg(target_thread_local)] + +#[thread_local] +pub static BAR: bool = true; + +#[inline(never)] +pub fn bar_addr() -> usize { + &BAR as *const bool as usize +} diff --git a/tests/ui/thread-local/tls-dylib-access.rs b/tests/ui/thread-local/tls-dylib-access.rs new file mode 100644 index 00000000000..12c46113cea --- /dev/null +++ b/tests/ui/thread-local/tls-dylib-access.rs @@ -0,0 +1,19 @@ +// aux-build: tls-rlib.rs +// aux-build: tls-export.rs +// run-pass + +#![feature(cfg_target_thread_local)] + +#[cfg(target_thread_local)] +extern crate tls_export; + +fn main() { + #[cfg(target_thread_local)] + { + // Check that we get the real address of the `FOO` TLS in the dylib + assert_eq!(&tls_export::FOO as *const bool as usize, tls_export::foo_addr()); + + // Check that we get the real address of the `BAR` TLS in the rlib linked into the dylib + assert_eq!(&tls_export::BAR as *const bool as usize, tls_export::bar_addr()); + } +} |
