xref: /llvm-project/llvm/test/tools/llvm-libtool-darwin/cpu-subtype-matching.test (revision 05f7b682192b79090b99f01ac7ea62ceaad631b7)
1## This test checks that the CPU subtype matching logic is handled correctly.
2
3# RUN: yaml2obj %s --docnum=1 -o %t-armv6.obj
4# RUN: yaml2obj %s --docnum=2 -o %t-armv7.obj
5# RUN: llvm-as %p/Inputs/arm64-ios.ll -o %t-arm64.bc
6# RUN: llvm-as %p/Inputs/armv7-ios.ll -o %t-armv7.bc
7
8# RUN: llvm-libtool-darwin -static -o %t.lib %t-armv6.obj %t-armv7.obj %t-arm64.bc %t-armv7.bc -arch_only armv7
9
10## Check that only armv7 binary is present:
11# RUN: llvm-ar t %t.lib | \
12# RUN:   FileCheck %s --check-prefix=ARM-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
13
14# ARM-NAMES: [[PREFIX]]-armv7.obj
15# ARM-NAMES-NEXT: [[PREFIX]]-armv7.bc
16
17## Check that only armv7 symbol is present:
18# RUN: llvm-nm --print-armap %t.lib | \
19# RUN:   FileCheck %s --check-prefix=ARM-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
20
21# ARM-SYMBOLS:      Archive map
22# ARM-SYMBOLS-NEXT: _armv7 in [[PREFIX]]-armv7.obj
23# ARM-SYMBOLS-NEXT: _armv7 in [[PREFIX]]-armv7.bc
24# ARM-SYMBOLS-EMPTY:
25
26## armv6.yaml
27## CPUTYPE:    CPU_TYPE_ARM
28## CPUSUBTYPE: CPU_SUBTYPE_ARM_V6
29--- !mach-o
30FileHeader:
31  magic:           0xFEEDFACE
32  cputype:         0x0000000C
33  cpusubtype:      0x00000006
34  filetype:        0x00000001
35  ncmds:           2
36  sizeofcmds:      148
37  flags:           0x00002000
38LoadCommands:
39  - cmd:             LC_SEGMENT
40    cmdsize:         124
41    segname:         ''
42    vmaddr:          0
43    vmsize:          24
44    fileoff:         296
45    filesize:        24
46    maxprot:         7
47    initprot:        7
48    nsects:          1
49    flags:           0
50    Sections:
51      - sectname:        __text
52        segname:         __TEXT
53        addr:            0x0000000000000000
54        size:            24
55        offset:          0x00000128
56        align:           2
57        reloff:          0x00000000
58        nreloc:          0
59        flags:           0x80000400
60        reserved1:       0x00000000
61        reserved2:       0x00000000
62        reserved3:       0x00000000
63        content:         04D04DE208009FE500008DE504D08DE21EFF2FE100000000
64  - cmd:             LC_SYMTAB
65    cmdsize:         24
66    symoff:          328
67    nsyms:           1
68    stroff:          340
69    strsize:         8
70LinkEditData:
71  NameList:
72    - n_strx:          1
73      n_type:          0x0F
74      n_sect:          1
75      n_desc:          0
76      n_value:         0
77  StringTable:
78    - ''
79    - _armv6
80    - ''
81...
82
83## armv7.yaml
84## CPUTYPE:    CPU_TYPE_ARM
85## CPUSUBTYPE: CPU_SUBTYPE_ARM_V7
86--- !mach-o
87FileHeader:
88  magic:           0xFEEDFACE
89  cputype:         0x0000000C
90  cpusubtype:      0x00000009
91  filetype:        0x00000001
92  ncmds:           2
93  sizeofcmds:      148
94  flags:           0x00002000
95LoadCommands:
96  - cmd:             LC_SEGMENT
97    cmdsize:         124
98    segname:         ''
99    vmaddr:          0
100    vmsize:          10
101    fileoff:         280
102    filesize:        10
103    maxprot:         7
104    initprot:        7
105    nsects:          1
106    flags:           0
107    Sections:
108      - sectname:        __text
109        segname:         __TEXT
110        addr:            0x0000000000000000
111        size:            10
112        offset:          0x00000118
113        align:           1
114        reloff:          0x00000000
115        nreloc:          0
116        flags:           0x80000400
117        reserved1:       0x00000000
118        reserved2:       0x00000000
119        reserved3:       0x00000000
120        content:         81B00020009001B07047
121  - cmd:             LC_SYMTAB
122    cmdsize:         24
123    symoff:          292
124    nsyms:           1
125    stroff:          304
126    strsize:         8
127LinkEditData:
128  NameList:
129    - n_strx:          1
130      n_type:          0x0F
131      n_sect:          1
132      n_desc:          8
133      n_value:         0
134  StringTable:
135    - ''
136    - _armv7
137    - ''
138...
139
140# RUN: yaml2obj %s --docnum=3 -o %t-x86_64.obj
141# RUN: yaml2obj %s --docnum=4 -o %t-x86_64_h.obj
142# RUN: llvm-as %p/Inputs/x86_64-osx.ll -o %t-x86_64.bc
143# RUN: llvm-as %p/Inputs/x86_64h-osx.ll -o %t-x86_64_h.bc
144
145# RUN: llvm-libtool-darwin -static -o %t.lib %t-x86_64.obj %t-x86_64_h.obj %t-x86_64.bc %t-x86_64_h.bc -arch_only x86_64
146
147## Check that only x86_64 binary is present:
148# RUN: llvm-ar t %t.lib | \
149# RUN:   FileCheck %s --check-prefix=X86-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
150
151# X86-NAMES: [[PREFIX]]-x86_64.obj
152# X86-NAMES-NEXT: [[PREFIX]]-x86_64.bc
153
154## Check that only x86_64 symbol is present:
155# RUN: llvm-nm --print-armap %t.lib | \
156# RUN:   FileCheck %s --check-prefix=X86-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
157
158# X86-SYMBOLS:      Archive map
159# X86-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.obj
160# X86-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
161# X86-SYMBOLS-EMPTY:
162
163## x86_64.yaml
164## CPUTYPE:    CPU_TYPE_X86_64
165## CPUSUBTYPE: CPU_SUBTYPE_X86_64_ALL
166--- !mach-o
167FileHeader:
168  magic:           0xFEEDFACF
169  cputype:         0x01000007
170  cpusubtype:      0x00000003
171  filetype:        0x00000001
172  ncmds:           2
173  sizeofcmds:      176
174  flags:           0x00002000
175  reserved:        0x00000000
176LoadCommands:
177  - cmd:             LC_SEGMENT_64
178    cmdsize:         152
179    segname:         ''
180    vmaddr:          0
181    vmsize:          15
182    fileoff:         312
183    filesize:        15
184    maxprot:         7
185    initprot:        7
186    nsects:          1
187    flags:           0
188    Sections:
189      - sectname:        __text
190        segname:         __TEXT
191        addr:            0x0000000000000000
192        size:            15
193        offset:          0x00000138
194        align:           4
195        reloff:          0x00000000
196        nreloc:          0
197        flags:           0x80000400
198        reserved1:       0x00000000
199        reserved2:       0x00000000
200        reserved3:       0x00000000
201        content:         554889E531C0C745FC000000005DC3
202  - cmd:             LC_SYMTAB
203    cmdsize:         24
204    symoff:          328
205    nsyms:           1
206    stroff:          344
207    strsize:         8
208LinkEditData:
209  NameList:
210    - n_strx:          1
211      n_type:          0x0F
212      n_sect:          1
213      n_desc:          0
214      n_value:         0
215  StringTable:
216    - ''
217    - _x86_64
218    - ''
219...
220
221## x86_64h.yaml
222## CPUTYPE:    CPU_TYPE_X86_64
223## CPUSUBTYPE: CPU_SUBTYPE_X86_64_H
224--- !mach-o
225FileHeader:
226  magic:           0xFEEDFACF
227  cputype:         0x01000007
228  cpusubtype:      0x00000008
229  filetype:        0x00000001
230  ncmds:           2
231  sizeofcmds:      176
232  flags:           0x00002000
233  reserved:        0x00000000
234LoadCommands:
235  - cmd:             LC_SEGMENT_64
236    cmdsize:         152
237    segname:         ''
238    vmaddr:          0
239    vmsize:          15
240    fileoff:         312
241    filesize:        15
242    maxprot:         7
243    initprot:        7
244    nsects:          1
245    flags:           0
246    Sections:
247      - sectname:        __text
248        segname:         __TEXT
249        addr:            0x0000000000000000
250        size:            15
251        offset:          0x00000138
252        align:           4
253        reloff:          0x00000000
254        nreloc:          0
255        flags:           0x80000400
256        reserved1:       0x00000000
257        reserved2:       0x00000000
258        reserved3:       0x00000000
259        content:         554889E531C0C745FC000000005DC3
260  - cmd:             LC_SYMTAB
261    cmdsize:         24
262    symoff:          328
263    nsyms:           1
264    stroff:          344
265    strsize:         8
266LinkEditData:
267  NameList:
268    - n_strx:          1
269      n_type:          0x0F
270      n_sect:          1
271      n_desc:          0
272      n_value:         0
273  StringTable:
274    - ''
275    - _x86_64_h
276    - ''
277...
278