[PATCH] D71572: [ItaniumCXXABI] Use linkonce_odr instead of weak_odr for tls wrappers on Windows

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 14:26:04 PST 2019


mstorsjo created this revision.
mstorsjo added reviewers: rnk, froydnj, compnerd.
Herald added a project: clang.

On Windows, weak_odr is a no-op, and thus a weak_odr tls wrapper function can result in linker errors due to multiply defined symbols. Therefore, use linkonce_odr instead of weak_odr for tls wrappers on windows.

This should hopefully fix https://bugzilla.mozilla.org/show_bug.cgi?id=1566288.


Repository:
  rG LLVM Github Monorepo

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 linkonce_odr hidden i32* @_ZTW2vtIiE()
+// MINGW-DAG: define linkonce_odr hidden i32* @_ZTW2vtIvE()
+
 struct A {
   ~A();
 };
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2516,6 +2516,10 @@
     if (!llvm::GlobalVariable::isLinkOnceLinkage(VarLinkage) &&
         !llvm::GlobalVariable::isWeakODRLinkage(VarLinkage))
       return VarLinkage;
+  // On Windows, WeakODR is a no-op, boiling down to the same as normal external
+  // linkage.
+  if (CGM.getTriple().isOSWindows())
+    return llvm::GlobalValue::LinkOnceODRLinkage;
   return llvm::GlobalValue::WeakODRLinkage;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71572.234154.patch
Type: text/x-patch
Size: 1428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191216/6d75d39f/attachment.bin>


More information about the cfe-commits mailing list