diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-02-02 05:22:42 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-02-02 05:22:42 +0000 |
commit | 4613626d49998297e3d3278cea359dbee495f742 (patch) | |
tree | 0df720168d73456d3b9b9fd15c83b238cca09c8d /llvm/lib/LTO/LTO.cpp | |
parent | c387e70c699330dbfb6599a005a281960ca6da70 (diff) | |
download | bcm5719-llvm-4613626d49998297e3d3278cea359dbee495f742.tar.gz bcm5719-llvm-4613626d49998297e3d3278cea359dbee495f742.zip |
LTO: Link non-prevailing weak_odr or linkonce_odr globals into the combined module with available_externally linkage.
These linkages mean that the ultimately prevailing symbol will have the same
semantics as any non-prevailing copy of the symbol, so we are free to ignore
the linker's resolution.
Differential Revision: https://reviews.llvm.org/D29367
llvm-svn: 293865
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 4d0c039891e..df19ded398d 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -446,6 +446,11 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI, if (GV.hasAppendingLinkage()) Keep.push_back(&GV); + DenseSet<GlobalObject *> AliasedGlobals; + for (auto &GA : M.aliases()) + if (GlobalObject *GO = GA.getBaseObject()) + AliasedGlobals.insert(GO); + for (const InputFile::Symbol &Sym : make_range(InputFile::symbol_iterator(SymTab.symbols().begin(), SymTab, nullptr), @@ -471,13 +476,21 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI, GV->setLinkage(GlobalValue::WeakODRLinkage); break; } - } else if (GV->hasAvailableExternallyLinkage()) { - // We can link available_externally symbols even if they are - // non-prevailing. + } else if (isa<GlobalObject>(GV) && + (GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage() || + GV->hasAvailableExternallyLinkage()) && + !AliasedGlobals.count(cast<GlobalObject>(GV))) { + // Either of the above three types of linkage indicates that the + // chosen prevailing symbol will have the same semantics as this copy of + // the symbol, so we can link it with available_externally linkage. We + // only need to do this if the symbol is undefined. GlobalValue *CombinedGV = RegularLTO.CombinedModule->getNamedValue(GV->getName()); - if (!CombinedGV || CombinedGV->isDeclaration()) + if (!CombinedGV || CombinedGV->isDeclaration()) { Keep.push_back(GV); + GV->setLinkage(GlobalValue::AvailableExternallyLinkage); + cast<GlobalObject>(GV)->setComdat(nullptr); + } } } // Common resolution: collect the maximum size/alignment over all commons. |