From 8e0a70be24832b4524233cb7d2ca3b309c390e54 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 10 Jan 2019 16:24:10 +0000 Subject: [PATCH] [llvm-objdump] - Do not include reserved undefined symbol in -t output. This is https://bugs.llvm.org/show_bug.cgi?id=26892, GNU objdump hides the special symbol entry: SYMBOL TABLE: 000000000000a7e0 l F .text 00000000000003f9 bi_copymodules while llvm-objdump does not: SYMBOL TABLE: 0000000000000000 *UND* 00000000 000000000000a7e0 l F .text 000003f9 bi_copymodules Patch makes the behavior of the llvm-objdump to be consistent with the GNU objdump. Differential revision: https://reviews.llvm.org/D56076 llvm-svn: 350840 --- llvm/test/tools/llvm-objdump/X86/demangle.s | 1 - llvm/test/tools/llvm-objdump/X86/out-of-section-sym.test | 1 - llvm/test/tools/llvm-objdump/symbol-table-elf.test | 1 - llvm/tools/llvm-objdump/llvm-objdump.cpp | 9 ++++++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/llvm/test/tools/llvm-objdump/X86/demangle.s b/llvm/test/tools/llvm-objdump/X86/demangle.s index d7c7bfb4596d..e20fa3de5c2c 100644 --- a/llvm/test/tools/llvm-objdump/X86/demangle.s +++ b/llvm/test/tools/llvm-objdump/X86/demangle.s @@ -6,7 +6,6 @@ ## Check we demangle symbols when printing symbol table. # CHECK: SYMBOL TABLE: -# CHECK-NEXT: 0000000000000000 *UND* 00000000 # CHECK-NEXT: 0000000000000000 g F .text 00000000 foo() ## Check the case when relocations are inlined into disassembly. diff --git a/llvm/test/tools/llvm-objdump/X86/out-of-section-sym.test b/llvm/test/tools/llvm-objdump/X86/out-of-section-sym.test index f70dce6a8ed8..55de107a60b3 100644 --- a/llvm/test/tools/llvm-objdump/X86/out-of-section-sym.test +++ b/llvm/test/tools/llvm-objdump/X86/out-of-section-sym.test @@ -6,7 +6,6 @@ CHECK: Disassembly of section .text: CHECK-NEXT: _start: CHECK-NEXT: 10: c3 retl CHECK-NEXT: SYMBOL TABLE: -CHECK-NEXT: 00000000 *UND* 00000000 CHECK-NEXT: 00000010 l d .text 00000000 .text CHECK-NEXT: 00000010 .text 00000000 _start CHECK-NEXT: 00000020 .text 00000000 _fdata diff --git a/llvm/test/tools/llvm-objdump/symbol-table-elf.test b/llvm/test/tools/llvm-objdump/symbol-table-elf.test index abe339d7d536..649e54c99bf8 100644 --- a/llvm/test/tools/llvm-objdump/symbol-table-elf.test +++ b/llvm/test/tools/llvm-objdump/symbol-table-elf.test @@ -5,7 +5,6 @@ # RUN: FileCheck %s --input-file=%t1 # CHECK: SYMBOL TABLE: -# CHECK-NEXT: 0000000000000000 *UND* 00000000 # CHECK-NEXT: 0000000000001004 l F .text 00000000 lfoo # CHECK-NEXT: 0000000000001008 l O .text 00000000 lbar # CHECK-NEXT: 0000000000001004 g F .text 00000000 foo diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 21359a702c67..b68714e624a5 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2015,7 +2015,14 @@ void llvm::PrintSymbolTable(const ObjectFile *o, StringRef ArchiveName, printCOFFSymbolTable(coff); return; } - for (const SymbolRef &Symbol : o->symbols()) { + + for (auto I = o->symbol_begin(), E = o->symbol_end(); I != E; ++I) { + // Skip printing the special zero symbol when dumping an ELF file. + // This makes the output consistent with the GNU objdump. + if (I == o->symbol_begin() && isa(o)) + continue; + + const SymbolRef &Symbol = *I; Expected AddressOrError = Symbol.getAddress(); if (!AddressOrError) report_error(ArchiveName, o->getFileName(), AddressOrError.takeError(),