[llvm-readobj]Fix error messages for bad archive members and add testing for archive handling

llvm-readobj's error messages were broken for bad archive members. This
patch fixes them, and also adds testing for archive and thin archive
handling within llvm-readobj.

Reviewed by: rupprecht, grimar, higuoxing

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

llvm-svn: 354960
This commit is contained in:
James Henderson 2019-02-27 11:07:08 +00:00
parent cc19dc75fb
commit 5b27402bee
3 changed files with 112 additions and 1 deletions

View File

@ -0,0 +1,42 @@
# Show that dumping operations apply to all members in an archive.
# RUN: rm -f %t.a
# RUN: llvm-ar rc %t.a %p/Inputs/trivial.obj.elf-x86-64 %p/Inputs/trivial.obj.elf-i386 %p/Inputs/trivial.obj.coff-arm
# RUN: llvm-readobj --all %t.a | FileCheck %s --check-prefixes=LLVM,COFF
# RUN: llvm-readelf --all %t.a | FileCheck %s --check-prefixes=GNU,COFF
# LLVM: File: trivial.obj.elf-x86-64
# LLVM: Format: ELF64-x86-64
# LLVM: ElfHeader {
# LLVM: Machine: EM_X86_64
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
# GNU: ELF Header:
# GNU: Machine: Advanced Micro Devices X86-64
# GNU: Section Headers:
# GNU: Relocation section '.rela.text'
# GNU: Symbol table '.symtab'
# LLVM: File: trivial.obj.elf-i386
# LLVM: Format: ELF32-i386
# LLVM: ElfHeader {
# LLVM: Machine: EM_386
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
# GNU: ELF Header:
# GNU: Machine: Intel 80386
# GNU: Section Headers:
# GNU: Relocation section '.rel.text'
# GNU: Symbol table '.symtab'
# LLVM: File: trivial.obj.coff-arm
# LLVM: Format: COFF-ARM
# COFF: ImageFileHeader {
# COFF: Machine: IMAGE_FILE_MACHINE_ARMNT
# COFF: Sections [
# COFF: Relocations [
# COFF: Symbols [

View File

@ -0,0 +1,69 @@
# RUN: rm -f %t.a
# RUN: rm -rf %t
# RUN: mkdir -p %t
# Make copies of the test inputs for placing in the archive so that we can mess
# about with them later on.
# RUN: cp %p/Inputs/trivial.obj.elf-x86-64 %t/1.o
# RUN: cp %p/Inputs/relocs.obj.elf-x86_64 %t/2.o
# RUN: cp %p/Inputs/trivial.obj.coff-arm %t/3.o
# RUN: llvm-ar rcT %t.a %t/1.o %t/2.o %t/3.o
# Test that basic dumping works for all members.
# RUN: llvm-readobj --all %t.a | FileCheck %s --check-prefixes=LLVM,COFF
# RUN: llvm-readelf --all %t.a | FileCheck %s --check-prefixes=GNU,COFF
# LLVM: File: {{.*}}1.o
# LLVM: Format: ELF64-x86-64
# LLVM: ElfHeader {
# LLVM: SectionHeaderCount: 10
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
# GNU: ELF Header:
# GNU: Number of section headers: 10
# GNU: Section Headers:
# GNU: Relocation section '.rela.text'
# GNU: Symbol table '.symtab'
# LLVM: File: {{.*}}2.o
# LLVM: Format: ELF64-x86-64
# LLVM: ElfHeader {
# LLVM: SectionHeaderCount: 8
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
# GNU: ELF Header:
# GNU: Number of section headers: 8
# GNU: Section Headers:
# GNU: Relocation section '.rela.text'
# GNU: Symbol table '.symtab'
# LLVM: File: {{.*}}3.o
# LLVM: Format: COFF-ARM
# COFF: ImageFileHeader {
# COFF: Sections [
# COFF: Relocations [
# COFF: Symbols [
# Overwrite one of the members with a member of a different size to show that
# the size field in the member header is not relevant.
# RUN: cp %t/1.o %t/2.o
# RUN: llvm-readobj --file-headers %t.a | FileCheck %s --check-prefix=RESIZED
# RESIZED: File: {{.*}}1.o
# RESIZED: SectionHeaderCount: 10
# RESIZED: File: {{.*}}2.o
# RESIZED: SectionHeaderCount: 10
# Remove the second member and show that the first can still be dumped, but that the last isn't.
# RUN: rm %t/2.o
# RUN: not llvm-readobj --file-headers %t.a 2> %t.err | FileCheck %s --check-prefix=MISSING
# RUN: FileCheck %s --check-prefix=ERR --input-file=%t.err
# MISSING: File: {{.*}}1.o
# MISSING: SectionHeaderCount: 10
# MISSING-NOT: File: {{.*}}3.o
# ERR: Error reading file: {{.*}}.a: '{{.*}}2.o': {{[Nn]}}o such file or directory

View File

@ -582,7 +582,7 @@ static void dumpArchive(const Archive *Arc, ScopedPrinter &Writer) {
Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
if (!ChildOrErr) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {
reportError(Arc->getFileName(), ChildOrErr.takeError());
reportError(Arc->getFileName(), std::move(E));
}
continue;
}