[PATCH] D153277: [BOLT][RISCV] Recognize mapping symbols

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 07:39:21 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, luke, treapster, pmatos, ayermolo, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, kristof.beyls, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.

The RISC-V psABI [1] defines them similarly to AArch64.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#mapping-symbol

Depends on D153260 <https://reviews.llvm.org/D153260>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153277

Files:
  bolt/lib/Core/BinaryContext.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/test/RISCV/mapping-syms.s


Index: bolt/test/RISCV/mapping-syms.s
===================================================================
--- /dev/null
+++ bolt/test/RISCV/mapping-syms.s
@@ -0,0 +1,23 @@
+// RUN: %clang %cflags -o %t %s
+// RUN: llvm-bolt --print-cfg --print-only=_start -o %t.bolt %t 2>&1 | FileCheck %s
+// RUN: llvm-objdump -d %t.bolt | FileCheck --check-prefix=CHECK-OBJDUMP %s
+
+// CHECK-NOT: BOLT-WARNING
+
+/// Check that .word is not disassembled by BOLT
+// CHECK: 00000000: nop
+// CHECK: 00000002: ret
+
+/// Check .word is still present in output
+// CHECK-OBJDUMP: <_start>:
+// CHECK-OBJDUMP-NEXT: nop
+// CHECK-OBJDUMP-NEXT: unimp
+// CHECK-OBJDUMP-NEXT: unimp
+// CHECK-OBJDUMP-NEXT: ret
+    .text
+    .globl _start
+    .p2align 1
+_start:
+    nop
+    .word 0x0
+    ret
Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -925,7 +925,7 @@
         }
       };
 
-  if (BC->isAArch64()) {
+  if (BC->isAArch64() || BC->isRISCV()) {
     addExtraDataMarkerPerSymbol(SortedFileSymbols, SortedMarkerSymbols);
     LastSymbol = std::stable_partition(
         SortedFileSymbols.begin(), SortedFileSymbols.end(),
Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -1752,10 +1752,10 @@
 }
 
 MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
-  // For aarch64, the ABI defines mapping symbols so we identify data in the
-  // code section (see IHI0056B). $x identifies a symbol starting code or the
-  // end of a data chunk inside code, $d indentifies start of data.
-  if (!isAArch64() || ELFSymbolRef(Symbol).getSize())
+  // For aarch64 and riscv, the ABI defines mapping symbols so we identify data
+  // in the code section (see IHI0056B). $x identifies a symbol starting code or
+  // the end of a data chunk inside code, $d indentifies start of data.
+  if ((!isAArch64() && !isRISCV()) || ELFSymbolRef(Symbol).getSize())
     return MarkerSymType::NONE;
 
   Expected<StringRef> NameOrError = Symbol.getName();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153277.532648.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230619/0361d42f/attachment.bin>


More information about the llvm-commits mailing list