Skip to content

[BOLT] Fix local out-of-range stub issue that leads to infinite loop in LongJmp pass #73918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions bolt/lib/Passes/LongJmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,23 @@ LongJmpPass::replaceTargetWithStub(BinaryBasicBlock &BB, MCInst &Inst,
}
} else if (LocalStubsIter != Stubs.end() &&
LocalStubsIter->second.count(TgtBB)) {
// If we are replacing a local stub (because it is now out of range),
// use its target instead of creating a stub to jump to another stub
// The TgtBB and TgtSym now are the local out-of-range stub and its label.
// So, we are attempting to restore BB to its previous state without using
// this stub.
TgtSym = BC.MIB->getTargetSymbol(*TgtBB->begin());
TgtBB = BB.getSuccessor(TgtSym, BI);
assert(TgtSym &&
"First instruction is expected to contain a target symbol.");
BinaryBasicBlock *TgtBBSucc = TgtBB->getSuccessor(TgtSym, BI);

// TgtBB might have no successor. e.g. a stub for a function call.
if (TgtBBSucc) {
BB.replaceSuccessor(TgtBB, TgtBBSucc, BI.Count, BI.MispredictedCount);
assert(TgtBB->getExecutionCount() >= BI.Count &&
"At least equal or greater than the branch count.");
TgtBB->setExecutionCount(TgtBB->getExecutionCount() - BI.Count);
}

TgtBB = TgtBBSucc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please add new line after }

}

BinaryBasicBlock *StubBB = lookupLocalStub(BB, Inst, TgtSym, DotAddress);
Expand Down