llvm-objdump: Handle BSS sections larger than the object file
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 14 Jul 2014 16:20:14 +0000 (16:20 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 14 Jul 2014 16:20:14 +0000 (16:20 +0000)
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.

llvm-svn: 212953

llvm/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 [new file with mode: 0644]
llvm/test/tools/llvm-objdump/coff-large-bss.test [new file with mode: 0644]
llvm/tools/llvm-objdump/llvm-objdump.cpp

diff --git a/llvm/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 b/llvm/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386
new file mode 100644 (file)
index 0000000..79311d3
Binary files /dev/null and b/llvm/test/tools/llvm-objdump/Inputs/large-bss.obj.coff-i386 differ
diff --git a/llvm/test/tools/llvm-objdump/coff-large-bss.test b/llvm/test/tools/llvm-objdump/coff-large-bss.test
new file mode 100644 (file)
index 0000000..2d7643e
--- /dev/null
@@ -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: <skipping contents of bss section at [0000, 010f)>
index 309bf23..3cd48e7 100644 (file)
@@ -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("<skipping contents of bss section at [%04" PRIx64
-                       ", %04" PRIx64 ")>\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);