Files
clang-p2996/lld/test/ELF/invalid/invalid-file-class.test
James Henderson a20168d030 [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
2020-10-01 14:03:34 +01:00

20 lines
1007 B
Plaintext

# REQUIRES: x86
# RUN: rm -rf %t && mkdir -p %t
## In this test, we check that able to report objects with
## invalid ELF class type. There are 2 cases we want to check:
## when the object is a regular input and when it is fetched from the archive.
## Create a broken ELF object with ELFCLASSNONE class using echo. We need to fill
## first 18 bytes which are used by LLD to check the object.
## 0x7f, 'E', 'L', 'F', ELFCLASSNONE(0), ELFDATA2LSB(1),
## EV_CURRENT(1), ELFOSABI_LINUX(3), <padding zero bytes>, ET_REL(1), EM_NONE(0)
# RUN: echo -e -n "\x7f\x45\x4c\x46\x00\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" > %t/invalid.o
# RUN: llvm-ar --format=gnu crS %t/invalid-class.a %t/invalid.o
# RUN: not ld.lld -whole-archive %t/invalid-class.a -o /dev/null 2>&1 | FileCheck %s
# CHECK: invalid-class.a(invalid.o): corrupted ELF file: invalid file class
# RUN: not ld.lld %t/invalid.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=OBJ
# OBJ: invalid.o: corrupted ELF file: invalid file class