[PATCH] D12084: [llvm-readobj] Add support for MachO DataInCodeDataCommand

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 21 13:29:30 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL245732: [llvm-readobj] Add support for MachO DataInCodeDataCommand. (authored by davide).

Changed prior to commit:
  http://reviews.llvm.org/D12084?vs=32301&id=32860#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12084

Files:
  llvm/trunk/tools/llvm-readobj/MachODumper.cpp
  llvm/trunk/tools/llvm-readobj/ObjDumper.h
  llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Index: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
===================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp
@@ -40,6 +40,9 @@
   void printUnwindInfo() override;
   void printStackMap() const override;
 
+  // MachO-specific.
+  void printMachODataInCode() override;
+
 private:
   template<class MachHeader>
   void printFileHeaders(const MachHeader &Header);
@@ -600,3 +603,25 @@
      prettyPrintStackMap(llvm::outs(),
                          StackMapV1Parser<support::big>(StackMapContentsArray));
 }
+
+void MachODumper::printMachODataInCode() {
+  for (const auto &Load : Obj->load_commands()) {
+    if (Load.C.cmd  == MachO::LC_DATA_IN_CODE) {
+      MachO::linkedit_data_command LLC = Obj->getLinkeditDataLoadCommand(Load);
+      DictScope Group(W, "DataInCode");
+      W.printNumber("Data offset", LLC.dataoff);
+      W.printNumber("Data size", LLC.datasize);
+      ListScope D(W, "Data entries");
+      unsigned NumRegions = LLC.datasize / sizeof(MachO::data_in_code_entry);
+      for (unsigned i = 0; i < NumRegions; ++i) {
+        MachO::data_in_code_entry DICE = Obj->getDataInCodeTableEntry(
+                                                              LLC.dataoff, i);
+        DictScope Group(W, "Entry");
+        W.printNumber("Index", i);
+        W.printNumber("Offset", DICE.offset);
+        W.printNumber("Length", DICE.length);
+        W.printNumber("Kind", DICE.kind);
+      }
+    }
+  }
+}
Index: llvm/trunk/tools/llvm-readobj/ObjDumper.h
===================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h
@@ -54,6 +54,9 @@
   virtual void printCOFFDirectives() { }
   virtual void printCOFFBaseReloc() { }
 
+  // Only implemented for MachO.
+  virtual void printMachODataInCode() { }
+
   virtual void printStackMap() const = 0;
 
 protected:
Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
===================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
@@ -181,6 +181,11 @@
   COFFBaseRelocs("coff-basereloc",
                  cl::desc("Display the PE/COFF .reloc section"));
 
+  // -macho-data-in-code
+  cl::opt<bool>
+  MachODataInCode("macho-data-in-code",
+                  cl::desc("Display MachO Data in Code command"));
+
   // -stackmap
   cl::opt<bool>
   PrintStackMap("stackmap",
@@ -312,6 +317,9 @@
     if (opts::COFFBaseRelocs)
       Dumper->printCOFFBaseReloc();
   }
+  if (Obj->isMachO())
+    if (opts::MachODataInCode)
+      Dumper->printMachODataInCode();
   if (opts::PrintStackMap)
     Dumper->printStackMap();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12084.32860.patch
Type: text/x-patch
Size: 2806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150821/60251c97/attachment.bin>


More information about the llvm-commits mailing list