Index: tools/llvm-readobj/MachODumper.cpp =================================================================== --- tools/llvm-readobj/MachODumper.cpp +++ tools/llvm-readobj/MachODumper.cpp @@ -38,6 +38,8 @@ void printDynamicSymbols() override; void printUnwindInfo() override; + void printNeededLibraries() override; + private: template void printFileHeaders(const MachHeader &Header); @@ -586,3 +588,33 @@ void MachODumper::printUnwindInfo() { W.startLine() << "UnwindInfo not implemented.\n"; } + +void MachODumper::printNeededLibraries() { + ListScope D(W, "NeededLibraries"); + + typedef std::vector LibsTy; + LibsTy Libs; + + uint32_t NumOfCommands = + Obj->is64Bit() ? Obj->getHeader64().ncmds : Obj->getHeader().ncmds; + MachOObjectFile::LoadCommandInfo Command = Obj->getFirstLoadCommandInfo(); + MachO::dylib_command DylibCommand; + uint32_t LoadCommandType; + for (uint32_t i = 0; i != NumOfCommands; + ++i, Command = Obj->getNextLoadCommandInfo(Command), LoadCommandType = Command.C.cmd) { + if (LoadCommandType == MachO::LC_LOAD_DYLIB || + LoadCommandType == MachO::LC_LOAD_WEAK_DYLIB || + LoadCommandType == MachO::LC_REEXPORT_DYLIB || + LoadCommandType == MachO::LC_LOAD_UPWARD_DYLIB || + LoadCommandType == MachO::LC_LAZY_LOAD_DYLIB) { + DylibCommand = Obj->getDylibIDLoadCommand(Command); + Libs.push_back(Command.Ptr + DylibCommand.dylib.name); + } + if (i == NumOfCommands -1) + break; + } + + for (LibsTy::const_iterator I = Libs.begin(), E = Libs.end(); I != E; ++I) { + outs() << " " << *I << "\n"; + } +}