[COFF] Gracefully handle empty .drectve sections
authorShoaib Meenai <smeenai@fb.com>
Sun, 14 May 2017 18:34:56 +0000 (18:34 +0000)
committerShoaib Meenai <smeenai@fb.com>
Sun, 14 May 2017 18:34:56 +0000 (18:34 +0000)
commitee97c5f0125e8f07ee53934bf607c5d518959cac
tree01dd3965aa76889366a401f7856c004932b59079
parent5bef9c627e44077e4ec5024be062faecc4eab3e5
[COFF] Gracefully handle empty .drectve sections

Running `llvm-readobj -coff-directives msvcrt.lib` resulted in this error:

    Invalid data was encountered while parsing the file

This happened because some of the object files in the archive have empty
`.drectve` sections. These empty sections result in a `parse_failed` error being
returned from `COFFObjectFile::getSectionContents()`, which in turn caused
`llvm-readobj` to stop. With this change, `getSectionContents` now returns
success, and like before the resulting array is empty.

Patch by Dave Lee.

Differential Revision: https://reviews.llvm.org/D32652

llvm-svn: 303014
llvm/lib/Object/COFFObjectFile.cpp
llvm/test/Object/Inputs/COFF/empty-drectve.yaml [new file with mode: 0644]
llvm/test/Object/coff-empty-drectve.test [new file with mode: 0644]