[llvm] [BOLT] Add validation for direct call/branch targets, bypassing invalid functions (PR #165406)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 8 17:03:12 PST 2025
================
@@ -1900,6 +1910,35 @@ bool BinaryFunction::scanExternalRefs() {
return Success;
}
+bool BinaryFunction::validateInternalBranches() {
+ if (!isSimple() || TrapsOnEntry)
+ return true;
+
+ for (const auto &KV : Labels) {
+ MCSymbol *Label = KV.second;
+ if (getSecondaryEntryPointSymbol(Label))
+ continue;
+
+ const uint32_t Offset = KV.first;
+ // Skip empty functions and out-of-bounds offsets,
+ // as they may not be disassembled.
+ if (!Offset || (Offset > getSize()))
+ continue;
+
+ if (!getInstructionAtOffset(Offset) ||
+ isInConstantIsland(getAddress() + Offset)) {
+ BC.outs() << "BOLT-WARNING: corrupted control flow detected in function "
+ << *this << ", an internal branch/call targets an invalid "
----------------
maksfb wrote:
nit:
```suggestion
<< *this << ": an internal branch/call targets an invalid "
```
https://github.com/llvm/llvm-project/pull/165406
More information about the llvm-commits
mailing list