From 1834682b97f498093684674f8f0d95113ef3cb66 Mon Sep 17 00:00:00 2001 From: Francis Visoiu Mistrih Date: Thu, 19 Apr 2018 17:02:57 +0000 Subject: [PATCH] [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 --- llvm/lib/Object/MachOObjectFile.cpp | 6 ++++-- llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s | 9 +++++++++ .../tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o | Bin 0 -> 448 bytes llvm/tools/llvm-objdump/llvm-objdump.cpp | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 llvm/test/tools/llvm-objdump/AArch64/macho-zerofill.s create mode 100644 llvm/test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index adc54b4..ae5efc5 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 0000000..b790bb8 --- /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 new file mode 100644 index 0000000000000000000000000000000000000000..272d7d5ccdffb26f5e9641b108370fc7a0e4ffbd GIT binary patch literal 448 zcmX^A>+L@t1_nk3AOI1}KpX((fkYS>B!Tz^n1!9V2vu8vqz9yu9g3Nt+T!C&QY%WJ z93T}RAL1Gjg5aaG(9HwNHz2Etk5A6e&CSn)iN(jeIEFaFcnBKiK7E-s1t850!~sAI0w8e^1_2li;So=Y1C{b2SuP0T!vYD&21z0F8RAnCOA^gY YO7n^{)ALeO7;;K-3k<=e0Z=Ie0A9TvdH?_b literal 0 HcmV?d00001 diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 718d5749..5bea3a7 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 -- 2.7.4