Skip to content

Commit 1ebceb7

Browse files
authored
Fix overly strict volatile reads in Windows TLS implementation
1 parent 3d8c1c1 commit 1ebceb7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/std/src/sys/thread_local/guard/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//!
5858
//! We don't actually use the `/INCLUDE` linker flag here like the article
5959
//! mentions because the Rust compiler doesn't propagate linker flags, but
60-
//! instead we use a shim function which performs a volatile 1-byte load from
60+
//! instead we use a shim function which performs a 1-byte unaligned load from
6161
//! the address of the _tls_used symbol to ensure it sticks around.
6262
//!
6363
//! [1]: https://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way
@@ -76,13 +76,13 @@ pub fn enable() {
7676
// When destructors are used, we need to add a reference to the _tls_used
7777
// symbol provided by the CRT, otherwise the TLS support code will get
7878
// GC'd by the linker and our callback won't be called.
79-
unsafe { ptr::from_ref(&TLS_USED).read_volatile() };
79+
unsafe { ptr::from_ref(&TLS_USED).read_unaligned() };
8080
// We also need to reference CALLBACK to make sure it does not get GC'd
8181
// by the compiler/LLVM. The callback will end up inside the TLS
8282
// callback array pointed to by _TLS_USED through linker shenanigans,
8383
// but as far as the compiler is concerned, it looks like the data is
8484
// unused, so we need this hack to prevent it from disappearing.
85-
unsafe { ptr::from_ref(&CALLBACK).read_volatile() };
85+
unsafe { ptr::from_ref(&CALLBACK).read_unaligned() };
8686
}
8787

8888
#[unsafe(link_section = ".CRT$XLB")]

0 commit comments

Comments
 (0)