From 7ab20090242a84ebba3afa25973fda03be5f2a7e Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Thu, 3 Sep 2015 18:10:28 +0000 Subject: [PATCH] [llvm-readobj] Dump MachO indirect symbols. Example output: File: Format: Mach-O 32-bit i386 Arch: i386 AddressSize: 32bit Indirect Symbols { Number: 3 Symbols [ Entry { Entry Index: 0 Symbol Index: 0x4 } Entry { Entry Index: 1 Symbol Index: 0x0 } Entry { Entry Index: 2 Symbol Index: 0x1 } ] } Differential Revision: http://reviews.llvm.org/D12570 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246789 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/MachODumper.cpp | 17 +++++++++++++++++ tools/llvm-readobj/ObjDumper.h | 1 + tools/llvm-readobj/llvm-readobj.cpp | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index a7c5d23b7e4..80c45dee3cc 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -45,6 +45,7 @@ public: void printMachOVersionMin() override; void printMachODysymtab() override; void printMachOSegment() override; + void printMachOIndirectSymbols() override; private: template @@ -774,3 +775,19 @@ void MachODumper::printMachOSegment() { } } } + +void MachODumper::printMachOIndirectSymbols() { + for (const auto &Load : Obj->load_commands()) { + if (Load.C.cmd == MachO::LC_DYSYMTAB) { + MachO::dysymtab_command DLC = Obj->getDysymtabLoadCommand(); + DictScope Group(W, "Indirect Symbols"); + W.printNumber("Number", DLC.nindirectsyms); + ListScope D(W, "Symbols"); + for (unsigned i = 0; i < DLC.nindirectsyms; ++i) { + DictScope Group(W, "Entry"); + W.printNumber("Entry Index", i); + W.printHex("Symbol Index", Obj->getIndirectSymbolTableEntry(DLC, i)); + } + } + } +} diff --git a/tools/llvm-readobj/ObjDumper.h b/tools/llvm-readobj/ObjDumper.h index 5fea403322d..65015213201 100644 --- a/tools/llvm-readobj/ObjDumper.h +++ b/tools/llvm-readobj/ObjDumper.h @@ -60,6 +60,7 @@ public: virtual void printMachOVersionMin() { } virtual void printMachODysymtab() { } virtual void printMachOSegment() { } + virtual void printMachOIndirectSymbols() { } virtual void printStackMap() const = 0; diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index f63bc81002f..2e17525ab71 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -187,6 +187,11 @@ namespace opts { MachODataInCode("macho-data-in-code", cl::desc("Display MachO Data in Code command")); + // -macho-indirect-symbols + cl::opt + MachOIndirectSymbols("macho-indirect-symbols", + cl::desc("Display MachO indirect symbols")); + // -macho-segment cl::opt MachOSegment("macho-segment", @@ -336,6 +341,8 @@ static void dumpObject(const ObjectFile *Obj) { if (Obj->isMachO()) { if (opts::MachODataInCode) Dumper->printMachODataInCode(); + if (opts::MachOIndirectSymbols) + Dumper->printMachOIndirectSymbols(); if (opts::MachOSegment) Dumper->printMachOSegment(); if (opts::MachOVersionMin) -- 2.34.1