Skip to content

Commit 1c499a7

Browse files
lhamestru
authored andcommitted
[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 (cherry picked from commit 7034ec4)
1 parent c011dce commit 1c499a7

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
@@ -3592,6 +3592,21 @@ ExecutionSession::IL_failSymbols(JITDylib &JD,
35923592
assert(MI.DefiningEDU->Symbols.count(NonOwningSymbolStringPtr(Name)) &&
35933593
"Symbol does not appear in its DefiningEDU");
35943594
MI.DefiningEDU->Symbols.erase(NonOwningSymbolStringPtr(Name));
3595+
3596+
// Remove this EDU from the dependants lists of its dependencies.
3597+
for (auto &[DepJD, DepSyms] : MI.DefiningEDU->Dependencies) {
3598+
for (auto DepSym : DepSyms) {
3599+
assert(DepJD->Symbols.count(SymbolStringPtr(DepSym)) &&
3600+
"DepSym not in DepJD");
3601+
assert(DepJD->MaterializingInfos.count(SymbolStringPtr(DepSym)) &&
3602+
"DepSym has not MaterializingInfo");
3603+
auto &SymMI = DepJD->MaterializingInfos[SymbolStringPtr(DepSym)];
3604+
assert(SymMI.DependantEDUs.count(MI.DefiningEDU.get()) &&
3605+
"DefiningEDU missing from DependantEDUs list of dependency");
3606+
SymMI.DependantEDUs.erase(MI.DefiningEDU.get());
3607+
}
3608+
}
3609+
35953610
MI.DefiningEDU = nullptr;
35963611
} else {
35973612
// Otherwise if there are any EDUs waiting on this symbol then move

0 commit comments

Comments
 (0)