diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h index ec8998c7465c..e05ae6c654c7 100644 --- a/llvm/include/llvm/Object/COFF.h +++ b/llvm/include/llvm/Object/COFF.h @@ -57,6 +57,8 @@ struct coff_file_header { support::ulittle32_t NumberOfSymbols; support::ulittle16_t SizeOfOptionalHeader; support::ulittle16_t Characteristics; + + bool isImportLibrary() const { return NumberOfSections == 0xffff; } }; /// The 32-bit PE header that follows the COFF header. diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index f33caee33495..42066c372b43 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -507,9 +507,10 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec) CurPtr += COFFHeader->SizeOfOptionalHeader; } - if ((ec = getObject(SectionTable, Data, base() + CurPtr, - COFFHeader->NumberOfSections * sizeof(coff_section)))) - return; + if (!COFFHeader->isImportLibrary()) + if ((ec = getObject(SectionTable, Data, base() + CurPtr, + COFFHeader->NumberOfSections * sizeof(coff_section)))) + return; // Initialize the pointer to the symbol table. if (COFFHeader->PointerToSymbolTable != 0) @@ -586,7 +587,9 @@ section_iterator COFFObjectFile::begin_sections() const { section_iterator COFFObjectFile::end_sections() const { DataRefImpl ret; - ret.p = reinterpret_cast(SectionTable + COFFHeader->NumberOfSections); + int numSections = COFFHeader->isImportLibrary() + ? 0 : COFFHeader->NumberOfSections; + ret.p = reinterpret_cast(SectionTable + numSections); return section_iterator(SectionRef(ret, this)); }