diff options
| author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2018-04-19 17:02:57 +0000 |
|---|---|---|
| committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2018-04-19 17:02:57 +0000 |
| commit | 1834682b97f498093684674f8f0d95113ef3cb66 (patch) | |
| tree | 7f13ae57ff184fa52b3d8edc807ec9f59956d121 | |
| parent | aa94393ec538f2d65eb9a419a61937bdc954d01d (diff) | |
| download | bcm5719-llvm-1834682b97f498093684674f8f0d95113ef3cb66.tar.gz bcm5719-llvm-1834682b97f498093684674f8f0d95113ef3cb66.zip | |
[llvm-objdump] Print "..." instead of random data for virtual sections
When disassembling with -D, skip virtual sections by printing "..." for
each symbol.
This patch also implements `MachOObjectFile::isSectionVirtual`.
Test case comes from:
```
.zerofill __DATA,__common,_data64unsigned,472,3
```
Differential Revision: https://reviews.llvm.org/D45824
llvm-svn: 330342
| -rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s | 9 | ||||
| -rw-r--r-- | llvm/test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o | bin | 0 -> 448 bytes | |||
| -rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 7 |
4 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index adc54b42eba..ae5efc52055 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1968,8 +1968,10 @@ unsigned MachOObjectFile::getSectionID(SectionRef Sec) const { } bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const { - // FIXME: Unimplemented. - return false; + uint32_t Flags = getSectionFlags(*this, Sec); + unsigned SectionType = Flags & MachO::SECTION_TYPE; + return SectionType == MachO::S_ZEROFILL || + SectionType == MachO::S_GB_ZEROFILL; } bool MachOObjectFile::isSectionBitcode(DataRefImpl Sec) const { diff --git a/llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s b/llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s new file mode 100644 index 00000000000..b790bb89f08 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s @@ -0,0 +1,9 @@ +// RUN: llvm-mc < %s -triple aarch64-macho -filetype=obj | llvm-objdump -triple=aarch64-- -D - | FileCheck %s + + +// Check that we don't print garbage when we dump zerofill sections. + +.zerofill __DATA,__common,_data64unsigned,472,3 +// CHECK: Disassembly of section __DATA,__common: +// CHECK: ltmp1: +// CHECK-NEXT: ... diff --git a/llvm/test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o b/llvm/test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o Binary files differnew file mode 100644 index 00000000000..272d7d5ccdf --- /dev/null +++ b/llvm/test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 718d5749412..5bea3a7860b 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1494,6 +1494,13 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { outs() << '\n' << std::get<1>(Symbols[si]) << ":\n"; + // Don't print raw contents of a virtual section. A virtual section + // doesn't have any contents in the file. + if (Section.isVirtual()) { + outs() << "...\n"; + continue; + } + #ifndef NDEBUG raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls(); #else |

