[lld] r354410 - [lld-link] preserve @llvm.used symbols in LTO

Bob Haarman via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 19 16:26:01 PST 2019


Author: inglorion
Date: Tue Feb 19 16:26:01 2019
New Revision: 354410

URL: http://llvm.org/viewvc/llvm-project?rev=354410&view=rev
Log:
[lld-link] preserve @llvm.used symbols in LTO

Summary:
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.

Reviewers: rnk, pcc, ruiu

Reviewed By: ruiu

Subscribers: mehdi_amini, steven_wu, dexonsmith, dang, llvm-commits

Tags: #llvm

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

Added:
    lld/trunk/test/COFF/used-lto.ll
Modified:
    lld/trunk/COFF/InputFiles.cpp

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=354410&r1=354409&r2=354410&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Tue Feb 19 16:26:01 2019
@@ -688,6 +688,8 @@ void BitcodeFile::parse() {
       Sym = Symtab->addRegular(this, SymName);
     }
     Symbols.push_back(Sym);
+    if (ObjSym.isUsed())
+      Config->GCRoot.push_back(Sym);
   }
   Directives = Obj->getCOFFLinkerOpts();
 }

Added: lld/trunk/test/COFF/used-lto.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/used-lto.ll?rev=354410&view=auto
==============================================================================
--- lld/trunk/test/COFF/used-lto.ll (added)
+++ lld/trunk/test/COFF/used-lto.ll Tue Feb 19 16:26:01 2019
@@ -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
+}




More information about the llvm-commits mailing list