summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LTO.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-03-28 15:44:21 +0000
committerDavide Italiano <davide@freebsd.org>2016-03-28 15:44:21 +0000
commit828ac541ef7620e7bccfded34866176d7186d2d1 (patch)
treed5d6e18b6ef53e4bcac8afc2365c3a2949eb6702 /lld/ELF/LTO.cpp
parent2d65ea74dcd26fe6468944900b7d6f762f64e54c (diff)
downloadbcm5719-llvm-828ac541ef7620e7bccfded34866176d7186d2d1.tar.gz
bcm5719-llvm-828ac541ef7620e7bccfded34866176d7186d2d1.zip
[LTO] Internalize symbols.
IPO doesn't work very well across symbols referenced by others TUs. The linker here tries to evaluate which symbols are safe to internalize and switches their linkage. Differential Revision: http://reviews.llvm.org/D18415 llvm-svn: 264585
Diffstat (limited to 'lld/ELF/LTO.cpp')
-rw-r--r--lld/ELF/LTO.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index cbdd49ab3d1..528a914b6a1 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -97,6 +97,18 @@ void BitcodeCompiler::add(BitcodeFile &F) {
GV->setLinkage(GlobalValue::WeakODRLinkage);
break;
}
+
+ // We collect the set of symbols we want to internalize here
+ // and change the linkage after the IRMover executed, i.e. after
+ // we imported the symbols and satisfied undefined references
+ // to it. We can't just change linkage here because otherwise
+ // the IRMover will just rename the symbol.
+ // Shared libraries need to be handled slightly differently.
+ // For now, let's be conservative and just never internalize
+ // symbols when creating a shared library.
+ if (!Config->Shared && !B->isUsedInRegularObj())
+ InternalizedSyms.insert(GV->getName());
+
Keep.push_back(GV);
}
@@ -104,10 +116,22 @@ void BitcodeCompiler::add(BitcodeFile &F) {
[](GlobalValue &, IRMover::ValueAdder) {});
}
+static void internalize(GlobalValue &GV) {
+ assert(!GV.hasLocalLinkage() &&
+ "Trying to internalize a symbol with local linkage!") ;
+ GV.setLinkage(GlobalValue::InternalLinkage);
+}
+
// Merge all the bitcode files we have seen, codegen the result
// and return the resulting ObjectFile.
template <class ELFT>
std::unique_ptr<elf::ObjectFile<ELFT>> BitcodeCompiler::compile() {
+ for (const auto &Name : InternalizedSyms) {
+ GlobalValue *GV = Combined.getNamedValue(Name.first());
+ assert(GV);
+ internalize(*GV);
+ }
+
if (Config->SaveTemps)
saveBCFile(Combined, ".lto.bc");
OpenPOWER on IntegriCloud