Readobj: If NumbersOfSections is 0xffff, it's an COFF import library.
0xffff does not mean that there are 65535 sections in a COFF file but
indicates that it's a COFF import library. This patch fixes SEGV error
when an import library file is passed to llvm-readobj.
llvm-svn: 194844
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index f33caee..42066c3 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -507,9 +507,10 @@
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::end_sections() const {
DataRefImpl ret;
- ret.p = reinterpret_cast<uintptr_t>(SectionTable + COFFHeader->NumberOfSections);
+ int numSections = COFFHeader->isImportLibrary()
+ ? 0 : COFFHeader->NumberOfSections;
+ ret.p = reinterpret_cast<uintptr_t>(SectionTable + numSections);
return section_iterator(SectionRef(ret, this));
}