[llvm] [BOLT] Add 'constant island' check in scanExternalRefs to prevent a crash when the function is disassembled fail or skipped (PR #165577)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 30 04:53:44 PDT 2025


https://github.com/Jinjie-Huang updated https://github.com/llvm/llvm-project/pull/165577

>From 0b280fea300a4ae89b9711ca2270607a11c42131 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Wed, 29 Oct 2025 23:21:26 +0800
Subject: [PATCH 1/2] add isInConstantIsland for scanExternalRefs

---
 bolt/lib/Core/BinaryFunction.cpp          | 17 ++++++++++++++---
 bolt/test/AArch64/constant-island-entry.s |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 84023efe1084e..1a6a8b16846d8 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1699,9 +1699,20 @@ bool BinaryFunction::scanExternalRefs() {
 
       const uint64_t FunctionOffset =
           TargetAddress - TargetFunction->getAddress();
-      BranchTargetSymbol =
-          FunctionOffset ? TargetFunction->addEntryPointAtOffset(FunctionOffset)
-                         : TargetFunction->getSymbol();
+      if (!TargetFunction->isInConstantIsland(TargetAddress)) {
+        BranchTargetSymbol =
+            FunctionOffset
+                ? TargetFunction->addEntryPointAtOffset(FunctionOffset)
+                : TargetFunction->getSymbol();
+      } else {
+        TargetFunction->setIgnored();
+        Success = false;
+        BC.outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
+                  << Twine::utohexstr(Address)
+                  << " in constant island of function " << *TargetFunction
+                  << '\n';
+        break;
+      }
     }
 
     // Can't find more references. Not creating relocations since we are not
diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s
index 6567114eb980a..2bf10526c601c 100644
--- a/bolt/test/AArch64/constant-island-entry.s
+++ b/bolt/test/AArch64/constant-island-entry.s
@@ -4,6 +4,7 @@
 # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
 # RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
 # RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+# RUN: llvm-bolt %t.exe -o %t.bolt -skip-funcs=caller 2>&1 | FileCheck %s
 
 # CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
 

>From a60a5223ab718d87d61b2e9a897f8a4bec5ccf24 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Thu, 30 Oct 2025 19:53:21 +0800
Subject: [PATCH 2/2] add document in test

---
 bolt/lib/Core/BinaryFunction.cpp          | 3 +--
 bolt/test/AArch64/constant-island-entry.s | 8 ++++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 1a6a8b16846d8..fbe186454351c 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1706,12 +1706,11 @@ bool BinaryFunction::scanExternalRefs() {
                 : TargetFunction->getSymbol();
       } else {
         TargetFunction->setIgnored();
-        Success = false;
         BC.outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
                   << Twine::utohexstr(Address)
                   << " in constant island of function " << *TargetFunction
                   << '\n';
-        break;
+        continue;
       }
     }
 
diff --git a/bolt/test/AArch64/constant-island-entry.s b/bolt/test/AArch64/constant-island-entry.s
index 2bf10526c601c..7f8449deea130 100644
--- a/bolt/test/AArch64/constant-island-entry.s
+++ b/bolt/test/AArch64/constant-island-entry.s
@@ -1,9 +1,13 @@
-// This test checks that we ignore functions which add an entry point that
-// is in a constant island.
+## This test checks that we ignore functions which add an entry point that
+## is in a constant island.
 
 # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
 # RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
+
+## Check when the caller is successfully disassembled.
 # RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
+
+## Skip caller to check the identical warning is triggered from ScanExternalRefs().
 # RUN: llvm-bolt %t.exe -o %t.bolt -skip-funcs=caller 2>&1 | FileCheck %s
 
 # CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func



More information about the llvm-commits mailing list