Index: test/tools/llvm-ar/create.test =================================================================== --- test/tools/llvm-ar/create.test +++ test/tools/llvm-ar/create.test @@ -0,0 +1,16 @@ +# Test the creation warning and supression of that warning. + +RUN: rm -f %t.warning.ar %t.supressed.ar +RUN: touch %t1.txt +RUN: touch %t2.txt + +RUN: llvm-ar r %t.warning.ar %t1.txt %t2.txt 2>&1 \ +RUN: | FileCheck %s --check-prefix=WARNING + +RUN: llvm-ar cr %t.supressed.ar %t1.txt %t2.txt 2>&1 \ +RUN: | FileCheck --allow-empty %s --check-prefix=SUPRESSED + +WARNING: warning: creating {{.*}}warning.ar +WARNING-NOT: {{.}} + +SUPRESSED-NOT: {{.}} Index: test/tools/llvm-ar/dash-before-letter.test =================================================================== --- test/tools/llvm-ar/dash-before-letter.test +++ test/tools/llvm-ar/dash-before-letter.test @@ -0,0 +1,12 @@ +# Test the use of dash before key letters. + +RUN: rm -f %t.ar +RUN: touch %t1.txt +RUN: touch %t2.txt + +RUN: llvm-ar -cr %t.ar %t1.txt +RUN: llvm-ar -r -s %t.ar %t2.txt +RUN: llvm-ar -t %t.ar | FileCheck %s + +CHECK: 1.txt +CHECK-NEXT: 2.txt Index: test/tools/llvm-ar/delete.test =================================================================== --- test/tools/llvm-ar/delete.test +++ test/tools/llvm-ar/delete.test @@ -0,0 +1,67 @@ +## Test the deletion of members and that symbols are removed from the symbol table. + +# RUN: rm -f %t.a +# RUN: yaml2obj %s -o %t-delete.o --docnum=1 +# RUN: yaml2obj %s -o %t-keep.o --docnum=2 +# RUN: touch %t1.txt +# RUN: touch %t2.txt + +## Add file: +# RUN: llvm-ar rc %t.a %t1.txt %t-delete.o %t-keep.o %t2.txt +# RUN: llvm-nm --print-armap %t.a \ +# RUN: | FileCheck %s --check-prefix=SYMBOL-ADDED +# RUN: llvm-ar t %t.a | FileCheck %s --check-prefix=FILE-ADDED + +# SYMBOL-ADDED: symbol1 +# SYMBOL-ADDED-NEXT: symbol2 + +# FILE-ADDED: 1.txt +# FILE-ADDED-NEXT: delete.o +# FILE-ADDED-NEXT: keep.o +# FILE-ADDED-NEXT: 2.txt + +## Delete file that is not a member: +# RUN: cp %t.a %t-archive-copy.a +# RUN: llvm-ar d %t.a t/missing.o +# RUN: cmp %t.a %t-archive-copy.a + +## Delete file: +# RUN: llvm-ar d %t.a %t-delete.o +# RUN: llvm-nm --print-armap %t.a \ +# RUN: | FileCheck %s --check-prefix=SYMBOL-DELETED --implicit-check-not symbol1 +# RUN: llvm-ar t %t.a \ +# RUN: | FileCheck %s --check-prefix=FILE-DELETED --implicit-check-not delete.o + +# SYMBOL-DELETED: symbol2 + +# FILE-DELETED: 1.txt +# FILE-DELETED-NEXT: keep.o +# FILE-DELETED-NEXT: 2.txt + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS +Symbols: + - Name: symbol1 + Binding: STB_GLOBAL + Section: .text + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS +Symbols: + - Name: symbol2 + Binding: STB_GLOBAL + Section: .text Index: test/tools/llvm-ar/extract.test =================================================================== --- test/tools/llvm-ar/extract.test +++ test/tools/llvm-ar/extract.test @@ -0,0 +1,21 @@ +# Test extract operation. +RUN: rm -rf %t && mkdir -p %t/extracted/ + +# Extracting from an empty archive should not warn or error: +RUN: llvm-ar cr %t/empty.a +RUN: llvm-ar x %t/empty.a 2>&1 \ +RUN: | FileCheck --allow-empty %s --implicit-check-not {{.}} + +RUN: echo filea > %t/a.txt +RUN: echo fileb > %t/b.txt +RUN: llvm-ar rc %t/archive.a %t/a.txt %t/b.txt + +# Single member: +RUN: cd %t/extracted && llvm-ar x %t/archive.a a.txt +RUN: diff %t/a.txt %t/extracted/a.txt + +# All members: +RUN: rm %t/extracted/a.txt +RUN: cd %t/extracted && llvm-ar x %t/archive.a +RUN: diff %t/a.txt %t/extracted/a.txt +RUN: diff %t/b.txt %t/extracted/b.txt Index: test/tools/llvm-ar/insert-after.test =================================================================== --- test/tools/llvm-ar/insert-after.test +++ test/tools/llvm-ar/insert-after.test @@ -0,0 +1,55 @@ +# Test inserting files after a file. + +RUN: rm -f %t-* +RUN: touch %t1.txt +RUN: touch %t2.txt +RUN: touch %t3.txt +RUN: touch %t4.txt + +# Insert one file: +RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt +RUN: llvm-ar ra %t1.txt %t-one.a %t3.txt +RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE + +ONE: 1.txt +ONE-NEXT: 3.txt +ONE-NEXT: 2.txt + +# Insert file at back: +RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt +RUN: llvm-ar ra %t2.txt %t-back.a %t3.txt +RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK + +BACK: 1.txt +BACK-NEXT: 2.txt +BACK-NEXT: 3.txt + +# Insert multiple files: +RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt +RUN: llvm-ar ra %t1.txt %t-multiple.a %t3.txt %t4.txt +RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE + +MULTIPLE: 1.txt +MULTIPLE-NEXT: 3.txt +MULTIPLE-NEXT: 4.txt +MULTIPLE-NEXT: 2.txt + +# Insert after invalid file: +RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt +RUN: not llvm-ar ra invalid.txt %t-invalid.a %t2.txt 2>&1 \ +RUN: | FileCheck %s --check-prefix=ERROR +RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID + +ERROR: error: Insertion point not found. +INVALID: 1.txt +INVALID-NEXT: 2.txt +INVALID-NEXT: 3.txt + +# Insert file at the same position: +RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar ra %t1.txt %t-position.a %t2.txt +RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION + +POSITION: 1.txt +POSITION-NEXT: 2.txt +POSITION-NEXT: 3.txt Index: test/tools/llvm-ar/insert-before.test =================================================================== --- test/tools/llvm-ar/insert-before.test +++ test/tools/llvm-ar/insert-before.test @@ -0,0 +1,55 @@ +# Test inserting files before a file. + +RUN: rm -f %t-* +RUN: touch %t1.txt +RUN: touch %t2.txt +RUN: touch %t3.txt +RUN: touch %t4.txt + +# Insert one file: +RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt +RUN: llvm-ar rb %t2.txt %t-one.a %t3.txt +RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE + +ONE: 1.txt +ONE-NEXT: 3.txt +ONE-NEXT: 2.txt + +# Insert file at front: +RUN: llvm-ar rc %t-front.a %t1.txt %t2.txt +RUN: llvm-ar rb %t1.txt %t-front.a %t3.txt +RUN: llvm-ar t %t-front.a | FileCheck %s --check-prefix=FRONT + +FRONT: 3.txt +FRONT-NEXT: 1.txt +FRONT-NEXT: 2.txt + +# Insert multiple files: +RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt +RUN: llvm-ar rb %t2.txt %t-multiple.a %t3.txt %t4.txt +RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE + +MULTIPLE: 1.txt +MULTIPLE-NEXT: 3.txt +MULTIPLE-NEXT: 4.txt +MULTIPLE-NEXT: 2.txt + +# Insert before an invalid file: +RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt +RUN: not llvm-ar rb invalid.txt %t-invalid.a %t2.txt 2>&1 \ +RUN: | FileCheck %s --check-prefix=ERROR +RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID + +ERROR: error: Insertion point not found. +INVALID: 1.txt +INVALID-NEXT: 2.txt +INVALID-NEXT: 3.txt + +# Insert file at the same position: +RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar rb %t3.txt %t-position.a %t2.txt +RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION + +POSITION: 1.txt +POSITION-NEXT: 2.txt +POSITION-NEXT: 3.txt Index: test/tools/llvm-ar/move-after.test =================================================================== --- test/tools/llvm-ar/move-after.test +++ test/tools/llvm-ar/move-after.test @@ -0,0 +1,55 @@ +# Test moving files after a file. + +RUN: rm -f %t-* +RUN: touch %t1.txt +RUN: touch %t2.txt +RUN: touch %t3.txt +RUN: touch %t4.txt + +# Move one file: +RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar ma %t1.txt %t-one.a %t3.txt +RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE + +ONE: 1.txt +ONE-NEXT: 3.txt +ONE-NEXT: 2.txt + +# Move file to back: +RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar ma %t2.txt %t-back.a %t1.txt +RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK + +BACK: 2.txt +BACK-NEXT: 1.txt +BACK-NEXT: 3.txt + +# Move multiple files: +RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt +RUN: llvm-ar ma %t1.txt %t-multiple.a %t3.txt %t4.txt +RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE + +MULTIPLE: 1.txt +MULTIPLE-NEXT: 3.txt +MULTIPLE-NEXT: 4.txt +MULTIPLE-NEXT: 2.txt + +# Move after invalid file: +RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt +RUN: not llvm-ar ma invalid.txt %t-invalid.a %t2.txt 2>&1 \ +RUN: | FileCheck %s --check-prefix=ERROR +RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID + +ERROR: error: Insertion point not found. +INVALID: 1.txt +INVALID-NEXT: 2.txt +INVALID-NEXT: 3.txt + +# Move file to the same position: +RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar ma %t1.txt %t-position.a %t2.txt +RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION + +POSITION: 1.txt +POSITION-NEXT: 2.txt +POSITION-NEXT: 3.txt Index: test/tools/llvm-ar/move-before.test =================================================================== --- test/tools/llvm-ar/move-before.test +++ test/tools/llvm-ar/move-before.test @@ -0,0 +1,64 @@ +# Test moving files after a file. + +RUN: rm -f %t-* +RUN: touch %t1.txt +RUN: touch %t2.txt +RUN: touch %t3.txt +RUN: touch %t4.txt + +# Move one file: +RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar mb %t2.txt %t-one.a %t3.txt +RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE + +ONE: 1.txt +ONE-NEXT: 3.txt +ONE-NEXT: 2.txt + +# Move file to front: +RUN: llvm-ar rc %t-front.ar %t1.txt %t2.txt %t3.txt +RUN: llvm-ar mb %t1.txt %t-front.ar %t3.txt +RUN: llvm-ar t %t-front.ar | FileCheck %s --check-prefix=FRONT + +FRONT: 3.txt +FRONT-NEXT: 1.txt +FRONT-NEXT: 2.txt + +# Move multiple files: +RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt +RUN: llvm-ar mb %t2.txt %t-multiple.a %t3.txt %t4.txt +RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE + +MULTIPLE: 1.txt +MULTIPLE-NEXT: 3.txt +MULTIPLE-NEXT: 4.txt +MULTIPLE-NEXT: 2.txt + +# Move before invalid file: +RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt +RUN: not llvm-ar mb invalid.txt %t-invalid.a %t2.txt 2>&1 \ +RUN: | FileCheck %s --check-prefix=ERROR +RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID + +ERROR: error: Insertion point not found. +INVALID: 1.txt +INVALID-NEXT: 2.txt +INVALID-NEXT: 3.txt + +# Move file to the same position: +RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt +RUN: llvm-ar mb %t3.txt %t-position.a %t2.txt +RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION + +POSITION: 1.txt +POSITION-NEXT: 2.txt +POSITION-NEXT: 3.txt + +# Move file after itself: +RUN: llvm-ar rc %t-same.ar %t1.txt %t2.txt %t3.txt +RUN: llvm-ar mb %t2.txt %t-same.ar %t2.txt +RUN: llvm-ar t %t-same.ar | FileCheck %s --check-prefix=SAME + +SAME: 1.txt +SAME-NEXT: 2.txt +SAME-NEXT: 3.txt Index: test/tools/llvm-ar/preserve-mod-time.test =================================================================== --- test/tools/llvm-ar/preserve-mod-time.test +++ test/tools/llvm-ar/preserve-mod-time.test @@ -0,0 +1,12 @@ +# Test the "o" modifier, preserving the original modification +# times of extracted files. + +RUN: rm -rf %t && mkdir -p %t/extracted/ +RUN: touch %t/a.txt + +RUN: env TZ=GMT touch -t 200001020304 %t/a.txt +RUN: llvm-ar rcU %t/timestamp.a %t/a.txt +RUN: cd %t/extracted && llvm-ar xo %t/timestamp.a +RUN: env TZ=GMT ls %t/extracted --full-time | FileCheck %s + +CHECK: 2000-01-02 03:04 Index: test/tools/llvm-ar/symtab.test =================================================================== --- test/tools/llvm-ar/symtab.test +++ test/tools/llvm-ar/symtab.test @@ -0,0 +1,64 @@ +## Test the s and S modifiers. Build and do not build a symbol table. + +# RUN: rm -f %t-* +# RUN: yaml2obj %s -o %t.o +# RUN: touch %t-other.txt + +## Default: +# RUN: llvm-ar rc %t-default.a %t.o +# RUN: llvm-nm --print-armap %t-default.a \ +# RUN: | FileCheck %s --check-prefix=SYMTAB + +## Use a modifer: +# RUN: llvm-ar rcs %t-symtab.a %t.o +# RUN: llvm-nm --print-armap %t-symtab.a \ +# RUN: | FileCheck %s --check-prefix=SYMTAB + +# RUN: llvm-ar rcS %t-no-symtab.a %t.o +# RUN: llvm-nm --print-armap %t-no-symtab.a \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +## Use both modifers: +# RUN: llvm-ar rcSs %t-symtab-last.a %t.o +# RUN: llvm-nm --print-armap %t-symtab-last.a \ +# RUN: | FileCheck %s --check-prefix=SYMTAB + +# RUN: llvm-ar rcsS %t-no-symtab-last.a %t.o +# RUN: llvm-nm --print-armap %t-no-symtab-last.a \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +## Use an existing archive: +# RUN: llvm-ar rcS %t-to-symtab.a %t.o +# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt +# RUN: llvm-nm --print-armap %t-to-symtab.a \ +# RUN: | FileCheck %s --check-prefix=SYMTAB + +# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt +# RUN: llvm-nm --print-armap %t-to-symtab.a \ +# RUN: | FileCheck %s --check-prefix=SYMTAB + +# RUN: llvm-ar rcs %t-to-no-symtab.a %t.o +# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt +# RUN: llvm-nm --print-armap %t-to-no-symtab.a \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt +# RUN: llvm-nm --print-armap %t-to-no-symtab.a \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +# SYMTAB: symbol in +# NO-SYMTAB-NOT: symbol in + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS +Symbols: + - Name: symbol + Binding: STB_GLOBAL + Section: .text