[Archive] Don't throw away errors for malformed archive members
authorJames Henderson <james.henderson@sony.com>
Fri, 25 Sep 2020 09:21:39 +0000 (10:21 +0100)
committerJames Henderson <james.henderson@sony.com>
Thu, 1 Oct 2020 13:03:34 +0000 (14:03 +0100)
commita20168d0307860047ad7c8a2074f98fc25b057c2
treeeee9b302c3a52f8c6a9c3c6c8d439f8beebd18b0
parent5101e7e8dd01719f9161e01e2f053c9797c247a8
[Archive] Don't throw away errors for malformed archive members

When adding an archive member with a problem, e.g. a new bitcode with an
old archiver, containing an unsupported attribute, or an ELF file with a
malformed symbol table, the archiver would throw away the error and
simply add the member to the archive without any symbol entries. This
meant that the resultant archive could be silently unusable when not
using --whole-archive, and result in unexpected undefined symbols.

This change fixes this issue by addressing two FIXMEs and only throwing
away not-an-object errors. However, this meant that some LLD tests which
didn't need symbol tables and were using invalid members deliberately to
test the linker's malformed input handling no longer worked, so this
patch also stops the archiver from looking for symbols in an object if
it doesn't require a symbol table, and updates the tests accordingly.

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

Reviewed by: grimar, rupprecht, MaskRay
lld/test/ELF/invalid/data-encoding.test
lld/test/ELF/invalid/invalid-file-class.test
llvm/include/llvm/Object/SymbolicFile.h
llvm/lib/Object/ArchiveWriter.cpp
llvm/lib/Object/SymbolicFile.cpp
llvm/test/Object/archive-malformed-object.test [new file with mode: 0644]
llvm/test/Object/archive-unknown-filetype.test [new file with mode: 0644]