[PATCH] D57105: [ELF] Return the section name when calling getSymbolName on a section symbol.

Matt Davis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 23 09:57:39 PST 2019


mattd created this revision.
mattd added reviewers: Bigcheese, davide.

Previously, llvm-nm would report symbols for .debug and .note sections as: '?' with an empty  section name:

  00000000 ?
  00000000 ?
  ...

With this patch the output more closely resembles GNU nm:

  00000000 N .debug_abbrev
  00000000 n .note.GNU-stack
  ...

This patch calls `getSectionName` for sections that belong to symbols of type `ELF::STT_SECTION`, which returns the name of the section from the section string table.


https://reviews.llvm.org/D57105

Files:
  include/llvm/Object/ELFObjectFile.h
  test/Object/nm-trivial-object.test


Index: test/Object/nm-trivial-object.test
===================================================================
--- test/Object/nm-trivial-object.test
+++ test/Object/nm-trivial-object.test
@@ -18,6 +18,8 @@
 RUN:         | FileCheck %s -check-prefix WEAK-ELF64
 RUN: llvm-nm %p/Inputs/absolute.elf-x86-64 \
 RUN:         | FileCheck %s -check-prefix ABSOLUTE-ELF64
+RUN: llvm-nm -a %p/Inputs/IsNAN.o \
+RUN:         | FileCheck %s -check-prefix ELF64-DEBUG-SYMS
 RUN: llvm-nm %p/Inputs/trivial-object-test.macho-i386 \
 RUN:         | FileCheck %s -check-prefix macho
 RUN: llvm-nm -U %p/Inputs/trivial-object-test.macho-i386 \
@@ -113,6 +115,14 @@
 ABSOLUTE-ELF64: 0000000000000123 a a1
 ABSOLUTE-ELF64: 0000000000000123 A a2
 
+ELF64-DEBUG-SYMS: 00000000 N .debug_abbrev
+ELF64-DEBUG-SYMS: 00000000 N .debug_aranges
+ELF64-DEBUG-SYMS: 00000000 N .debug_frame
+ELF64-DEBUG-SYMS: 00000000 N .debug_info
+ELF64-DEBUG-SYMS: 00000000 N .debug_line
+ELF64-DEBUG-SYMS: 00000000 N .debug_pubnames
+ELF64-DEBUG-SYMS: 00000000 n .note.GNU-stack
+
 macho:          U _SomeOtherFunction
 macho: 00000000 T _main
 macho:          U _puts
Index: include/llvm/Object/ELFObjectFile.h
===================================================================
--- include/llvm/Object/ELFObjectFile.h
+++ include/llvm/Object/ELFObjectFile.h
@@ -440,6 +440,12 @@
   auto SymStrTabOrErr = EF.getStringTable(StringTableSec);
   if (!SymStrTabOrErr)
     return SymStrTabOrErr.takeError();
+  if (ESym->getType() == ELF::STT_SECTION) {
+    StringRef SecName;
+    auto Sec = getSymbolSection(Sym);
+    if (Sec && !Sec.get()->getName(SecName))
+      return SecName;
+  }
   return ESym->getName(*SymStrTabOrErr);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57105.183120.patch
Type: text/x-patch
Size: 1692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190123/e4d0b652/attachment.bin>


More information about the llvm-commits mailing list