1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ORC] Bail out early if a replacement MaterializationUnit is empty.

The MU may define no symbols, but still contain a non-trivial destructor (e.g.
an LLVM IR module that has been stripped of all externally visible
definitions, but which still needs to lock its context to be destroyed).
Bailing out early ensures that we destroy the unit outside the session lock,
rather than under it which may cause deadlocks.

Also adds some extra sanity-checking assertions.
This commit is contained in:
Lang Hames 2020-03-18 19:48:01 -07:00
parent 5c8fcd9cfc
commit 91189ff985

View File

@ -516,8 +516,15 @@ void MaterializationResponsibility::failMaterialization() {
void MaterializationResponsibility::replace(
std::unique_ptr<MaterializationUnit> MU) {
for (auto &KV : MU->getSymbols())
// If the replacement MU is empty then return.
if (MU->getSymbols().empty())
return;
for (auto &KV : MU->getSymbols()) {
assert(SymbolFlags.count(KV.first) &&
"Replacing definition outside this responsibility set");
SymbolFlags.erase(KV.first);
}
if (MU->getInitializerSymbol() == InitSymbol)
InitSymbol = nullptr;
@ -934,7 +941,11 @@ void JITDylib::replace(std::unique_ptr<MaterializationUnit> MU) {
"Unexpected materializer entry in map");
SymI->second.setAddress(SymI->second.getAddress());
SymI->second.setMaterializerAttached(true);
UnmaterializedInfos[KV.first] = UMI;
auto &UMIEntry = UnmaterializedInfos[KV.first];
assert((!UMIEntry || !UMIEntry->MU) &&
"Replacing symbol with materializer still attached");
UMIEntry = UMI;
}
return nullptr;