[PATCH] D41527: [llvm-readobj] Support -needed-libs option for Mach-O files

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 21 15:56:48 PST 2017


phosek created this revision.
phosek added reviewers: beanz, davide, rafael.

This implements the -needed-libs option functionality in Mach-O dumper.


Repository:
  rL LLVM

https://reviews.llvm.org/D41527

Files:
  tools/llvm-readobj/MachODumper.cpp


Index: tools/llvm-readobj/MachODumper.cpp
===================================================================
--- tools/llvm-readobj/MachODumper.cpp
+++ tools/llvm-readobj/MachODumper.cpp
@@ -39,6 +39,8 @@
   void printUnwindInfo() override;
   void printStackMap() const override;
 
+  void printNeededLibraries() override;
+
   // MachO-specific.
   void printMachODataInCode() override;
   void printMachOVersionMin() override;
@@ -675,6 +677,34 @@
                          StackMapV2Parser<support::big>(StackMapContentsArray));
 }
 
+void MachODumper::printNeededLibraries() {
+  ListScope D(W, "NeededLibraries");
+
+  using LibsTy = std::vector<StringRef>;
+  LibsTy Libs;
+
+  for (const auto &Command : Obj->load_commands()) {
+    if (Command.C.cmd == MachO::LC_LOAD_DYLIB ||
+        Command.C.cmd == MachO::LC_ID_DYLIB ||
+        Command.C.cmd == MachO::LC_LOAD_WEAK_DYLIB ||
+        Command.C.cmd == MachO::LC_REEXPORT_DYLIB ||
+        Command.C.cmd == MachO::LC_LAZY_LOAD_DYLIB ||
+        Command.C.cmd == MachO::LC_LOAD_UPWARD_DYLIB) {
+      MachO::dylib_command Dl = Obj->getDylibIDLoadCommand(Command);
+      if (Dl.dylib.name < Dl.cmdsize) {
+        const char *P = (const char *)(Command.Ptr) + Dl.dylib.name;
+        Libs.push_back(P);
+      }
+    }
+  }
+
+  std::stable_sort(Libs.begin(), Libs.end());
+
+  for (const auto &L : Libs) {
+    outs() << "  " << L << "\n";
+  }
+}
+
 void MachODumper::printMachODataInCode() {
   for (const auto &Load : Obj->load_commands()) {
     if (Load.C.cmd  == MachO::LC_DATA_IN_CODE) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41527.127964.patch
Type: text/x-patch
Size: 1558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171221/e45bc98e/attachment.bin>


More information about the llvm-commits mailing list