[PATCH] D45824: [llvm-objdump] Print "..." instead of random data for virtual sections

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 19 09:09:46 PDT 2018


thegameg created this revision.
thegameg added reviewers: enderby, ab, rafauler, espindola.
Herald added a subscriber: jkorous.

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


https://reviews.llvm.org/D45824

Files:
  lib/Object/MachOObjectFile.cpp
  test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o
  test/tools/llvm-objdump/macho-zerofill.test
  tools/llvm-objdump/llvm-objdump.cpp


Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -1494,6 +1494,11 @@
 
       outs() << '\n' << std::get<1>(Symbols[si]) << ":\n";
 
+      if (Section.isVirtual()) {
+        outs() << "...\n";
+        continue;
+      }
+
 #ifndef NDEBUG
       raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls();
 #else
Index: test/tools/llvm-objdump/macho-zerofill.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/macho-zerofill.test
@@ -0,0 +1,7 @@
+# RUN: llvm-objdump -D %p/Inputs/zerofill.macho-x86_64.o 2>/dev/null | FileCheck %s
+
+# Check that we don't print garbage when we dump zerofill sections.
+
+# CHECK: Disassembly of section __DATA,__common:
+# CHECK: ltmp1:
+# CHECK-NEXT: ...
Index: lib/Object/MachOObjectFile.cpp
===================================================================
--- lib/Object/MachOObjectFile.cpp
+++ lib/Object/MachOObjectFile.cpp
@@ -1968,8 +1968,10 @@
 }
 
 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45824.143108.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180419/cc04dc53/attachment.bin>


More information about the llvm-commits mailing list