From: Lang Hames Date: Thu, 29 Apr 2021 20:47:44 +0000 (-0700) Subject: [ORC] JITDylib::addDependencies should be run under the session lock. X-Git-Tag: llvmorg-14-init~8034 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaf026d9da3885a951dcdc5edd64c8e7d23b6285;p=platform%2Fupstream%2Fllvm.git [ORC] JITDylib::addDependencies should be run under the session lock. --- diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 2959139..1e3384d 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -800,76 +800,79 @@ JITDylib::getRequestedSymbols(const SymbolFlagsMap &SymbolFlags) const { void JITDylib::addDependencies(const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies) { - assert(Symbols.count(Name) && "Name not in symbol table"); - assert(Symbols[Name].getState() < SymbolState::Emitted && - "Can not add dependencies for a symbol that is not materializing"); + ES.runSessionLocked([&]() { + assert(Symbols.count(Name) && "Name not in symbol table"); + assert(Symbols[Name].getState() < SymbolState::Emitted && + "Can not add dependencies for a symbol that is not materializing"); - LLVM_DEBUG({ - dbgs() << "In " << getName() << " adding dependencies for " - << *Name << ": " << Dependencies << "\n"; + LLVM_DEBUG({ + dbgs() << "In " << getName() << " adding dependencies for " << *Name + << ": " << Dependencies << "\n"; }); - // If Name is already in an error state then just bail out. - if (Symbols[Name].getFlags().hasError()) - return; + // If Name is already in an error state then just bail out. + if (Symbols[Name].getFlags().hasError()) + return; - auto &MI = MaterializingInfos[Name]; - assert(Symbols[Name].getState() != SymbolState::Emitted && - "Can not add dependencies to an emitted symbol"); + auto &MI = MaterializingInfos[Name]; + assert(Symbols[Name].getState() != SymbolState::Emitted && + "Can not add dependencies to an emitted symbol"); - bool DependsOnSymbolInErrorState = false; + bool DependsOnSymbolInErrorState = false; - // Register dependencies, record whether any depenendency is in the error - // state. - for (auto &KV : Dependencies) { - assert(KV.first && "Null JITDylib in dependency?"); - auto &OtherJITDylib = *KV.first; - auto &DepsOnOtherJITDylib = MI.UnemittedDependencies[&OtherJITDylib]; + // Register dependencies, record whether any depenendency is in the error + // state. + for (auto &KV : Dependencies) { + assert(KV.first && "Null JITDylib in dependency?"); + auto &OtherJITDylib = *KV.first; + auto &DepsOnOtherJITDylib = MI.UnemittedDependencies[&OtherJITDylib]; - for (auto &OtherSymbol : KV.second) { + for (auto &OtherSymbol : KV.second) { - // Check the sym entry for the dependency. - auto OtherSymI = OtherJITDylib.Symbols.find(OtherSymbol); + // Check the sym entry for the dependency. + auto OtherSymI = OtherJITDylib.Symbols.find(OtherSymbol); - // Assert that this symbol exists and has not reached the ready state - // already. - assert(OtherSymI != OtherJITDylib.Symbols.end() && - "Dependency on unknown symbol"); + // Assert that this symbol exists and has not reached the ready state + // already. + assert(OtherSymI != OtherJITDylib.Symbols.end() && + "Dependency on unknown symbol"); - auto &OtherSymEntry = OtherSymI->second; + auto &OtherSymEntry = OtherSymI->second; - // If the other symbol is already in the Ready state then there's no - // dependency to add. - if (OtherSymEntry.getState() == SymbolState::Ready) - continue; + // If the other symbol is already in the Ready state then there's no + // dependency to add. + if (OtherSymEntry.getState() == SymbolState::Ready) + continue; - // If the dependency is in an error state then note this and continue, - // we will move this symbol to the error state below. - if (OtherSymEntry.getFlags().hasError()) { - DependsOnSymbolInErrorState = true; - continue; - } + // If the dependency is in an error state then note this and continue, + // we will move this symbol to the error state below. + if (OtherSymEntry.getFlags().hasError()) { + DependsOnSymbolInErrorState = true; + continue; + } - // If the dependency was not in the error state then add it to - // our list of dependencies. - auto &OtherMI = OtherJITDylib.MaterializingInfos[OtherSymbol]; + // If the dependency was not in the error state then add it to + // our list of dependencies. + auto &OtherMI = OtherJITDylib.MaterializingInfos[OtherSymbol]; - if (OtherSymEntry.getState() == SymbolState::Emitted) - transferEmittedNodeDependencies(MI, Name, OtherMI); - else if (&OtherJITDylib != this || OtherSymbol != Name) { - OtherMI.Dependants[this].insert(Name); - DepsOnOtherJITDylib.insert(OtherSymbol); + if (OtherSymEntry.getState() == SymbolState::Emitted) + transferEmittedNodeDependencies(MI, Name, OtherMI); + else if (&OtherJITDylib != this || OtherSymbol != Name) { + OtherMI.Dependants[this].insert(Name); + DepsOnOtherJITDylib.insert(OtherSymbol); + } } - } - if (DepsOnOtherJITDylib.empty()) - MI.UnemittedDependencies.erase(&OtherJITDylib); - } + if (DepsOnOtherJITDylib.empty()) + MI.UnemittedDependencies.erase(&OtherJITDylib); + } - // If this symbol dependended on any symbols in the error state then move - // this symbol to the error state too. - if (DependsOnSymbolInErrorState) - Symbols[Name].setFlags(Symbols[Name].getFlags() | JITSymbolFlags::HasError); + // If this symbol dependended on any symbols in the error state then move + // this symbol to the error state too. + if (DependsOnSymbolInErrorState) + Symbols[Name].setFlags(Symbols[Name].getFlags() | + JITSymbolFlags::HasError); + }); } Error JITDylib::resolve(MaterializationResponsibility &MR,