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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221855 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rui Ueyama 2014-11-13 03:22:54 +00:00
parent 7880ed5d21
commit 08f70b58cb
4 changed files with 53 additions and 5 deletions

View File

@ -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;

View File

@ -1258,6 +1258,20 @@ getDelayImportTable(const delay_import_directory_table_entry *&Result) const {
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;

View File

@ -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: }

View File

@ -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());
}
}