llvm.org GIT mirror llvm / e3578d8
Reapply [llvm-ar][test] Increase llvm-ar test coverage This reapplies 365316 without extract.test due to failing on Darwin. Differential Revision: https://reviews.llvm.org/D63935 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366206 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Reynolds 2 months ago
9 changed file(s) with 413 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
0 ## Test the creation warning and supression of that warning.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4
5 RUN: rm -f %t.warning.ar
6 RUN: llvm-ar r %t.warning.ar %t1.txt %t2.txt 2>&1 \
7 RUN: | FileCheck %s -DOUTPUT=%t.warning.ar
8
9 CHECK: warning: creating [[OUTPUT]]
10
11 RUN: rm -f %t.supressed.ar
12 RUN: llvm-ar cr %t.supressed.ar %t1.txt %t2.txt 2>&1 \
13 RUN: | FileCheck --allow-empty /dev/null --implicit-check-not={{.}}
0 # Test the use of dash before key letters.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4
5 RUN: rm -f %t.ar
6 RUN: llvm-ar s -cr %t.ar %t1.txt
7 RUN: llvm-ar -r -s %t.ar %t2.txt -s
8 RUN: llvm-ar -t %t.ar | FileCheck %s
9
10 CHECK: 1.txt
11 CHECK-NEXT: 2.txt
0 RUN: yaml2obj %S/Inputs/macho.yaml -o %t-macho.o
11 RUN: yaml2obj %S/Inputs/coff.yaml -o %t-coff.o
2 RUN: yaml2obj %S/Inputs/elf.yaml -o %t-elf.o
23
34 RUN: rm -f %t.ar
45 RUN: llvm-ar crs %t.ar %t-macho.o
5 RUN: grep -q __.SYMDEF %t.ar
6 Test that an option string prefixed by a dash works.
7 RUN: llvm-ar -crs %t.ar %t-coff.o
86 RUN: grep -q __.SYMDEF %t.ar
97
108 RUN: rm -f %t.ar
1210 RUN: not grep -q __.SYMDEF %t.ar
1311 RUN: llvm-ar crs %t.ar %t-macho.o
1412 RUN: not grep -q __.SYMDEF %t.ar
15
16 RUN: rm -f %t.ar
17 Test that multiple dashed options works.
18 RUN: llvm-ar -c -r -s %t.ar %t-macho.o
19 RUN: grep -q __.SYMDEF %t.ar
20 Test with duplicated options.
21 RUN: llvm-ar -c -r -s -c -s %t.ar %t-coff.o
22 RUN: grep -q __.SYMDEF %t.ar
13 RUN: llvm-ar crs %t.ar %t-elf.o
14 RUN: not grep -q __.SYMDEF %t.ar
2315
2416 RUN: rm -f %t.ar
2517 Test with the options in a different order.
2618 RUN: llvm-ar rsc %t.ar %t-macho.o
27 RUN: grep -q __.SYMDEF %t.ar
28 Test with options everywhere.
29 RUN: llvm-ar rsc -cs -sc %t.ar %t-coff.o -cs -sc
30 RUN: grep -q __.SYMDEF %t.ar
31
32 Ensure that we select the existing format when updating.
33
19 RUN: grep -q __.SYMDEF %t.ar
0 ## Test the deletion of members and that symbols are removed from the symbol table.
1
2 # RUN: yaml2obj %s -o %t-delete.o --docnum=1
3 # RUN: yaml2obj %s -o %t-keep.o --docnum=2
4 # RUN: touch %t1.txt
5 # RUN: touch %t2.txt
6
7 ## Add file:
8 # RUN: rm -f %t.a
9 # RUN: llvm-ar rc %t.a %t1.txt %t-delete.o %t-keep.o %t2.txt
10 # RUN: llvm-nm --print-armap %t.a \
11 # RUN: | FileCheck %s --check-prefix=SYMBOL-ADDED
12 # RUN: llvm-ar t %t.a | FileCheck %s --check-prefix=FILE-ADDED
13
14 # SYMBOL-ADDED: symbol1
15 # SYMBOL-ADDED-NEXT: symbol2
16
17 # FILE-ADDED: 1.txt
18 # FILE-ADDED-NEXT: delete.o
19 # FILE-ADDED-NEXT: keep.o
20 # FILE-ADDED-NEXT: 2.txt
21
22 ## Delete file that is not a member:
23 # RUN: cp %t.a %t-archive-copy.a
24 # RUN: llvm-ar d %t.a t/missing.o
25 # RUN: cmp %t.a %t-archive-copy.a
26
27 ## Delete file:
28 # RUN: llvm-ar d %t.a %t-delete.o
29 # RUN: llvm-nm --print-armap %t.a \
30 # RUN: | FileCheck %s --check-prefix=SYMBOL-DELETED --implicit-check-not symbol1
31 # RUN: llvm-ar t %t.a \
32 # RUN: | FileCheck %s --check-prefix=FILE-DELETED --implicit-check-not delete.o
33
34 # SYMBOL-DELETED: symbol2
35
36 # FILE-DELETED: 1.txt
37 # FILE-DELETED-NEXT: keep.o
38 # FILE-DELETED-NEXT: 2.txt
39
40 --- !ELF
41 FileHeader:
42 Class: ELFCLASS64
43 Data: ELFDATA2LSB
44 Type: ET_REL
45 Machine: EM_X86_64
46 Sections:
47 - Name: .text
48 Type: SHT_PROGBITS
49 Symbols:
50 - Name: symbol1
51 Binding: STB_GLOBAL
52 Section: .text
53
54 --- !ELF
55 FileHeader:
56 Class: ELFCLASS64
57 Data: ELFDATA2LSB
58 Type: ET_REL
59 Machine: EM_X86_64
60 Sections:
61 - Name: .text
62 Type: SHT_PROGBITS
63 Symbols:
64 - Name: symbol2
65 Binding: STB_GLOBAL
66 Section: .text
0 ## Test inserting files after a file.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4 RUN: touch %t3.txt
5 RUN: touch %t4.txt
6
7 # Insert one file:
8 RUN: rm -f %t-one.a
9 RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt
10 RUN: llvm-ar ra %t1.txt %t-one.a %t3.txt
11 RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
12
13 ONE: 1.txt
14 ONE-NEXT: 3.txt
15 ONE-NEXT: 2.txt
16
17 # Insert file at back:
18 RUN: rm -f %t-back.a
19 RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt
20 RUN: llvm-ar ra %t2.txt %t-back.a %t3.txt
21 RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK
22
23 BACK: 1.txt
24 BACK-NEXT: 2.txt
25 BACK-NEXT: 3.txt
26
27 # Insert multiple files:
28 RUN: rm -f %t-multiple.a
29 RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt
30 RUN: llvm-ar ra %t1.txt %t-multiple.a %t4.txt %t3.txt
31 RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
32
33 MULTIPLE: 1.txt
34 MULTIPLE-NEXT: 4.txt
35 MULTIPLE-NEXT: 3.txt
36 MULTIPLE-NEXT: 2.txt
37
38 # Insert after invalid file:
39 RUN: rm -f %t-invalid.a
40 RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
41 RUN: not llvm-ar ra invalid.txt %t-invalid.a %t2.txt 2>&1 \
42 RUN: | FileCheck %s --check-prefix=ERROR
43 RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
44
45 ERROR: error: Insertion point not found.
46 INVALID: 1.txt
47 INVALID-NEXT: 2.txt
48 INVALID-NEXT: 3.txt
49
50 # Insert file at the same position:
51 RUN: rm -f %t-position.a
52 RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
53 RUN: llvm-ar ra %t1.txt %t-position.a %t2.txt
54 RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
55
56 POSITION: 1.txt
57 POSITION-NEXT: 2.txt
58 POSITION-NEXT: 3.txt
0 ## Test inserting files before a file.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4 RUN: touch %t3.txt
5 RUN: touch %t4.txt
6
7 # Insert one file:
8 RUN: rm -f %t-one.a
9 RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt
10 RUN: llvm-ar rb %t2.txt %t-one.a %t3.txt
11 RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
12
13 ONE: 1.txt
14 ONE-NEXT: 3.txt
15 ONE-NEXT: 2.txt
16
17 # Insert file at front:
18 RUN: rm -f %t-front.a
19 RUN: llvm-ar rc %t-front.a %t1.txt %t2.txt
20 RUN: llvm-ar rb %t1.txt %t-front.a %t3.txt
21 RUN: llvm-ar t %t-front.a | FileCheck %s --check-prefix=FRONT
22
23 FRONT: 3.txt
24 FRONT-NEXT: 1.txt
25 FRONT-NEXT: 2.txt
26
27 # Insert multiple files:
28 RUN: rm -f %t-multiple.a
29 RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt
30 RUN: llvm-ar rb %t2.txt %t-multiple.a %t4.txt %t3.txt
31 RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
32
33 MULTIPLE: 1.txt
34 MULTIPLE-NEXT: 4.txt
35 MULTIPLE-NEXT: 3.txt
36 MULTIPLE-NEXT: 2.txt
37
38 # Insert before an invalid file:
39 RUN: rm -f %t-invalid.a
40 RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
41 RUN: not llvm-ar rb invalid.txt %t-invalid.a %t2.txt 2>&1 \
42 RUN: | FileCheck %s --check-prefix=ERROR
43 RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
44
45 ERROR: error: Insertion point not found.
46 INVALID: 1.txt
47 INVALID-NEXT: 2.txt
48 INVALID-NEXT: 3.txt
49
50 # Insert file at the same position:
51 RUN: rm -f %t-position.a
52 RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
53 RUN: llvm-ar rb %t3.txt %t-position.a %t2.txt
54 RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
55
56 POSITION: 1.txt
57 POSITION-NEXT: 2.txt
58 POSITION-NEXT: 3.txt
0 ## Test moving files after a file.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4 RUN: touch %t3.txt
5 RUN: touch %t4.txt
6
7 # Move one file:
8 RUN: rm -f %t-one.ar
9 RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt
10 RUN: llvm-ar ma %t1.txt %t-one.a %t3.txt
11 RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
12
13 ONE: 1.txt
14 ONE-NEXT: 3.txt
15 ONE-NEXT: 2.txt
16
17 # Move file to back:
18 RUN: rm -f %t-back.ar
19 RUN: llvm-ar rc %t-back.a %t1.txt %t2.txt %t3.txt
20 RUN: llvm-ar ma %t2.txt %t-back.a %t1.txt
21 RUN: llvm-ar t %t-back.a | FileCheck %s --check-prefix=BACK
22
23 BACK: 2.txt
24 BACK-NEXT: 1.txt
25 BACK-NEXT: 3.txt
26
27 # Move multiple files:
28 RUN: rm -f %t-multiple.ar
29 RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt
30 RUN: llvm-ar ma %t1.txt %t-multiple.a %t4.txt %t3.txt
31 RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
32
33 MULTIPLE: 1.txt
34 MULTIPLE-NEXT: 3.txt
35 MULTIPLE-NEXT: 4.txt
36 MULTIPLE-NEXT: 2.txt
37
38 # Move after invalid file:
39 RUN: rm -f %t-invalid.ar
40 RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
41 RUN: not llvm-ar ma invalid.txt %t-invalid.a %t2.txt 2>&1 \
42 RUN: | FileCheck %s --check-prefix=ERROR
43 RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
44
45 ERROR: error: Insertion point not found.
46 INVALID: 1.txt
47 INVALID-NEXT: 2.txt
48 INVALID-NEXT: 3.txt
49
50 # Move file to the same position:
51 RUN: rm -f %t-position.ar
52 RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
53 RUN: llvm-ar ma %t1.txt %t-position.a %t2.txt
54 RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
55
56 POSITION: 1.txt
57 POSITION-NEXT: 2.txt
58 POSITION-NEXT: 3.txt
0 ## Test moving files after a file.
1
2 RUN: touch %t1.txt
3 RUN: touch %t2.txt
4 RUN: touch %t3.txt
5 RUN: touch %t4.txt
6
7 # Move one file:
8 RUN: rm -f %t-one.ar
9 RUN: llvm-ar rc %t-one.a %t1.txt %t2.txt %t3.txt
10 RUN: llvm-ar mb %t2.txt %t-one.a %t3.txt
11 RUN: llvm-ar t %t-one.a | FileCheck %s --check-prefix=ONE
12
13 ONE: 1.txt
14 ONE-NEXT: 3.txt
15 ONE-NEXT: 2.txt
16
17 # Move file to front:
18 RUN: rm -f %t-front.ar
19 RUN: llvm-ar rc %t-front.ar %t1.txt %t2.txt %t3.txt
20 RUN: llvm-ar mb %t1.txt %t-front.ar %t3.txt
21 RUN: llvm-ar t %t-front.ar | FileCheck %s --check-prefix=FRONT
22
23 FRONT: 3.txt
24 FRONT-NEXT: 1.txt
25 FRONT-NEXT: 2.txt
26
27 # Move multiple files:
28 RUN: rm -f %t-multiple.ar
29 RUN: llvm-ar rc %t-multiple.a %t1.txt %t2.txt %t3.txt %t4.txt
30 RUN: llvm-ar mb %t2.txt %t-multiple.a %t4.txt %t3.txt
31 RUN: llvm-ar t %t-multiple.a | FileCheck %s --check-prefix=MULTIPLE
32
33 MULTIPLE: 1.txt
34 MULTIPLE-NEXT: 3.txt
35 MULTIPLE-NEXT: 4.txt
36 MULTIPLE-NEXT: 2.txt
37
38 # Move before invalid file:
39 RUN: rm -f %t-invalid.ar
40 RUN: llvm-ar rc %t-invalid.a %t1.txt %t2.txt %t3.txt
41 RUN: not llvm-ar mb invalid.txt %t-invalid.a %t2.txt 2>&1 \
42 RUN: | FileCheck %s --check-prefix=ERROR
43 RUN: llvm-ar t %t-invalid.a | FileCheck %s --check-prefix=INVALID
44
45 ERROR: error: Insertion point not found.
46 INVALID: 1.txt
47 INVALID-NEXT: 2.txt
48 INVALID-NEXT: 3.txt
49
50 # Move file to the same position:
51 RUN: rm -f %t-position.ar
52 RUN: llvm-ar rc %t-position.a %t1.txt %t2.txt %t3.txt
53 RUN: llvm-ar mb %t3.txt %t-position.a %t2.txt
54 RUN: llvm-ar t %t-position.a | FileCheck %s --check-prefix=POSITION
55
56 POSITION: 1.txt
57 POSITION-NEXT: 2.txt
58 POSITION-NEXT: 3.txt
59
60 # Move file after itself:
61 RUN: rm -f %t-same.ar
62 RUN: llvm-ar rc %t-same.ar %t1.txt %t2.txt %t3.txt
63 RUN: llvm-ar mb %t2.txt %t-same.ar %t2.txt
64 RUN: llvm-ar t %t-same.ar | FileCheck %s --check-prefix=SAME
65
66 SAME: 1.txt
67 SAME-NEXT: 2.txt
68 SAME-NEXT: 3.txt
0 ## Test the s and S modifiers. Build and do not build a symbol table.
1
2 # RUN: yaml2obj %s -o %t.o
3 # RUN: touch %t-other.txt
4
5 ## Default:
6 # RUN: rm -f %t-default.a
7 # RUN: llvm-ar rc %t-default.a %t.o
8 # RUN: llvm-nm --print-armap %t-default.a \
9 # RUN: | FileCheck %s --check-prefix=SYMTAB
10
11 ## Use a modifer:
12 # RUN: rm -f %t-symtab.a
13 # RUN: llvm-ar rcs %t-symtab.a %t.o
14 # RUN: llvm-nm --print-armap %t-symtab.a \
15 # RUN: | FileCheck %s --check-prefix=SYMTAB
16
17 # RUN: rm -f %t-no-symtab.a
18 # RUN: llvm-ar rcS %t-no-symtab.a %t.o
19 # RUN: llvm-nm --print-armap %t-no-symtab.a \
20 # RUN: | FileCheck %s --check-prefix=NO-SYMTAB
21
22 ## Use both modifers:
23 # RUN: rm -f %t-symtab-last.a
24 # RUN: llvm-ar rcSs %t-symtab-last.a %t.o
25 # RUN: llvm-nm --print-armap %t-symtab-last.a \
26 # RUN: | FileCheck %s --check-prefix=SYMTAB
27
28 # RUN: rm -f %t-no-symtab-last.a
29 # RUN: llvm-ar rcsS %t-no-symtab-last.a %t.o
30 # RUN: llvm-nm --print-armap %t-no-symtab-last.a \
31 # RUN: | FileCheck %s --check-prefix=NO-SYMTAB
32
33 ## Use an existing archive:
34 # RUN: rm -f %t-to-symtab.a
35 # RUN: llvm-ar rcS %t-to-symtab.a %t.o
36 # RUN: llvm-ar rs %t-to-symtab.a %t-other.txt
37 # RUN: llvm-nm --print-armap %t-to-symtab.a \
38 # RUN: | FileCheck %s --check-prefix=SYMTAB
39
40 # RUN: llvm-ar rs %t-to-symtab.a %t-other.txt
41 # RUN: llvm-nm --print-armap %t-to-symtab.a \
42 # RUN: | FileCheck %s --check-prefix=SYMTAB
43
44 # RUN: rm -f %t-to-no-symtab.a
45 # RUN: llvm-ar rcs %t-to-no-symtab.a %t.o
46 # RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt
47 # RUN: llvm-nm --print-armap %t-to-no-symtab.a \
48 # RUN: | FileCheck %s --check-prefix=NO-SYMTAB
49
50 # RUN: llvm-ar rS %t-to-no-symtab.a %t-other.txt
51 # RUN: llvm-nm --print-armap %t-to-no-symtab.a \
52 # RUN: | FileCheck %s --check-prefix=NO-SYMTAB
53
54 # SYMTAB: symbol in
55 # NO-SYMTAB-NOT: symbol in
56
57 --- !ELF
58 FileHeader:
59 Class: ELFCLASS64
60 Data: ELFDATA2LSB
61 Type: ET_REL
62 Machine: EM_X86_64
63 Sections:
64 - Name: .text
65 Type: SHT_PROGBITS
66 Symbols:
67 - Name: symbol
68 Binding: STB_GLOBAL
69 Section: .text