[llvm] r352785 - [ELF] Return the section name when calling getSymbolName on a section symbol.
Matt Davis via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 31 11:42:22 PST 2019
Author: mattd
Date: Thu Jan 31 11:42:21 2019
New Revision: 352785
URL: http://llvm.org/viewvc/llvm-project?rev=352785&view=rev
Log:
[ELF] Return the section name when calling getSymbolName on a section symbol.
Summary:
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.
Reviewers: Bigcheese, davide, jhenderson
Reviewed By: davide, jhenderson
Subscribers: rupprecht, jhenderson, llvm-commits
Differential Revision: https://reviews.llvm.org/D57105
Modified:
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/test/Object/nm-trivial-object.test
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=352785&r1=352784&r2=352785&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu Jan 31 11:42:21 2019
@@ -440,7 +440,16 @@ Expected<StringRef> ELFObjectFile<ELFT>:
auto SymStrTabOrErr = EF.getStringTable(StringTableSec);
if (!SymStrTabOrErr)
return SymStrTabOrErr.takeError();
- return ESym->getName(*SymStrTabOrErr);
+ Expected<StringRef> Name = ESym->getName(*SymStrTabOrErr);
+
+ // If the symbol name is empty use the section name.
+ if ((!Name || Name->empty()) && ESym->getType() == ELF::STT_SECTION) {
+ StringRef SecName;
+ Expected<section_iterator> Sec = getSymbolSection(Sym);
+ if (Sec && !(*Sec)->getName(SecName))
+ return SecName;
+ }
+ return Name;
}
template <class ELFT>
Modified: llvm/trunk/test/Object/nm-trivial-object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-trivial-object.test?rev=352785&r1=352784&r2=352785&view=diff
==============================================================================
--- llvm/trunk/test/Object/nm-trivial-object.test (original)
+++ llvm/trunk/test/Object/nm-trivial-object.test Thu Jan 31 11:42:21 2019
@@ -18,6 +18,8 @@ RUN: llvm-nm %p/Inputs/weak.elf-x86-64 \
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,22 @@ WEAK-ELF64: 0000000000000000 V x2
ABSOLUTE-ELF64: 0000000000000123 a a1
ABSOLUTE-ELF64: 0000000000000123 A a2
+ELF64-DEBUG-SYMS: 00000000 b .bss
+ELF64-DEBUG-SYMS: 00000000 d .data
+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
+ELF64-DEBUG-SYMS: 00000000 t .text
+ELF64-DEBUG-SYMS: 00000000 a IsNAN.cpp
+ELF64-DEBUG-SYMS: 00000014 T _ZN4llvm5IsNANEd
+ELF64-DEBUG-SYMS: 00000000 T _ZN4llvm5IsNANEf
+ELF64-DEBUG-SYMS: U __isnan
+ELF64-DEBUG-SYMS: U __isnanf
+
macho: U _SomeOtherFunction
macho: 00000000 T _main
macho: U _puts
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=352785&r1=352784&r2=352785&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Thu Jan 31 11:42:21 2019
@@ -941,8 +941,11 @@ static void disassembleObject(const Targ
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())
More information about the llvm-commits
mailing list