diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2684,7 +2684,9 @@ if (Init) { Init->setVisibility(Var->getVisibility()); - Init->setDSOLocal(Var->isDSOLocal()); + // Don't mark an extern_weak function DSO local on windows. + if (!CGM.getTriple().isOSWindows() || !Init->hasExternalWeakLinkage()) + Init->setDSOLocal(Var->isDSOLocal()); } llvm::LLVMContext &Context = CGM.getModule().getContext(); diff --git a/clang/test/CodeGenCXX/mingw-thread-local.cpp b/clang/test/CodeGenCXX/mingw-thread-local.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/mingw-thread-local.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-w64-mingw32 | FileCheck %s + +extern thread_local int var; + +int get() { + return var; +} + +// CHECK: declare extern_weak void @_ZTH3var()