[PATCH] D71572: [ItaniumCXXABI] Make tls wrappers comdat on Windows
Martin Storsjö via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 17 04:25:44 PST 2019
mstorsjo updated this revision to Diff 234269.
mstorsjo retitled this revision from "[ItaniumCXXABI] Use linkonce_odr instead of weak_odr for tls wrappers on Windows" to "[ItaniumCXXABI] Make tls wrappers comdat on Windows".
mstorsjo edited the summary of this revision.
mstorsjo added a reviewer: rsmith.
mstorsjo added a comment.
Changed to make it a comdat; unless I'm mistaken, neither linkonce_odr nor weak_odr actually make it possible to link multiple copies of the symbol on windows, unless it's made a comdat. With that in place, the previous change (weak_odr to linkonce_odr) actually isn't needed.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71572/new/
https://reviews.llvm.org/D71572
Files:
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/tls-init-funcs.cpp
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();
};
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71572.234269.patch
Type: text/x-patch
Size: 1641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191217/6b86829e/attachment.bin>
More information about the cfe-commits
mailing list