xref: /llvm-project/llvm/test/tools/llvm-ar/option-X.test (revision 4f2cfbe5314b064625b2c87bde6ce5c8d04004c5)
1# REQUIRES: system-aix
2## Test the "-X" option.
3## The option specifies the type of object file llvm-ar will operate on.
4
5# RUN: rm -rf %t && mkdir %t && cd %t
6# RUN: unset OBJECT_MODE
7# RUN: yaml2obj --docnum=1 -DCLASS=ELFCLASS32 %s -o elf32.o
8# RUN: yaml2obj --docnum=1 -DCLASS=ELFCLASS64 %s -o elf64.o
9
10# RUN: yaml2obj --docnum=2 -DFLAG=0x1DF %s -o xcoff32.o
11# RUN: yaml2obj --docnum=2 -DFLAG=0x1F7 %s -o xcoff64.o
12
13## Test default -X option when creating a new archive.
14# RUN: llvm-ar -q -c archive-default.a xcoff32.o elf32.o xcoff64.o elf64.o  2>&1 | \
15# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
16# RUN: llvm-ar -t -Xany archive-default.a | \
17# RUN:   FileCheck %s --check-prefixes=OBJ32
18
19## Test -X32 option when creating a new archive.
20# RUN: llvm-ar -q -c -X 32 archive-32.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
21# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
22# RUN: llvm-ar -t -Xany archive-32.a | \
23# RUN:   FileCheck %s --check-prefixes=OBJ32
24
25## Test -X option will override the "OBJECT_MODE" environment variable.
26# RUN: env OBJECT_MODE=64 llvm-ar -q -c -X32 archive-32-env1.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
27# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
28# RUN: llvm-ar -t -Xany archive-32-env1.a | \
29# RUN:   FileCheck %s --check-prefixes=OBJ32
30
31# RUN: env OBJECT_MODE=32_64 llvm-ar -q -c -X32 archive-32-env2.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
32# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
33# RUN: llvm-ar -t -Xany archive-32-env2.a | \
34# RUN:   FileCheck %s --check-prefixes=OBJ32
35
36# RUN: env OBJECT_MODE=any llvm-ar -q -c -X32 archive-32-env3.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
37# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
38# RUN: llvm-ar -t -Xany archive-32-env3.a | \
39# RUN:   FileCheck %s --check-prefixes=OBJ32
40
41## Test -X64 option when creating a new archive.
42# RUN: llvm-ar -q -c -X 64 archive-64.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
43# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF32,WARN-ELF32
44# RUN: llvm-ar -t -Xany archive-64.a | \
45# RUN:   FileCheck %s --check-prefixes=OBJ64
46
47## Test -X32_64 option when creating a new archive.
48## RUN: llvm-ar -q -c -X32_64 archive-32_64.a xcoff32.o elf32.o xcoff64.o elf64.o
49## RUN: llvm-ar -t -Xany archive-32_64.a | \
50## RUN:   FileCheck %s --check-prefixes=OBJ32_64
51
52## Test -Xany option when creating a new archive.
53# RUN: llvm-ar -q -c -Xany archive-any.a xcoff32.o elf32.o xcoff64.o elf64.o
54# RUN: llvm-ar -t -Xany archive-any.a | \
55# RUN:   FileCheck %s --check-prefixes=OBJ32_64
56
57## Test envionment "OBJECT_MODE" when creating a new archive.
58# RUN: env OBJECT_MODE=32 llvm-ar -q -c archive-env32.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
59# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF64,WARN-ELF64
60# RUN: llvm-ar -t -Xany archive-env32.a | \
61# RUN:   FileCheck %s --check-prefixes=OBJ32
62
63# RUN: env OBJECT_MODE=64 llvm-ar -q -c archive-env64.a xcoff32.o elf32.o xcoff64.o elf64.o 2>&1 | \
64# RUN:   FileCheck %s --check-prefixes=WARN-XCOFF32,WARN-ELF32
65# RUN: llvm-ar -t -Xany archive-env64.a | \
66# RUN:   FileCheck %s --check-prefixes=OBJ64
67
68# RUN: env OBJECT_MODE=32_64 llvm-ar -q -c archive-env32_64.a xcoff32.o elf32.o xcoff64.o elf64.o
69# RUN: llvm-ar -t -Xany archive-env32_64.a | \
70# RUN:   FileCheck %s --check-prefixes=OBJ32_64
71
72# RUN: env OBJECT_MODE=any llvm-ar -q -c archive-envany.a xcoff32.o elf32.o xcoff64.o elf64.o
73# RUN: llvm-ar -t -Xany archive-envany.a | \
74# RUN:   FileCheck %s --check-prefixes=OBJ32_64
75
76## Test -X option for print operation.
77# RUN: llvm-ar -t archive-any.a | \
78# RUN:   FileCheck %s --check-prefixes=OBJ32
79
80# RUN: llvm-ar -t -X32 archive-any.a | \
81# RUN:   FileCheck %s --check-prefixes=OBJ32
82
83# RUN: llvm-ar -t -X64 archive-any.a | \
84# RUN:   FileCheck %s --check-prefixes=OBJ64
85
86# RUN: llvm-ar -t -X32_64 archive-any.a | \
87# RUN:   FileCheck %s --check-prefixes=OBJ32_64
88
89# RUN: llvm-ar -t -Xany archive-any.a | \
90# RUN:   FileCheck %s --check-prefixes=OBJ32_64
91
92## Test -X option for extract operation.
93# RUN: llvm-ar --output=32 -x -X32 archive-any.a
94# RUN: cmp xcoff32.o 32/xcoff32.o
95# RUN: cmp elf32.o 32/elf32.o
96# RUN: not ls 32/coff64.o
97# RUN: not ls 32/elf64.o
98
99# RUN: llvm-ar --output=64 -x -X64 archive-any.a
100# RUN: cmp xcoff64.o 64/xcoff64.o
101# RUN: cmp elf64.o 64/elf64.o
102# RUN: not ls 64/xcoff32.o
103# RUN: not ls 64/elf32.o
104
105# RUN: llvm-ar --output=32_64 -x -X32_64 archive-any.a
106# RUN: cmp xcoff32.o 32_64/xcoff32.o
107# RUN: cmp elf32.o 32_64/elf32.o
108# RUN: cmp xcoff64.o 32_64/xcoff64.o
109# RUN: cmp elf64.o 32_64/elf64.o
110
111# RUN: llvm-ar --output=any -x -Xany archive-any.a
112# RUN: cmp xcoff32.o any/xcoff32.o
113# RUN: cmp elf32.o any/elf32.o
114# RUN: cmp xcoff64.o any/xcoff64.o
115# RUN: cmp elf64.o any/elf64.o
116
117## Extract a 64-bit object file with option -X32 (or default object mode).
118# RUN: not llvm-ar --output=err64 -x archive-any.a xcoff64.o 2>&1 | \
119# RUN:   FileCheck %s -DFILE=xcoff64.o --check-prefixes=ERR64
120# RUN: not llvm-ar --output=err64 -x -X32 archive-any.a xcoff64.o 2>&1 | \
121# RUN:   FileCheck %s -DFILE=xcoff64.o --check-prefixes=ERR64
122
123# ERR64: llvm-ar: error: '[[FILE]]' was not found
124# RUN: not ls err64/xcoff64.o
125
126## Extract a 32-bit object file with option -X64.
127# RUN: not llvm-ar --output=err32 -x -X64 archive-any.a xcoff32.o 2>&1 | \
128# RUN:   FileCheck %s -DFILE=xcoff32.o --check-prefixes=ERR32
129
130# ERR32: llvm-ar: error: '[[FILE]]' was not found
131# RUN: not ls err32/xcoff32.o
132
133## Test deleting an object file from a big archive file.
134# RUN: cp archive-any.a archive.a
135# RUN: llvm-ar -d -X32 archive.a xcoff64.o elf64.o
136# RUN: llvm-ar -t -Xany archive.a | \
137# RUN:   FileCheck %s --check-prefixes=OBJ32_64
138
139# RUN: cp archive-any.a archive.a
140# RUN: llvm-ar -d -X64 archive.a xcoff64.o elf64.o
141# RUN: llvm-ar -t -Xany archive.a | \
142# RUN:   FileCheck %s --check-prefixes=OBJ32
143
144# RUN: cp archive-any.a archive.a
145# RUN: llvm-ar -d -Xany archive.a xcoff64.o elf64.o
146# RUN: llvm-ar -t -Xany archive.a | \
147# RUN:   FileCheck %s --check-prefixes=OBJ32
148
149# Test replace/insert an object file in a big archive file.
150# RUN: cp xcoff32.o xcoff.o
151# RUN: llvm-ar -q -c archive-rep.a xcoff.o
152
153## xcoff.o is a 64-bit object file here.
154# RUN: yaml2obj --docnum=2 -DFLAG=0x1F7 %s -o xcoff.o
155
156## Without -X64, -X32_64 or -Xany, nothing changed here,
157## since xcoff.o is a 64-bit object file in command line, but
158## the xcoff.o member in archive-rep.a is a 32-bit object file.
159# RUN: llvm-ar -r archive-rep.a xcoff.o
160# RUN: llvm-ar -t -Xany archive-rep.a | \
161# RUN:   FileCheck %s --check-prefixes=REP
162# RUN: llvm-nm -Xany --print-armap archive-rep.a | \
163# RUN:   FileCheck %s --check-prefixes=SYM32
164
165## With options -X64, -X32_64 or -Xany, the old 32-bit xcoff.o
166## member is still in the archive
167## and a new 64-bit object file xcoff.o is added to the archive.
168# RUN: llvm-ar -r -X64 archive-rep.a xcoff.o
169# RUN: llvm-ar -t -Xany archive-rep.a | \
170# RUN:   FileCheck %s --check-prefixes=REP,REP-DUP
171# RUN: llvm-nm -Xany --print-armap archive-rep.a | \
172# RUN:   FileCheck %s --check-prefixes=SYM32_64
173
174# REP:            xcoff.o
175# REP-DUP-NEXT:   xcoff.o
176# REP-EMPTY:
177
178## Test move member.
179# RUN: cp archive-any.a archive.a
180## Do not move 64-bit object without options -X64, -X32_64, Xany.
181# RUN: llvm-ar -ma elf32.o archive.a xcoff64.o 2>&1 | \
182# RUN:   FileCheck %s --check-prefix=WARN-XCOFF64
183
184# RUN: llvm-ar -t -Xany archive.a | \
185# RUN:   FileCheck %s --check-prefixes=OBJ32_64
186
187## Do not move 32-bit object with -X64.
188# RUN: llvm-ar -ma -X64 elf64.o archive.a xcoff32.o 2>&1 | \
189# RUN:   FileCheck %s --check-prefix=WARN-XCOFF32
190
191# WARN-XCOFF32: warning: 'xcoff32.o' is not valid with the current object file mode
192# WARN-XCOFF64: warning: 'xcoff64.o' is not valid with the current object file mode
193# WARN-ELF32:   warning: 'elf32.o' is not valid with the current object file mode
194# WARN-ELF64:   warning: 'elf64.o' is not valid with the current object file mode
195
196# RUN: llvm-ar -ma -X64 elf64.o archive.a xcoff64.o
197# RUN: llvm-ar -t -Xany archive.a | \
198# RUN:   FileCheck %s --check-prefixes=MOVE64
199
200# RUN: cp archive-any.a archive.a
201# RUN: llvm-ar -ma -X32_64 elf64.o archive.a xcoff64.o
202# RUN: llvm-ar -t -Xany archive.a | \
203# RUN:   FileCheck %s --check-prefixes=MOVE64
204
205# RUN: cp archive-any.a archive.a
206# RUN: llvm-ar -ma -Xany elf64.o archive.a xcoff64.o
207# RUN: llvm-ar -t -Xany archive.a | \
208# RUN:   FileCheck %s --check-prefixes=MOVE64
209
210# MOVE64:       xcoff32.o
211# MOVE64-NEXT:  elf32.o
212# MOVE64-NEXT:  elf64.o
213# MOVE64-NEXT:  xcoff64.o
214# MOVE64-EMPTY:
215
216# RUN: cp archive-any.a archive.a
217# RUN: llvm-ar -ma elf32.o archive.a xcoff32.o
218# RUN: llvm-ar -t -Xany archive.a | \
219# RUN:   FileCheck %s --check-prefixes=MOVE32
220
221# RUN: cp archive-any.a archive.a
222# RUN: llvm-ar -ma -X32 elf32.o archive.a xcoff32.o
223# RUN: llvm-ar -t -Xany archive.a | \
224# RUN:   FileCheck %s --check-prefixes=MOVE32
225
226# RUN: cp archive-any.a archive.a
227# RUN: llvm-ar -ma -X32_64 elf32.o archive.a xcoff32.o
228# RUN: llvm-ar -t -Xany archive.a | \
229# RUN:   FileCheck %s --check-prefixes=MOVE32
230
231# RUN: cp archive-any.a archive.a
232# RUN: llvm-ar -ma -Xany elf32.o archive.a xcoff32.o
233# RUN: llvm-ar -t -Xany archive.a | \
234# RUN:   FileCheck %s --check-prefixes=MOVE32
235
236# MOVE32:       elf32.o
237# MOVE32-NEXT:  xcoff32.o
238# MOVE32-NEXT:  xcoff64.o
239# MOVE32-NEXT:  elf64.o
240# MOVE32-EMPTY:
241
242## Move after a file with a bitness that doesn't match the object mode.
243# RUN: not llvm-ar -ma xcoff64.o archive-any.a xcoff32.o 2>&1 | \
244# RUN:   FileCheck %s --check-prefixes=ERR-INSERT-POINT
245
246# RUN: not llvm-ar -X32 -ma xcoff64.o archive-any.a xcoff32.o 2>&1 | \
247# RUN:   FileCheck %s --check-prefixes=ERR-INSERT-POINT
248
249# RUN: not llvm-ar -X64 -ma xcoff32.o archive-any.a xcoff64.o 2>&1 | \
250# RUN:   FileCheck %s --check-prefixes=ERR-INSERT-POINT
251
252# ERR-INSERT-POINT: error: insertion point not found
253
254## Test move operation for archive when there are two object files with
255## the same name, but different bitness in archive.
256## There are two files named xcoff.o in archive-rep.a (the first one in
257## the archive is 32-bit, the second one is 64-bit).
258# RUN: cp archive-rep.a archive-rep-mov32.a
259# RUN: llvm-ar -Xany -q archive-rep-mov32.a elf32.o elf64.o
260## Move elf32.o to after the 32-bit xcoff.o.
261# RUN: llvm-ar -X32 -ma xcoff.o archive-rep-mov32.a elf32.o
262# RUN: llvm-ar -t -Xany archive-rep-mov32.a | \
263# RUN:   FileCheck %s --check-prefixes=MOVE32-DUP
264
265# MOVE32-DUP:         xcoff.o
266# MOVE32-DUP-NEXT:    elf32.o
267# MOVE32-DUP-NEXT:    xcoff.o
268# MOVE32-DUP-NEXT:    elf64.o
269
270# RUN: cp archive-rep.a archive-rep-mov64.a
271# RUN: llvm-ar -Xany -q archive-rep-mov64.a elf32.o elf64.o
272## Move elf64.o to after the 64-bit xcoff.o.
273# RUN: llvm-ar -X64 -ma xcoff.o archive-rep-mov64.a elf64.o
274# RUN: llvm-ar -t -Xany archive-rep-mov64.a | \
275# RUN:   FileCheck %s --check-prefixes=MOVE64-DUP
276
277# MOVE64-DUP:         xcoff.o
278# MOVE64-DUP-NEXT:    xcoff.o
279# MOVE64-DUP-NEXT:    elf64.o
280# MOVE64-DUP-NEXT:    elf32.o
281
282# OBJ32:          xcoff32.o
283# OBJ32-NEXT:     elf32.o
284# OBJ32-EMPTY:
285
286# OBJ64:        xcoff64.o
287# OBJ64-NEXT:   elf64.o
288# OBJ64-EMPTY:
289
290# OBJ32_64:       xcoff32.o
291# OBJ32_64-NEXT:  elf32.o
292# OBJ32_64-NEXT:  xcoff64.o
293# OBJ32_64-NEXT:  elf64.o
294# OBJ32_64-EMPTY:
295
296# SYM32:       var_0x1DF
297# SYM32-NOT:   var_0x1F7
298
299# SYM32_64:   var_0x1DF
300# SYM32_64:   var_0x1F7
301
302## Test -X option with other output formats.
303
304# RUN: llvm-as -o 32.bc %p/Inputs/bitcode-sym32.ll
305# RUN: llvm-as -o 64.bc %p/Inputs/bitcode-sym64.ll
306# RUN: yaml2obj --docnum=3 %s -o macho32.o
307# RUN: yaml2obj --docnum=4 %s -o macho64.o
308# RUN: yaml2obj --docnum=5 %s -o wasm.o
309# RUN: yaml2obj --docnum=6 %s -o coff.o
310
311# RUN: llvm-ar -q -c archive-other32.a coff.o 32.bc 64.bc wasm.o macho32.o macho64.o 2>&1 | \
312# RUN:   FileCheck %s --check-prefixes=WARN-64
313# RUN: llvm-ar -t -Xany archive-other32.a | \
314# RUN:   FileCheck %s --check-prefixes=OTHER32
315
316# WARN-64:      warning: '64.bc' is not valid with the current object file mode
317# WARN-64-NEXT: warning: 'macho64.o' is not valid with the current object file mode
318
319# OTHER32:       coff.o
320# OTHER32-NEXT:  32.bc
321# OTHER32-NEXT:  wasm.o
322# OTHER32-NEXT:  macho32.o
323# OTHER32-EMPTY:
324
325# RUN: llvm-ar -q -c -X64 archive-other64.a coff.o 32.bc 64.bc wasm.o macho32.o macho64.o 2>&1 | \
326# RUN:   FileCheck %s --check-prefixes=WARN-32
327# RUN: llvm-ar -t -Xany archive-other64.a | \
328# RUN:   FileCheck %s --check-prefixes=OTHER64
329
330# WARN-32:      warning: 'coff.o' is not valid with the current object file mode
331# WARN-32-NEXT: warning: '32.bc' is not valid with the current object file mode
332# WARN-32-NEXT: warning: 'wasm.o' is not valid with the current object file mode
333# WARN-32-NEXT: warning: 'macho32.o' is not valid with the current object file mode
334
335# OTHER64:      64.bc
336# OTHER64-NEXT: macho64.o
337# OTHER64-EMPTY:
338
339
340--- !ELF
341FileHeader:
342  Class:   [[CLASS]]
343  Data:    ELFDATA2LSB
344  Type:    ET_REL
345Symbols:
346  - Name:    [[CLASS]]_var
347
348--- !XCOFF
349FileHeader:
350  MagicNumber:       [[FLAG]]
351Symbols:
352  - Name:            var_[[FLAG]]
353
354--- !mach-o
355FileHeader:
356  magic:      0xFEEDFACE
357  cputype:    0x00000007
358  cpusubtype: 0x00000003
359  filetype:   0x00000001
360  ncmds:      0
361  sizeofcmds: 0
362  flags:      0x00002000
363
364## mach-o 64 bit
365--- !mach-o
366FileHeader:
367  magic:           0xFEEDFACF
368  cputype:         0x0100000C
369  cpusubtype:      0x00000000
370  filetype:        0x00000001
371  ncmds:           0
372  sizeofcmds:      0
373  flags:           0x00000000
374  reserved:        0x00000000
375
376--- !WASM
377FileHeader:
378  Version: 0x00000001
379
380--- !COFF
381header:
382  Machine:         IMAGE_FILE_MACHINE_ARMNT
383  Characteristics: [  ]
384sections:
385symbols:
386