[PATCH] llvm-readobj: implement MachODumper::printNeededLibraries

Chilledheart rwindz0 at gmail.com
Tue Mar 3 19:22:17 PST 2015


apply some minor improvements

I saw the LC_ID_DYLIB items in the output of `otool -L` command, so I thought
they were needed to be printed (double-checked with cctool source code, version 862).
I have removed this, anyway.

The file mach-o/loader.h states that struct fvmlib is obsoleted,
so there is no need to add the support for LC_IDFVMLIB and LC_LOADFVMLIB.


http://reviews.llvm.org/D7378

Files:
  tools/llvm-readobj/MachODumper.cpp

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<class MachHeader>
   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<StringRef> 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";
+  }
+}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7378.21166.patch
Type: text/x-patch
Size: 1654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150304/bce1b3fb/attachment.bin>


More information about the llvm-commits mailing list