diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-04-26 10:35:01 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-04-26 10:35:01 +0000 |
commit | aa309b1a81e669ee80754ed0fe2d30dc32bfb6ad (patch) | |
tree | 3b6e97718270aca2c975d0c6554801d49b5b48ec /llvm/lib | |
parent | 6e2f32c56123d5ab83051ef8641a8f7d3db505be (diff) | |
download | bcm5719-llvm-aa309b1a81e669ee80754ed0fe2d30dc32bfb6ad.tar.gz bcm5719-llvm-aa309b1a81e669ee80754ed0fe2d30dc32bfb6ad.zip |
ThinLTOCodeGenerator: preserve linkonce when in "MustPreserved" set
If the linker specifically requested for a linkonce to be preserved,
we need to make sure we won't drop it even if all the uses in the
current module disappear.
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 267543
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 51dcc084b49..f4430081dd9 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -137,6 +137,7 @@ bool IsFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList, static GlobalValue::LinkageTypes ResolveODR(const ModuleSummaryIndex &Index, const FunctionImporter::ExportSetTy &ExportList, + const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, StringRef ModuleIdentifier, GlobalValue::GUID GUID, const GlobalValueSummary &GV) { auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) { @@ -163,7 +164,7 @@ ResolveODR(const ModuleSummaryIndex &Index, if (!HasMultipleCopies(GVSummaryList)) { // Exported LinkonceODR needs to be promoted to not be discarded if (GlobalValue::isDiscardableIfUnused(OriginalLinkage) && - ExportList.count(GUID)) + (ExportList.count(GUID) || GUIDPreservedSymbols.count(GUID))) return GlobalValue::WeakODRLinkage; break; } @@ -187,6 +188,7 @@ ResolveODR(const ModuleSummaryIndex &Index, static void ResolveODR( const ModuleSummaryIndex &Index, const FunctionImporter::ExportSetTy &ExportList, + const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols, const GVSummaryMapTy &DefinedGlobals, StringRef ModuleIdentifier, std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR) { if (Index.modulePaths().size() == 1) @@ -206,7 +208,7 @@ static void ResolveODR( if (GlobalInvolvedWithAlias.count(GV.second)) continue; auto NewLinkage = - ResolveODR(Index, ExportList, ModuleIdentifier, GV.first, *GV.second); + ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleIdentifier, GV.first, *GV.second); if (NewLinkage != GV.second->linkage()) { ResolvedODR[GV.first] = NewLinkage; } @@ -681,13 +683,17 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ExportLists); auto &ExportList = ExportLists[ModuleIdentifier]; + // Convert the preserved symbols set from string to GUID + auto GUIDPreservedSymbols = + computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple); + // Resolve the LinkOnceODR, trying to turn them into "available_externally" // where possible. // This is a compile-time optimization. // We use a std::map here to be able to have a defined ordering when // producing a hash for the cache entry. std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR; - ResolveODR(Index, ExportList, ModuleToDefinedGVSummaries[ModuleIdentifier], + ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleToDefinedGVSummaries[ModuleIdentifier], ModuleIdentifier, ResolvedODR); fixupODR(TheModule, ResolvedODR); @@ -841,7 +847,7 @@ void ThinLTOCodeGenerator::run() { // We use a std::map here to be able to have a defined ordering when // producing a hash for the cache entry. std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR; - ResolveODR(*Index, ExportList, DefinedFunctions, ModuleIdentifier, + ResolveODR(*Index, ExportList, GUIDPreservedSymbols, DefinedFunctions, ModuleIdentifier, ResolvedODR); // The module may be cached, this helps handling it. |