Index: test/tools/llvm-readobj/coff-needed-libs.test =================================================================== --- /dev/null +++ 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: ] Index: tools/llvm-readobj/COFFDumper.cpp =================================================================== --- tools/llvm-readobj/COFFDumper.cpp +++ 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; + 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 Range) { for (const ImportedSymbolRef &I : Range) {