summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Haarman <llvm@inglorion.net>2019-02-20 00:26:01 +0000
committerBob Haarman <llvm@inglorion.net>2019-02-20 00:26:01 +0000
commit61e8735f17fd81aac20abb1775efbbbaea97893a (patch)
tree2ada958f774382708a6a02f6d317ba1197ad66cd
parent8e21c08593deb5d29c896c7ed02611307fe0c038 (diff)
downloadbcm5719-llvm-61e8735f17fd81aac20abb1775efbbbaea97893a.tar.gz
bcm5719-llvm-61e8735f17fd81aac20abb1775efbbbaea97893a.zip
[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 llvm-svn: 354410
-rw-r--r--lld/COFF/InputFiles.cpp2
-rw-r--r--lld/test/COFF/used-lto.ll15
-rw-r--r--llvm/include/llvm/LTO/LTO.h1
3 files changed, 18 insertions, 0 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 1ebb5da1b71..ae68cbe0d44 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -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();
}
diff --git a/lld/test/COFF/used-lto.ll b/lld/test/COFF/used-lto.ll
new file mode 100644
index 00000000000..c269fbac85d
--- /dev/null
+++ b/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"
+
+@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
+
+define void @foo() {
+ ret void
+}
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index 1f9d764f068..ab4d874b55e 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -139,6 +139,7 @@ public:
using irsymtab::Symbol::getCOFFWeakExternalFallback;
using irsymtab::Symbol::getSectionName;
using irsymtab::Symbol::isExecutable;
+ using irsymtab::Symbol::isUsed;
};
/// A range over the symbols in this InputFile.
OpenPOWER on IntegriCloud