--- /dev/null
+## Test the creation warning and supression of that warning.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+\r
+RUN: rm -f %t.warning.ar\r
+RUN: llvm-ar r %t.warning.ar %t1.txt %t2.txt 2>&1 \\r
+RUN: | FileCheck %s -DOUTPUT=%t.warning.ar\r
+\r
+CHECK: warning: creating [[OUTPUT]]\r
+\r
+RUN: rm -f %t.supressed.ar\r
+RUN: llvm-ar cr %t.supressed.ar %t1.txt %t2.txt 2>&1 \\r
+RUN: | FileCheck --allow-empty /dev/null --implicit-check-not={{.}}\r
--- /dev/null
+# Test the use of dash before key letters.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+\r
+RUN: rm -f %t.ar\r
+RUN: llvm-ar s -cr %t.ar %t1.txt\r
+RUN: llvm-ar -r -s %t.ar %t2.txt -s\r
+RUN: llvm-ar -t %t.ar | FileCheck %s\r
+\r
+CHECK: 1.txt\r
+CHECK-NEXT: 2.txt\r
RUN: yaml2obj %S/Inputs/macho.yaml -o %t-macho.o
RUN: yaml2obj %S/Inputs/coff.yaml -o %t-coff.o
+RUN: yaml2obj %S/Inputs/elf.yaml -o %t-elf.o
RUN: rm -f %t.ar
RUN: llvm-ar crs %t.ar %t-macho.o
RUN: grep -q __.SYMDEF %t.ar
-Test that an option string prefixed by a dash works.
-RUN: llvm-ar -crs %t.ar %t-coff.o
-RUN: grep -q __.SYMDEF %t.ar
RUN: rm -f %t.ar
RUN: llvm-ar crs %t.ar %t-coff.o
RUN: not grep -q __.SYMDEF %t.ar
RUN: llvm-ar crs %t.ar %t-macho.o
RUN: not grep -q __.SYMDEF %t.ar
-
-RUN: rm -f %t.ar
-Test that multiple dashed options works.
-RUN: llvm-ar -c -r -s %t.ar %t-macho.o
-RUN: grep -q __.SYMDEF %t.ar
-Test with duplicated options.
-RUN: llvm-ar -c -r -s -c -s %t.ar %t-coff.o
-RUN: grep -q __.SYMDEF %t.ar
+RUN: llvm-ar crs %t.ar %t-elf.o
+RUN: not grep -q __.SYMDEF %t.ar
RUN: rm -f %t.ar
Test with the options in a different order.
RUN: llvm-ar rsc %t.ar %t-macho.o
-RUN: grep -q __.SYMDEF %t.ar
-Test with options everywhere.
-RUN: llvm-ar rsc -cs -sc %t.ar %t-coff.o -cs -sc
-RUN: grep -q __.SYMDEF %t.ar
-
-Ensure that we select the existing format when updating.
-
+RUN: grep -q __.SYMDEF %t.ar
\ No newline at end of file
--- /dev/null
+## Test the deletion of members and that symbols are removed from the symbol table.\r
+\r
+# RUN: yaml2obj %s -o %t-delete.o --docnum=1\r
+# RUN: yaml2obj %s -o %t-keep.o --docnum=2\r
+# RUN: touch %t1.txt\r
+# RUN: touch %t2.txt\r
+\r
+## Add file:\r
+# RUN: rm -f %t.a\r
+# RUN: llvm-ar rc %t.a %t1.txt %t-delete.o %t-keep.o %t2.txt\r
+# RUN: llvm-nm --print-armap %t.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMBOL-ADDED\r
+# RUN: llvm-ar t %t.a | FileCheck %s --check-prefix=FILE-ADDED\r
+\r
+# SYMBOL-ADDED: symbol1\r
+# SYMBOL-ADDED-NEXT: symbol2\r
+\r
+# FILE-ADDED: 1.txt\r
+# FILE-ADDED-NEXT: delete.o\r
+# FILE-ADDED-NEXT: keep.o\r
+# FILE-ADDED-NEXT: 2.txt\r
+\r
+## Delete file that is not a member:\r
+# RUN: cp %t.a %t-archive-copy.a\r
+# RUN: llvm-ar d %t.a t/missing.o\r
+# RUN: cmp %t.a %t-archive-copy.a\r
+\r
+## Delete file:\r
+# RUN: llvm-ar d %t.a %t-delete.o\r
+# RUN: llvm-nm --print-armap %t.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMBOL-DELETED --implicit-check-not symbol1\r
+# RUN: llvm-ar t %t.a \\r
+# RUN: | FileCheck %s --check-prefix=FILE-DELETED --implicit-check-not delete.o\r
+\r
+# SYMBOL-DELETED: symbol2\r
+\r
+# FILE-DELETED: 1.txt\r
+# FILE-DELETED-NEXT: keep.o\r
+# FILE-DELETED-NEXT: 2.txt\r
+\r
+--- !ELF\r
+FileHeader:\r
+ Class: ELFCLASS64\r
+ Data: ELFDATA2LSB\r
+ Type: ET_REL\r
+ Machine: EM_X86_64\r
+Sections:\r
+ - Name: .text\r
+ Type: SHT_PROGBITS\r
+Symbols:\r
+ - Name: symbol1\r
+ Binding: STB_GLOBAL\r
+ Section: .text\r
+\r
+--- !ELF\r
+FileHeader:\r
+ Class: ELFCLASS64\r
+ Data: ELFDATA2LSB\r
+ Type: ET_REL\r
+ Machine: EM_X86_64\r
+Sections:\r
+ - Name: .text\r
+ Type: SHT_PROGBITS\r
+Symbols:\r
+ - Name: symbol2\r
+ Binding: STB_GLOBAL\r
+ Section: .text\r
--- /dev/null
+## Test inserting files after a file.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+RUN: touch %t3.txt\r
+RUN: touch %t4.txt\r
+\r
+# Insert one file:\r
+RUN: rm -f %t-one.a\r
+RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt\r
+RUN: llvm-ar ra %t1.txt %t-one.a %t3.txt\r
+RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE\r
+\r
+ONE: 1.txt\r
+ONE-NEXT: 3.txt\r
+ONE-NEXT: 2.txt\r
+\r
+# Insert file at back:\r
+RUN: rm -f %t-back.a\r
+RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt\r
+RUN: llvm-ar ra %t2.txt %t-back.a %t3.txt\r
+RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK\r
+\r
+BACK: 1.txt\r
+BACK-NEXT: 2.txt\r
+BACK-NEXT: 3.txt\r
+\r
+# Insert multiple files:\r
+RUN: rm -f %t-multiple.a\r
+RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt\r
+RUN: llvm-ar ra %t1.txt %t-multiple.a %t4.txt %t3.txt\r
+RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE\r
+\r
+MULTIPLE: 1.txt\r
+MULTIPLE-NEXT: 4.txt\r
+MULTIPLE-NEXT: 3.txt\r
+MULTIPLE-NEXT: 2.txt\r
+\r
+# Insert after invalid file:\r
+RUN: rm -f %t-invalid.a\r
+RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt\r
+RUN: not llvm-ar ra invalid.txt %t-invalid.a %t2.txt 2>&1 \\r
+RUN: | FileCheck %s --check-prefix=ERROR\r
+RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID\r
+\r
+ERROR: error: Insertion point not found.\r
+INVALID: 1.txt\r
+INVALID-NEXT: 2.txt\r
+INVALID-NEXT: 3.txt\r
+\r
+# Insert file at the same position:\r
+RUN: rm -f %t-position.a\r
+RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar ra %t1.txt %t-position.a %t2.txt\r
+RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION\r
+\r
+POSITION: 1.txt\r
+POSITION-NEXT: 2.txt\r
+POSITION-NEXT: 3.txt\r
--- /dev/null
+## Test inserting files before a file.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+RUN: touch %t3.txt\r
+RUN: touch %t4.txt\r
+\r
+# Insert one file:\r
+RUN: rm -f %t-one.a\r
+RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt\r
+RUN: llvm-ar rb %t2.txt %t-one.a %t3.txt\r
+RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE\r
+\r
+ONE: 1.txt\r
+ONE-NEXT: 3.txt\r
+ONE-NEXT: 2.txt\r
+\r
+# Insert file at front:\r
+RUN: rm -f %t-front.a\r
+RUN: llvm-ar rc %t-front.a %t1.txt %t2.txt\r
+RUN: llvm-ar rb %t1.txt %t-front.a %t3.txt\r
+RUN: llvm-ar t %t-front.a | FileCheck %s --check-prefix=FRONT\r
+\r
+FRONT: 3.txt\r
+FRONT-NEXT: 1.txt\r
+FRONT-NEXT: 2.txt\r
+\r
+# Insert multiple files:\r
+RUN: rm -f %t-multiple.a\r
+RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt\r
+RUN: llvm-ar rb %t2.txt %t-multiple.a %t4.txt %t3.txt\r
+RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE\r
+\r
+MULTIPLE: 1.txt\r
+MULTIPLE-NEXT: 4.txt\r
+MULTIPLE-NEXT: 3.txt\r
+MULTIPLE-NEXT: 2.txt\r
+\r
+# Insert before an invalid file:\r
+RUN: rm -f %t-invalid.a\r
+RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt\r
+RUN: not llvm-ar rb invalid.txt %t-invalid.a %t2.txt 2>&1 \\r
+RUN: | FileCheck %s --check-prefix=ERROR\r
+RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID\r
+\r
+ERROR: error: Insertion point not found.\r
+INVALID: 1.txt\r
+INVALID-NEXT: 2.txt\r
+INVALID-NEXT: 3.txt\r
+\r
+# Insert file at the same position:\r
+RUN: rm -f %t-position.a\r
+RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar rb %t3.txt %t-position.a %t2.txt\r
+RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION\r
+\r
+POSITION: 1.txt\r
+POSITION-NEXT: 2.txt\r
+POSITION-NEXT: 3.txt\r
--- /dev/null
+## Test moving files after a file.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+RUN: touch %t3.txt\r
+RUN: touch %t4.txt\r
+\r
+# Move one file:\r
+RUN: rm -f %t-one.ar\r
+RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar ma %t1.txt %t-one.a %t3.txt\r
+RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE\r
+\r
+ONE: 1.txt\r
+ONE-NEXT: 3.txt\r
+ONE-NEXT: 2.txt\r
+\r
+# Move file to back:\r
+RUN: rm -f %t-back.ar\r
+RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar ma %t2.txt %t-back.a %t1.txt\r
+RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK\r
+\r
+BACK: 2.txt\r
+BACK-NEXT: 1.txt\r
+BACK-NEXT: 3.txt\r
+\r
+# Move multiple files:\r
+RUN: rm -f %t-multiple.ar\r
+RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt\r
+RUN: llvm-ar ma %t1.txt %t-multiple.a %t4.txt %t3.txt\r
+RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE\r
+\r
+MULTIPLE: 1.txt\r
+MULTIPLE-NEXT: 3.txt\r
+MULTIPLE-NEXT: 4.txt\r
+MULTIPLE-NEXT: 2.txt\r
+\r
+# Move after invalid file:\r
+RUN: rm -f %t-invalid.ar\r
+RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt\r
+RUN: not llvm-ar ma invalid.txt %t-invalid.a %t2.txt 2>&1 \\r
+RUN: | FileCheck %s --check-prefix=ERROR\r
+RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID\r
+\r
+ERROR: error: Insertion point not found.\r
+INVALID: 1.txt\r
+INVALID-NEXT: 2.txt\r
+INVALID-NEXT: 3.txt\r
+\r
+# Move file to the same position:\r
+RUN: rm -f %t-position.ar\r
+RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar ma %t1.txt %t-position.a %t2.txt\r
+RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION\r
+\r
+POSITION: 1.txt\r
+POSITION-NEXT: 2.txt\r
+POSITION-NEXT: 3.txt\r
--- /dev/null
+## Test moving files after a file.\r
+\r
+RUN: touch %t1.txt\r
+RUN: touch %t2.txt\r
+RUN: touch %t3.txt\r
+RUN: touch %t4.txt\r
+\r
+# Move one file:\r
+RUN: rm -f %t-one.ar\r
+RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar mb %t2.txt %t-one.a %t3.txt\r
+RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE\r
+\r
+ONE: 1.txt\r
+ONE-NEXT: 3.txt\r
+ONE-NEXT: 2.txt\r
+\r
+# Move file to front:\r
+RUN: rm -f %t-front.ar\r
+RUN: llvm-ar rc %t-front.ar %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar mb %t1.txt %t-front.ar %t3.txt\r
+RUN: llvm-ar t %t-front.ar | FileCheck %s --check-prefix=FRONT\r
+\r
+FRONT: 3.txt\r
+FRONT-NEXT: 1.txt\r
+FRONT-NEXT: 2.txt\r
+\r
+# Move multiple files:\r
+RUN: rm -f %t-multiple.ar\r
+RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt\r
+RUN: llvm-ar mb %t2.txt %t-multiple.a %t4.txt %t3.txt\r
+RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE\r
+\r
+MULTIPLE: 1.txt\r
+MULTIPLE-NEXT: 3.txt\r
+MULTIPLE-NEXT: 4.txt\r
+MULTIPLE-NEXT: 2.txt\r
+\r
+# Move before invalid file:\r
+RUN: rm -f %t-invalid.ar\r
+RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt\r
+RUN: not llvm-ar mb invalid.txt %t-invalid.a %t2.txt 2>&1 \\r
+RUN: | FileCheck %s --check-prefix=ERROR\r
+RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID\r
+\r
+ERROR: error: Insertion point not found.\r
+INVALID: 1.txt\r
+INVALID-NEXT: 2.txt\r
+INVALID-NEXT: 3.txt\r
+\r
+# Move file to the same position:\r
+RUN: rm -f %t-position.ar\r
+RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar mb %t3.txt %t-position.a %t2.txt\r
+RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION\r
+\r
+POSITION: 1.txt\r
+POSITION-NEXT: 2.txt\r
+POSITION-NEXT: 3.txt\r
+\r
+# Move file after itself:\r
+RUN: rm -f %t-same.ar\r
+RUN: llvm-ar rc %t-same.ar %t1.txt %t2.txt %t3.txt\r
+RUN: llvm-ar mb %t2.txt %t-same.ar %t2.txt\r
+RUN: llvm-ar t %t-same.ar | FileCheck %s --check-prefix=SAME\r
+\r
+SAME: 1.txt\r
+SAME-NEXT: 2.txt\r
+SAME-NEXT: 3.txt\r
--- /dev/null
+## Test the s and S modifiers. Build and do not build a symbol table.\r
+\r
+# RUN: yaml2obj %s -o %t.o\r
+# RUN: touch %t-other.txt\r
+\r
+## Default:\r
+# RUN: rm -f %t-default.a\r
+# RUN: llvm-ar rc %t-default.a %t.o\r
+# RUN: llvm-nm --print-armap %t-default.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMTAB\r
+\r
+## Use a modifer:\r
+# RUN: rm -f %t-symtab.a\r
+# RUN: llvm-ar rcs %t-symtab.a %t.o\r
+# RUN: llvm-nm --print-armap %t-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMTAB\r
+\r
+# RUN: rm -f %t-no-symtab.a\r
+# RUN: llvm-ar rcS %t-no-symtab.a %t.o\r
+# RUN: llvm-nm --print-armap %t-no-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=NO-SYMTAB\r
+\r
+## Use both modifers:\r
+# RUN: rm -f %t-symtab-last.a\r
+# RUN: llvm-ar rcSs %t-symtab-last.a %t.o\r
+# RUN: llvm-nm --print-armap %t-symtab-last.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMTAB\r
+\r
+# RUN: rm -f %t-no-symtab-last.a\r
+# RUN: llvm-ar rcsS %t-no-symtab-last.a %t.o\r
+# RUN: llvm-nm --print-armap %t-no-symtab-last.a \\r
+# RUN: | FileCheck %s --check-prefix=NO-SYMTAB\r
+\r
+## Use an existing archive:\r
+# RUN: rm -f %t-to-symtab.a\r
+# RUN: llvm-ar rcS %t-to-symtab.a %t.o\r
+# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt\r
+# RUN: llvm-nm --print-armap %t-to-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMTAB\r
+\r
+# RUN: llvm-ar rs %t-to-symtab.a %t-other.txt\r
+# RUN: llvm-nm --print-armap %t-to-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=SYMTAB\r
+\r
+# RUN: rm -f %t-to-no-symtab.a\r
+# RUN: llvm-ar rcs %t-to-no-symtab.a %t.o\r
+# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt\r
+# RUN: llvm-nm --print-armap %t-to-no-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=NO-SYMTAB\r
+\r
+# RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt\r
+# RUN: llvm-nm --print-armap %t-to-no-symtab.a \\r
+# RUN: | FileCheck %s --check-prefix=NO-SYMTAB\r
+\r
+# SYMTAB: symbol in\r
+# NO-SYMTAB-NOT: symbol in\r
+\r
+--- !ELF\r
+FileHeader:\r
+ Class: ELFCLASS64\r
+ Data: ELFDATA2LSB\r
+ Type: ET_REL\r
+ Machine: EM_X86_64\r
+Sections:\r
+ - Name: .text\r
+ Type: SHT_PROGBITS\r
+Symbols:\r
+ - Name: symbol\r
+ Binding: STB_GLOBAL\r
+ Section: .text\r