[PATCH] D58255: [lld-link] preserve @llvm.used symbols in LTO

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 14 15:04:38 PST 2019


inglorion created this revision.
inglorion added reviewers: rnk, pcc, ruiu.
Herald added subscribers: dang, dexonsmith, steven_wu, mehdi_amini.
Herald added a project: LLVM.

We translate @llvm.used to COFF by generating /include directives
in the .drectve section. However, in LTO links, this happens after
directives have already been processed, so the new directives do
not take effect. This change marks @llvm.used symbols as GCRoots
so that they are preserved as intended.

Fixes PR40733.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58255

Files:
  lld/COFF/InputFiles.cpp
  lld/test/COFF/used-lto.ll
  llvm/include/llvm/LTO/LTO.h


Index: llvm/include/llvm/LTO/LTO.h
===================================================================
--- llvm/include/llvm/LTO/LTO.h
+++ llvm/include/llvm/LTO/LTO.h
@@ -139,6 +139,7 @@
     using irsymtab::Symbol::getCOFFWeakExternalFallback;
     using irsymtab::Symbol::getSectionName;
     using irsymtab::Symbol::isExecutable;
+    using irsymtab::Symbol::isUsed;
   };
 
   /// A range over the symbols in this InputFile.
Index: lld/test/COFF/used-lto.ll
===================================================================
--- /dev/null
+++ lld/test/COFF/used-lto.ll
@@ -0,0 +1,15 @@
+; REQUIRES: x86
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link -dll -debug -opt:ref -noentry -out:%t.dll %t.obj
+; RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
+
+; CHECK: S_PUB32 {{.*}} `foo`
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+
+define void @foo() {
+  ret void
+}
Index: lld/COFF/InputFiles.cpp
===================================================================
--- lld/COFF/InputFiles.cpp
+++ lld/COFF/InputFiles.cpp
@@ -688,6 +688,8 @@
       Sym = Symtab->addRegular(this, SymName);
     }
     Symbols.push_back(Sym);
+    if (ObjSym.isUsed())
+      Config->GCRoot.push_back(Sym);
   }
   Directives = Obj->getCOFFLinkerOpts();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58255.186924.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/5f3c71e4/attachment.bin>


More information about the llvm-commits mailing list