[BOLT] Add constant island check in scanExternalRefs() (#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. The same issue may occur if without a check for it

So, this patch complements the 'constant island' check in
scanExternalRefs().
This commit is contained in:
Jinjie Huang
2025-10-31 10:29:00 +08:00
committed by GitHub
parent 27eabd5219
commit 6ba2127a5c
2 changed files with 20 additions and 5 deletions

View File

@@ -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();
BC.outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
<< Twine::utohexstr(Address)
<< " in constant island of function " << *TargetFunction
<< '\n';
continue;
}
}
// Can't find more references. Not creating relocations since we are not

View File

@@ -1,10 +1,15 @@
// 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
.globl func