Skip to content

Commit 75df635

Browse files
committed
std: Don't inline TLS accessor on MinGW
This is causing [issues] on Cargo's own CI for MinGW and given the original investigation there's no reason that MinGW should work when MSVC doesn't, this this tweaks the MSVC exception to being a Windows exception. [issues]: https://github.com/rust-lang/cargo/runs/2626676503?check_suite_focus=true#step:9:2453
1 parent 9a3214e commit 75df635

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

library/std/src/thread/local.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ macro_rules! thread_local {
162162
macro_rules! __thread_local_inner {
163163
// used to generate the `LocalKey` value for const-initialized thread locals
164164
(@key $t:ty, const $init:expr) => {{
165-
#[cfg_attr(not(target_env = "msvc"), inline)] // see comments below
165+
#[cfg_attr(not(windows), inline)] // see comments below
166166
unsafe fn __getit() -> $crate::option::Option<&'static $t> {
167167
const _REQUIRE_UNSTABLE: () = $crate::thread::require_unstable_const_init_thread_local();
168168

@@ -262,28 +262,28 @@ macro_rules! __thread_local_inner {
262262
fn __init() -> $t { $init }
263263

264264
// When reading this function you might ask "why is this inlined
265-
// everywhere other than MSVC?", and that's a very reasonable
265+
// everywhere other than Windows?", and that's a very reasonable
266266
// question to ask. The short story is that it segfaults rustc if
267-
// this function is inlined. The longer story is that MSVC looks to
268-
// not support `extern` references to thread locals across DLL
267+
// this function is inlined. The longer story is that Windows looks
268+
// to not support `extern` references to thread locals across DLL
269269
// boundaries. This appears to at least not be supported in the ABI
270270
// that LLVM implements.
271271
//
272-
// Because of this we never inline on MVSC, but we do inline on
272+
// Because of this we never inline on Windows, but we do inline on
273273
// other platforms (where external references to thread locals
274274
// across DLLs are supported). A better fix for this would be to
275-
// inline this function on MSVC, but only for "statically linked"
275+
// inline this function on Windows, but only for "statically linked"
276276
// components. For example if two separately compiled rlibs end up
277277
// getting linked into a DLL then it's fine to inline this function
278278
// across that boundary. It's only not fine to inline this function
279-
// across a DLL boundary. Unfortunately rustc doesn't currently have
280-
// this sort of logic available in an attribute, and it's not clear
281-
// that rustc is even equipped to answer this (it's more of a Cargo
282-
// question kinda). This means that, unfortunately, MSVC gets the
283-
// pessimistic path for now where it's never inlined.
279+
// across a DLL boundary. Unfortunately rustc doesn't currently
280+
// have this sort of logic available in an attribute, and it's not
281+
// clear that rustc is even equipped to answer this (it's more of a
282+
// Cargo question kinda). This means that, unfortunately, Windows
283+
// gets the pessimistic path for now where it's never inlined.
284284
//
285-
// The issue of "should enable on MSVC sometimes" is #84933
286-
#[cfg_attr(not(target_env = "msvc"), inline)]
285+
// The issue of "should enable on Windows sometimes" is #84933
286+
#[cfg_attr(not(windows), inline)]
287287
unsafe fn __getit() -> $crate::option::Option<&'static $t> {
288288
#[cfg(all(target_arch = "wasm32", not(target_feature = "atomics")))]
289289
static __KEY: $crate::thread::__StaticLocalKeyInner<$t> =

0 commit comments

Comments
 (0)