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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits