From 185b5b1d24e1f3b61a2b964cbd7438d376466514 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 11 Nov 2014 09:58:25 +0000 Subject: [PATCH] llvm-objdump: Skip empty sections when dumping contents Empty sections are just noise when using objdump. This is similar to what binutils does. llvm-svn: 221680 --- llvm/test/MC/Mips/cpload.s | 4 ++-- llvm/test/MC/Mips/elf-objdump.s | 11 ----------- llvm/test/tools/llvm-objdump/coff-large-bss.test | 5 +---- llvm/tools/llvm-objdump/llvm-objdump.cpp | 9 ++++++--- 4 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 llvm/test/MC/Mips/elf-objdump.s diff --git a/llvm/test/MC/Mips/cpload.s b/llvm/test/MC/Mips/cpload.s index 99b020a..46b3ee4 100644 --- a/llvm/test/MC/Mips/cpload.s +++ b/llvm/test/MC/Mips/cpload.s @@ -25,12 +25,12 @@ # OBJ-O32: R_MIPS_LO16 _gp_disp # OBJ-O32: addu $gp, $gp, $25 -# OBJ-N32: .text +# OBJ-N32-NOT: .text # OBJ-N32-NOT: lui $gp, 0 # OBJ-N32-NOT: addiu $gp, $gp, 0 # OBJ-N32-NOT: addu $gp, $gp, $25 -# OBJ-N64: .text +# OBJ-N64-NOT: .text # OBJ-N64-NOT: lui $gp, 0 # OBJ-N64-NOT: addiu $gp, $gp, 0 # OBJ-N64-NOT: addu $gp, $gp, $25 diff --git a/llvm/test/MC/Mips/elf-objdump.s b/llvm/test/MC/Mips/elf-objdump.s deleted file mode 100644 index 6a5c2a5..0000000 --- a/llvm/test/MC/Mips/elf-objdump.s +++ /dev/null @@ -1,11 +0,0 @@ -// 32 bit big endian -// RUN: llvm-mc -filetype=obj -triple mips-unknown-linux %s -o - | llvm-objdump -d -triple mips-unknown-linux - | FileCheck %s -// 32 bit little endian -// RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux %s -o - | llvm-objdump -d -triple mips-unknown-linux - | FileCheck %s -// 64 bit big endian -// RUN: llvm-mc -filetype=obj -arch=mips64 -triple mips64-unknown-linux %s -o - | llvm-objdump -d -triple mips-unknown-linux - | FileCheck %s -// 64 bit little endian -// RUN: llvm-mc -filetype=obj -arch=mips64el -triple mips64el-unknown-linux %s -o - | llvm-objdump -d -triple mips-unknown-linux - | FileCheck %s - -// We just want to see if llvm-objdump works at all. -// CHECK: .text diff --git a/llvm/test/tools/llvm-objdump/coff-large-bss.test b/llvm/test/tools/llvm-objdump/coff-large-bss.test index 2d7643e..dc0fc67 100644 --- a/llvm/test/tools/llvm-objdump/coff-large-bss.test +++ b/llvm/test/tools/llvm-objdump/coff-large-bss.test @@ -1,6 +1,3 @@ RUN: llvm-objdump -s %p/Inputs/large-bss.obj.coff-i386 | FileCheck %s -; CHECK: Contents of section .text: -: CHECK-NEXT: Contents of section .data: -: CHECK-NEXT: Contents of section .bss: -: CHECK-NEXT: +: CHECK: diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 2d1c86c..c61a5b2 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -313,6 +313,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { uint64_t SectionAddr = Section.getAddress(); uint64_t SectSize = Section.getSize(); + if (!SectSize) + continue; // Make a list of all the symbols in this section. std::vector> Symbols; @@ -514,11 +516,12 @@ static void PrintSectionContents(const ObjectFile *Obj) { if (error(Section.getName(Name))) continue; uint64_t BaseAddr = Section.getAddress(); - bool BSS = Section.isBSS(); + uint64_t Size = Section.getSize(); + if (!Size) + continue; outs() << "Contents of section " << Name << ":\n"; - if (BSS) { - uint64_t Size = Section.getSize(); + if (Section.isBSS()) { outs() << format("\n", BaseAddr, BaseAddr + Size); -- 2.7.4