Index: llvm/include/llvm/Object/ELFObjectFile.h =================================================================== --- llvm/include/llvm/Object/ELFObjectFile.h +++ llvm/include/llvm/Object/ELFObjectFile.h @@ -440,7 +440,16 @@ auto SymStrTabOrErr = EF.getStringTable(StringTableSec); if (!SymStrTabOrErr) return SymStrTabOrErr.takeError(); - return ESym->getName(*SymStrTabOrErr); + Expected 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; + Expected Sec = getSymbolSection(Sym); + if (Sec && !(*Sec)->getName(SecName)) + return SecName; + } + return Name; } template Index: llvm/test/Object/nm-trivial-object.test =================================================================== --- llvm/test/Object/nm-trivial-object.test +++ llvm/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,22 @@ 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 Index: llvm/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -941,8 +941,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())