@@ -674,7 +674,8 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
674
674
MCPlusBuilder *MIB = Function.getBinaryContext ().MIB .get ();
675
675
for (BinaryBasicBlock &BB : Function) {
676
676
auto checkAndPatch = [&](BinaryBasicBlock *Pred, BinaryBasicBlock *Succ,
677
- const MCSymbol *SuccSym) {
677
+ const MCSymbol *SuccSym,
678
+ std::optional<uint32_t > Offset) {
678
679
// Ignore infinite loop jumps or fallthrough tail jumps.
679
680
if (Pred == Succ || Succ == &BB)
680
681
return false ;
@@ -715,9 +716,11 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
715
716
Pred->removeSuccessor (&BB);
716
717
Pred->eraseInstruction (Pred->findInstruction (Branch));
717
718
Pred->addTailCallInstruction (SuccSym);
718
- MCInst *TailCall = Pred->getLastNonPseudoInstr ();
719
- assert (TailCall);
720
- MIB->setOffset (*TailCall, BB.getOffset ());
719
+ if (Offset) {
720
+ MCInst *TailCall = Pred->getLastNonPseudoInstr ();
721
+ assert (TailCall);
722
+ MIB->setOffset (*TailCall, *Offset);
723
+ }
721
724
} else {
722
725
return false ;
723
726
}
@@ -760,7 +763,8 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
760
763
if (Pred->getSuccessor () == &BB ||
761
764
(Pred->getConditionalSuccessor (true ) == &BB && !IsTailCall) ||
762
765
Pred->getConditionalSuccessor (false ) == &BB)
763
- if (checkAndPatch (Pred, Succ, SuccSym) && MarkInvalid)
766
+ if (checkAndPatch (Pred, Succ, SuccSym, MIB->getOffset (*Inst)) &&
767
+ MarkInvalid)
764
768
BB.markValid (BB.pred_size () != 0 || BB.isLandingPad () ||
765
769
BB.isEntryPoint ());
766
770
}
0 commit comments