[BOLT] Move postProcessEntryPoints after disassembly

Summary:
Call postProcessEntryPoints only after all functions have been
disassembled and all interprocedural references have been processed,
when all possible entry points have been accounted for. This makes our
detection of bad entries more robust as it does not depend on the order
of the functions any more.

(cherry picked from FBD19404767)
This commit is contained in:
Rafael Auler
2020-01-14 17:12:03 -08:00
committed by Maksim Panchenko
parent 0283271f29
commit 961d3d02d8
3 changed files with 23 additions and 24 deletions

View File

@@ -1347,8 +1347,6 @@ add_instruction:
clearList(Relocations);
updateState(State::Disassembled);
postProcessEntryPoints();
}
void BinaryFunction::postProcessEntryPoints() {
@@ -1356,28 +1354,27 @@ void BinaryFunction::postProcessEntryPoints() {
return;
for (auto Offset : EntryOffsets) {
if (!getInstructionAtOffset(Offset)) {
// On AArch64 there are legitimate reasons to have references past the
// end of the function, e.g. jump tables.
if (BC.isAArch64() && Offset == getSize()) {
continue;
}
// If we are at Offset 0 and there is no instruction associated with it,
// this means this is an empty function. Just ignore.
if (Offset == 0) {
continue;
}
errs() << "BOLT-WARNING: reference in the middle of instruction "
"detected in function " << *this
<< " at offset 0x" << Twine::utohexstr(Offset) << '\n';
if (BC.HasRelocations) {
errs() << "BOLT-ERROR: unable to keep processing in relocation mode\n";
exit(1);
}
setSimple(false);
// If we are at Offset 0 and there is no instruction associated with it,
// this means this is an empty function. Just ignore. If we find an
// instruction at this offset, this entry point is valid.
if (getInstructionAtOffset(Offset) || !Offset) {
continue;
}
// On AArch64 there are legitimate reasons to have references past the
// end of the function, e.g. jump tables.
if (BC.isAArch64() && Offset == getSize()) {
continue;
}
errs() << "BOLT-WARNING: reference in the middle of instruction "
"detected in function " << *this
<< " at offset 0x" << Twine::utohexstr(Offset) << '\n';
if (BC.HasRelocations) {
errs() << "BOLT-ERROR: unable to keep processing in relocation mode\n";
exit(1);
}
setSimple(false);
}
}

View File

@@ -1946,7 +1946,8 @@ public:
/// Returns false if disassembly failed.
void disassemble(ArrayRef<uint8_t> FunctionData);
/// Validate entry points.
/// Check that entry points have an associated instruction at their
/// offsets after disassembly.
void postProcessEntryPoints();
/// Post-processing for jump tables after disassembly. Since their

View File

@@ -2660,6 +2660,7 @@ void RewriteInstance::disassembleFunctions() {
if (!shouldDisassemble(Function))
continue;
Function.postProcessEntryPoints();
Function.postProcessJumpTables();
}