[PATCH] D108689: [Linker] Support weak symbols in nodeduplicate COMDAT group
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 31 17:52:13 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92f54e1c7522: [Linker] Support weak symbols in nodeduplicate COMDAT group (authored by phosek).
Changed prior to commit:
https://reviews.llvm.org/D108689?vs=369141&id=369824#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108689/new/
https://reviews.llvm.org/D108689
Files:
llvm/lib/Linker/LinkModules.cpp
llvm/test/Linker/comdat-nodeduplicate.ll
Index: llvm/test/Linker/comdat-nodeduplicate.ll
===================================================================
--- llvm/test/Linker/comdat-nodeduplicate.ll
+++ llvm/test/Linker/comdat-nodeduplicate.ll
@@ -3,14 +3,16 @@
; CHECK: error: Linking COMDATs named 'foo': nodeduplicate has been violated!
-; RUN: not llvm-link -S %t/2.ll %t/2-aux.ll 2>&1 | FileCheck %s --check-prefix=CHECK2
-; RUN: not llvm-link -S %t/2-aux.ll %t/2.ll 2>&1 | FileCheck %s --check-prefix=CHECK2
+; RUN: llvm-link -S %t/2.ll %t/2-aux.ll | FileCheck %s --check-prefix=CHECK2
+; RUN: llvm-link -S %t/2-aux.ll %t/2.ll | FileCheck %s --check-prefix=CHECK2
-; CHECK2: error: Linking COMDATs named 'foo'
+; CHECK2-DAG: @foo = global i64 2, section "data", comdat, align 8
+; CHECK2-DAG: @bar = weak global i64 0, section "cnts", comdat($foo)
+; CHECK2-DAG: @qux = weak_odr global i64 4, comdat($foo)
; RUN: not llvm-link -S %t/non-var.ll %t/non-var.ll 2>&1 | FileCheck %s --check-prefix=NONVAR
-; NONVAR: error: Linking COMDATs named 'foo': nodeduplicate has been violated!
+; NONVAR: error: Linking COMDATs named 'foo': GlobalVariable required for data dependent selection!
;--- 1.ll
$foo = comdat nodeduplicate
Index: llvm/lib/Linker/LinkModules.cpp
===================================================================
--- llvm/lib/Linker/LinkModules.cpp
+++ llvm/lib/Linker/LinkModules.cpp
@@ -179,9 +179,25 @@
// Go with Dst.
From = LinkFrom::Dst;
break;
- case Comdat::SelectionKind::NoDeduplicate:
- return emitError("Linking COMDATs named '" + ComdatName +
- "': nodeduplicate has been violated!");
+ case Comdat::SelectionKind::NoDeduplicate: {
+ const GlobalVariable *DstGV;
+ const GlobalVariable *SrcGV;
+ if (getComdatLeader(DstM, ComdatName, DstGV) ||
+ getComdatLeader(*SrcM, ComdatName, SrcGV))
+ return true;
+
+ if (SrcGV->isWeakForLinker()) {
+ // Go with Dst.
+ From = LinkFrom::Dst;
+ } else if (DstGV->isWeakForLinker()) {
+ // Go with Src.
+ From = LinkFrom::Src;
+ } else {
+ return emitError("Linking COMDATs named '" + ComdatName +
+ "': nodeduplicate has been violated!");
+ }
+ break;
+ }
case Comdat::SelectionKind::ExactMatch:
case Comdat::SelectionKind::Largest:
case Comdat::SelectionKind::SameSize: {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108689.369824.patch
Type: text/x-patch
Size: 2355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210901/e36a92f8/attachment.bin>
More information about the llvm-commits
mailing list