Skip to content

Commit 6c7c643

Browse files
Asher8118Lukacma
authored andcommitted
[BOLT] Check entry point address is not in constant island (llvm#163418)
There are cases where `addEntryPointAtOffset` is called with a given `Offset` that points to an address within a constant island. This triggers `assert(!isInConstantIsland(EntryPointAddress)` and causes BOLT to crash. This patch adds a check which ignores functions that would add such entry points and warns the user.
1 parent f9ab70c commit 6c7c643

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,17 @@ void BinaryContext::processInterproceduralReferences() {
13371337
<< Function.getPrintName() << " and "
13381338
<< TargetFunction->getPrintName() << '\n';
13391339
}
1340-
if (uint64_t Offset = Address - TargetFunction->getAddress())
1341-
TargetFunction->addEntryPointAtOffset(Offset);
1340+
if (uint64_t Offset = Address - TargetFunction->getAddress()) {
1341+
if (!TargetFunction->isInConstantIsland(Address)) {
1342+
TargetFunction->addEntryPointAtOffset(Offset);
1343+
} else {
1344+
TargetFunction->setIgnored();
1345+
this->outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
1346+
<< Twine::utohexstr(Address)
1347+
<< " in constant island of function " << *TargetFunction
1348+
<< '\n';
1349+
}
1350+
}
13421351

13431352
continue;
13441353
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This test checks that we ignore functions which add an entry point that
2+
// is in a constant island.
3+
4+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
5+
# RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
6+
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
7+
8+
# CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
9+
10+
.globl func
11+
.type func, %function
12+
func:
13+
b .Lafter_constant
14+
15+
.type constant_island, %object
16+
constant_island:
17+
.xword 0xabcdef
18+
19+
.Lafter_constant:
20+
ret
21+
.size func, .-func
22+
23+
.globl caller
24+
.type caller, %function
25+
caller:
26+
bl constant_island
27+
ret

0 commit comments

Comments
 (0)