xref: /llvm-project/llvm/test/tools/llvm-libtool-darwin/universal-object-flattening.test (revision 939c03512d26b053196b9819bb64830482eab777)
1## This test checks that a universal object file is flattened correctly.
2
3# RUN: yaml2obj %s -o %t-universal.o
4# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
5# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
6
7# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only arm64
8
9## Check that the binary is present:
10# RUN: llvm-ar t %t.lib | \
11# RUN:   FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
12
13# CHECK-NAMES: [[PREFIX]]-universal.o
14
15## Check that symbols are present:
16# RUN: llvm-nm --print-armap %t.lib | \
17# RUN:   FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
18
19# CHECK-SYMBOLS:      Archive map
20# CHECK-SYMBOLS-NEXT: _arm64 in [[PREFIX]]-universal.o
21# CHECK-SYMBOLS-EMPTY:
22
23## Check that the output archive is in Darwin format:
24# RUN: llvm-objdump --macho --archive-headers %t.lib | \
25# RUN:   FileCheck %s --check-prefix=FORMAT -DPREFIX=%basename_t.tmp -DARCHIVE=%t.lib
26
27# FORMAT:      Archive : [[ARCHIVE]]
28# FORMAT-NEXT: __.SYMDEF
29# FORMAT-NEXT: [[PREFIX]]-universal.o
30# FORMAT-NOT:  {{.}}
31
32## Passing both a universal file and an object file:
33# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o %t-input1.o -arch_only x86_64
34# RUN: llvm-ar t %t.lib | \
35# RUN:   FileCheck %s --check-prefix=BOTH-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
36# RUN: llvm-nm --print-armap %t.lib | \
37# RUN:   FileCheck %s --check-prefix=BOTH-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
38
39# BOTH-NAMES:      [[PREFIX]]-universal.o
40# BOTH-NAMES-NEXT: [[PREFIX]]-input1.o
41
42# BOTH-SYMBOLS:      Archive map
43# BOTH-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-universal.o
44# BOTH-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
45# BOTH-SYMBOLS-EMPTY:
46
47## Passing both a universal file and an object file but filtering out the object file:
48# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o %t-input1.o -arch_only arm64
49# RUN: llvm-ar t %t.lib | \
50# RUN:   FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
51# RUN: llvm-nm --print-armap %t.lib | \
52# RUN:   FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
53
54## Universal file containing an archive:
55# RUN: rm -f %t.ar
56# RUN: llvm-ar cr %t.ar %t-input1.o %t-input2.o
57# RUN: llvm-lipo %t.ar -create -output %t-fat-with-archive.o
58# RUN: llvm-libtool-darwin -static -o %t.lib %t-fat-with-archive.o -arch_only x86_64
59# RUN: llvm-ar t %t.lib | \
60# RUN:   FileCheck %s --check-prefix=ARCHIVE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
61# RUN: llvm-nm --print-armap %t.lib | \
62# RUN:   FileCheck %s --check-prefix=ARCHIVE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
63
64# ARCHIVE-NAMES:      [[PREFIX]]-input1.o
65# ARCHIVE-NAMES-NEXT: [[PREFIX]]-input2.o
66
67# ARCHIVE-SYMBOLS:      Archive map
68# ARCHIVE-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
69# ARCHIVE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
70# ARCHIVE-SYMBOLS-EMPTY:
71
72## Allow arch_only to be specified more than once (pick the last one):
73# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only arm64 -arch_only x86_64
74# RUN: llvm-ar t %t.lib | \
75# RUN:   FileCheck %s --check-prefix=DOUBLE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
76# RUN: llvm-nm --print-armap %t.lib | \
77# RUN:   FileCheck %s --check-prefix=DOUBLE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
78
79# DOUBLE-NAMES: [[PREFIX]]-universal.o
80
81# DOUBLE-SYMBOLS:      Archive map
82# DOUBLE-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-universal.o
83# DOUBLE-SYMBOLS-EMPTY:
84
85## Invalid architecture:
86# RUN: not llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only arch101 2>&1 | \
87# RUN:   FileCheck %s --check-prefix=INVALID-ARCH
88
89# INVALID-ARCH: invalid architecture 'arch101': valid architecture names are
90
91## Empty architecture:
92# RUN: not llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only "" 2>&1 | \
93# RUN:   FileCheck %s --check-prefix=EMPTY-ARCH
94
95# EMPTY-ARCH: invalid architecture '': valid architecture names are
96
97## Missing architecture:
98# RUN: not llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only ppc 2>&1 | \
99# RUN:   FileCheck %s --check-prefix=MISSING-ARCH
100
101# MISSING-ARCH: error: no library created (no object files in input files matching -arch_only ppc)
102
103## arch_only missing argument:
104# RUN: not llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only 2>&1 | \
105# RUN:   FileCheck %s --check-prefix=REQUIRE-ARCH
106
107# REQUIRE-ARCH: -arch_only: missing argument
108
109## x86_64-arm64-universal.yaml
110--- !fat-mach-o
111FatHeader:
112  magic:           0xCAFEBABE
113  nfat_arch:       2
114FatArchs:
115  - cputype:         0x01000007
116    cpusubtype:      0x00000003
117    offset:          0x0000000000001000
118    size:            352
119    align:           12
120  - cputype:         0x0100000C
121    cpusubtype:      0x00000000
122    offset:          0x0000000000004000
123    size:            384
124    align:           14
125Slices:
126  - !mach-o
127    FileHeader:
128      magic:           0xFEEDFACF
129      cputype:         0x01000007
130      cpusubtype:      0x00000003
131      filetype:        0x00000001
132      ncmds:           2
133      sizeofcmds:      176
134      flags:           0x00002000
135      reserved:        0x00000000
136    LoadCommands:
137      - cmd:             LC_SEGMENT_64
138        cmdsize:         152
139        segname:         ''
140        vmaddr:          0
141        vmsize:          15
142        fileoff:         312
143        filesize:        15
144        maxprot:         7
145        initprot:        7
146        nsects:          1
147        flags:           0
148        Sections:
149          - sectname:        __text
150            segname:         __TEXT
151            addr:            0x0000000000000000
152            size:            15
153            offset:          0x00000138
154            align:           4
155            reloff:          0x00000000
156            nreloc:          0
157            flags:           0x80000400
158            reserved1:       0x00000000
159            reserved2:       0x00000000
160            reserved3:       0x00000000
161            content:         554889E531C0C745FC000000005DC3
162      - cmd:             LC_SYMTAB
163        cmdsize:         24
164        symoff:          328
165        nsyms:           1
166        stroff:          344
167        strsize:         8
168    LinkEditData:
169      NameList:
170        - n_strx:          1
171          n_type:          0x0F
172          n_sect:          1
173          n_desc:          0
174          n_value:         0
175      StringTable:
176        - ''
177        - _x86_64
178        - ''
179  - !mach-o
180    FileHeader:
181      magic:           0xFEEDFACF
182      cputype:         0x0100000C
183      cpusubtype:      0x00000000
184      filetype:        0x00000001
185      ncmds:           2
186      sizeofcmds:      176
187      flags:           0x00002000
188      reserved:        0x00000000
189    LoadCommands:
190      - cmd:             LC_SEGMENT_64
191        cmdsize:         152
192        segname:         ''
193        vmaddr:          0
194        vmsize:          24
195        fileoff:         312
196        filesize:        24
197        maxprot:         7
198        initprot:        7
199        nsects:          1
200        flags:           0
201        Sections:
202          - sectname:        __text
203            segname:         __TEXT
204            addr:            0x0000000000000000
205            size:            24
206            offset:          0x00000138
207            align:           2
208            reloff:          0x00000000
209            nreloc:          0
210            flags:           0x80000400
211            reserved1:       0x00000000
212            reserved2:       0x00000000
213            reserved3:       0x00000000
214            content:         FF4300D1FF0F00B908008052E00308AAFF430091C0035FD6
215      - cmd:             LC_SYMTAB
216        cmdsize:         24
217        symoff:          336
218        nsyms:           2
219        stroff:          368
220        strsize:         16
221    LinkEditData:
222      NameList:
223        - n_strx:          7
224          n_type:          0x0E
225          n_sect:          1
226          n_desc:          0
227          n_value:         0
228        - n_strx:          1
229          n_type:          0x0F
230          n_sect:          1
231          n_desc:          0
232          n_value:         0
233      StringTable:
234        - ''
235        - _arm64
236        - ltmp0
237        - ''
238        - ''
239        - ''
240...
241