[llvm] [BOLT] Add validation for direct call/branch targets (PR #165406)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 23:59:54 PST 2025


================
@@ -531,20 +531,40 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
 }
 
 MCSymbol *BinaryContext::handleExternalBranchTarget(uint64_t Address,
-                                                    BinaryFunction &BF) {
-  if (BF.isInConstantIsland(Address)) {
-    BF.setIgnored();
-    this->outs() << "BOLT-WARNING: ignoring entry point at address 0x"
-                 << Twine::utohexstr(Address)
-                 << " in constant island of function " << BF << '\n';
-    return nullptr;
+                                                    BinaryFunction &Source,
+                                                    BinaryFunction &Target) {
+  const uint64_t Offset = Address - Target.getAddress();
+  assert(Offset < Target.getSize() &&
+         "Address should be inside the referenced function");
+
+  bool IsValid = true;
+  if (Source.NeedBranchValidation) {
----------------
Jinjie-Huang wrote:

Yes, that is indeed possible. A good approach might be to continue scanning after identifying the first invalid target, before setting `Source.NeedBranchValidation` to false. And I'd be happy to address this in a follow-up change.

https://github.com/llvm/llvm-project/pull/165406


More information about the llvm-commits mailing list