Skip to content

Commit 67cee1d

Browse files
committedJul 15, 2019
[llvm-lipo] Implement -create (with hardcoded alignments)
Creates universal binary output file from input files. Currently uses hard coded value for alignment. Want to get the create functionality approved before implementing the alignment function. Patch by Anusha Basana <anusha.basana@gmail.com> Differential Revision: https://reviews.llvm.org/D64102 llvm-svn: 366142
1 parent 8538132 commit 67cee1d

9 files changed

+527
-19
lines changed
 
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
--- !mach-o
2+
FileHeader:
3+
magic: 0xFEEDFACF
4+
cputype: 0x0100000C
5+
cpusubtype: 0x00000000
6+
filetype: 0x00000001
7+
ncmds: 4
8+
sizeofcmds: 352
9+
flags: 0x00002000
10+
reserved: 0x00000000
11+
LoadCommands:
12+
- cmd: LC_SEGMENT_64
13+
cmdsize: 232
14+
segname: ''
15+
vmaddr: 0
16+
vmsize: 56
17+
fileoff: 384
18+
filesize: 56
19+
maxprot: 7
20+
initprot: 7
21+
nsects: 2
22+
flags: 0
23+
Sections:
24+
- sectname: __text
25+
segname: __TEXT
26+
addr: 0x0000000000000000
27+
size: 20
28+
offset: 0x00000180
29+
align: 2
30+
reloff: 0x00000000
31+
nreloc: 0
32+
flags: 0x80000400
33+
reserved1: 0x00000000
34+
reserved2: 0x00000000
35+
reserved3: 0x00000000
36+
- sectname: __compact_unwind
37+
segname: __LD
38+
addr: 0x0000000000000018
39+
size: 32
40+
offset: 0x00000198
41+
align: 3
42+
reloff: 0x000001B8
43+
nreloc: 1
44+
flags: 0x02000000
45+
reserved1: 0x00000000
46+
reserved2: 0x00000000
47+
reserved3: 0x00000000
48+
- cmd: LC_VERSION_MIN_IPHONEOS
49+
cmdsize: 16
50+
version: 327680
51+
sdk: 0
52+
- cmd: LC_SYMTAB
53+
cmdsize: 24
54+
symoff: 448
55+
nsyms: 3
56+
stroff: 496
57+
strsize: 20
58+
- cmd: LC_DYSYMTAB
59+
cmdsize: 80
60+
ilocalsym: 0
61+
nlocalsym: 2
62+
iextdefsym: 2
63+
nextdefsym: 1
64+
iundefsym: 3
65+
nundefsym: 0
66+
tocoff: 0
67+
ntoc: 0
68+
modtaboff: 0
69+
nmodtab: 0
70+
extrefsymoff: 0
71+
nextrefsyms: 0
72+
indirectsymoff: 0
73+
nindirectsyms: 0
74+
extreloff: 0
75+
nextrel: 0
76+
locreloff: 0
77+
nlocrel: 0
78+
LinkEditData:
79+
NameList:
80+
- n_strx: 13
81+
n_type: 0x0E
82+
n_sect: 1
83+
n_desc: 0
84+
n_value: 0
85+
- n_strx: 7
86+
n_type: 0x0E
87+
n_sect: 2
88+
n_desc: 0
89+
n_value: 24
90+
- n_strx: 1
91+
n_type: 0x0F
92+
n_sect: 1
93+
n_desc: 0
94+
n_value: 0
95+
StringTable:
96+
- ''
97+
- _main
98+
- ltmp1
99+
- ltmp0
100+
- ''
101+
...
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
--- !mach-o
2+
FileHeader:
3+
magic: 0xFEEDFACE
4+
cputype: 0x0000000C
5+
cpusubtype: 0x00000009
6+
filetype: 0x00000001
7+
ncmds: 4
8+
sizeofcmds: 244
9+
flags: 0x00002000
10+
LoadCommands:
11+
- cmd: LC_SEGMENT
12+
cmdsize: 124
13+
segname: ''
14+
vmaddr: 0
15+
vmsize: 10
16+
fileoff: 272
17+
filesize: 10
18+
maxprot: 7
19+
initprot: 7
20+
nsects: 1
21+
flags: 0
22+
Sections:
23+
- sectname: __text
24+
segname: __TEXT
25+
addr: 0x0000000000000000
26+
size: 10
27+
offset: 0x00000110
28+
align: 1
29+
reloff: 0x00000000
30+
nreloc: 0
31+
flags: 0x80000400
32+
reserved1: 0x00000000
33+
reserved2: 0x00000000
34+
reserved3: 0x00000000
35+
- cmd: LC_VERSION_MIN_IPHONEOS
36+
cmdsize: 16
37+
version: 327680
38+
sdk: 0
39+
- cmd: LC_SYMTAB
40+
cmdsize: 24
41+
symoff: 284
42+
nsyms: 1
43+
stroff: 296
44+
strsize: 8
45+
- cmd: LC_DYSYMTAB
46+
cmdsize: 80
47+
ilocalsym: 0
48+
nlocalsym: 0
49+
iextdefsym: 0
50+
nextdefsym: 1
51+
iundefsym: 1
52+
nundefsym: 0
53+
tocoff: 0
54+
ntoc: 0
55+
modtaboff: 0
56+
nmodtab: 0
57+
extrefsymoff: 0
58+
nextrefsyms: 0
59+
indirectsymoff: 0
60+
nindirectsyms: 0
61+
extreloff: 0
62+
nextrel: 0
63+
locreloff: 0
64+
nlocrel: 0
65+
LinkEditData:
66+
NameList:
67+
- n_strx: 1
68+
n_type: 0x0F
69+
n_sect: 1
70+
n_desc: 8
71+
n_value: 0
72+
StringTable:
73+
- ''
74+
- _main
75+
- ''
76+
...
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
--- !mach-o
2+
FileHeader:
3+
magic: 0xFEEDFACF
4+
cputype: 0x01000007
5+
cpusubtype: 0x00000003
6+
filetype: 0x00000001
7+
ncmds: 4
8+
sizeofcmds: 352
9+
flags: 0x00002000
10+
reserved: 0x00000000
11+
LoadCommands:
12+
- cmd: LC_SEGMENT_64
13+
cmdsize: 232
14+
segname: ''
15+
vmaddr: 0
16+
vmsize: 80
17+
fileoff: 384
18+
filesize: 80
19+
maxprot: 7
20+
initprot: 7
21+
nsects: 2
22+
flags: 0
23+
Sections:
24+
- sectname: __text
25+
segname: __TEXT
26+
addr: 0x0000000000000000
27+
size: 15
28+
offset: 0x00000180
29+
align: 4
30+
reloff: 0x00000000
31+
nreloc: 0
32+
flags: 0x80000400
33+
reserved1: 0x00000000
34+
reserved2: 0x00000000
35+
reserved3: 0x00000000
36+
- sectname: __eh_frame
37+
segname: __TEXT
38+
addr: 0x0000000000000010
39+
size: 64
40+
offset: 0x00000190
41+
align: 3
42+
reloff: 0x00000000
43+
nreloc: 0
44+
flags: 0x6800000B
45+
reserved1: 0x00000000
46+
reserved2: 0x00000000
47+
reserved3: 0x00000000
48+
- cmd: LC_VERSION_MIN_MACOSX
49+
cmdsize: 16
50+
version: 656384
51+
sdk: 0
52+
- cmd: LC_SYMTAB
53+
cmdsize: 24
54+
symoff: 464
55+
nsyms: 1
56+
stroff: 480
57+
strsize: 8
58+
- cmd: LC_DYSYMTAB
59+
cmdsize: 80
60+
ilocalsym: 0
61+
nlocalsym: 0
62+
iextdefsym: 0
63+
nextdefsym: 1
64+
iundefsym: 1
65+
nundefsym: 0
66+
tocoff: 0
67+
ntoc: 0
68+
modtaboff: 0
69+
nmodtab: 0
70+
extrefsymoff: 0
71+
nextrefsyms: 0
72+
indirectsymoff: 0
73+
nindirectsyms: 0
74+
extreloff: 0
75+
nextrel: 0
76+
locreloff: 0
77+
nlocrel: 0
78+
LinkEditData:
79+
NameList:
80+
- n_strx: 1
81+
n_type: 0x0F
82+
n_sect: 1
83+
n_desc: 0
84+
n_value: 0
85+
StringTable:
86+
- ''
87+
- _main
88+
- ''
89+
...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: yaml2obj %p/Inputs/i386-slice.yaml > %t-i386.o
2+
# RUN: yaml2obj %p/Inputs/x86_64-slice.yaml > %t-x86_64.o
3+
4+
# RUN: chmod -x %t-i386.o
5+
# RUN: chmod -x %t-x86_64.o
6+
# RUN: llvm-lipo %t-i386.o %t-x86_64.o -create -output %t-universal.o
7+
# RUN: ! test -x %t-universal.o
8+
9+
# RUN: chmod +x %t-i386.o
10+
# RUN: llvm-lipo %t-i386.o %t-x86_64.o -create -output %t-universal.o
11+
# RUN: test -x %t-universal.o
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: yaml2obj %p/Inputs/i386-slice.yaml > %t-32.o
2+
# RUN: yaml2obj %p/Inputs/i386-x86_64-universal.yaml > %t-universal.o
3+
4+
# RUN: not llvm-lipo %t-32.o -create 2>&1 | FileCheck --check-prefix=NO_OUTPUT %s
5+
# NO_OUTPUT: error: create expects a single output file to be specified
6+
7+
# RUN: not llvm-lipo %t-universal.o %t-32.o -create -output %t.o 2>&1 | FileCheck --check-prefix=DUPLICATE_ARCHS %s
8+
# DUPLICATE_ARCHS: have the same architecture i386 and therefore cannot be in the same universal binary
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RUN: yaml2obj %p/Inputs/i386-slice.yaml > %t-i386.o
2+
# RUN: yaml2obj %p/Inputs/x86_64-slice.yaml > %t-x86_64.o
3+
4+
# RUN: llvm-lipo %t-i386.o %t-x86_64.o -create -output %t-universal-llvm.o
5+
6+
# RUN: yaml2obj %p/Inputs/i386-x86_64-universal.yaml > %t-universal.o
7+
# RUN: cmp %t-universal-llvm.o %t-universal.o
8+
9+
# RUN: yaml2obj %p/Inputs/armv7-slice.yaml > %t-armv7.o
10+
# RUN: yaml2obj %p/Inputs/arm64-slice.yaml > %t-arm64.o
11+
12+
# RUN: llvm-lipo %t-arm64.o %t-armv7.o %t-universal.o -create -output %t-universal-2.o
13+
# RUN: llvm-lipo %t-universal-2.o -thin x86_64 -output %t-x86_64_extracted.o
14+
# RUN: cmp %t-x86_64_extracted.o %t-x86_64.o
15+
# RUN: llvm-lipo %t-universal-2.o -thin armv7 -output %t-armv7-extracted.o
16+
# RUN: cmp %t-armv7-extracted.o %t-armv7.o
17+
18+
# RUN: llvm-objdump %t-universal-2.o -m --universal-headers | FileCheck %s
19+
# CHECK: fat_magic FAT_MAGIC
20+
# CHECK: nfat_arch 4
21+
# CHECK: architecture i386
22+
# CHECK: offset 4096
23+
# CHECK: align 2^12 (4096)
24+
# CHECK: architecture x86_64
25+
# CHECK: offset 8192
26+
# CHECK: align 2^12 (4096)
27+
# CHECK: architecture armv7
28+
# CHECK: offset 16384
29+
# CHECK: align 2^14 (16384)
30+
# CHECK: architecture arm64
31+
# CHECK: offset 32768
32+
# CHECK: align 2^14 (16384)

‎llvm/test/tools/llvm-lipo/thin-executable-universal-binary.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# RUN: chmod -x %t-universal.o
66
# RUN: llvm-lipo %t-universal.o -thin i386 -output %t32.o
7-
# RUN: test ! -x %t32.o
7+
# RUN: ! test -x %t32.o
88

99
# RUN: chmod +x %t-universal.o
1010
# RUN: llvm-lipo %t-universal.o -thin i386 -output %t32-ex.o

‎llvm/tools/llvm-lipo/LipoOpts.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def thin : Option<["-", "--"], "thin", KIND_SEPARATE>,
2323
HelpText<"Create a thin output file of specified arch_type from the "
2424
"fat input file. Requires -output option">;
2525

26+
def create : Option<["-", "--"], "create", KIND_FLAG>,
27+
Group<action_group>,
28+
HelpText<"Create a universal binary output file from the input "
29+
"files. Requires -output option">;
30+
2631
def output : Option<["-", "--"], "output", KIND_SEPARATE>,
2732
HelpText<"Create output file with specified name">;
2833
def o : JoinedOrSeparate<["-"], "o">, Alias<output>;

0 commit comments

Comments
 (0)