aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CodeGenModule.cpp8
-rw-r--r--lib/CodeGen/ItaniumCXXABI.cpp6
-rw-r--r--test/CodeGenCXX/tls-init-funcs.cpp10
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index bf67bd1007..66c3983a4b 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1916,7 +1916,13 @@ CodeGenModule::GetLLVMLinkageVarDefinition(const VarDecl *D,
!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;
}
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
index 2714c9e728..e117e2867b 100644
--- a/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1206,7 +1206,11 @@ static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
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
diff --git a/test/CodeGenCXX/tls-init-funcs.cpp b/test/CodeGenCXX/tls-init-funcs.cpp
new file mode 100644
index 0000000000..17299dcb7b
--- /dev/null
+++ b/test/CodeGenCXX/tls-init-funcs.cpp
@@ -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;