[PATCH] D159285: [BOLT] Prevent adding secondary entry points for BB labels

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 05:05:08 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1cf2599a6410: [BOLT] Prevent adding secondary entry points for BB labels (authored by jobnoorman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159285/new/

https://reviews.llvm.org/D159285

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/RISCV/branch-no-secondary-entry.s


Index: bolt/test/RISCV/branch-no-secondary-entry.s
===================================================================
--- /dev/null
+++ bolt/test/RISCV/branch-no-secondary-entry.s
@@ -0,0 +1,18 @@
+/// Test that no secondary entry points are created for basic block labels used
+/// by branches.
+// RUN: %clang %cflags -o %t %s
+// RUN: llvm-bolt -print-cfg -o /dev/null %t 2>&1 | FileCheck %s
+
+// CHECK: Binary Function "_start" after building cfg {
+// CHECK: IsMultiEntry: 0
+// CHECK: beq t0, t1, .Ltmp0
+// CHECK: {{^}}.Ltmp0
+// CHECK: ret
+
+    .globl _start
+_start:
+    beq t0, t1, 1f
+1:
+    ret
+    .size _start, .-_start
+
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1586,6 +1586,16 @@
       if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
         break;
 
+      // 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.
+      const auto PrivateLabelPrefix = BC->AsmInfo->getPrivateLabelPrefix();
+      if (!PrivateLabelPrefix.empty() &&
+          cantFail(Symbol.getName()).starts_with(PrivateLabelPrefix)) {
+        ++NextSymRefI;
+        continue;
+      }
+
       // This is potentially another entry point into the function.
       uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
       LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159285.556552.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230912/2c7ea741/attachment.bin>


More information about the llvm-commits mailing list