-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[thread_local] from windows DLLs gets duplicated by inlining. #44391
Comments
I think this may be a dllexport/import problem, looks like |
Hm no I take that back, I forgot that we don't use I wonder if this is just not supposed to work? Or maybe this is how TLS works on Windows? |
MSVC doesn't support this. Tried this on compiler explorer:
I don't know if it's possible or not to do using the DLL loader, but LLVM probably doesn't support it even if it would work. cc @retep998 |
This also means that the bug applies to |
#44391 (comment) works fine on windows-gnu. @rustbot modify labels: -O-windows +O-windows-msvc |
To be clear the TLS isn't duplicated, it simply doesn't exist in On Windows, native TLS is scoped to the module (where "module" means either a dll or exe file). So when the dylib is built, the TLS value is in that scope. This would be fine in a normal dll file but Rust's dylibs are special in that they're kind of a weird cross between an actual dll and a static lib. So when compiling an exe with the dylib, the value itself remains declared in the dylib but the (inlined) code for accessing it is moved to the exe, where it ends up referencing some arbitrary memory. At best it's a |
On further investigation it looks like the exe does get an entry embedded in the binary's TLS data array. But it's only one byte no matter the size of the value. And it is always zero initialized. So I guess it is legal to access the first byte of the TLS value. The dylib has the full value in its TLS data array, properly initialized. |
…ichaelwoerister Never inline Windows dtor access Inlining can cause problem If used in a Rust dylib. See rust-lang#44391. r? `@Mark-Simulacrum`
…haelwoerister Never inline Windows dtor access Inlining can cause problem If used in a Rust dylib. See rust-lang#44391. r? `@Mark-Simulacrum`
This is most likely responsible for the windows failures from #43931 when the
__getit
function, which may return a reference to a#[thread_local] static
, was#[inline]
(cc @alexcrichton):Running
b
, on x64 MSVC (thanks, @bcata6!) results in:The text was updated successfully, but these errors were encountered: