[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:49:31 PDT 2018


thegameg updated this revision to Diff 143110.
thegameg added a comment.
Herald added a subscriber: javed.absar.

Thanks Jonas!

Added assembly test and a missing comment.


https://reviews.llvm.org/D45824

Files:
  lib/Object/MachOObjectFile.cpp
  test/tools/llvm-objdump/AArch64/macho-zerofill.s
  test/tools/llvm-objdump/Inputs/zerofill.macho-x86_64.o
  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,13 @@
 
       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
Index: test/tools/llvm-objdump/AArch64/macho-zerofill.s
===================================================================
--- /dev/null
+++ 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: ...
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.143110.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180419/e28d5e9a/attachment.bin>


More information about the llvm-commits mailing list