From e2fac43a5aa2f186581d3008409091b27717d740 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 31 Jul 2016 19:25:21 +0000 Subject: [PATCH] [COFF] Remove a duplicate import_directory_table_entry definition We had import_directory_table_entry and coff_import_directory_table_entry, remove one. Also, factor out the logic which determins if a descriptor is a terminator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277296 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/COFF.h | 22 +++++++++------------- lib/Object/COFFObjectFile.cpp | 8 ++++---- tools/llvm-objdump/COFFDump.cpp | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index dcc58b06e22..896a9ded555 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -161,14 +161,6 @@ struct data_directory { support::ulittle32_t Size; }; -struct import_directory_table_entry { - support::ulittle32_t ImportLookupTableRVA; - support::ulittle32_t TimeDateStamp; - support::ulittle32_t ForwarderChain; - support::ulittle32_t NameRVA; - support::ulittle32_t ImportAddressTableRVA; -}; - struct debug_directory { support::ulittle32_t Characteristics; support::ulittle32_t TimeDateStamp; @@ -534,6 +526,10 @@ struct coff_import_directory_table_entry { support::ulittle32_t ForwarderChain; support::ulittle32_t NameRVA; support::ulittle32_t ImportAddressTableRVA; + bool isNull() const { + return ImportLookupTableRVA == 0 && TimeDateStamp == 0 && + ForwarderChain == 0 && NameRVA == 0 && ImportAddressTableRVA == 0; + } }; template @@ -633,7 +629,7 @@ private: const coff_symbol32 *SymbolTable32; const char *StringTable; uint32_t StringTableSize; - const import_directory_table_entry *ImportDirectory; + const coff_import_directory_table_entry *ImportDirectory; const delay_import_directory_table_entry *DelayImportDirectory; uint32_t NumberOfDelayImportDirectory; const export_directory_table_entry *ExportDirectory; @@ -892,8 +888,8 @@ public: class ImportDirectoryEntryRef { public: ImportDirectoryEntryRef() : OwningObject(nullptr) {} - ImportDirectoryEntryRef(const import_directory_table_entry *Table, uint32_t I, - const COFFObjectFile *Owner) + ImportDirectoryEntryRef(const coff_import_directory_table_entry *Table, + uint32_t I, const COFFObjectFile *Owner) : ImportTable(Table), Index(I), OwningObject(Owner) {} bool operator==(const ImportDirectoryEntryRef &Other) const; @@ -908,10 +904,10 @@ public: std::error_code getImportAddressTableRVA(uint32_t &Result) const; std::error_code - getImportTableEntry(const import_directory_table_entry *&Result) const; + getImportTableEntry(const coff_import_directory_table_entry *&Result) const; private: - const import_directory_table_entry *ImportTable; + const coff_import_directory_table_entry *ImportTable; uint32_t Index; const COFFObjectFile *OwningObject; }; diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 0f790086cfc..07cff3b06f1 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -538,7 +538,7 @@ std::error_code COFFObjectFile::initImportTablePtr() { if (std::error_code EC = checkOffset(Data, IntPtr, DataEntry->Size)) return EC; ImportDirectory = reinterpret_cast< - const import_directory_table_entry *>(IntPtr); + const coff_import_directory_table_entry *>(IntPtr); return std::error_code(); } @@ -772,7 +772,7 @@ basic_symbol_iterator COFFObjectFile::symbol_end_impl() const { import_directory_iterator COFFObjectFile::import_directory_begin() const { if (!ImportDirectory) return import_directory_end(); - if (ImportDirectory[0].ImportLookupTableRVA == 0) + if (ImportDirectory->isNull()) return import_directory_end(); return import_directory_iterator( ImportDirectoryEntryRef(ImportDirectory, 0, this)); @@ -1201,14 +1201,14 @@ operator==(const ImportDirectoryEntryRef &Other) const { void ImportDirectoryEntryRef::moveNext() { ++Index; - if (ImportTable[Index].ImportLookupTableRVA == 0) { + if (ImportTable[Index].isNull()) { Index = -1; ImportTable = nullptr; } } std::error_code ImportDirectoryEntryRef::getImportTableEntry( - const import_directory_table_entry *&Result) const { + const coff_import_directory_table_entry *&Result) const { return getObject(Result, OwningObject->Data, ImportTable + Index); } diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 3ec6a1f7375..b7ab86024b4 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -353,7 +353,7 @@ static void printImportTables(const COFFObjectFile *Obj) { return; outs() << "The Import Tables:\n"; for (const ImportDirectoryEntryRef &DirRef : Obj->import_directories()) { - const import_directory_table_entry *Dir; + const coff_import_directory_table_entry *Dir; StringRef Name; if (DirRef.getImportTableEntry(Dir)) return; if (DirRef.getName(Name)) return; -- 2.11.0