about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorThe rustc-josh-sync Cronjob Bot <github-actions@github.com>2025-07-24 04:15:39 +0000
committerThe rustc-josh-sync Cronjob Bot <github-actions@github.com>2025-07-24 04:15:39 +0000
commite5b1e7d192780463c35d3a08ad79c6764119297e (patch)
tree7e4fa13bc2c055d6c08a75275412d50d641d9564 /library/std
parent11153451845ff40624a3887d6312e563951932b0 (diff)
parentefd420c770bb179537c01063e98cb6990c439654 (diff)
downloadrust-e5b1e7d192780463c35d3a08ad79c6764119297e.tar.gz
rust-e5b1e7d192780463c35d3a08ad79c6764119297e.zip
Merge ref 'efd420c770bb' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: efd420c770bb179537c01063e98cb6990c439654
Filtered ref: d11dbbb02905535a89393e80c24274bee81fa928

This merge was created using https://github.com/rust-lang/josh-sync.
Diffstat (limited to 'library/std')
-rw-r--r--library/std/Cargo.toml7
-rw-r--r--library/std/src/sys/thread_local/guard/windows.rs17
2 files changed, 16 insertions, 8 deletions
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
index 5c3132a7375..ba1e1f5218a 100644
--- a/library/std/Cargo.toml
+++ b/library/std/Cargo.toml
@@ -23,9 +23,7 @@ unwind = { path = "../unwind" }
 hashbrown = { version = "0.15", default-features = false, features = [
     'rustc-dep-of-std',
 ] }
-std_detect = { path = "../stdarch/crates/std_detect", public = true, default-features = false, features = [
-    'rustc-dep-of-std',
-] }
+std_detect = { path = "../std_detect", public = true }
 
 # Dependencies of the `backtrace` crate
 rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] }
@@ -118,8 +116,7 @@ optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
 debug_refcell = ["core/debug_refcell"]
 
 
-# Enable std_detect default features for stdarch/crates/std_detect:
-# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
+# Enable std_detect features:
 std_detect_file_io = ["std_detect/std_detect_file_io"]
 std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
 
diff --git a/library/std/src/sys/thread_local/guard/windows.rs b/library/std/src/sys/thread_local/guard/windows.rs
index b15a0d7c0bd..f747129465d 100644
--- a/library/std/src/sys/thread_local/guard/windows.rs
+++ b/library/std/src/sys/thread_local/guard/windows.rs
@@ -58,7 +58,7 @@
 //! We don't actually use the `/INCLUDE` linker flag here like the article
 //! mentions because the Rust compiler doesn't propagate linker flags, but
 //! instead we use a shim function which performs a volatile 1-byte load from
-//! the address of the symbol to ensure it sticks around.
+//! the address of the _tls_used symbol to ensure it sticks around.
 //!
 //! [1]: https://www.codeproject.com/Articles/8113/Thread-Local-Storage-The-C-Way
 //! [2]: https://github.com/ChromiumWebApps/chromium/blob/master/base/threading/thread_local_storage_win.cc#L42
@@ -68,9 +68,20 @@ use core::ffi::c_void;
 use crate::ptr;
 use crate::sys::c;
 
+unsafe extern "C" {
+    #[link_name = "_tls_used"]
+    static TLS_USED: u8;
+}
 pub fn enable() {
-    // When destructors are used, we don't want LLVM eliminating CALLBACK for any
-    // reason. Once the symbol makes it to the linker, it will do the rest.
+    // When destructors are used, we need to add a reference to the _tls_used
+    // symbol provided by the CRT, otherwise the TLS support code will get
+    // GC'd by the linker and our callback won't be called.
+    unsafe { ptr::from_ref(&TLS_USED).read_volatile() };
+    // We also need to reference CALLBACK to make sure it does not get GC'd
+    // by the compiler/LLVM. The callback will end up inside the TLS
+    // callback array pointed to by _TLS_USED through linker shenanigans,
+    // but as far as the compiler is concerned, it looks like the data is
+    // unused, so we need this hack to prevent it from disappearing.
     unsafe { ptr::from_ref(&CALLBACK).read_volatile() };
 }