1a20168d0SJames Henderson## Show that the archive library emits error messages when adding malformed 2*c675a9beSpcc## object files and skips symbol tables for "malformed" bitcode files, which 3*c675a9beSpcc## are assumed to be bitcode files generated by compilers from the future. 4a20168d0SJames Henderson 5a20168d0SJames Henderson# RUN: rm -rf %t.dir 6a20168d0SJames Henderson# RUN: split-file %s %t.dir 7a20168d0SJames Henderson# RUN: cd %t.dir 8a20168d0SJames Henderson 9*c675a9beSpcc## Create a malformed bitcode object. 10a20168d0SJames Henderson# RUN: llvm-as input.ll -o input.bc 114cc7c749Szhijian# RUN: cp input.bc good.bc 12a20168d0SJames Henderson# RUN: %python -c "with open('input.bc', 'a') as f: f.truncate(10)" 13a20168d0SJames Henderson 14*c675a9beSpcc## Malformed bitcode objects either warn or error depending on the archive format 15*c675a9beSpcc## (see switch in getSymbolicFile). If the archive was created with a warning, 16*c675a9beSpcc## we want to check that the archive map is empty. llvm-nm will fail when it 17*c675a9beSpcc## tries to read the malformed bitcode file, but it's supposed to print the 18*c675a9beSpcc## archive map first, which in this case it won't because there won't be one. 194cc7c749Szhijian# RUN: rm -rf bad.a 20*c675a9beSpcc# RUN: llvm-ar --format=bsd rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1 21*c675a9beSpcc# RUN: not llvm-nm --print-armap bad.a | count 0 22*c675a9beSpcc# RUN: rm -rf bad.a 23*c675a9beSpcc# RUN: llvm-ar --format=gnu rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1 24*c675a9beSpcc# RUN: not llvm-nm --print-armap bad.a | count 0 25*c675a9beSpcc# RUN: rm -rf bad.a 26*c675a9beSpcc# RUN: not llvm-ar --format=bigarchive rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1 27*c675a9beSpcc# RUN: rm -rf bad.a 28*c675a9beSpcc# RUN: not llvm-ar --format=coff rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1 29*c675a9beSpcc# RUN: rm -rf bad.a 30*c675a9beSpcc# RUN: not llvm-ar --format=darwin rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1 31*c675a9beSpcc 32*c675a9beSpcc## Malformed bitcode object is the last file member of archive and 33*c675a9beSpcc## the symbol table is required. In this case we check that the 34*c675a9beSpcc## symbol table contains entries for the good object only. 35*c675a9beSpcc# RUN: rm -rf bad.a 36*c675a9beSpcc# RUN: llvm-ar rc bad.a good.bc input.bc 2>&1 | FileCheck %s --check-prefix=WARN1 37*c675a9beSpcc# RUN: not llvm-nm --print-armap bad.a | FileCheck %s --check-prefix=ARMAP 384cc7c749Szhijian 394cc7c749Szhijian## Malformed bitcode object if the symbol table is not required for big archive. 40*c675a9beSpcc## For big archives we print an error instead of a warning because the AIX linker 41*c675a9beSpcc## presumably requires the index. 424cc7c749Szhijian# RUN: rm -rf bad.a 434cc7c749Szhijian# RUN: not llvm-ar --format=bigarchive rcS bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1 444cc7c749Szhijian# RUN: rm -rf bad.a 454cc7c749Szhijian# RUN: not llvm-ar --format=bigarchive rcS bad.a good.bc input.bc 2>&1 | FileCheck %s --check-prefix=ERR1 464cc7c749Szhijian 47bc0725a4SYi Kong# ERR1: error: bad.a: 'input.bc': Invalid bitcode signature 48*c675a9beSpcc# WARN1: warning: 'input.bc': Invalid bitcode signature 49a20168d0SJames Henderson 50a20168d0SJames Henderson## Non-bitcode malformed file. 51a20168d0SJames Henderson# RUN: yaml2obj input.yaml -o input.o 52a20168d0SJames Henderson# RUN: not llvm-ar rc bad.a input.o 2>&1 | FileCheck %s --check-prefix=ERR2 53a20168d0SJames Henderson 54bc0725a4SYi Kong# ERR2: error: bad.a: 'input.o': section header table goes past the end of the file: e_shoff = 0x9999 55a20168d0SJames Henderson 56*c675a9beSpcc## Don't emit an error or warning if the symbol table is not required for formats other than the big archive format. 57*c675a9beSpcc# RUN: llvm-ar --format=gnu rcS good.a input.o input.bc 2>&1 | count 0 58a20168d0SJames Henderson# RUN: llvm-ar t good.a | FileCheck %s --check-prefix=CONTENTS 59a20168d0SJames Henderson 60a20168d0SJames Henderson# CONTENTS: input.o 61a20168d0SJames Henderson# CONTENTS-NEXT: input.bc 62a20168d0SJames Henderson 63*c675a9beSpcc# ARMAP: Archive map 64*c675a9beSpcc# ARMAP-NEXT: foo in good.bc 65*c675a9beSpcc# ARMAP-EMPTY: 66*c675a9beSpcc 67a20168d0SJames Henderson#--- input.ll 68a20168d0SJames Hendersontarget datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 69a20168d0SJames Hendersontarget triple = "x86_64-pc-linux" 70a20168d0SJames Henderson 71*c675a9beSpcc@foo = global i32 1 72*c675a9beSpcc 73a20168d0SJames Henderson#--- input.yaml 74a20168d0SJames Henderson--- !ELF 75a20168d0SJames HendersonFileHeader: 76a20168d0SJames Henderson Class: ELFCLASS64 77a20168d0SJames Henderson Data: ELFDATA2LSB 78a20168d0SJames Henderson Type: ET_REL 79a20168d0SJames Henderson EShOff: 0x9999 80