[PATCH] MS ABI: Implement thread_local for global variables

David Majnemer david.majnemer at gmail.com
Fri Oct 3 00:48:08 PDT 2014


Hi rnk, rsmith, rjmccall,

This add support for the C++11 feature, thread_local global variables.
The ABI Clang implements is an improvement of the MSVC ABI.  Sadly,
further improvements could be made but not without sacrificing ABI
compatibility.

The feature is implemented as follows:
- All thread_local initialization routines are pointed to from the
  .CRT$XDU section.
- All non-weak thread_local variables have their initialization routines
  call from a single function instead of getting their own .CRT$XDU
  section entry.  This is done to open up optimization opportunities to
  the compiler.
- All weak thread_local variables have their own .CRT$XDU section entry.
  This entry is in a COMDAT with the global variable it is initializing;
  this ensures that we will initialize the global exactly once.
- Destructors are registered in the initialization function using
  __tlregdtor.

http://reviews.llvm.org/D5597

Files:
  lib/CodeGen/CGCXXABI.cpp
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/ms-thread_local.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5597.14369.patch
Type: text/x-patch
Size: 22220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141003/3457ba87/attachment.bin>


More information about the cfe-commits mailing list