Skip to content

Commit 7034ec4

Browse files
committed
[ORC] Remove EDU from dependants list of dependencies before destroying.
Dependant lists hold raw pointers back to EDUs that depend on them. We need to remove these entries before destroying the EDU or we'll be left with a dangling reference that can result in use-after-free bugs. No testcase: This has only been observed in multi-threaded setups that reproduce the issue inconsistently. rdar://135403614
1 parent 02ab435 commit 7034ec4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,21 @@ ExecutionSession::IL_failSymbols(JITDylib &JD,
36073607
assert(MI.DefiningEDU->Symbols.count(NonOwningSymbolStringPtr(Name)) &&
36083608
"Symbol does not appear in its DefiningEDU");
36093609
MI.DefiningEDU->Symbols.erase(NonOwningSymbolStringPtr(Name));
3610+
3611+
// Remove this EDU from the dependants lists of its dependencies.
3612+
for (auto &[DepJD, DepSyms] : MI.DefiningEDU->Dependencies) {
3613+
for (auto DepSym : DepSyms) {
3614+
assert(DepJD->Symbols.count(SymbolStringPtr(DepSym)) &&
3615+
"DepSym not in DepJD");
3616+
assert(DepJD->MaterializingInfos.count(SymbolStringPtr(DepSym)) &&
3617+
"DepSym has not MaterializingInfo");
3618+
auto &SymMI = DepJD->MaterializingInfos[SymbolStringPtr(DepSym)];
3619+
assert(SymMI.DependantEDUs.count(MI.DefiningEDU.get()) &&
3620+
"DefiningEDU missing from DependantEDUs list of dependency");
3621+
SymMI.DependantEDUs.erase(MI.DefiningEDU.get());
3622+
}
3623+
}
3624+
36103625
MI.DefiningEDU = nullptr;
36113626
} else {
36123627
// Otherwise if there are any EDUs waiting on this symbol then move

0 commit comments

Comments
 (0)