[patch] Fix pr25919

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 07:46:12 PST 2015

The asserts for checking all uses while the module is being
materialized found the first problem.

The issues happens when libLTO is trying to set
LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN. It needs all uses in order to
produce a valid answer.

The attached patch adds a graceful degradation.

What is done instead in the gold plugin is to check the uses in the
merged module.

If this degrades quality too much, a solution would be to check the
uses and add unnamed_addr marks at the end of IRGen. That way
canBeOmittedFromSymbolTable would not need to run analyzeGlobal at

-------------- next part --------------
diff --git a/lib/CodeGen/Analysis.cpp b/lib/CodeGen/Analysis.cpp
index 75579a2..7146876 100644
--- a/lib/CodeGen/Analysis.cpp
+++ b/lib/CodeGen/Analysis.cpp
@@ -639,6 +639,11 @@ bool llvm::canBeOmittedFromSymbolTable(const GlobalValue *GV) {
   if (isa<GlobalAlias>(GV))
     return false;
+  // If we don't see every use, we have to be conservative and assume the value
+  // address is significant.
+  if (!GV->getParent()->isMaterialized())
+    return false;
   GlobalStatus GS;
   if (GlobalStatus::analyzeGlobal(GV, GS))
     return false;
diff --git a/test/LTO/X86/pr25919.ll b/test/LTO/X86/pr25919.ll
new file mode 100644
index 0000000..b7fe0c6
--- /dev/null
+++ b/test/LTO/X86/pr25919.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s >%t1
+; RUN: llvm-lto -list-symbols-only %t1 | FileCheck %s
+; This tests that we don't crash trying to find all uses in a lazily loaded
+; module.
+; CHECK: foo
+target triple = "x86_64-unknown-linux-gnu"
+define linkonce_odr void @foo() {
+  ret void

More information about the llvm-commits mailing list