From e3aafccae99546644433e50022db364dfa516ae3 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 14 Jul 2014 16:20:14 +0000 Subject: [PATCH] llvm-objdump: Handle BSS sections larger than the object file The size of the uninitialized sections, like BSS, can exceed the size of the object file. Do not attempt to grab the contents of such sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212953 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm-objdump/Inputs/large-bss.obj.coff-i386 | Bin 0 -> 270 bytes test/tools/llvm-objdump/coff-large-bss.test | 6 ++++++ tools/llvm-objdump/llvm-objdump.cpp | 12 ++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 create mode 100644 test/tools/llvm-objdump/coff-large-bss.test diff --git a/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 b/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 new file mode 100644 index 0000000000000000000000000000000000000000..79311d34688833ecba0c838cd00032d5920ed1d4 GIT binary patch literal 270 zcmeZaWM%+?9w251vltlkN>VFIpllcgl1By#3+@3s5BhT4WK5 literal 0 HcmV?d00001 diff --git a/test/tools/llvm-objdump/coff-large-bss.test b/test/tools/llvm-objdump/coff-large-bss.test new file mode 100644 index 00000000000..2d7643eb61a --- /dev/null +++ b/test/tools/llvm-objdump/coff-large-bss.test @@ -0,0 +1,6 @@ +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: diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 309bf2369a8..3cd48e7f0d1 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -628,8 +628,6 @@ static void PrintSectionContents(const ObjectFile *Obj) { bool BSS; if (error(Section.getName(Name))) continue; - if (error(Section.getContents(Contents))) - continue; if (error(Section.getAddress(BaseAddr))) continue; if (error(Section.isBSS(BSS))) @@ -637,12 +635,18 @@ static void PrintSectionContents(const ObjectFile *Obj) { outs() << "Contents of section " << Name << ":\n"; if (BSS) { + uint64_t Size; + if (error(Section.getSize(Size))) + continue; outs() << format("\n", BaseAddr, - BaseAddr + Contents.size()); + ", %04" PRIx64 ")>\n", + BaseAddr, BaseAddr + Size); continue; } + if (error(Section.getContents(Contents))) + continue; + // Dump out the content as hex and printable ascii characters. for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) { outs() << format(" %04" PRIx64 " ", BaseAddr + addr);