[llvm] r221855 - llvm-readobj: Print out address table when dumping COFF delay-import table

Rui Ueyama ruiu at google.com
Wed Nov 12 19:22:55 PST 2014


Author: ruiu
Date: Wed Nov 12 21:22:54 2014
New Revision: 221855

URL: http://llvm.org/viewvc/llvm-project?rev=221855&view=rev
Log:
llvm-readobj: Print out address table when dumping COFF delay-import table

Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/test/tools/llvm-readobj/imports.test
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=221855&r1=221854&r2=221855&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Wed Nov 12 21:22:54 2014
@@ -688,6 +688,7 @@ public:
                               StringRef &Name) const;
 
   bool isRelocatableObject() const override;
+  bool is64() const { return PE32PlusHeader; }
 
   static inline bool classof(const Binary *v) { return v->isCOFF(); }
 };
@@ -740,6 +741,7 @@ public:
   std::error_code getName(StringRef &Result) const;
   std::error_code getDelayImportTable(
       const delay_import_directory_table_entry *&Result) const;
+  std::error_code getImportAddress(int AddrIndex, uint64_t &Result) const;
 
 private:
   const delay_import_directory_table_entry *Table;

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=221855&r1=221854&r2=221855&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Wed Nov 12 21:22:54 2014
@@ -1258,6 +1258,20 @@ getDelayImportTable(const delay_import_d
   return object_error::success;
 }
 
+std::error_code DelayImportDirectoryEntryRef::
+getImportAddress(int AddrIndex, uint64_t &Result) const {
+  uint32_t RVA = Table[Index].DelayImportAddressTable +
+      AddrIndex * (OwningObject->is64() ? 8 : 4);
+  uintptr_t IntPtr = 0;
+  if (std::error_code EC = OwningObject->getRvaPtr(RVA, IntPtr))
+    return EC;
+  if (OwningObject->is64())
+    Result = *reinterpret_cast<const uint64_t *>(IntPtr);
+  else
+    Result = *reinterpret_cast<const uint32_t *>(IntPtr);
+  return object_error::success;
+}
+
 bool ExportDirectoryEntryRef::
 operator==(const ExportDirectoryEntryRef &Other) const {
   return ExportTable == Other.ExportTable && Index == Other.Index;

Modified: llvm/trunk/test/tools/llvm-readobj/imports.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/imports.test?rev=221855&r1=221854&r2=221855&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/imports.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/imports.test Wed Nov 12 21:22:54 2014
@@ -34,8 +34,14 @@ X86-NEXT:   ImportAddressTable: 0x3010
 X86-NEXT:   ImportNameTable: 0x2090
 X86-NEXT:   BoundDelayImportTable: 0x20AC
 X86-NEXT:   UnloadDelayImportTable: 0x0
-X86-NEXT:   Symbol: Func5 (0)
-X86-NEXT:   Symbol: Func4 (0)
+X86-NEXT:   Import {
+X86-NEXT:     Symbol: Func5 (0)
+X86-NEXT:     Address: 0x401073
+X86-NEXT:   }
+X86-NEXT:   Import {
+X86-NEXT:     Symbol: Func4 (0)
+X86-NEXT:     Address: 0x401052
+X86-NEXT:   }
 X86-NEXT: }
 
 X64:      Import {
@@ -71,6 +77,12 @@ X64-NEXT:   ImportAddressTable: 0x3010
 X64-NEXT:   ImportNameTable: 0x20E0
 X64-NEXT:   BoundDelayImportTable: 0x2108
 X64-NEXT:   UnloadDelayImportTable: 0x0
-X64-NEXT:   Symbol: Func5 (0)
-X64-NEXT:   Symbol: Func4 (0)
+X64-NEXT:   Import {
+X64-NEXT:     Symbol: Func5 (0)
+X64-NEXT:     Address: 0x1400010F1
+X64-NEXT:   }
+X64-NEXT:   Import {
+X64-NEXT:     Symbol: Func4 (0)
+X64-NEXT:     Address: 0x140001066
+X64-NEXT:   }
 X64-NEXT: }

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=221855&r1=221854&r2=221855&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Wed Nov 12 21:22:54 2014
@@ -81,6 +81,9 @@ private:
   std::error_code resolveSymbolName(const coff_section *Section,
                                     uint64_t Offset, StringRef &Name);
   void printImportedSymbols(iterator_range<imported_symbol_iterator> Range);
+  void printDelayImportedSymbols(
+      const DelayImportDirectoryEntryRef &I,
+      iterator_range<imported_symbol_iterator> Range);
 
   typedef DenseMap<const coff_section*, std::vector<RelocationRef> > RelocMapTy;
 
@@ -1002,6 +1005,23 @@ void COFFDumper::printImportedSymbols(
   }
 }
 
+void COFFDumper::printDelayImportedSymbols(
+    const DelayImportDirectoryEntryRef &I,
+    iterator_range<imported_symbol_iterator> Range) {
+  int Index = 0;
+  for (const ImportedSymbolRef &S : Range) {
+    DictScope Import(W, "Import");
+    StringRef Sym;
+    if (error(S.getSymbolName(Sym))) return;
+    uint16_t Ordinal;
+    if (error(S.getOrdinal(Ordinal))) return;
+    W.printNumber("Symbol", Sym, Ordinal);
+    uint64_t Addr;
+    if (error(I.getImportAddress(Index++, Addr))) return;
+    W.printHex("Address", Addr);
+  }
+}
+
 void COFFDumper::printCOFFImports() {
   // Regular imports
   for (const ImportDirectoryEntryRef &I : Obj->import_directories()) {
@@ -1031,7 +1051,7 @@ void COFFDumper::printCOFFImports() {
     W.printHex("ImportNameTable", Table->DelayImportNameTable);
     W.printHex("BoundDelayImportTable", Table->BoundDelayImportTable);
     W.printHex("UnloadDelayImportTable", Table->UnloadDelayImportTable);
-    printImportedSymbols(I.imported_symbols());
+    printDelayImportedSymbols(I, I.imported_symbols());
   }
 }
 





More information about the llvm-commits mailing list