mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
[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:
@@ -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 &&
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user