[llvm] r321980 - [llvm-readobj] Support -needed-libs option for Mach-O files

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 7 22:36:44 PST 2018


Would it be possible to cherry-pick this to 6.0? The corresponding COFF side change (r321498) made it in before the branch cut, and it would be really nice if the 6.0 release was able to handle -needed-libs for all three object file formats.

From: llvm-commits <llvm-commits-bounces at lists.llvm.org> on behalf of Petr Hosek via llvm-commits <llvm-commits at lists.llvm.org>
Reply-To: Petr Hosek <phosek at chromium.org>
Date: Sunday, January 7, 2018 at 6:24 PM
To: "llvm-commits at lists.llvm.org" <llvm-commits at lists.llvm.org>
Subject: [llvm] r321980 - [llvm-readobj] Support -needed-libs option for Mach-O files

Author: phosek
Date: Sun Jan  7 18:23:10 2018
New Revision: 321980

URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D321980-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=E2FMyT23FarZeKRKWBGOndodNlyr-x_bTU7LSCiXUc0&s=LQELnKiBH9s1JnAmAAvCU5GfmaHIlafImC2dApuVIE0&e=
Log:
[llvm-readobj] Support -needed-libs option for Mach-O files

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

Differential Revision: https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D41527&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=E2FMyT23FarZeKRKWBGOndodNlyr-x_bTU7LSCiXUc0&s=oKPFZol1WEcNdf6Bm42mErZkMHAwUhJ0sDfG5RIuXNw&e=

Added:
    llvm/trunk/test/tools/llvm-readobj/macho-needed-libs.test
Modified:
    llvm/trunk/tools/llvm-readobj/MachODumper.cpp

Added: llvm/trunk/test/tools/llvm-readobj/macho-needed-libs.test
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_tools_llvm-2Dreadobj_macho-2Dneeded-2Dlibs.test-3Frev-3D321980-26view-3Dauto&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=E2FMyT23FarZeKRKWBGOndodNlyr-x_bTU7LSCiXUc0&s=7tYe3o9epnd9-QpdboQ82TWJNLZADNwK01t60ZP2-RQ&e=
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/macho-needed-libs.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/macho-needed-libs.test Sun Jan  7 18:23:10 2018
@@ -0,0 +1,26 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-readobj -needed-libs %t.o | FileCheck %s
+
+# CHECK:      NeededLibraries [
+# CHECK-NEXT:   /usr/lib/libSystem.B.dylib
+# CHECK-NEXT: ]
+
+!mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x01000007
+  cpusubtype:      0x00000003
+  filetype:        0x00000001
+  ncmds:           1
+  sizeofcmds:      56
+  flags:           0x00002000
+  reserved:        0x00000000
+LoadCommands:
+  - cmd:             LC_LOAD_DYLIB
+    cmdsize:         56
+    dylib:
+      name:            24
+      timestamp:       2
+      current_version: 81985536
+      compatibility_version: 65536
+    PayloadString:   /usr/lib/libSystem.B.dylib

Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_tools_llvm-2Dreadobj_MachODumper.cpp-3Frev-3D321980-26r1-3D321979-26r2-3D321980-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=E2FMyT23FarZeKRKWBGOndodNlyr-x_bTU7LSCiXUc0&s=bsrDlom1RmbOzZR9NRB6uDwxoguVOhlUZ1vRtkeyViU&e=
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Sun Jan  7 18:23:10 2018
@@ -39,6 +39,8 @@ public:
   void printUnwindInfo() override;
   void printStackMap() const override;
+  void printNeededLibraries() override;
+
   // MachO-specific.
   void printMachODataInCode() override;
   void printMachOVersionMin() override;
@@ -675,6 +677,34 @@ void MachODumper::printStackMap() const
                          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) {
+        auto *P = static_cast<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) {


_______________________________________________
llvm-commits mailing list
llvm-commits at lists.llvm.org<mailto:llvm-commits at lists.llvm.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=E2FMyT23FarZeKRKWBGOndodNlyr-x_bTU7LSCiXUc0&s=TdyNyGmOlGChU1wvZhGFsO2qVNTKL_VS_ZvHHEs5Evg&e=

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180108/6acdca53/attachment.html>


More information about the llvm-commits mailing list