diff options
author | evgeny <eleviant@accesssoftek.com> | 2019-11-15 16:13:19 +0300 |
---|---|---|
committer | evgeny <eleviant@accesssoftek.com> | 2019-11-15 16:13:19 +0300 |
commit | 3d708bf5c2672cae01e5ecb0ed1877e3d56ee451 (patch) | |
tree | 24fe2d3ee2ecc0286cd4a07a4b90d890605a8fdb /llvm/lib/LTO/LTO.cpp | |
parent | 5f0c3bad2f03b9bba7f899d7b0ce667ca355f69d (diff) | |
download | llvm-3d708bf5c2672cae01e5ecb0ed1877e3d56ee451.zip llvm-3d708bf5c2672cae01e5ecb0ed1877e3d56ee451.tar.gz llvm-3d708bf5c2672cae01e5ecb0ed1877e3d56ee451.tar.bz2 |
Recommit "[ThinLTO] Add correctness check for RO/WO variable import"
ValueInfo has user-defined 'operator bool' which allows incorrect implicit conversion
to GlobalValue::GUID (which is unsigned long). This causes bugs which are hard to
track and should be removed in future.
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 112858c..85a14b7 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -147,9 +147,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 @@ -384,12 +386,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 && @@ -397,7 +399,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. @@ -416,12 +418,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>. @@ -1331,11 +1333,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 |