[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330342 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Francis Visoiu Mistrih 2018-04-19 17:02:57 +00:00
parent 3e0bad65f9
commit 7effcbd254
4 changed files with 20 additions and 2 deletions

View File

@ -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 {

View File

@ -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: ...

Binary file not shown.

View File

@ -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