Skip to content

Commit

Permalink
llvm-objdump: Don't print contents of BSS sections: it makes no sense…
Browse files Browse the repository at this point in the history
… and crashes llvm-objdump on relocated objects with large bss

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179589 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Alexey Samsonov committed Apr 16, 2013
1 parent 6334e13 commit 0eaa6f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/Object/objdump-section-content.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-objdump -s - | FileCheck %s -check-prefix COFF-i386
RUN: llvm-objdump -s %p/Inputs/trivial-object-test.elf-i386 \
RUN: | FileCheck %s -check-prefix ELF-i386
RUN: llvm-objdump -s %p/Inputs/shared-object-test.elf-i386 \
RUN: | FileCheck %s -check-prefix BSS

COFF-i386: file format
COFF-i386: Contents of section .text:
Expand All @@ -17,3 +19,6 @@ ELF-i386: 0010 0000e8fc ffffffe8 fcffffff 8b442408 .............D$.
ELF-i386: 0020 83c40cc3 ....
ELF-i386: Contents of section .rodata.str1.1:
ELF-i386: 0024 48656c6c 6f20576f 726c6421 00 Hello World!.

BSS: Contents of section .bss:
BSS-NEXT: <skipping contents of bss section at [12c8, 12cc)>
8 changes: 8 additions & 0 deletions tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,19 @@ static void PrintSectionContents(const ObjectFile *o) {
StringRef Name;
StringRef Contents;
uint64_t BaseAddr;
bool BSS;
if (error(si->getName(Name))) continue;
if (error(si->getContents(Contents))) continue;
if (error(si->getAddress(BaseAddr))) continue;
if (error(si->isBSS(BSS))) continue;

outs() << "Contents of section " << Name << ":\n";
if (BSS) {
outs() << format("<skipping contents of bss section at [%04" PRIx64
", %04" PRIx64 ")>\n", BaseAddr,
BaseAddr + Contents.size());
continue;
}

// Dump out the content as hex and printable ascii characters.
for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) {
Expand Down

0 comments on commit 0eaa6f6

Please sign in to comment.