macho-dump: Add support for dumping dysymtab indirect symbol table.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 27 Nov 2010 13:26:12 +0000 (13:26 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 27 Nov 2010 13:26:12 +0000 (13:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120214 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/MachOFormat.h
include/llvm/Object/MachOObject.h
lib/Object/MachOObject.cpp
tools/macho-dump/macho-dump.cpp

index 9e18d2f209bdf3f6afabaa6cce56081b7b12b1ec..a6f0afbd94a63ec520dab83dd9be97d6423465c5 100644 (file)
@@ -220,6 +220,15 @@ namespace macho {
 
   /// @}
 
+  /// @name Indirect Symbol Table
+  /// @{
+
+  struct IndirectSymbolTableEntry {
+    uint32_t Index;
+  };
+
+  /// @}
+
   // See <mach-o/nlist.h>.
   enum SymbolTypeType {
     STT_Undefined = 0x00,
index 90065810991029e9a48f23cfcbf60bf4d627cc6d..79fbfd21b64542961805e52dea2ce9da939ea4e5 100644 (file)
@@ -125,6 +125,10 @@ public:
   void ReadDysymtabLoadCommand(
     const LoadCommandInfo &LCI,
     InMemoryStruct<macho::DysymtabLoadCommand> &Res) const;
+  void ReadIndirectSymbolTableEntry(
+    const macho::DysymtabLoadCommand &DLC,
+    unsigned Index,
+    InMemoryStruct<macho::IndirectSymbolTableEntry> &Res) const;
 
   /// @}
 };
index 94f6d7763a4b774042235ece5a92ba17b52ba5df..236dfe0ce507c5a4d43be06d4a26a996c2f8fdbf 100644 (file)
@@ -230,3 +230,16 @@ void MachOObject::ReadDysymtabLoadCommand(const LoadCommandInfo &LCI,
                         InMemoryStruct<macho::DysymtabLoadCommand> &Res) const {
   ReadInMemoryStruct(*this, Buffer->getBuffer(), LCI.Offset, Res);
 }
+
+template<>
+void SwapStruct(macho::IndirectSymbolTableEntry &Value) {
+  SwapValue(Value.Index);
+}
+void
+MachOObject::ReadIndirectSymbolTableEntry(const macho::DysymtabLoadCommand &DLC,
+                                          unsigned Index,
+                   InMemoryStruct<macho::IndirectSymbolTableEntry> &Res) const {
+  uint64_t Offset = (DLC.IndirectSymbolTableOffset +
+                     Index * sizeof(macho::IndirectSymbolTableEntry));
+  ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res);
+}
index 9648caec5584c4de16b67b8e1cddff0712ddd734..487a00607b8844a3813cd25f20e9f9b3f2147876 100644 (file)
@@ -14,6 +14,7 @@
 #include "llvm/Object/MachOObject.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -154,7 +155,24 @@ static int DumpDysymtabCommand(MachOObject &Obj,
   outs() << "  ('locreloff', " << DLC->LocalRelocationTableOffset << ")\n";
   outs() << "  ('nlocrel', " << DLC->NumLocalRelocationTableEntries << ")\n";
 
-  return 0;
+  // Dump the indirect symbol table.
+  int Res = 0;
+  outs() << "  ('_indirect_symbols', [\n";
+  for (unsigned i = 0; i != DLC->NumIndirectSymbolTableEntries; ++i) {
+    InMemoryStruct<macho::IndirectSymbolTableEntry> ISTE;
+    Obj.ReadIndirectSymbolTableEntry(*DLC, i, ISTE);
+    if (!ISTE) {
+      Res = Error("unable to read segment load command");
+      break;
+    }
+
+    outs() << "    # Indirect Symbol " << i << "\n";
+    outs() << "    (('symbol_index', "
+           << format("%#x", ISTE->Index) << "),),\n";
+  }
+  outs() << "  ])\n";
+
+  return Res;
 }
 
 static int DumpLoadCommand(MachOObject &Obj, unsigned Index) {