From 86c9831bb40d2c50c36b748b08a75860c4640875 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Thu, 19 Dec 2019 13:57:47 +0200 Subject: [PATCH] [ItaniumCXXABI] Don't mark an extern_weak init function as dso_local on windows Since 6bf108d77a3c, we try to not mark extern_weak symbols as dso_local, to allow using COFF stubs for references to those symbols (as the symbol may be missing, resolving to an absolute address zero, outside of the current DSO). Differential Revision: https://reviews.llvm.org/D71716 --- clang/lib/CodeGen/ItaniumCXXABI.cpp | 4 +++- clang/test/CodeGenCXX/mingw-thread-local.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenCXX/mingw-thread-local.cpp diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 9256142..cf3074d 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2684,7 +2684,9 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs( 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 index 0000000..ffcc697 --- /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() -- 2.7.4