[llvm] r225120 - llvm-readobj: add support to dump COFF export tables

Saleem Abdulrasool compnerd at compnerd.org
Sat Jan 3 13:35:10 PST 2015


Author: compnerd
Date: Sat Jan  3 15:35:09 2015
New Revision: 225120

URL: http://llvm.org/viewvc/llvm-project?rev=225120&view=rev
Log:
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.

Added:
    llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll   (with props)
    llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll   (with props)
    llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll   (with props)
    llvm/trunk/test/tools/llvm-readobj/coff-exports.test
Modified:
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
    llvm/trunk/tools/llvm-readobj/ObjDumper.h
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Added: llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll?rev=225120&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll Sat Jan  3 15:35:09 2015 differ

Propchange: llvm/trunk/test/tools/llvm-readobj/Inputs/export-arm.dll
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll?rev=225120&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll Sat Jan  3 15:35:09 2015 differ

Propchange: llvm/trunk/test/tools/llvm-readobj/Inputs/export-x64.dll
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll?rev=225120&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll (added) and llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll Sat Jan  3 15:35:09 2015 differ

Propchange: llvm/trunk/test/tools/llvm-readobj/Inputs/export-x86.dll
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/tools/llvm-readobj/coff-exports.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/coff-exports.test?rev=225120&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/coff-exports.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/coff-exports.test Sat Jan  3 15:35:09 2015
@@ -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: }

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=225120&r1=225119&r2=225120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Sat Jan  3 15:35:09 2015
@@ -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;

Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.h?rev=225120&r1=225119&r2=225120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h Sat Jan  3 15:35:09 2015
@@ -45,6 +45,7 @@ public:
 
   // Only implemented for PE/COFF.
   virtual void printCOFFImports() { }
+  virtual void printCOFFExports() { }
   virtual void printCOFFDirectives() { }
   virtual void printCOFFBaseReloc() { }
 

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=225120&r1=225119&r2=225120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Sat Jan  3 15:35:09 2015
@@ -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
       Dumper->printMipsPLTGOT();
   if (opts::COFFImports)
     Dumper->printCOFFImports();
+  if (opts::COFFExports)
+    Dumper->printCOFFExports();
   if (opts::COFFDirectives)
     Dumper->printCOFFDirectives();
   if (opts::COFFBaseRelocs)





More information about the llvm-commits mailing list