summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Object/COFF.h2
-rw-r--r--lib/Object/COFFObjectFile.cpp14
-rw-r--r--test/tools/llvm-readobj/imports.test20
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp22
4 files changed, 53 insertions, 5 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 579cbadbc94..cf98285e8fb 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -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;
diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp
index eea84c78762..dadad1f2603 100644
--- a/lib/Object/COFFObjectFile.cpp
+++ b/lib/Object/COFFObjectFile.cpp
@@ -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;
diff --git a/test/tools/llvm-readobj/imports.test b/test/tools/llvm-readobj/imports.test
index 82b7dc711c8..58512f42adc 100644
--- a/test/tools/llvm-readobj/imports.test
+++ b/test/tools/llvm-readobj/imports.test
@@ -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: }
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 65659ad9fc9..7c12f068a82 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -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());
}
}