diff options
author | evgeny <eleviant@accesssoftek.com> | 2019-11-14 12:24:05 +0300 |
---|---|---|
committer | evgeny <eleviant@accesssoftek.com> | 2019-11-14 12:24:05 +0300 |
commit | a2292cc537b561416c21e8d4017715d652c144cc (patch) | |
tree | 25a1ee4080caa66aaeec153b3d15289ee545317e /llvm/lib/LTO/LTO.cpp | |
parent | eafe0cf5fa8255257bac3923237e62382610e6d6 (diff) | |
download | bcm5719-llvm-a2292cc537b561416c21e8d4017715d652c144cc.tar.gz bcm5719-llvm-a2292cc537b561416c21e8d4017715d652c144cc.zip |
[ThinLTO] Add correctness check for RO/WO variable import
This patch adds an assertion check for exported read/write-only
variables to be also in import list for module. If they aren't
we may face linker errors, because read/write-only variables are
internalized in their source modules. The patch also changes
export lists to store ValueInfo instead of GUID for performance
considerations.
Differential revision: https://reviews.llvm.org/D70128
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 1e345e7dd89..9c59ec40274 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -146,9 +146,11 @@ void llvm::computeLTOCacheKey( // Include the hash for the current module auto ModHash = Index.getModuleHash(ModuleID); Hasher.update(ArrayRef<uint8_t>((uint8_t *)&ModHash[0], sizeof(ModHash))); - for (auto F : ExportList) + for (const auto &VI : ExportList) { + auto GUID = VI.getGUID(); // The export list can impact the internalization, be conservative here - Hasher.update(ArrayRef<uint8_t>((uint8_t *)&F, sizeof(F))); + Hasher.update(ArrayRef<uint8_t>((uint8_t *)&GUID, sizeof(GUID))); + } // Include the hash for every module we import functions from. The set of // imported symbols for each module may affect code generation and is @@ -383,12 +385,12 @@ static bool isWeakObjectWithRWAccess(GlobalValueSummary *GVS) { } static void thinLTOInternalizeAndPromoteGUID( - GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID, - function_ref<bool(StringRef, GlobalValue::GUID)> isExported, + GlobalValueSummaryList &GVSummaryList, ValueInfo VI, + function_ref<bool(StringRef, ValueInfo)> isExported, function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) { for (auto &S : GVSummaryList) { - if (isExported(S->modulePath(), GUID)) { + if (isExported(S->modulePath(), VI)) { if (GlobalValue::isLocalLinkage(S->linkage())) S->setLinkage(GlobalValue::ExternalLinkage); } else if (EnableLTOInternalization && @@ -396,7 +398,7 @@ static void thinLTOInternalizeAndPromoteGUID( // doesn't resolve them. !GlobalValue::isLocalLinkage(S->linkage()) && (!GlobalValue::isInterposableLinkage(S->linkage()) || - isPrevailing(GUID, S.get())) && + isPrevailing(VI.getGUID(), S.get())) && S->linkage() != GlobalValue::AppendingLinkage && // We can't internalize available_externally globals because this // can break function pointer equality. @@ -415,12 +417,12 @@ static void thinLTOInternalizeAndPromoteGUID( // as external and non-exported values as internal. void llvm::thinLTOInternalizeAndPromoteInIndex( ModuleSummaryIndex &Index, - function_ref<bool(StringRef, GlobalValue::GUID)> isExported, + function_ref<bool(StringRef, ValueInfo)> isExported, function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)> isPrevailing) { for (auto &I : Index) - thinLTOInternalizeAndPromoteGUID(I.second.SummaryList, I.first, isExported, - isPrevailing); + thinLTOInternalizeAndPromoteGUID( + I.second.SummaryList, Index.getValueInfo(I), isExported, isPrevailing); } // Requires a destructor for std::vector<InputModule>. @@ -1330,11 +1332,10 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, ExportedGUIDs.insert( GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Def))); - auto isExported = [&](StringRef ModuleIdentifier, GlobalValue::GUID GUID) { + auto isExported = [&](StringRef ModuleIdentifier, ValueInfo VI) { const auto &ExportList = ExportLists.find(ModuleIdentifier); - return (ExportList != ExportLists.end() && - ExportList->second.count(GUID)) || - ExportedGUIDs.count(GUID); + return (ExportList != ExportLists.end() && ExportList->second.count(VI)) || + ExportedGUIDs.count(VI.getGUID()); }; // Update local devirtualized targets that were exported by cross-module |