Skip to content

Commit 14c36db

Browse files
author
Lang Hames
committed
[ORC] Generalize GetDylibInterface to support MachO Universal Binaries.
Also adds a testcase for dylib handling in llvm-jitlink`s -weak-lx and -weak_library options.
1 parent 725a7b6 commit 14c36db

File tree

3 files changed

+391
-7
lines changed

3 files changed

+391
-7
lines changed

Diff for: llvm/lib/ExecutionEngine/Orc/GetDylibInterface.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ Expected<SymbolNameSet> getDylibInterfaceFromDylib(ExecutionSession &ES,
3131
if (!Buf)
3232
return createFileError(Path, Buf.getError());
3333

34-
auto SymFile =
35-
object::SymbolicFile::createSymbolicFile((*Buf)->getMemBufferRef());
36-
if (!SymFile)
37-
return SymFile.takeError();
34+
auto BinFile = object::createBinary((*Buf)->getMemBufferRef());
35+
if (!BinFile)
36+
return BinFile.takeError();
3837

3938
std::unique_ptr<object::MachOObjectFile> MachOFile;
40-
if (isa<object::MachOObjectFile>(**SymFile))
41-
MachOFile.reset(dyn_cast<object::MachOObjectFile>(SymFile->release()));
39+
if (isa<object::MachOObjectFile>(**BinFile))
40+
MachOFile.reset(dyn_cast<object::MachOObjectFile>(BinFile->release()));
4241
else if (auto *MachOUni =
43-
dyn_cast<object::MachOUniversalBinary>(SymFile->get())) {
42+
dyn_cast<object::MachOUniversalBinary>(BinFile->get())) {
4443
for (auto &O : MachOUni->objects()) {
4544
if (O.getCPUType() == *CPUType && O.getCPUSubType() == *CPUSubType) {
4645
if (auto Obj = O.getAsObjectFile())
@@ -114,6 +113,7 @@ Expected<SymbolNameSet> getDylibInterface(ExecutionSession &ES, Twine Path) {
114113

115114
SymbolNameSet Symbols;
116115
switch (Magic) {
116+
case file_magic::macho_universal_binary:
117117
case file_magic::macho_dynamically_linked_shared_lib:
118118
return getDylibInterfaceFromDylib(ES, Path);
119119
case file_magic::tapi_file:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,359 @@
1+
--- !fat-mach-o
2+
FatHeader:
3+
magic: 0xCAFEBABE
4+
nfat_arch: 2
5+
FatArchs:
6+
- cputype: 0x1000007
7+
cpusubtype: 0x3
8+
offset: 0x1000
9+
size: 4208
10+
align: 12
11+
- cputype: 0x100000C
12+
cpusubtype: 0x0
13+
offset: 0x4000
14+
size: 16784
15+
align: 14
16+
Slices:
17+
- !mach-o
18+
FileHeader:
19+
magic: 0xFEEDFACF
20+
cputype: 0x1000007
21+
cpusubtype: 0x3
22+
filetype: 0x6
23+
ncmds: 13
24+
sizeofcmds: 640
25+
flags: 0x100085
26+
reserved: 0x0
27+
LoadCommands:
28+
- cmd: LC_SEGMENT_64
29+
cmdsize: 232
30+
segname: __TEXT
31+
vmaddr: 0
32+
vmsize: 4096
33+
fileoff: 0
34+
filesize: 4096
35+
maxprot: 5
36+
initprot: 5
37+
nsects: 2
38+
flags: 0
39+
Sections:
40+
- sectname: __text
41+
segname: __TEXT
42+
addr: 0xFA0
43+
size: 8
44+
offset: 0xFA0
45+
align: 4
46+
reloff: 0x0
47+
nreloc: 0
48+
flags: 0x80000400
49+
reserved1: 0x0
50+
reserved2: 0x0
51+
reserved3: 0x0
52+
content: 554889E531C05DC3
53+
- sectname: __unwind_info
54+
segname: __TEXT
55+
addr: 0xFA8
56+
size: 88
57+
offset: 0xFA8
58+
align: 2
59+
reloff: 0x0
60+
nreloc: 0
61+
flags: 0x0
62+
reserved1: 0x0
63+
reserved2: 0x0
64+
reserved3: 0x0
65+
content: 010000001C000000000000001C000000000000001C00000002000000A00F00004000000040000000A80F00000000000040000000000000000000000000000000030000000C00010010000100000000000000000100000000
66+
- cmd: LC_SEGMENT_64
67+
cmdsize: 72
68+
segname: __LINKEDIT
69+
vmaddr: 4096
70+
vmsize: 4096
71+
fileoff: 4096
72+
filesize: 112
73+
maxprot: 1
74+
initprot: 1
75+
nsects: 0
76+
flags: 0
77+
- cmd: LC_ID_DYLIB
78+
cmdsize: 40
79+
dylib:
80+
name: 24
81+
timestamp: 1
82+
current_version: 0
83+
compatibility_version: 0
84+
Content: libfoo.dylib
85+
ZeroPadBytes: 4
86+
- cmd: LC_DYLD_CHAINED_FIXUPS
87+
cmdsize: 16
88+
dataoff: 4096
89+
datasize: 56
90+
- cmd: LC_DYLD_EXPORTS_TRIE
91+
cmdsize: 16
92+
dataoff: 4152
93+
datasize: 24
94+
- cmd: LC_SYMTAB
95+
cmdsize: 24
96+
symoff: 4184
97+
nsyms: 1
98+
stroff: 4200
99+
strsize: 8
100+
- cmd: LC_DYSYMTAB
101+
cmdsize: 80
102+
ilocalsym: 0
103+
nlocalsym: 0
104+
iextdefsym: 0
105+
nextdefsym: 1
106+
iundefsym: 1
107+
nundefsym: 0
108+
tocoff: 0
109+
ntoc: 0
110+
modtaboff: 0
111+
nmodtab: 0
112+
extrefsymoff: 0
113+
nextrefsyms: 0
114+
indirectsymoff: 0
115+
nindirectsyms: 0
116+
extreloff: 0
117+
nextrel: 0
118+
locreloff: 0
119+
nlocrel: 0
120+
- cmd: LC_UUID
121+
cmdsize: 24
122+
uuid: 473C3F15-F7E8-39A3-AD71-23755AB9A6BF
123+
- cmd: LC_BUILD_VERSION
124+
cmdsize: 32
125+
platform: 1
126+
minos: 983040
127+
sdk: 984064
128+
ntools: 1
129+
Tools:
130+
- tool: 3
131+
version: 73074435
132+
- cmd: LC_SOURCE_VERSION
133+
cmdsize: 16
134+
version: 0
135+
- cmd: LC_LOAD_DYLIB
136+
cmdsize: 56
137+
dylib:
138+
name: 24
139+
timestamp: 2
140+
current_version: 88539136
141+
compatibility_version: 65536
142+
Content: '/usr/lib/libSystem.B.dylib'
143+
ZeroPadBytes: 6
144+
- cmd: LC_FUNCTION_STARTS
145+
cmdsize: 16
146+
dataoff: 4176
147+
datasize: 8
148+
- cmd: LC_DATA_IN_CODE
149+
cmdsize: 16
150+
dataoff: 4184
151+
datasize: 0
152+
LinkEditData:
153+
ExportTrie:
154+
TerminalSize: 0
155+
NodeOffset: 0
156+
Name: ''
157+
Flags: 0x0
158+
Address: 0x0
159+
Other: 0x0
160+
ImportName: ''
161+
Children:
162+
- TerminalSize: 3
163+
NodeOffset: 12
164+
Name: _foo
165+
Flags: 0x0
166+
Address: 0xFA0
167+
Other: 0x0
168+
ImportName: ''
169+
NameList:
170+
- n_strx: 2
171+
n_type: 0xF
172+
n_sect: 1
173+
n_desc: 0
174+
n_value: 4000
175+
StringTable:
176+
- ' '
177+
- _foo
178+
- ''
179+
FunctionStarts: [ 0xFA0 ]
180+
ChainedFixups: [ 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x30,
181+
0x0, 0x0, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0,
182+
0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
183+
0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0,
184+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
185+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
186+
- !mach-o
187+
FileHeader:
188+
magic: 0xFEEDFACF
189+
cputype: 0x100000C
190+
cpusubtype: 0x0
191+
filetype: 0x6
192+
ncmds: 14
193+
sizeofcmds: 656
194+
flags: 0x100085
195+
reserved: 0x0
196+
LoadCommands:
197+
- cmd: LC_SEGMENT_64
198+
cmdsize: 232
199+
segname: __TEXT
200+
vmaddr: 0
201+
vmsize: 16384
202+
fileoff: 0
203+
filesize: 16384
204+
maxprot: 5
205+
initprot: 5
206+
nsects: 2
207+
flags: 0
208+
Sections:
209+
- sectname: __text
210+
segname: __TEXT
211+
addr: 0x3FA0
212+
size: 8
213+
offset: 0x3FA0
214+
align: 2
215+
reloff: 0x0
216+
nreloc: 0
217+
flags: 0x80000400
218+
reserved1: 0x0
219+
reserved2: 0x0
220+
reserved3: 0x0
221+
content: 00008052C0035FD6
222+
- sectname: __unwind_info
223+
segname: __TEXT
224+
addr: 0x3FA8
225+
size: 88
226+
offset: 0x3FA8
227+
align: 2
228+
reloff: 0x0
229+
nreloc: 0
230+
flags: 0x0
231+
reserved1: 0x0
232+
reserved2: 0x0
233+
reserved3: 0x0
234+
content: 010000001C000000000000001C000000000000001C00000002000000A03F00004000000040000000A83F00000000000040000000000000000000000000000000030000000C00010010000100000000000000000200000000
235+
- cmd: LC_SEGMENT_64
236+
cmdsize: 72
237+
segname: __LINKEDIT
238+
vmaddr: 16384
239+
vmsize: 16384
240+
fileoff: 16384
241+
filesize: 400
242+
maxprot: 1
243+
initprot: 1
244+
nsects: 0
245+
flags: 0
246+
- cmd: LC_ID_DYLIB
247+
cmdsize: 40
248+
dylib:
249+
name: 24
250+
timestamp: 1
251+
current_version: 0
252+
compatibility_version: 0
253+
Content: libfoo.dylib
254+
ZeroPadBytes: 4
255+
- cmd: LC_DYLD_CHAINED_FIXUPS
256+
cmdsize: 16
257+
dataoff: 16384
258+
datasize: 56
259+
- cmd: LC_DYLD_EXPORTS_TRIE
260+
cmdsize: 16
261+
dataoff: 16440
262+
datasize: 24
263+
- cmd: LC_SYMTAB
264+
cmdsize: 24
265+
symoff: 16472
266+
nsyms: 1
267+
stroff: 16488
268+
strsize: 8
269+
- cmd: LC_DYSYMTAB
270+
cmdsize: 80
271+
ilocalsym: 0
272+
nlocalsym: 0
273+
iextdefsym: 0
274+
nextdefsym: 1
275+
iundefsym: 1
276+
nundefsym: 0
277+
tocoff: 0
278+
ntoc: 0
279+
modtaboff: 0
280+
nmodtab: 0
281+
extrefsymoff: 0
282+
nextrefsyms: 0
283+
indirectsymoff: 0
284+
nindirectsyms: 0
285+
extreloff: 0
286+
nextrel: 0
287+
locreloff: 0
288+
nlocrel: 0
289+
- cmd: LC_UUID
290+
cmdsize: 24
291+
uuid: 34F58EE3-FEB6-3592-9EBB-86E95197E788
292+
- cmd: LC_BUILD_VERSION
293+
cmdsize: 32
294+
platform: 1
295+
minos: 983040
296+
sdk: 984064
297+
ntools: 1
298+
Tools:
299+
- tool: 3
300+
version: 73074435
301+
- cmd: LC_SOURCE_VERSION
302+
cmdsize: 16
303+
version: 0
304+
- cmd: LC_LOAD_DYLIB
305+
cmdsize: 56
306+
dylib:
307+
name: 24
308+
timestamp: 2
309+
current_version: 88539136
310+
compatibility_version: 65536
311+
Content: '/usr/lib/libSystem.B.dylib'
312+
ZeroPadBytes: 6
313+
- cmd: LC_FUNCTION_STARTS
314+
cmdsize: 16
315+
dataoff: 16464
316+
datasize: 8
317+
- cmd: LC_DATA_IN_CODE
318+
cmdsize: 16
319+
dataoff: 16472
320+
datasize: 0
321+
- cmd: LC_CODE_SIGNATURE
322+
cmdsize: 16
323+
dataoff: 16496
324+
datasize: 288
325+
LinkEditData:
326+
ExportTrie:
327+
TerminalSize: 0
328+
NodeOffset: 0
329+
Name: ''
330+
Flags: 0x0
331+
Address: 0x0
332+
Other: 0x0
333+
ImportName: ''
334+
Children:
335+
- TerminalSize: 3
336+
NodeOffset: 12
337+
Name: _foo
338+
Flags: 0x0
339+
Address: 0x3FA0
340+
Other: 0x0
341+
ImportName: ''
342+
NameList:
343+
- n_strx: 2
344+
n_type: 0xF
345+
n_sect: 1
346+
n_desc: 0
347+
n_value: 16288
348+
StringTable:
349+
- ' '
350+
- _foo
351+
- ''
352+
FunctionStarts: [ 0x3FA0 ]
353+
ChainedFixups: [ 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x30,
354+
0x0, 0x0, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0,
355+
0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
356+
0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0,
357+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
358+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
359+
...

0 commit comments

Comments
 (0)