From fb432acff8c160749ac99576ec8da2a3f1987bc4 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 16 Jan 2014 07:05:49 +0000 Subject: llmv-objdump/COFF: Print export table contents. This patch adds the capability to dump export table contents. An example output is this: Export Table: Ordinal RVA Name 5 0x2008 exportfn1 6 0x2010 exportfn2 By adding this feature to llvm-objdump, we will be able to use it to check export table contents in LLD's tests. Currently we are doing binary comparison in the tests, which is fragile and not readable to humans. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199358 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/COFFDump.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'tools/llvm-objdump') diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 9c380100e8..df9c2cf2da 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -271,6 +271,36 @@ static void printImportTables(const COFFObjectFile *Obj) { } } +// Prints export tables. The export table is a table containing the list of +// exported symbol from the DLL. +static void printExportTable(const COFFObjectFile *Obj) { + outs() << "Export Table:\n"; + export_directory_iterator I = Obj->export_directory_begin(); + export_directory_iterator E = Obj->export_directory_end(); + if (I == E) + return; + outs() << " Ordinal RVA Name\n"; + error_code EC; + for (; I != E; I = I.increment(EC)) { + if (EC) + return; + uint32_t Ordinal; + if (I->getOrdinal(Ordinal)) + return; + uint32_t RVA; + if (I->getExportRVA(RVA)) + return; + outs() << format(" % 4d %# 8x", Ordinal, RVA); + + StringRef Name; + if (I->getName(Name)) + continue; + if (!Name.empty()) + outs() << " " << Name; + outs() << "\n"; + } +} + void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { const coff_file_header *Header; if (error(Obj->getCOFFHeader(Header))) return; @@ -399,5 +429,7 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { } void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) { - printImportTables(dyn_cast(Obj)); + const COFFObjectFile *file = dyn_cast(Obj); + printImportTables(file); + printExportTable(file); } -- cgit v1.2.3