[BOLT] Check instruction boundaries while populating jump tables

Summary:
Now that we populate jump tables after all functions are disassembled,
we can check for instruction boundaries corresponding to jump table
entries. No need to delegate this task to postProcessJumpTables().

(cherry picked from FBD15814762)
This commit is contained in:
Maksim Panchenko
2019-06-13 15:31:30 -07:00
parent 9e2ad3f593
commit 9894de0094
2 changed files with 8 additions and 17 deletions

View File

@@ -406,12 +406,14 @@ void BinaryContext::populateJumpTables() {
}
// We assume that a jump table cannot have function start as an entry.
if (BF.containsAddress(Value) && Value != BF.getAddress()) {
JT->OffsetEntries.emplace_back(Value - BF.getAddress());
continue;
}
if (!BF.containsAddress(Value) || Value == BF.getAddress())
break;
break;
// Check there's an instruction at this offset.
if (!BF.getInstructionAtOffset(Value - BF.getAddress()))
break;
JT->OffsetEntries.emplace_back(Value - BF.getAddress());
}
assert(JT->OffsetEntries.size() > 1 &&

View File

@@ -1351,18 +1351,7 @@ void BinaryFunction::postProcessJumpTables() {
"detected in function " << *this << '\n';
}
for (unsigned I = 0; I < JT.OffsetEntries.size(); ++I) {
auto Offset = JT.OffsetEntries[I];
if (Offset != getSize() && !getInstructionAtOffset(Offset)) {
DEBUG(dbgs() << "BOLT-DEBUG: truncating jump table " << JT.getName()
<< " at index " << I << " containing offset 0x"
<< Twine::utohexstr(Offset) << '\n');
assert(I > 1 && "jump table with a size smaller than 1 detected");
assert(JT.Type == JumpTable::JTT_PIC &&
"unexpected truncation of non-PIC jump table");
JT.OffsetEntries.resize(I);
break;
}
auto *Label = getOrCreateLocalLabel(getAddress() + Offset,
auto *Label = getOrCreateLocalLabel(getAddress() + JT.OffsetEntries[I],
/*CreatePastEnd*/ true);
JT.Entries.push_back(Label);
}