-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Windows TLS destructors don't run in a statically linked binary #28111
Comments
and
are comments from the chromium’s TLS impl pointing towards something that might be missing from our implementation: we do not make sure data is constant on x64 and we do not make sure our symbol is |
The bug here for threads in general specifically has to do with linkage, and I'm about to fix that in #28130, and for the main thread I've opened #28129 as it's not specific to Windows unfortunately. For now I'm gonna recategorize this as "TLS destructors don't run in a statically linked binary on Windows" |
Running TLS destructors for a MSVC Windows binary requires the linker doesn't elide the `_tls_used` or `__tls_used` symbols (depending on the architecture). This is currently achieved via a `#[link_args]` hack but this only works for dynamically linked binaries because the link arguments aren't propagated to statically linked binaries. This commit alters the strategy to instead emit a volatile load from those symbols so LLVM can't elide it, forcing the reference to the symbol to stay alive as long as the callback function stays alive (which we've made sure of with the `#[linkage]` attribute). Closes rust-lang#28111
Running TLS destructors for a MSVC Windows binary requires the linker doesn't elide the `_tls_used` or `__tls_used` symbols (depending on the architecture). This is currently achieved via a `#[link_args]` hack but this only works for dynamically linked binaries because the link arguments aren't propagated to statically linked binaries. This commit alters the strategy to instead emit a volatile load from those symbols so LLVM can't elide it, forcing the reference to the symbol to stay alive as long as the callback function stays alive (which we've made sure of with the `#[linkage]` attribute). Closes #28111
On
-msvc
TLS destructors do not appear to be run at all.On
-gnu
TLS destructors appear to run when a non-main thread exits (as expected) orstd::process:exit
is called (es expected), but not run when main thread is terminated normally (by returning fromfn main
; not expected).Various variations of this/this program has been used for testing.
cc @retep998 who did the testing
The text was updated successfully, but these errors were encountered: