diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index cf5d93ee9ed..3f5a233c1ee 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -95,9 +95,7 @@ public: return TypeID > ID_StartObjects && TypeID < ID_EndObjects; } - bool isSymbolic() const { - return isIR() || isObject(); - } + bool isSymbolic() const { return isIR() || isObject() || isCOFFImportFile(); } bool isArchive() const { return TypeID == ID_Archive; diff --git a/test/tools/llvm-nm/X86/Inputs/example.lib b/test/tools/llvm-nm/X86/Inputs/example.lib new file mode 100644 index 00000000000..edcd888f2ba Binary files /dev/null and b/test/tools/llvm-nm/X86/Inputs/example.lib differ diff --git a/test/tools/llvm-nm/X86/importlibrary.test b/test/tools/llvm-nm/X86/importlibrary.test new file mode 100644 index 00000000000..9111694c2c6 --- /dev/null +++ b/test/tools/llvm-nm/X86/importlibrary.test @@ -0,0 +1,7 @@ +# RUN: llvm-nm -B %S/Inputs/example.lib | FileCheck --match-full-lines %s + +CHECK: 00000000 R __imp__constant +CHECK: 00000000 R _constant +CHECK: 00000000 D __imp__data +CHECK: 00000000 T __imp__function +CHECK: 00000000 T _function diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index a07fcef35eb..b022c300756 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -24,6 +24,7 @@ #include "llvm/IR/Module.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/COFFImportFile.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/IRObjectFile.h" #include "llvm/Object/MachO.h" @@ -269,7 +270,7 @@ static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) { static char isSymbolList64Bit(SymbolicFile &Obj) { if (auto *IRObj = dyn_cast(&Obj)) return Triple(IRObj->getTargetTriple()).isArch64Bit(); - if (isa(Obj)) + if (isa(Obj) || isa(Obj)) return false; if (isa(Obj)) return false; @@ -849,6 +850,18 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) { return '?'; } +static char getSymbolNMTypeChar(COFFImportFile &Obj) { + switch (Obj.getCOFFImportHeader()->getType()) { + case COFF::IMPORT_CODE: + return 't'; + case COFF::IMPORT_DATA: + return 'd'; + case COFF::IMPORT_CONST: + return 'r'; + } + return '?'; +} + static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) { DataRefImpl Symb = I->getRawDataRefImpl(); uint8_t NType = Obj.is64Bit() ? Obj.getSymbol64TableEntry(Symb).n_type @@ -932,6 +945,8 @@ static char getNMTypeChar(SymbolicFile &Obj, basic_symbol_iterator I) { Ret = getSymbolNMTypeChar(*IR, I); else if (COFFObjectFile *COFF = dyn_cast(&Obj)) Ret = getSymbolNMTypeChar(*COFF, I); + else if (COFFImportFile *COFFImport = dyn_cast(&Obj)) + Ret = getSymbolNMTypeChar(*COFFImport); else if (MachOObjectFile *MachO = dyn_cast(&Obj)) Ret = getSymbolNMTypeChar(*MachO, I); else if (WasmObjectFile *Wasm = dyn_cast(&Obj))