[llvm] r264288 - Fix resolution of linkonce symbols in comdats.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 07:58:44 PDT 2016


Author: rafael
Date: Thu Mar 24 09:58:44 2016
New Revision: 264288

URL: http://llvm.org/viewvc/llvm-project?rev=264288&view=rev
Log:
Fix resolution of linkonce symbols in comdats.

After comdat processing, the symbols still go through regular symbol
resolution.

We were not doing it for linkonce symbols since they are lazy linked.

This fixes pr27044.

Added:
    llvm/trunk/test/Linker/Inputs/pr27044.ll
    llvm/trunk/test/Linker/pr27044.ll
Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=264288&r1=264287&r2=264288&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Mar 24 09:58:44 2016
@@ -566,8 +566,14 @@ bool ModuleLinker::run() {
     const Comdat *SC = GV->getComdat();
     if (!SC)
       continue;
-    for (GlobalValue *GV2 : LazyComdatMembers[SC])
-      ValuesToLink.insert(GV2);
+    for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
+      GlobalValue *DGV = getLinkedToGlobal(GV2);
+      bool LinkFromSrc = true;
+      if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
+        return true;
+      if (LinkFromSrc)
+        ValuesToLink.insert(GV2);
+    }
   }
 
   if (shouldInternalizeLinkedSymbols()) {

Added: llvm/trunk/test/Linker/Inputs/pr27044.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/pr27044.ll?rev=264288&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/pr27044.ll (added)
+++ llvm/trunk/test/Linker/Inputs/pr27044.ll Thu Mar 24 09:58:44 2016
@@ -0,0 +1,7 @@
+$foo = comdat any
+define linkonce_odr i32 @f1() comdat($foo) {
+  ret i32 1
+}
+define void @f2() comdat($foo) {
+  ret void
+}

Added: llvm/trunk/test/Linker/pr27044.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/pr27044.ll?rev=264288&view=auto
==============================================================================
--- llvm/trunk/test/Linker/pr27044.ll (added)
+++ llvm/trunk/test/Linker/pr27044.ll Thu Mar 24 09:58:44 2016
@@ -0,0 +1,8 @@
+; RUN: llvm-link -S %s %p/Inputs/pr27044.ll -o - | FileCheck %s
+
+; CHECK: define i32 @f1() {
+; CHECK: define void @f2() comdat($foo) {
+
+define i32 @f1() {
+  ret i32 0
+}




More information about the llvm-commits mailing list