[PATCH] Readobj: If NumbersOfSections is 0xffff, it's an COFF import library.
Rui Ueyama
ruiu at google.com
Thu Nov 14 14:56:46 PST 2013
Hi rafael,
0xffff does not mean that there are 65535 sections in a COFF file but
indicated that it's a COFF import library. This patch fixes SEGV error
when an import library file is passed to llvm-readobj.
I'll check in a test for this change with
http://llvm-reviews.chandlerc.com/D2165.
http://llvm-reviews.chandlerc.com/D2182
Files:
include/llvm/Object/COFF.h
lib/Object/COFFObjectFile.cpp
Index: include/llvm/Object/COFF.h
===================================================================
--- include/llvm/Object/COFF.h
+++ include/llvm/Object/COFF.h
@@ -57,6 +57,8 @@
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.
Index: lib/Object/COFFObjectFile.cpp
===================================================================
--- lib/Object/COFFObjectFile.cpp
+++ 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));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2182.1.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131114/cfe71151/attachment.bin>
More information about the llvm-commits
mailing list