mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 04:17:17 +08:00
[BOLT] Detect internal references into a middle of instruction
Summary: Some instructions in assembly-written functions could reference 8-byte constants from another instructions using 4-byte offsets, presumably to save a couple of bytes. Detect such cases, and skip processing such functions until we teach BOLT how to handle references into a middle of instruction. (cherry picked from FBD14768212)
This commit is contained in:
@@ -1464,9 +1464,32 @@ add_instruction:
|
||||
|
||||
updateState(State::Disassembled);
|
||||
|
||||
postProcessEntryPoints();
|
||||
|
||||
postProcessJumpTables();
|
||||
}
|
||||
|
||||
void BinaryFunction::postProcessEntryPoints() {
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryFunction::postProcessJumpTables() {
|
||||
// Create labels for all entries.
|
||||
for (auto &JTI : JumpTables) {
|
||||
@@ -1683,7 +1706,7 @@ bool BinaryFunction::buildCFG() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(CurrentState == State::Disassembled))
|
||||
if (CurrentState != State::Disassembled)
|
||||
return false;
|
||||
|
||||
assert(BasicBlocks.empty() && "basic block list should be empty");
|
||||
|
||||
Reference in New Issue
Block a user