[llvm-commits] [llvm] r120214 - in /llvm/trunk: include/llvm/Object/MachOFormat.h include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp

Daniel Dunbar daniel at zuster.org
Sat Nov 27 05:26:12 PST 2010


Author: ddunbar
Date: Sat Nov 27 07:26:12 2010
New Revision: 120214

URL: http://llvm.org/viewvc/llvm-project?rev=120214&view=rev
Log:
macho-dump: Add support for dumping dysymtab indirect symbol table.

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

Modified: llvm/trunk/include/llvm/Object/MachOFormat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOFormat.h?rev=120214&r1=120213&r2=120214&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOFormat.h (original)
+++ llvm/trunk/include/llvm/Object/MachOFormat.h Sat Nov 27 07:26:12 2010
@@ -220,6 +220,15 @@
 
   /// @}
 
+  /// @name Indirect Symbol Table
+  /// @{
+
+  struct IndirectSymbolTableEntry {
+    uint32_t Index;
+  };
+
+  /// @}
+
   // See <mach-o/nlist.h>.
   enum SymbolTypeType {
     STT_Undefined = 0x00,

Modified: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=120214&r1=120213&r2=120214&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Sat Nov 27 07:26:12 2010
@@ -125,6 +125,10 @@
   void ReadDysymtabLoadCommand(
     const LoadCommandInfo &LCI,
     InMemoryStruct<macho::DysymtabLoadCommand> &Res) const;
+  void ReadIndirectSymbolTableEntry(
+    const macho::DysymtabLoadCommand &DLC,
+    unsigned Index,
+    InMemoryStruct<macho::IndirectSymbolTableEntry> &Res) const;
 
   /// @}
 };

Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=120214&r1=120213&r2=120214&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Sat Nov 27 07:26:12 2010
@@ -230,3 +230,16 @@
                         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);
+}

Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=120214&r1=120213&r2=120214&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sat Nov 27 07:26:12 2010
@@ -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 @@
   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) {





More information about the llvm-commits mailing list