[PATCH] D156236: [RISCV] Make mapping symbols SF_FormatSpecific

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 06:44:26 PDT 2023


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

This ensures that llvm-symbolizer ignores them for symbolization.

Note: unlike aarch64-mapping-symbol.s, the test included here does not
test if the mapping symbols are actually in the symbol table. The reason
is that llvm-mc support for RISC-V mapping symbols (D153260 <https://reviews.llvm.org/D153260>) has not
landed yet, so the mapping symbols simply aren't there. However, D153260 <https://reviews.llvm.org/D153260>
would like to depend on this patch together with D156190 <https://reviews.llvm.org/D156190> to avoid having
to update a large amount of tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156236

Files:
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/test/DebugInfo/Symbolize/ELF/riscv-mapping-symbol.s


Index: llvm/test/DebugInfo/Symbolize/ELF/riscv-mapping-symbol.s
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/Symbolize/ELF/riscv-mapping-symbol.s
@@ -0,0 +1,21 @@
+# REQUIRES: riscv-registered-target
+## Ignore RISCC-V mapping symbols (with a prefix of $d or $x).
+
+# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t
+# RUN: llvm-symbolizer --obj=%t 0 4 0xc | FileCheck %s
+
+# CHECK:      foo
+# CHECK-NEXT: ??:0:0
+# CHECK-EMPTY:
+# CHECK:      foo
+# CHECK-NEXT: ??:0:0
+# CHECK-EMPTY:
+# CHECK:      foo
+# CHECK-NEXT: ??:0:0
+
+    .global foo
+foo:
+    .word 32
+    nop
+    nop
+    .word 42
Index: llvm/include/llvm/Object/ELFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/ELFObjectFile.h
+++ llvm/include/llvm/Object/ELFObjectFile.h
@@ -763,8 +763,10 @@
       Result |= SymbolRef::SF_Thumb;
   } else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
     if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
-      // Mark empty name symbols used for label differences.
-      if (NameOrErr->empty())
+      StringRef Name = *NameOrErr;
+      // Mark empty name symbols (used for label differences) and mapping
+      // symbols.
+      if (Name.empty() || Name.startswith("$d") || Name.startswith("$x"))
         Result |= SymbolRef::SF_FormatSpecific;
     } else {
       // TODO: Actually report errors helpfully.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156236.543949.patch
Type: text/x-patch
Size: 1464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230725/39eb6e03/attachment.bin>


More information about the llvm-commits mailing list