[PATCH] D41529: [llvm-readobj] Support -needed-libs option for COFF files

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 27 12:00:55 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL321498: [llvm-readobj] Support -needed-libs option for COFF files (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41529?vs=128066&id=128239#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41529

Files:
  llvm/trunk/test/tools/llvm-readobj/Inputs/needed-libs.obj.coff-am64
  llvm/trunk/test/tools/llvm-readobj/coff-needed-libs.test
  llvm/trunk/tools/llvm-readobj/COFFDumper.cpp


Index: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
@@ -81,6 +81,9 @@
   void printSymbols() override;
   void printDynamicSymbols() override;
   void printUnwindInfo() override;
+
+  void printNeededLibraries() override;
+
   void printCOFFImports() override;
   void printCOFFExports() override;
   void printCOFFDirectives() override;
@@ -1522,6 +1525,25 @@
   }
 }
 
+void COFFDumper::printNeededLibraries() {
+  ListScope D(W, "NeededLibraries");
+
+  using LibsTy = std::vector<StringRef>;
+  LibsTy Libs;
+
+  for (const ImportDirectoryEntryRef &DirRef : Obj->import_directories()) {
+    StringRef Name;
+    if (!DirRef.getName(Name))
+      Libs.push_back(Name);
+  }
+
+  std::stable_sort(Libs.begin(), Libs.end());
+
+  for (const auto &L : Libs) {
+    outs() << "  " << L << "\n";
+  }
+}
+
 void COFFDumper::printImportedSymbols(
     iterator_range<imported_symbol_iterator> Range) {
   for (const ImportedSymbolRef &I : Range) {
Index: llvm/trunk/test/tools/llvm-readobj/coff-needed-libs.test
===================================================================
--- llvm/trunk/test/tools/llvm-readobj/coff-needed-libs.test
+++ llvm/trunk/test/tools/llvm-readobj/coff-needed-libs.test
@@ -0,0 +1,5 @@
+RUN: llvm-readobj -needed-libs %p/Inputs/needed-libs.obj.coff-am64 | FileCheck %s
+
+CHECK:      NeededLibraries [
+CHECK-NEXT:   KERNEL32.dll
+CHECK-NEXT: ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41529.128239.patch
Type: text/x-patch
Size: 1541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171227/9c835002/attachment.bin>


More information about the llvm-commits mailing list