Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2546,6 +2546,12 @@ llvm::Function::Create(FnTy, getThreadLocalWrapperLinkage(VD, CGM), WrapperName.str(), &CGM.getModule()); + // On Windows, we need to make the weak/linkonce wrapper comdat to + // actually handle multiple TUs defining the same wrapper. + if (CGM.getTriple().isOSWindows() && CGM.supportsCOMDAT() && + Wrapper->isWeakForLinker()) + Wrapper->setComdat(CGM.getModule().getOrInsertComdat(Wrapper->getName())); + CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Wrapper); // Always resolve references to the wrapper at link time. Index: clang/test/CodeGenCXX/tls-init-funcs.cpp =================================================================== --- clang/test/CodeGenCXX/tls-init-funcs.cpp +++ clang/test/CodeGenCXX/tls-init-funcs.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.8 -std=c++1y -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-windows-gnu -std=c++1y -S -emit-llvm %s -o - | FileCheck %s --check-prefix=MINGW // CHECK: @a = internal thread_local global // CHECK: @_Z2vtIiE = linkonce_odr thread_local global i32 5 @@ -10,6 +11,9 @@ // CHECK-DAG: define weak_odr hidden cxx_fast_tlscc i32* @_ZTW2vtIvE() // CHECK-DAG: define {{.*}} @_ZTW1a +// MINGW-DAG: define weak_odr hidden i32* @_ZTW2vtIiE() {{.*}} comdat +// MINGW-DAG: define weak_odr hidden i32* @_ZTW2vtIvE() {{.*}} comdat + struct A { ~A(); };