Skip to content

Commit 1cf2599

Browse files
committed
[BOLT] Prevent adding secondary entry points for BB labels
When linker relaxation is enabled on RISC-V, every branch has a relocation and a corresponding symbol in the symbol table. BOLT currently registers all these symbols as secondary entry points causing almost every function to be marked as multi entry on RISC-V. This patch modifies `adjustFunctionBoundaries` to ignore these symbols. Note that I currently try to detect them by checking if a symbol's name starts with the private label prefix as defined by `MCAsmInfo`. Since I'm not entirely sure what multi-entry functions look like on different targets, please check if this condition is correct. Maybe it could make sense to only check this on RISC-V? Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D159285
1 parent 4793c2c commit 1cf2599

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,16 @@ void RewriteInstance::adjustFunctionBoundaries() {
15861586
if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
15871587
break;
15881588

1589+
// Skip basic block labels. This happens on RISC-V with linker relaxation
1590+
// enabled because every branch needs a relocation and corresponding
1591+
// symbol. We don't want to add such symbols as entry points.
1592+
const auto PrivateLabelPrefix = BC->AsmInfo->getPrivateLabelPrefix();
1593+
if (!PrivateLabelPrefix.empty() &&
1594+
cantFail(Symbol.getName()).starts_with(PrivateLabelPrefix)) {
1595+
++NextSymRefI;
1596+
continue;
1597+
}
1598+
15891599
// This is potentially another entry point into the function.
15901600
uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
15911601
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// Test that no secondary entry points are created for basic block labels used
2+
/// by branches.
3+
// RUN: %clang %cflags -o %t %s
4+
// RUN: llvm-bolt -print-cfg -o /dev/null %t 2>&1 | FileCheck %s
5+
6+
// CHECK: Binary Function "_start" after building cfg {
7+
// CHECK: IsMultiEntry: 0
8+
// CHECK: beq t0, t1, .Ltmp0
9+
// CHECK: {{^}}.Ltmp0
10+
// CHECK: ret
11+
12+
.globl _start
13+
_start:
14+
beq t0, t1, 1f
15+
1:
16+
ret
17+
.size _start, .-_start
18+

0 commit comments

Comments
 (0)