llvm-readobj: add support to dump COFF export tables

This enhances llvm-readobj to print out the COFF export table, similar to the
-coff-import option.  This is useful for testing in lld.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225120 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Saleem Abdulrasool 2015-01-03 21:35:09 +00:00
parent 97f8f69a7f
commit b19a485253
7 changed files with 39 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,11 @@
RUN: llvm-readobj -coff-exports %p/Inputs/export-x86.dll | FileCheck %s -check-prefix CHECK -check-prefix CHECK-X86
RUN: llvm-readobj -coff-exports %p/Inputs/export-x64.dll | FileCheck %s -check-prefix CHECK -check-prefix CHECK-X64
RUN: llvm-readobj -coff-exports %p/Inputs/export-arm.dll | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM
CHECK: Export {
CHECK: Ordinal: 1
CHECK: Name: function
CHECK-X86: RVA: 0x1000
CHECK-X64: RVA: 0x1000
CHECK-ARM: RVA: 0x1001
CHECK: }

View File

@ -57,6 +57,7 @@ public:
void printDynamicSymbols() override;
void printUnwindInfo() override;
void printCOFFImports() override;
void printCOFFExports() override;
void printCOFFDirectives() override;
void printCOFFBaseReloc() override;
@ -1062,6 +1063,26 @@ void COFFDumper::printCOFFImports() {
}
}
void COFFDumper::printCOFFExports() {
for (const ExportDirectoryEntryRef &E : Obj->export_directories()) {
DictScope Export(W, "Export");
StringRef Name;
uint32_t Ordinal, RVA;
if (error(E.getSymbolName(Name)))
continue;
if (error(E.getOrdinal(Ordinal)))
continue;
if (error(E.getExportRVA(RVA)))
continue;
W.printNumber("Ordinal", Ordinal);
W.printString("Name", Name);
W.printHex("RVA", RVA);
}
}
void COFFDumper::printCOFFDirectives() {
for (const SectionRef &Section : Obj->sections()) {
StringRef Contents;

View File

@ -45,6 +45,7 @@ public:
// Only implemented for PE/COFF.
virtual void printCOFFImports() { }
virtual void printCOFFExports() { }
virtual void printCOFFDirectives() { }
virtual void printCOFFBaseReloc() { }

View File

@ -146,6 +146,10 @@ namespace opts {
cl::opt<bool>
COFFImports("coff-imports", cl::desc("Display the PE/COFF import table"));
// -coff-exports
cl::opt<bool>
COFFExports("coff-exports", cl::desc("Display the PE/COFF export table"));
// -coff-directives
cl::opt<bool>
COFFDirectives("coff-directives",
@ -282,6 +286,8 @@ static void dumpObject(const ObjectFile *Obj) {
Dumper->printMipsPLTGOT();
if (opts::COFFImports)
Dumper->printCOFFImports();
if (opts::COFFExports)
Dumper->printCOFFExports();
if (opts::COFFDirectives)
Dumper->printCOFFDirectives();
if (opts::COFFBaseRelocs)