diff options
| author | bors <bors@rust-lang.org> | 2023-03-29 16:20:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-29 16:20:37 +0000 |
| commit | f98598c6cd34947efa9e3977338e9bce62d1997c (patch) | |
| tree | dbcaccc8c251182adeb2beccb32b687f598e0623 /tests | |
| parent | 86792086646b61342c9417b78b8a535392f1045f (diff) | |
| parent | d499bbb99d72c991f1d1691f83ffe96bcfafc80a (diff) | |
| download | rust-f98598c6cd34947efa9e3977338e9bce62d1997c.tar.gz rust-f98598c6cd34947efa9e3977338e9bce62d1997c.zip | |
Auto merge of #108089 - Zoxc:windows-tls, r=bjorn3
Support TLS access into dylibs on Windows This allows access to `#[thread_local]` in upstream dylibs on Windows by introducing a MIR shim to return the address of the thread local. Accesses that go into an upstream dylib will call the MIR shim to get the address of it. `convert_tls_rvalues` is introduced in `rustc_codegen_ssa` which rewrites MIR TLS accesses to dummy calls which are replaced with calls to the MIR shims when the dummy calls are lowered to backend calls. A new `dll_tls_export` target option enables this behavior with a `false` value which is set for Windows platforms. This fixes https://github.com/rust-lang/rust/issues/84933.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/thread-local/auxiliary/tls-export.rs | 17 | ||||
| -rw-r--r-- | tests/ui/thread-local/auxiliary/tls-rlib.rs | 15 | ||||
| -rw-r--r-- | tests/ui/thread-local/tls-dylib-access.rs | 19 |
3 files changed, 51 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..027213bc033 --- /dev/null +++ b/tests/ui/thread-local/auxiliary/tls-export.rs @@ -0,0 +1,17 @@ +#![crate_type = "dylib"] +#![feature(thread_local)] +#![feature(cfg_target_thread_local)] + +extern crate tls_rlib; + +pub use tls_rlib::*; + +#[cfg(target_thread_local)] +#[thread_local] +pub static FOO: bool = true; + +#[cfg(target_thread_local)] +#[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..20bc998ec11 --- /dev/null +++ b/tests/ui/thread-local/auxiliary/tls-rlib.rs @@ -0,0 +1,15 @@ +// 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; + +#[cfg(target_thread_local)] +#[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()); + } +} |
