Skip to content

Commit 6ba2127

Browse files
authored
[BOLT] Add constant island check in scanExternalRefs() (#165577)
The [previous patch](#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().
1 parent 27eabd5 commit 6ba2127

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,9 +1699,19 @@ bool BinaryFunction::scanExternalRefs() {
16991699

17001700
const uint64_t FunctionOffset =
17011701
TargetAddress - TargetFunction->getAddress();
1702-
BranchTargetSymbol =
1703-
FunctionOffset ? TargetFunction->addEntryPointAtOffset(FunctionOffset)
1704-
: TargetFunction->getSymbol();
1702+
if (!TargetFunction->isInConstantIsland(TargetAddress)) {
1703+
BranchTargetSymbol =
1704+
FunctionOffset
1705+
? TargetFunction->addEntryPointAtOffset(FunctionOffset)
1706+
: TargetFunction->getSymbol();
1707+
} else {
1708+
TargetFunction->setIgnored();
1709+
BC.outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
1710+
<< Twine::utohexstr(Address)
1711+
<< " in constant island of function " << *TargetFunction
1712+
<< '\n';
1713+
continue;
1714+
}
17051715
}
17061716

17071717
// Can't find more references. Not creating relocations since we are not

bolt/test/AArch64/constant-island-entry.s

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
// This test checks that we ignore functions which add an entry point that
2-
// is in a constant island.
1+
## This test checks that we ignore functions which add an entry point that
2+
## is in a constant island.
33

44
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
55
# RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
6+
7+
## Check when the caller is successfully disassembled.
68
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
79

10+
## Skip caller to check the identical warning is triggered from ScanExternalRefs().
11+
# RUN: llvm-bolt %t.exe -o %t.bolt -skip-funcs=caller 2>&1 | FileCheck %s
12+
813
# CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
914

1015
.globl func

0 commit comments

Comments
 (0)