[llvm] r303939 - LTO: Do summary-based prevailing symbol resolution at --lto-O0.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 16:40:11 PDT 2017


Author: pcc
Date: Thu May 25 18:40:11 2017
New Revision: 303939

URL: http://llvm.org/viewvc/llvm-project?rev=303939&view=rev
Log:
LTO: Do summary-based prevailing symbol resolution at --lto-O0.

Prevailing symbol resolution is necessary for correctness. Without
this we can end up dropping a referenced linkonce symbol from the link.

Differential Revision: https://reviews.llvm.org/D33570

Added:
    llvm/trunk/test/LTO/Resolution/X86/linkonce.ll
Modified:
    llvm/trunk/lib/LTO/LTO.cpp

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=303939&r1=303938&r2=303939&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Thu May 25 18:40:11 2017
@@ -1002,10 +1002,6 @@ Error LTO::runThinLTO(AddStreamFn AddStr
         ExportedGUIDs.insert(GUID);
     }
 
-    auto isPrevailing = [&](GlobalValue::GUID GUID,
-                            const GlobalValueSummary *S) {
-      return ThinLTO.PrevailingModuleForGUID[GUID] == S->modulePath();
-    };
     auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) {
       const auto &ExportList = ExportLists.find(ModuleIdentifier);
       return (ExportList != ExportLists.end() &&
@@ -1013,17 +1009,20 @@ Error LTO::runThinLTO(AddStreamFn AddStr
              ExportedGUIDs.count(GUID);
     };
     thinLTOInternalizeAndPromoteInIndex(ThinLTO.CombinedIndex, isExported);
-
-    auto recordNewLinkage = [&](StringRef ModuleIdentifier,
-                                GlobalValue::GUID GUID,
-                                GlobalValue::LinkageTypes NewLinkage) {
-      ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
-    };
-
-    thinLTOResolveWeakForLinkerInIndex(ThinLTO.CombinedIndex, isPrevailing,
-                                       recordNewLinkage);
   }
 
+  auto isPrevailing = [&](GlobalValue::GUID GUID,
+                          const GlobalValueSummary *S) {
+    return ThinLTO.PrevailingModuleForGUID[GUID] == S->modulePath();
+  };
+  auto recordNewLinkage = [&](StringRef ModuleIdentifier,
+                              GlobalValue::GUID GUID,
+                              GlobalValue::LinkageTypes NewLinkage) {
+    ResolvedODR[ModuleIdentifier][GUID] = NewLinkage;
+  };
+  thinLTOResolveWeakForLinkerInIndex(ThinLTO.CombinedIndex, isPrevailing,
+                                     recordNewLinkage);
+
   std::unique_ptr<ThinBackendProc> BackendProc =
       ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
                       AddStream, Cache);

Added: llvm/trunk/test/LTO/Resolution/X86/linkonce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/linkonce.ll?rev=303939&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/linkonce.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/linkonce.ll Thu May 25 18:40:11 2017
@@ -0,0 +1,11 @@
+; RUN: opt -module-summary -o %t %s
+; RUN: llvm-lto2 run %t -O0 -r %t,foo,px -o %t2
+; RUN: llvm-nm %t2.0 | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: W foo
+define linkonce_odr void @foo() {
+  ret void
+}




More information about the llvm-commits mailing list