xref: /llvm-project/llvm/test/tools/llvm-ar/mri-addlib.test (revision 7de277d684fdbb12f5bfa761efe7dbbed681137d)
1## Test the ADDLIB MRI command.
2
3# RUN: rm -rf %t && split-file %s %t
4# RUN: cd %t
5# RUN: yaml2obj %s -o f.o
6# RUN: llvm-ar r f.a f.o
7
8## Merge contents of archives.
9# RUN: llvm-ar -M < add-lib.mri
10# RUN: llvm-nm --print-armap add-lib.a | FileCheck --check-prefix=SYMS %s
11# RUN: llvm-ar t add-lib.a | FileCheck --check-prefix=FILES %s
12
13# SYMS: f in {{.*}}
14# FILES: f.o
15
16## ADDLIB with non-archive file.
17# RUN: not llvm-ar -M < bad-lib.mri 2>&1 | FileCheck --check-prefix=PARSE %s
18# RUN: not ls bad-lib.a
19
20# PARSE: error: script line 2: could not parse library
21
22## No create command.
23# RUN: not llvm-ar -M < no-create.mri 2>&1 | FileCheck --check-prefix=NOCREATE %s
24
25# NOCREATE: error: script line 1: no output archive has been opened
26
27## ADDLIB with missing file.
28# RUN: not llvm-ar -M < missing.mri 2>&1 | FileCheck -DMSG=%errc_ENOENT %s --check-prefix=MISSING
29# RUN: not ls missing.a
30
31# MISSING: error: script line 2: could not open library missing-lib.a: [[MSG]]
32
33## ADD same lib twice.
34# RUN: llvm-ar -M < duplicate.mri
35# RUN: llvm-nm --print-armap duplicate.a | FileCheck --check-prefix=SYMS2 %s
36# RUN: llvm-ar t duplicate.a | FileCheck --check-prefix=FILES2 %s
37
38# SYMS2-COUNT-2: f in {{.*}}
39# FILES2-COUNT-2: f.o
40
41#--- f.yaml
42--- !ELF
43FileHeader:
44  Class:   ELFCLASS64
45  Data:    ELFDATA2LSB
46  Type:    ET_REL
47  Machine: EM_X86_64
48Sections:
49  - Name: .text
50    Type: SHT_PROGBITS
51Symbols:
52    - Name:    f
53      Binding: STB_GLOBAL
54      Section: .text
55...
56#--- add-lib.mri
57CREATE add-lib.a
58ADDLIB f.a
59SAVE
60
61#--- text.txt
62I AM NOT AN ARCHIVE
63
64#--- bad-lib.mri
65CREATE bad-lib.a
66ADDLIB text.txt
67SAVE
68
69#--- no-create.mri
70ADDLIB f.a
71SAVE
72
73#--- missing.mri
74CREATE missing.a
75ADDLIB missing-lib.a
76SAVE
77
78#--- duplicate.mri
79CREATE duplicate.a
80ADDLIB f.a
81ADDLIB f.a
82SAVE
83