[PATCH] D32544: LTO: Mark undefined module inline asm symbols as visible outside of ThinLTO.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 10:12:24 PDT 2017


pcc created this revision.
Herald added subscribers: inglorion, Prazek, mehdi_amini.

Fixes PR32798.


https://reviews.llvm.org/D32544

Files:
  llvm/lib/LTO/LTO.cpp
  llvm/lib/Object/IRSymtab.cpp
  llvm/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll
  llvm/test/LTO/Resolution/X86/mod-asm-used.ll


Index: llvm/test/LTO/Resolution/X86/mod-asm-used.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/mod-asm-used.ll
@@ -0,0 +1,10 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: opt -module-summary -o %t2.bc %S/Inputs/mod-asm-used.ll
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,l %t2.bc -r %t2.bc,foo,pl -o %t3
+; RUN: llvm-nm %t3.1 | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: D foo
+module asm ".quad foo"
Index: llvm/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll
@@ -0,0 +1,4 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = global i32 1, align 4
Index: llvm/lib/Object/IRSymtab.cpp
===================================================================
--- llvm/lib/Object/IRSymtab.cpp
+++ llvm/lib/Object/IRSymtab.cpp
@@ -163,6 +163,9 @@
   Sym.ComdatIndex = -1;
   auto *GV = Msym.dyn_cast<GlobalValue *>();
   if (!GV) {
+    // Undefined module asm symbols act as GC roots and are implicitly used.
+    if (Flags & object::BasicSymbolRef::SF_Undefined)
+      Sym.Flags |= 1 << storage::Symbol::FB_used;
     setStr(Sym.IRName, "");
     return Error::success();
   }
Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -415,7 +415,8 @@
   // Flag as visible outside of ThinLTO if visible from a regular object or
   // if this is a reference in the regular LTO partition.
   GlobalRes.VisibleOutsideThinLTO |=
-      (Res.VisibleToRegularObj || (Partition == GlobalResolution::RegularLTO));
+      (Res.VisibleToRegularObj || Sym.isUsed() ||
+       Partition == GlobalResolution::RegularLTO);
 }
 
 static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32544.96779.patch
Type: text/x-patch
Size: 2036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170426/cf6f579f/attachment.bin>


More information about the llvm-commits mailing list