Skip to content

Commit ae0eb67

Browse files
committed
msvc: Fix TLS destructors
Just like the original article our Windows TLS support is based on predicted, this symbol must be linked in on MSVC to pull in the necessary support for TLS variables. This commit fixes a number of unit tests which require that TLS destructors are run.
1 parent 91c22b6 commit ae0eb67

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
#![cfg_attr(windows, feature(str_utf16))]
152152
#![cfg_attr(test, feature(float_from_str_radix, range_inclusive, float_extras))]
153153
#![cfg_attr(test, feature(test, rustc_private, float_consts))]
154+
#![cfg_attr(target_env = "msvc", feature(link_args))]
154155

155156
// Don't link to std. We are std.
156157
#![no_std]

src/libstd/sys/windows/thread_local.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ unsafe fn unregister_dtor(key: Key) -> bool {
221221
//
222222
// # The article mentions crazy stuff about "/INCLUDE"?
223223
//
224-
// It sure does! This seems to work for now, so maybe we'll just run into
225-
// that if we start linking with msvc?
224+
// It sure does! We include it below for MSVC targets, but it look like for GNU
225+
// targets we don't require it.
226226

227227
#[link_section = ".CRT$XLB"]
228228
#[linkage = "external"]
@@ -231,6 +231,10 @@ pub static p_thread_callback: unsafe extern "system" fn(LPVOID, DWORD,
231231
LPVOID) =
232232
on_tls_callback;
233233

234+
#[cfg(target_env = "msvc")]
235+
#[link_args = "/INCLUDE:_tls_used"]
236+
extern {}
237+
234238
#[allow(warnings)]
235239
unsafe extern "system" fn on_tls_callback(h: LPVOID,
236240
dwReason: DWORD,

0 commit comments

Comments
 (0)