Skip to content

Commit c67b862

Browse files
authored
[BOLT][RISCV] Don't create function entry points for unnamed symbols (#68977)
Unnamed symbols are used, for example, for debug info related relocations on RISC-V.
1 parent d8de38b commit c67b862

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,12 @@ void RewriteInstance::adjustFunctionBoundaries() {
15821582
if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
15831583
break;
15841584

1585+
// Ignore unnamed symbols. Used, for example, by debugging info on RISC-V.
1586+
if (BC->isRISCV() && cantFail(Symbol.getName()).empty()) {
1587+
++NextSymRefI;
1588+
continue;
1589+
}
1590+
15851591
// Skip basic block labels. This happens on RISC-V with linker relaxation
15861592
// enabled because every branch needs a relocation and corresponding
15871593
// symbol. We don't want to add such symbols as entry points.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// Verify that unnamed symbols are not added as function entry points. Such
2+
/// symbols are used by relocations in debugging sections.
3+
4+
// clang-format off
5+
6+
// RUN: %clang %cflags -g -Wl,-q -o %t %s
7+
8+
/// Verify that the binary indeed contains an unnamed symbol at _start
9+
// RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=CHECK-ELF
10+
// CHECK-ELF-DAG: [[#%x,START:]] {{.*}} FUNC GLOBAL DEFAULT [[#%d,SECTION:]] _start{{$}}
11+
// CHECK-ELF-DAG: [[#%x,START]] {{.*}} NOTYPE LOCAL DEFAULT [[#SECTION]] {{$}}
12+
13+
/// Verify that BOLT did not create an extra entry point for the unnamed symbol
14+
// RUN: llvm-bolt -o %t.bolt %t --print-cfg | FileCheck %s
15+
// CHECK: Binary Function "_start" after building cfg {
16+
// CHECK: IsMultiEntry: 0
17+
18+
void _start() {}

0 commit comments

Comments
 (0)