[llvm] [BOLT] Don't create function entry points for unnamed symbols (PR #68977)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 13 04:23:49 PDT 2023


https://github.com/mtvec created https://github.com/llvm/llvm-project/pull/68977

Unnamed symbols are used, for example, for debug info related relocations on RISC-V.

>From 3d346a4138d2edfddef726d9bd933eb15b70d5bd Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Fri, 13 Oct 2023 13:20:56 +0200
Subject: [PATCH] [BOLT] Don't create function entry points for unnamed symbols

Unnamed symbols are used, for example, for debug info related
relocations on RISC-V.
---
 bolt/lib/Rewrite/RewriteInstance.cpp   |  6 ++++++
 bolt/test/RISCV/unnamed-sym-no-entry.c | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 bolt/test/RISCV/unnamed-sym-no-entry.c

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index ddcc21878abb818..3f3cd4ed5ffc6b6 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1582,6 +1582,12 @@ void RewriteInstance::adjustFunctionBoundaries() {
       if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
         break;
 
+      // Ignore unnamed symbols. Used, for example, by debugging info on RISC-V.
+      if (cantFail(Symbol.getName()).empty()) {
+        ++NextSymRefI;
+        continue;
+      }
+
       // Skip basic block labels. This happens on RISC-V with linker relaxation
       // enabled because every branch needs a relocation and corresponding
       // symbol. We don't want to add such symbols as entry points.
diff --git a/bolt/test/RISCV/unnamed-sym-no-entry.c b/bolt/test/RISCV/unnamed-sym-no-entry.c
new file mode 100644
index 000000000000000..57ba292fe6e5a8b
--- /dev/null
+++ b/bolt/test/RISCV/unnamed-sym-no-entry.c
@@ -0,0 +1,16 @@
+/// Verify that unnamed symbols are not added as function entry points. Such
+/// symbols are used by relocations in debugging sections.
+
+// RUN: %clang %cflags -g -Wl,-q -o %t %s
+
+/// Verify that the binary indeed contains an unnamed symbol at _start
+// RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=CHECK-ELF
+// CHECK-ELF-DAG: [[#%x,START:]] {{.*}} FUNC GLOBAL DEFAULT [[#%d,SECTION:]] _start{{$}}
+// CHECK-ELF-DAG: [[#%x,START]] {{.*}} NOTYPE LOCAL DEFAULT [[#SECTION]] {{$}}
+
+/// Verify that BOLT did not create an extra entry point for the unnamed symbol
+// RUN: llvm-bolt -o %t.bolt %t --print-cfg | FileCheck %s
+// CHECK: Binary Function "_start" after building cfg {
+// CHECK:  IsMultiEntry: 0
+
+void _start() {}



More information about the llvm-commits mailing list