diff --git a/include/llvm/Object/MachOFormat.h b/include/llvm/Object/MachOFormat.h index 9e18d2f209b..a6f0afbd94a 100644 --- a/include/llvm/Object/MachOFormat.h +++ b/include/llvm/Object/MachOFormat.h @@ -220,6 +220,15 @@ namespace macho { /// @} + /// @name Indirect Symbol Table + /// @{ + + struct IndirectSymbolTableEntry { + uint32_t Index; + }; + + /// @} + // See . enum SymbolTypeType { STT_Undefined = 0x00, diff --git a/include/llvm/Object/MachOObject.h b/include/llvm/Object/MachOObject.h index 90065810991..79fbfd21b64 100644 --- a/include/llvm/Object/MachOObject.h +++ b/include/llvm/Object/MachOObject.h @@ -125,6 +125,10 @@ public: void ReadDysymtabLoadCommand( const LoadCommandInfo &LCI, InMemoryStruct &Res) const; + void ReadIndirectSymbolTableEntry( + const macho::DysymtabLoadCommand &DLC, + unsigned Index, + InMemoryStruct &Res) const; /// @} }; diff --git a/lib/Object/MachOObject.cpp b/lib/Object/MachOObject.cpp index 94f6d7763a4..236dfe0ce50 100644 --- a/lib/Object/MachOObject.cpp +++ b/lib/Object/MachOObject.cpp @@ -230,3 +230,16 @@ void MachOObject::ReadDysymtabLoadCommand(const LoadCommandInfo &LCI, InMemoryStruct &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 &Res) const { + uint64_t Offset = (DLC.IndirectSymbolTableOffset + + Index * sizeof(macho::IndirectSymbolTableEntry)); + ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res); +} diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp index 9648caec558..487a00607b8 100644 --- a/tools/macho-dump/macho-dump.cpp +++ b/tools/macho-dump/macho-dump.cpp @@ -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 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) {