Skip to content

Commit bd2853f

Browse files
committed
[llvm-libtool-darwin] Add support for -arch_only
Add support for -arch_only option for llvm-libtool-darwin. This diff also adds support for accepting universal files as input and flattening them to create the required static library. Supports input universal files contaning both Mach-O object files or archives. Differences from cctools' libtool: - `-arch_only` can be specified multiple times - archives containing universal files are considered invalid (libtool allows such archives) Reviewed by jhenderson, smeenai Differential Revision: https://reviews.llvm.org/D84770
1 parent 05169af commit bd2853f

File tree

6 files changed

+703
-53
lines changed

6 files changed

+703
-53
lines changed

llvm/docs/CommandGuide/llvm-libtool-darwin.rst

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,50 @@ OPTIONS
2121
--------
2222
:program:`llvm-libtool-darwin` supports the following options:
2323

24-
.. option:: -h, -help
25-
26-
Show help and usage for this command.
24+
.. option:: -arch_only <architecture>
2725

28-
.. option:: -help-list
29-
30-
Show help and usage for this command without grouping the options
31-
into categories.
26+
Build a static library only for the specified `<architecture>` and ignore all
27+
other architectures in the files.
3228

3329
.. option:: -color
3430

3531
Use colors in output.
3632

37-
.. option:: -version
33+
.. option:: -D
3834

39-
Display the version of this program.
35+
Use zero for timestamps and UIDs/GIDs. This is set by default.
4036

41-
.. option:: -D
37+
.. option:: -filelist <listfile[,dirname]>
4238

43-
Use zero for timestamps and UIDs/GIDs. This is set by default.
39+
Read input file names from `<listfile>`. File names are specified in `<listfile>`
40+
one per line, separated only by newlines. Whitespace on a line is assumed
41+
to be part of the filename. If the directory name, `dirname`, is also
42+
specified then it is prepended to each file name in the `<listfile>`.
4443

45-
.. option:: -U
44+
.. option:: -h, -help
45+
46+
Show help and usage for this command.
4647

47-
Use actual timestamps and UIDs/GIDs.
48+
.. option:: -help-list
49+
50+
Show help and usage for this command without grouping the options
51+
into categories.
4852

4953
.. option:: -o <filename>
5054

5155
Specify the output file name. Must be specified exactly once.
5256

5357
.. option:: -static
5458

55-
Produces a static library from the input files.
59+
Produces a static library from the input files.
5660

57-
.. option:: -filelist <listfile[,dirname]>
61+
.. option:: -U
62+
63+
Use actual timestamps and UIDs/GIDs.
5864

59-
Read input file names from `<listfile>`. File names are specified in `<listfile>`
60-
one per line, separated only by newlines. Whitespace on a line is assumed
61-
to be part of the filename. If the directory name, `dirname`, is also
62-
specified then it is prepended to each file name in the `<listfile>`.
65+
.. option:: -version
66+
67+
Display the version of this program.
6368

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

0 commit comments

Comments
 (0)