summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LTO.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-03-29 21:46:35 +0000
committerDavide Italiano <davide@freebsd.org>2016-03-29 21:46:35 +0000
commit86f2bd5ca117562e78150a12a473e8db3d47faaa (patch)
treedcc01e591b79c2e5dfad66cd3fead98a59c828d0 /lld/ELF/LTO.cpp
parenta144fb148bed550baab070e86aedfeb2d3e8338b (diff)
downloadbcm5719-llvm-86f2bd5ca117562e78150a12a473e8db3d47faaa.tar.gz
bcm5719-llvm-86f2bd5ca117562e78150a12a473e8db3d47faaa.zip
[LTO] Teach LTO about @llvm.used global.
If a symbol appears in @llvm.used, the linker is forced to treat the symbol as there's a reference to it. llvm-svn: 264790
Diffstat (limited to 'lld/ELF/LTO.cpp')
-rw-r--r--lld/ELF/LTO.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 191ec725fab..9a24115dfa8 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -21,6 +21,7 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;
@@ -76,6 +77,10 @@ void BitcodeCompiler::add(BitcodeFile &F) {
unsigned BodyIndex = 0;
ArrayRef<SymbolBody *> Bodies = F.getSymbols();
+ Module &M = Obj->getModule();
+ SmallPtrSet<GlobalValue *, 8> Used;
+ collectUsedGlobalVariables(M, Used, /* CompilerUsed */ false);
+
for (const BasicSymbolRef &Sym : Obj->symbols()) {
GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
assert(GV);
@@ -108,7 +113,8 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// For now, let's be conservative and just never internalize
// symbols when creating a shared library.
if (!Config->Shared && !Config->ExportDynamic && !B->isUsedInRegularObj())
- InternalizedSyms.insert(GV->getName());
+ if (!Used.count(GV))
+ InternalizedSyms.insert(GV->getName());
Keep.push_back(GV);
}
OpenPOWER on IntegriCloud