diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1842,6 +1842,33 @@ if (HasInternalLabelReference) return false; + // Validate that all data references to function offsets are claimed by + // recognized jump tables. Register externally referenced blocks as entry + // points. Unknown control flow requires + if (!opts::StrictMode && hasInternalReference()) { + SmallPtrSet JTTargets; + for (const JumpTable *JT : llvm::make_second_range(JumpTables)) + JTTargets.insert(JT->Entries.begin(), JT->Entries.end()); + for (uint64_t Destination : ExternallyReferencedOffsets) { + if (BinaryBasicBlock *BB = getBasicBlockAtOffset(Destination)) { + bool Found = JTTargets.contains(BB->getLabel()); + if (!Found) { + if (opts::Verbosity >= 1) { + outs() << "BOLT-WARNING: registering externally referenced " + << BB->getName() << " as a secondary entry point in " + << *this << ".\n"; + } + addEntryPoint(*BB); + } + } else { + outs() << "BOLT-WARNING: external reference to offset " + << formatv("{0:x}", Destination) + << " does not point to a valid BB in " << *this << ".\n"; + return false; + } + } + } + // If there's only one jump table, and one indirect jump, and no other // references, then we should be able to derive the jump table even if we // fail to match the pattern.