[PATCH] Readobj: If NumbersOfSections is 0xffff, it's an COFF import library.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Nov 15 07:14:20 PST 2013


LGTM

On 14 November 2013 17:56, Rui Ueyama <ruiu at google.com> wrote:
> 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));
>  }



More information about the llvm-commits mailing list