llvm.org GIT mirror llvm / 08f70b5
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 Rui Ueyama 6 years ago
4 changed file(s) with 53 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
687687 StringRef &Name) const;
688688
689689 bool isRelocatableObject() const override;
690 bool is64() const { return PE32PlusHeader; }
690691
691692 static inline bool classof(const Binary *v) { return v->isCOFF(); }
692693 };
739740 std::error_code getName(StringRef &Result) const;
740741 std::error_code getDelayImportTable(
741742 const delay_import_directory_table_entry *&Result) const;
743 std::error_code getImportAddress(int AddrIndex, uint64_t &Result) const;
742744
743745 private:
744746 const delay_import_directory_table_entry *Table;
12571257 return object_error::success;
12581258 }
12591259
1260 std::error_code DelayImportDirectoryEntryRef::
1261 getImportAddress(int AddrIndex, uint64_t &Result) const {
1262 uint32_t RVA = Table[Index].DelayImportAddressTable +
1263 AddrIndex * (OwningObject->is64() ? 8 : 4);
1264 uintptr_t IntPtr = 0;
1265 if (std::error_code EC = OwningObject->getRvaPtr(RVA, IntPtr))
1266 return EC;
1267 if (OwningObject->is64())
1268 Result = *reinterpret_cast(IntPtr);
1269 else
1270 Result = *reinterpret_cast(IntPtr);
1271 return object_error::success;
1272 }
1273
12601274 bool ExportDirectoryEntryRef::
12611275 operator==(const ExportDirectoryEntryRef &Other) const {
12621276 return ExportTable == Other.ExportTable && Index == Other.Index;
3333 X86-NEXT: ImportNameTable: 0x2090
3434 X86-NEXT: BoundDelayImportTable: 0x20AC
3535 X86-NEXT: UnloadDelayImportTable: 0x0
36 X86-NEXT: Symbol: Func5 (0)
37 X86-NEXT: Symbol: Func4 (0)
36 X86-NEXT: Import {
37 X86-NEXT: Symbol: Func5 (0)
38 X86-NEXT: Address: 0x401073
39 X86-NEXT: }
40 X86-NEXT: Import {
41 X86-NEXT: Symbol: Func4 (0)
42 X86-NEXT: Address: 0x401052
43 X86-NEXT: }
3844 X86-NEXT: }
3945
4046 X64: Import {
7076 X64-NEXT: ImportNameTable: 0x20E0
7177 X64-NEXT: BoundDelayImportTable: 0x2108
7278 X64-NEXT: UnloadDelayImportTable: 0x0
73 X64-NEXT: Symbol: Func5 (0)
74 X64-NEXT: Symbol: Func4 (0)
79 X64-NEXT: Import {
80 X64-NEXT: Symbol: Func5 (0)
81 X64-NEXT: Address: 0x1400010F1
82 X64-NEXT: }
83 X64-NEXT: Import {
84 X64-NEXT: Symbol: Func4 (0)
85 X64-NEXT: Address: 0x140001066
86 X64-NEXT: }
7587 X64-NEXT: }
8080 std::error_code resolveSymbolName(const coff_section *Section,
8181 uint64_t Offset, StringRef &Name);
8282 void printImportedSymbols(iterator_range Range);
83 void printDelayImportedSymbols(
84 const DelayImportDirectoryEntryRef &I,
85 iterator_range Range);
8386
8487 typedef DenseMap > RelocMapTy;
8588
10011004 }
10021005 }
10031006
1007 void COFFDumper::printDelayImportedSymbols(
1008 const DelayImportDirectoryEntryRef &I,
1009 iterator_range Range) {
1010 int Index = 0;
1011 for (const ImportedSymbolRef &S : Range) {
1012 DictScope Import(W, "Import");
1013 StringRef Sym;
1014 if (error(S.getSymbolName(Sym))) return;
1015 uint16_t Ordinal;
1016 if (error(S.getOrdinal(Ordinal))) return;
1017 W.printNumber("Symbol", Sym, Ordinal);
1018 uint64_t Addr;
1019 if (error(I.getImportAddress(Index++, Addr))) return;
1020 W.printHex("Address", Addr);
1021 }
1022 }
1023
10041024 void COFFDumper::printCOFFImports() {
10051025 // Regular imports
10061026 for (const ImportDirectoryEntryRef &I : Obj->import_directories()) {
10301050 W.printHex("ImportNameTable", Table->DelayImportNameTable);
10311051 W.printHex("BoundDelayImportTable", Table->BoundDelayImportTable);
10321052 W.printHex("UnloadDelayImportTable", Table->UnloadDelayImportTable);
1033 printImportedSymbols(I.imported_symbols());
1053 printDelayImportedSymbols(I, I.imported_symbols());
10341054 }
10351055 }
10361056