[PATCH] D115456: Implement on-demand TLS initialization for Microsoft CXX ABI

Maurice Heumann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 9 10:29:01 PST 2021


momo5502 created this revision.
momo5502 added reviewers: rnk, eugenis.
momo5502 added a project: clang.
momo5502 requested review of this revision.
Herald added a subscriber: cfe-commits.

TLS initializers, for example constructors of thread-local variables, don't necessarily get called. If for example a thread was created before a module is loaded, the module's TLS initializers are not executed for this particular thread.

This is why Microsoft added support for dynamic TLS initialization. Before every use of thread-local variables, a check is added that runs the module's TLS initializers on-demand.

To do this, the method `__dyn_tls_on_demand_init` gets called. Internally, it simply calls `__dyn_tls_init`.
To prevent calling initializers again, a guard variable called `__tls_guard` is checked and set before executing the call.

No additional TLS initializer that sets the guard needs to be emitted, as the guard always gets set by `__dyn_tls_init`.
The guard is also checked again within `__dyn_tls_init`. This makes our check redundant, however, as Microsoft's compiler also emits this check, the behaviour is adopted here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115456

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/ms-thread_local.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115456.393206.patch
Type: text/x-patch
Size: 5652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211209/82ff4004/attachment.bin>


More information about the cfe-commits mailing list