r180941 - Use the Itanium ABI for thread_local on Darwin.

Bill Wendling isanbard at gmail.com
Thu May 2 12:18:04 PDT 2013


Author: void
Date: Thu May  2 14:18:03 2013
New Revision: 180941

URL: http://llvm.org/viewvc/llvm-project?rev=180941&view=rev
Log:
Use the Itanium ABI for thread_local on Darwin.

After some discussion, it was decided to use the Itanium ABI for thread_local on
Darwin OS X platforms. This involved a couple of changes. First, we use
"_tlv_atexit" instead of "__cxa_thread_atexit". Secondly, the global variables
are marked with 'internal' linkage, because we want all access to be calls to
the Itanium-specific entry point, which has normal linkage.
<rdar://problem/13733006>

Added:
    cfe/trunk/test/CodeGenCXX/tls-init-funcs.cpp
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=180941&r1=180940&r2=180941&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May  2 14:18:03 2013
@@ -1916,7 +1916,13 @@ CodeGenModule::GetLLVMLinkageVarDefiniti
            !D->getAttr<WeakImportAttr>()) {
     // Thread local vars aren't considered common linkage.
     return llvm::GlobalVariable::CommonLinkage;
-  }
+  } else if (D->getTLSKind() == VarDecl::TLS_Dynamic &&
+             getTarget().getTriple().isMacOSX())
+    // On Darwin, the backing variable for a C++11 thread_local variable always
+    // has internal linkage; all accesses should just be calls to the
+    // Itanium-specified entry point, which has the normal linkage of the
+    // variable.
+    return llvm::GlobalValue::InternalLinkage;
   return llvm::GlobalVariable::ExternalLinkage;
 }
 

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=180941&r1=180940&r2=180941&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu May  2 14:18:03 2013
@@ -1206,7 +1206,11 @@ static void emitGlobalDtorWithCXAAtExit(
                                         llvm::Constant *dtor,
                                         llvm::Constant *addr,
                                         bool TLS) {
-  const char *Name = TLS ? "__cxa_thread_atexit" : "__cxa_atexit";
+  const char *Name = "__cxa_atexit";
+  if (TLS) {
+    const llvm::Triple &T = CGF.getTarget().getTriple();
+    Name = T.isMacOSX() ?  "_tlv_atexit" : "__cxa_thread_atexit";
+  }
 
   // We're assuming that the destructor function is something we can
   // reasonably call with the default CC.  Go ahead and cast it to the

Added: cfe/trunk/test/CodeGenCXX/tls-init-funcs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/tls-init-funcs.cpp?rev=180941&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/tls-init-funcs.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/tls-init-funcs.cpp Thu May  2 14:18:03 2013
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.8 -std=c++11 -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @a = internal thread_local global
+// CHECK: @_tlv_atexit({{.*}}@_ZN1AD1Ev
+
+struct A {
+  ~A();
+};
+
+thread_local A a;





More information about the cfe-commits mailing list