Index: llvm/lib/LTO/LTO.cpp =================================================================== --- llvm/lib/LTO/LTO.cpp +++ llvm/lib/LTO/LTO.cpp @@ -139,8 +139,17 @@ // Include the hash for the current module auto ModHash = Index.getModuleHash(ModuleID); Hasher.update(ArrayRef((uint8_t *)&ModHash[0], sizeof(ModHash))); + + std::vector ExportsGUID; + ExportsGUID.reserve(ExportList.size()); for (const auto &VI : ExportList) { auto GUID = VI.getGUID(); + ExportsGUID.push_back(GUID); + } + + // Sort the export list elemets GUIDs. + std::stable_sort(ExportsGUID.begin(), ExportsGUID.end()); + for (uint64_t GUID : ExportsGUID) { // The export list can impact the internalization, be conservative here Hasher.update(ArrayRef((uint8_t *)&GUID, sizeof(GUID))); } @@ -148,12 +157,22 @@ // Include the hash for every module we import functions from. The set of // imported symbols for each module may affect code generation and is // sensitive to link order, so include that as well. + std::vector ImportModulesVector; for (auto &Entry : ImportList) { - auto ModHash = Index.getModuleHash(Entry.first()); + llvm::StringRef ModId = Entry.first(); + ImportModulesVector.push_back(ModId); + } + std::sort(ImportModulesVector.begin(), ImportModulesVector.end()); + + for (StringRef ModId : ImportModulesVector) { + auto EntryIt = ImportList.find(ModId); + assert(EntryIt != ImportList.end() && + "Internal error - No Module ID has been found in the Imports list."); + auto ModHash = Index.getModuleHash(EntryIt->first()); Hasher.update(ArrayRef((uint8_t *)&ModHash[0], sizeof(ModHash))); - AddUint64(Entry.second.size()); - for (auto &Fn : Entry.second) + AddUint64(EntryIt->second.size()); + for (auto &Fn : EntryIt->second) AddUint64(Fn); }