Skip to content

Commit a671cee

Browse files
committed
[ORC] Fix an EDU-update bug in ExecutionSession::IL_failSymbols.
We were catching a local variable, SymMI, by value instead of by reference during EDU cleanup and this was leaving the dependence graph in an inconsistent state that could lead to crashes on subsequent emits. Fixing this bug required us to also avoid aliasing between SymMI and MI (which would have caused cleanup to clear the MI.DependantEDUs set that we're iterating over). No testcase: the crash only triggered in very specific circumstances (including concurrent linking) in an out-of-tree ORC client. I'm working on a session state verifier that could be turned on when compiling with expensive-checks turned on and that should help us catch issues like this in the future. rdar://125164262 Coding my way home: 0.89527S, 89.61313W
1 parent 953aa10 commit a671cee

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,12 +3379,17 @@ ExecutionSession::IL_failSymbols(JITDylib &JD,
33793379
for (auto &DependantEDU : MI.DependantEDUs) {
33803380

33813381
// Remove DependantEDU from all of its users DependantEDUs lists.
3382-
for (auto &[JD, Syms] : DependantEDU->Dependencies) {
3383-
for (auto Sym : Syms) {
3384-
assert(JD->Symbols.count(SymbolStringPtr(Sym)) && "Sym not in JD?");
3385-
assert(JD->MaterializingInfos.count(SymbolStringPtr(Sym)) &&
3382+
for (auto &[DepJD, DepSyms] : DependantEDU->Dependencies) {
3383+
for (auto DepSym : DepSyms) {
3384+
// Skip self-reference to avoid invalidating the MI.DependantEDUs
3385+
// map. We'll clear this later.
3386+
if (DepJD == &JD && DepSym == Name)
3387+
continue;
3388+
assert(DepJD->Symbols.count(SymbolStringPtr(DepSym)) &&
3389+
"DepSym not in DepJD?");
3390+
assert(DepJD->MaterializingInfos.count(SymbolStringPtr(DepSym)) &&
33863391
"DependantEDU not registered with symbol it depends on");
3387-
auto SymMI = JD->MaterializingInfos[SymbolStringPtr(Sym)];
3392+
auto &SymMI = DepJD->MaterializingInfos[SymbolStringPtr(DepSym)];
33883393
assert(SymMI.DependantEDUs.count(DependantEDU) &&
33893394
"DependantEDU missing from DependantEDUs list");
33903395
SymMI.DependantEDUs.erase(DependantEDU);

0 commit comments

Comments
 (0)