[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
Thu Jan 24 11:54:35 PST 2019


mattd updated this revision to Diff 183358.
mattd added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rupprecht.

- Added a comment to the change in ELFObjectFile.h.
- Updated the condition to  retrieve the section name if the symbol is a section and has no name.
- I discovered that my original patch broke an aarch64 test.  In that case, llvm-objdump was using the section name (produced from my patch) instead of ignoring the section in general.  That had the effect of  the section name being displayed in the disassembly instead of the aarch64/arm mapping name "$x."  This patch now ignores section names and preserves the mapping name in that case.  I'm not sure that the change to llvm-objdump is the best choice, but it  doesn't seem to break any llvm tests or any test I generated while fiddling around with this patch.


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

https://reviews.llvm.org/D57105

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


Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -971,8 +971,11 @@
       report_error(Obj->getFileName(), SectionOrErr.takeError());
 
     uint8_t SymbolType = ELF::STT_NOTYPE;
-    if (Obj->isELF())
+    if (Obj->isELF()) {
       SymbolType = getElfSymbolType(Obj, Symbol);
+      if (SymbolType == ELF::STT_SECTION)
+        continue;
+    }
 
     section_iterator SecI = *SectionOrErr;
     if (SecI != Obj->section_end())
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,7 +440,16 @@
   auto SymStrTabOrErr = EF.getStringTable(StringTableSec);
   if (!SymStrTabOrErr)
     return SymStrTabOrErr.takeError();
-  return ESym->getName(*SymStrTabOrErr);
+  Expected<StringRef> Name = ESym->getName(*SymStrTabOrErr);
+
+  // If we can't locate a name and the symbol is a section, use the section name.
+  if ((!Name || Name->empty()) && ESym->getType() == ELF::STT_SECTION) {
+    StringRef SecName;
+    auto Sec = getSymbolSection(Sym);
+    if (Sec && !(*Sec)->getName(SecName))
+      return SecName;
+  }
+  return Name;
 }
 
 template <class ELFT>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57105.183358.patch
Type: text/x-patch
Size: 2478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190124/0471d8f0/attachment.bin>


More information about the llvm-commits mailing list