[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
Wed Oct 29 08:14:29 PDT 2025
https://github.com/Jinjie-Huang created https://github.com/llvm/llvm-project/pull/165577
The [previous patch](https://github.com/llvm/llvm-project/pull/163418) has added a check to prevent adding an entry point into a constant island, but only for successfully disassembled functions.
Because scanExternalRefs() is also called when a function fails to be disassembled or is skipped, it can still attempt to add an entry point at constant islands. Without a check for it, the same issue occurs.
So, this patch complements the 'constant island' check in scanExternalRefs().
>From 2ec56d3e07e48e9934e5aabb841c8b025866d7d0 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Wed, 29 Oct 2025 22:51:12 +0800
Subject: [PATCH] add isInConstantIsland for scanExternalRefs
---
bolt/lib/Core/BinaryFunction.cpp | 16 +++++++++++++---
bolt/test/AArch64/constant-island-entry.s | 1 +
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 84023efe1084e..f8ef80d75653f 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1699,9 +1699,19 @@ 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
More information about the llvm-commits
mailing list