llvm.org GIT mirror llvm / 4aa4497
[obj2yaml] [yaml2obj] Support for MachO nlist and string table This commit adds round tripping for MachO symbol data. Symbols are entries in the name list, that contain offsets into the string table which is at the end of the __LINKEDIT segment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271604 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 3 years ago
5 changed file(s) with 610 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5656 uint64_t ZeroPadBytes;
5757 };
5858
59 struct NListEntry {
60 uint32_t n_strx;
61 uint8_t n_type;
62 uint8_t n_sect;
63 uint16_t n_desc;
64 uint64_t n_value;
65 };
5966 struct RebaseOpcode {
6067 MachO::RebaseOpcode Opcode;
6168 uint8_t Imm;
9097 std::vector WeakBindOpcodes;
9198 std::vector LazyBindOpcodes;
9299 MachOYAML::ExportEntry ExportTrie;
100 std::vector NameList;
101 std::vector StringTable;
93102 };
94103
95104 struct Object {
110119 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
111120 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
112121 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)
122 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::NListEntry)
123 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
113124
114125 namespace llvm {
115126 namespace yaml {
144155
145156 template <> struct MappingTraits {
146157 static void mapping(IO &IO, MachOYAML::Section &Section);
158 };
159
160 template <> struct MappingTraits {
161 static void mapping(IO &IO, MachOYAML::NListEntry &NListEntry);
147162 };
148163
149164 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
103103 IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
104104 IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
105105 IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
106 IO.mapOptional("NameList", LinkEditData.NameList);
107 IO.mapOptional("StringTable", LinkEditData.StringTable);
106108 }
107109
108110 void MappingTraits::mapping(
131133 IO.mapOptional("Other", ExportEntry.Other);
132134 IO.mapOptional("ImportName", ExportEntry.ImportName);
133135 IO.mapOptional("Children", ExportEntry.Children);
136 }
137
138 void MappingTraits::mapping(
139 IO &IO, MachOYAML::NListEntry &NListEntry) {
140 IO.mapRequired("n_strx", NListEntry.n_strx);
141 IO.mapRequired("n_type", NListEntry.n_type);
142 IO.mapRequired("n_sect", NListEntry.n_sect);
143 IO.mapRequired("n_desc", NListEntry.n_desc);
144 IO.mapRequired("n_value", NListEntry.n_value);
134145 }
135146
136147 template
0 # RUN: yaml2obj -format=macho %s | obj2yaml | FileCheck %s
1
2 --- !mach-o
3 FileHeader:
4 magic: 0xFEEDFACF
5 cputype: 0x01000007
6 cpusubtype: 0x80000003
7 filetype: 0x00000002
8 ncmds: 16
9 sizeofcmds: 1408
10 flags: 0x00218085
11 reserved: 0x00000000
12 LoadCommands:
13 - cmd: LC_SEGMENT_64
14 cmdsize: 72
15 segname: __PAGEZERO
16 vmaddr: 0
17 vmsize: 4294967296
18 fileoff: 0
19 filesize: 0
20 maxprot: 0
21 initprot: 0
22 nsects: 0
23 flags: 0
24 - cmd: LC_SEGMENT_64
25 cmdsize: 552
26 segname: __TEXT
27 vmaddr: 4294967296
28 vmsize: 8192
29 fileoff: 0
30 filesize: 8192
31 maxprot: 7
32 initprot: 5
33 nsects: 6
34 flags: 0
35 Sections:
36 - cmd: LC_SEGMENT_64
37 cmdsize: 312
38 segname: __DATA
39 vmaddr: 4294975488
40 vmsize: 4096
41 fileoff: 8192
42 filesize: 4096
43 maxprot: 7
44 initprot: 3
45 nsects: 3
46 flags: 0
47 Sections:
48 - cmd: LC_SEGMENT_64
49 cmdsize: 72
50 segname: __LINKEDIT
51 vmaddr: 4294979584
52 vmsize: 4096
53 fileoff: 12288
54 filesize: 2508
55 maxprot: 7
56 initprot: 1
57 nsects: 0
58 flags: 0
59 - cmd: LC_DYLD_INFO_ONLY
60 cmdsize: 48
61 rebase_off: 12288
62 rebase_size: 8
63 bind_off: 12296
64 bind_size: 96
65 weak_bind_off: 0
66 weak_bind_size: 0
67 lazy_bind_off: 12392
68 lazy_bind_size: 624
69 export_off: 13016
70 export_size: 48
71 - cmd: LC_SYMTAB
72 cmdsize: 24
73 symoff: 13080
74 nsyms: 30
75 stroff: 13700
76 strsize: 1096
77 - cmd: LC_DYSYMTAB
78 cmdsize: 80
79 ilocalsym: 0
80 nlocalsym: 9
81 iextdefsym: 9
82 nextdefsym: 2
83 iundefsym: 11
84 nundefsym: 19
85 tocoff: 0
86 ntoc: 0
87 modtaboff: 0
88 nmodtab: 0
89 extrefsymoff: 0
90 nextrefsyms: 0
91 indirectsymoff: 13560
92 nindirectsyms: 35
93 extreloff: 0
94 nextrel: 0
95 locreloff: 0
96 nlocrel: 0
97 - cmd: LC_LOAD_DYLINKER
98 cmdsize: 32
99 name: 12
100 PayloadString: /usr/lib/dyld
101 ZeroPadBytes: 7
102 - cmd: LC_UUID
103 cmdsize: 24
104 uuid: 461A1B28-822F-3F38-B670-645419E636F5
105 - cmd: LC_VERSION_MIN_MACOSX
106 cmdsize: 16
107 version: 658176
108 sdk: 658176
109 - cmd: LC_SOURCE_VERSION
110 cmdsize: 16
111 version: 0
112 - cmd: LC_MAIN
113 cmdsize: 24
114 entryoff: 4448
115 stacksize: 0
116 - cmd: LC_LOAD_DYLIB
117 cmdsize: 48
118 dylib:
119 name: 24
120 timestamp: 2
121 current_version: 7864576
122 compatibility_version: 65536
123 PayloadString: '/usr/lib/libc++.1.dylib'
124 ZeroPadBytes: 1
125 - cmd: LC_LOAD_DYLIB
126 cmdsize: 56
127 dylib:
128 name: 24
129 timestamp: 2
130 current_version: 80349697
131 compatibility_version: 65536
132 PayloadString: /usr/lib/libSystem.B.dylib
133 ZeroPadBytes: 6
134 - cmd: LC_FUNCTION_STARTS
135 cmdsize: 16
136 dataoff: 13064
137 datasize: 16
138 - cmd: LC_DATA_IN_CODE
139 cmdsize: 16
140 dataoff: 13080
141 datasize: 0
142 LinkEditData:
143 NameList:
144 - n_strx: 2
145 n_type: 30
146 n_sect: 1
147 n_desc: 128
148 n_value: 4294971808
149 - n_strx: 69
150 n_type: 30
151 n_sect: 1
152 n_desc: 128
153 n_value: 4294971888
154 - n_strx: 166
155 n_type: 30
156 n_sect: 1
157 n_desc: 128
158 n_value: 4294973024
159 - n_strx: 204
160 n_type: 30
161 n_sect: 1
162 n_desc: 128
163 n_value: 4294973056
164 - n_strx: 320
165 n_type: 30
166 n_sect: 1
167 n_desc: 128
168 n_value: 4294974784
169 - n_strx: 344
170 n_type: 30
171 n_sect: 1
172 n_desc: 128
173 n_value: 4294974800
174 - n_strx: 387
175 n_type: 30
176 n_sect: 1
177 n_desc: 128
178 n_value: 4294974832
179 - n_strx: 420
180 n_type: 14
181 n_sect: 4
182 n_desc: 0
183 n_value: 4294975104
184 - n_strx: 438
185 n_type: 14
186 n_sect: 4
187 n_desc: 0
188 n_value: 4294975280
189 - n_strx: 456
190 n_type: 15
191 n_sect: 1
192 n_desc: 16
193 n_value: 4294967296
194 - n_strx: 476
195 n_type: 15
196 n_sect: 1
197 n_desc: 0
198 n_value: 4294971744
199 - n_strx: 482
200 n_type: 1
201 n_sect: 0
202 n_desc: 512
203 n_value: 0
204 - n_strx: 498
205 n_type: 1
206 n_sect: 0
207 n_desc: 256
208 n_value: 0
209 - n_strx: 537
210 n_type: 1
211 n_sect: 0
212 n_desc: 256
213 n_value: 0
214 - n_strx: 567
215 n_type: 1
216 n_sect: 0
217 n_desc: 256
218 n_value: 0
219 - n_strx: 642
220 n_type: 1
221 n_sect: 0
222 n_desc: 256
223 n_value: 0
224 - n_strx: 711
225 n_type: 1
226 n_sect: 0
227 n_desc: 256
228 n_value: 0
229 - n_strx: 774
230 n_type: 1
231 n_sect: 0
232 n_desc: 256
233 n_value: 0
234 - n_strx: 834
235 n_type: 1
236 n_sect: 0
237 n_desc: 256
238 n_value: 0
239 - n_strx: 851
240 n_type: 1
241 n_sect: 0
242 n_desc: 256
243 n_value: 0
244 - n_strx: 875
245 n_type: 1
246 n_sect: 0
247 n_desc: 256
248 n_value: 0
249 - n_strx: 897
250 n_type: 1
251 n_sect: 0
252 n_desc: 256
253 n_value: 0
254 - n_strx: 954
255 n_type: 1
256 n_sect: 0
257 n_desc: 256
258 n_value: 0
259 - n_strx: 982
260 n_type: 1
261 n_sect: 0
262 n_desc: 256
263 n_value: 0
264 - n_strx: 999
265 n_type: 1
266 n_sect: 0
267 n_desc: 256
268 n_value: 0
269 - n_strx: 1018
270 n_type: 1
271 n_sect: 0
272 n_desc: 256
273 n_value: 0
274 - n_strx: 1035
275 n_type: 1
276 n_sect: 0
277 n_desc: 256
278 n_value: 0
279 - n_strx: 1057
280 n_type: 1
281 n_sect: 0
282 n_desc: 512
283 n_value: 0
284 - n_strx: 1065
285 n_type: 1
286 n_sect: 0
287 n_desc: 512
288 n_value: 0
289 - n_strx: 1073
290 n_type: 1
291 n_sect: 0
292 n_desc: 512
293 n_value: 0
294 StringTable:
295 - ' '
296 - __ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc
297 - __ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m
298 - __ZNSt3__111char_traitsIcE6lengthEPKc
299 - __ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_
300 - ___clang_call_terminate
301 - __ZNSt3__111char_traitsIcE11eq_int_typeEii
302 - __ZNSt3__111char_traitsIcE3eofEv
303 - GCC_except_table2
304 - GCC_except_table4
305 - __mh_execute_header
306 - _main
307 - __Unwind_Resume
308 - __ZNKSt3__16locale9use_facetERNS0_2idE
309 - __ZNKSt3__18ios_base6getlocEv
310 - __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc
311 - __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
312 - __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryC1ERS3_
313 - __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD1Ev
314 - __ZNSt3__14coutE
315 - __ZNSt3__15ctypeIcE2idE
316 - __ZNSt3__16localeD1Ev
317 - __ZNSt3__18ios_base33__set_badbit_and_consider_rethrowEv
318 - __ZNSt3__18ios_base5clearEj
319 - __ZSt9terminatev
320 - ___cxa_begin_catch
321 - ___cxa_end_catch
322 - ___gxx_personality_v0
323 - _memset
324 - _strlen
325 - dyld_stub_binder
326 ...
327
328 #CHECK: NameList:
329 #CHECK: - n_strx: 2
330 #CHECK: n_type: 30
331 #CHECK: n_sect: 1
332 #CHECK: n_desc: 128
333 #CHECK: n_value: 4294971808
334 #CHECK: - n_strx: 69
335 #CHECK: n_type: 30
336 #CHECK: n_sect: 1
337 #CHECK: n_desc: 128
338 #CHECK: n_value: 4294971888
339 #CHECK: - n_strx: 166
340 #CHECK: n_type: 30
341 #CHECK: n_sect: 1
342 #CHECK: n_desc: 128
343 #CHECK: n_value: 4294973024
344 #CHECK: - n_strx: 204
345 #CHECK: n_type: 30
346 #CHECK: n_sect: 1
347 #CHECK: n_desc: 128
348 #CHECK: n_value: 4294973056
349 #CHECK: - n_strx: 320
350 #CHECK: n_type: 30
351 #CHECK: n_sect: 1
352 #CHECK: n_desc: 128
353 #CHECK: n_value: 4294974784
354 #CHECK: - n_strx: 344
355 #CHECK: n_type: 30
356 #CHECK: n_sect: 1
357 #CHECK: n_desc: 128
358 #CHECK: n_value: 4294974800
359 #CHECK: - n_strx: 387
360 #CHECK: n_type: 30
361 #CHECK: n_sect: 1
362 #CHECK: n_desc: 128
363 #CHECK: n_value: 4294974832
364 #CHECK: - n_strx: 420
365 #CHECK: n_type: 14
366 #CHECK: n_sect: 4
367 #CHECK: n_desc: 0
368 #CHECK: n_value: 4294975104
369 #CHECK: - n_strx: 438
370 #CHECK: n_type: 14
371 #CHECK: n_sect: 4
372 #CHECK: n_desc: 0
373 #CHECK: n_value: 4294975280
374 #CHECK: - n_strx: 456
375 #CHECK: n_type: 15
376 #CHECK: n_sect: 1
377 #CHECK: n_desc: 16
378 #CHECK: n_value: 4294967296
379 #CHECK: - n_strx: 476
380 #CHECK: n_type: 15
381 #CHECK: n_sect: 1
382 #CHECK: n_desc: 0
383 #CHECK: n_value: 4294971744
384 #CHECK: - n_strx: 482
385 #CHECK: n_type: 1
386 #CHECK: n_sect: 0
387 #CHECK: n_desc: 512
388 #CHECK: n_value: 0
389 #CHECK: - n_strx: 498
390 #CHECK: n_type: 1
391 #CHECK: n_sect: 0
392 #CHECK: n_desc: 256
393 #CHECK: n_value: 0
394 #CHECK: - n_strx: 537
395 #CHECK: n_type: 1
396 #CHECK: n_sect: 0
397 #CHECK: n_desc: 256
398 #CHECK: n_value: 0
399 #CHECK: - n_strx: 567
400 #CHECK: n_type: 1
401 #CHECK: n_sect: 0
402 #CHECK: n_desc: 256
403 #CHECK: n_value: 0
404 #CHECK: - n_strx: 642
405 #CHECK: n_type: 1
406 #CHECK: n_sect: 0
407 #CHECK: n_desc: 256
408 #CHECK: n_value: 0
409 #CHECK: - n_strx: 711
410 #CHECK: n_type: 1
411 #CHECK: n_sect: 0
412 #CHECK: n_desc: 256
413 #CHECK: n_value: 0
414 #CHECK: - n_strx: 774
415 #CHECK: n_type: 1
416 #CHECK: n_sect: 0
417 #CHECK: n_desc: 256
418 #CHECK: n_value: 0
419 #CHECK: - n_strx: 834
420 #CHECK: n_type: 1
421 #CHECK: n_sect: 0
422 #CHECK: n_desc: 256
423 #CHECK: n_value: 0
424 #CHECK: - n_strx: 851
425 #CHECK: n_type: 1
426 #CHECK: n_sect: 0
427 #CHECK: n_desc: 256
428 #CHECK: n_value: 0
429 #CHECK: - n_strx: 875
430 #CHECK: n_type: 1
431 #CHECK: n_sect: 0
432 #CHECK: n_desc: 256
433 #CHECK: n_value: 0
434 #CHECK: - n_strx: 897
435 #CHECK: n_type: 1
436 #CHECK: n_sect: 0
437 #CHECK: n_desc: 256
438 #CHECK: n_value: 0
439 #CHECK: - n_strx: 954
440 #CHECK: n_type: 1
441 #CHECK: n_sect: 0
442 #CHECK: n_desc: 256
443 #CHECK: n_value: 0
444 #CHECK: - n_strx: 982
445 #CHECK: n_type: 1
446 #CHECK: n_sect: 0
447 #CHECK: n_desc: 256
448 #CHECK: n_value: 0
449 #CHECK: - n_strx: 999
450 #CHECK: n_type: 1
451 #CHECK: n_sect: 0
452 #CHECK: n_desc: 256
453 #CHECK: n_value: 0
454 #CHECK: - n_strx: 1018
455 #CHECK: n_type: 1
456 #CHECK: n_sect: 0
457 #CHECK: n_desc: 256
458 #CHECK: n_value: 0
459 #CHECK: - n_strx: 1035
460 #CHECK: n_type: 1
461 #CHECK: n_sect: 0
462 #CHECK: n_desc: 256
463 #CHECK: n_value: 0
464 #CHECK: - n_strx: 1057
465 #CHECK: n_type: 1
466 #CHECK: n_sect: 0
467 #CHECK: n_desc: 512
468 #CHECK: n_value: 0
469 #CHECK: - n_strx: 1065
470 #CHECK: n_type: 1
471 #CHECK: n_sect: 0
472 #CHECK: n_desc: 512
473 #CHECK: n_value: 0
474 #CHECK: - n_strx: 1073
475 #CHECK: n_type: 1
476 #CHECK: n_sect: 0
477 #CHECK: n_desc: 512
478 #CHECK: n_value: 0
479 #CHECK: StringTable:
480 #CHECK: - ' '
481 #CHECK: - __ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc
482 #CHECK: - __ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m
483 #CHECK: - __ZNSt3__111char_traitsIcE6lengthEPKc
484 #CHECK: - __ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_
485 #CHECK: - ___clang_call_terminate
486 #CHECK: - __ZNSt3__111char_traitsIcE11eq_int_typeEii
487 #CHECK: - __ZNSt3__111char_traitsIcE3eofEv
488 #CHECK: - GCC_except_table2
489 #CHECK: - GCC_except_table4
490 #CHECK: - __mh_execute_header
491 #CHECK: - _main
492 #CHECK: - __Unwind_Resume
493 #CHECK: - __ZNKSt3__16locale9use_facetERNS0_2idE
494 #CHECK: - __ZNKSt3__18ios_base6getlocEv
495 #CHECK: - __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc
496 #CHECK: - __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
497 #CHECK: - __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryC1ERS3_
498 #CHECK: - __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD1Ev
499 #CHECK: - __ZNSt3__14coutE
500 #CHECK: - __ZNSt3__15ctypeIcE2idE
501 #CHECK: - __ZNSt3__16localeD1Ev
502 #CHECK: - __ZNSt3__18ios_base33__set_badbit_and_consider_rethrowEv
503 #CHECK: - __ZNSt3__18ios_base5clearEj
504 #CHECK: - __ZSt9terminatev
505 #CHECK: - ___cxa_begin_catch
506 #CHECK: - ___cxa_end_catch
507 #CHECK: - ___gxx_personality_v0
508 #CHECK: - _memset
509 #CHECK: - _strlen
510 #CHECK: - dyld_stub_binder
3232 void dumpBindOpcodes(std::vector &BindOpcodes,
3333 ArrayRef OpcodeBuffer, bool Lazy = false);
3434 void dumpExportTrie(std::unique_ptr &Y);
35 void dumpSymbols(std::unique_ptr &Y);
3536
3637 public:
3738 MachODumper(const object::MachOObjectFile &O) : Obj(O) {}
209210 dumpBindOpcodes(Y->LinkEdit.LazyBindOpcodes, Obj.getDyldInfoLazyBindOpcodes(),
210211 true);
211212 dumpExportTrie(Y);
213 dumpSymbols(Y);
212214 }
213215
214216 void MachODumper::dumpRebaseOpcodes(std::unique_ptr &Y) {
423425 processExportNode(ExportsTrie.begin(), ExportsTrie.end(), LEData.ExportTrie);
424426 }
425427
428 template
429 MachOYAML::NListEntry constructNameList(const nlist_t &nlist) {
430 MachOYAML::NListEntry NL;
431 NL.n_strx = nlist.n_strx;
432 NL.n_type = nlist.n_type;
433 NL.n_sect = nlist.n_sect;
434 NL.n_desc = nlist.n_desc;
435 NL.n_value = nlist.n_value;
436 return NL;
437 }
438
439 void MachODumper::dumpSymbols(std::unique_ptr &Y) {
440 MachOYAML::LinkEditData &LEData = Y->LinkEdit;
441
442 for (auto Symbol : Obj.symbols()) {
443 MachOYAML::NListEntry NLE =
444 Obj.is64Bit() ? constructNameList(
445 *reinterpret_cast(
446 Symbol.getRawDataRefImpl().p))
447 : constructNameList(
448 *reinterpret_cast(
449 Symbol.getRawDataRefImpl().p));
450 LEData.NameList.push_back(NLE);
451 }
452
453 StringRef RemainingTable = Obj.getStringTableData();
454 while (RemainingTable.size() > 0) {
455 auto SymbolPair = RemainingTable.split('\0');
456 RemainingTable = SymbolPair.second;
457 if (SymbolPair.first.empty())
458 break;
459 LEData.StringTable.push_back(SymbolPair.first);
460 }
461 }
462
426463 Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {
427464 MachODumper Dumper(Obj);
428465 Expected> YAML = Dumper.dump();
164164
165165 template <>
166166 size_t writeLoadCommandData(MachOYAML::LoadCommand &LC,
167 raw_ostream &OS) {
167 raw_ostream &OS) {
168168 return writePayloadString(LC, OS);
169169 }
170170
294294 }
295295 }
296296
297 void MachOWriter::dumpExportEntry(raw_ostream &OS, MachOYAML::ExportEntry &Entry) {
297 void MachOWriter::dumpExportEntry(raw_ostream &OS,
298 MachOYAML::ExportEntry &Entry) {
298299 encodeSLEB128(Entry.TerminalSize, OS);
299300 if (Entry.TerminalSize > 0) {
300301 encodeSLEB128(Entry.Flags, OS);
301 if ( Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT ) {
302 if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT) {
302303 encodeSLEB128(Entry.Other, OS);
303304 OS << Entry.ImportName;
304305 OS.write('\0');
305 }
306 else {
306 } else {
307307 encodeSLEB128(Entry.Address, OS);
308308 if (Entry.Flags & MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER)
309309 encodeSLEB128(Entry.Other, OS);
310310 }
311311 }
312312 OS.write(static_cast(Entry.Children.size()));
313 for (auto EE : Entry.Children){
313 for (auto EE : Entry.Children) {
314314 OS << EE.Name;
315315 OS.write('\0');
316316 encodeSLEB128(EE.NodeOffset, OS);
322322 Error MachOWriter::writeExportTrie(raw_ostream &OS) {
323323 dumpExportEntry(OS, Obj.LinkEdit.ExportTrie);
324324 return Error::success();
325 }
326
327 template
328 void writeNListEntry(MachOYAML::NListEntry &NLE, raw_ostream &OS) {
329 NListType ListEntry;
330 ListEntry.n_strx = NLE.n_strx;
331 ListEntry.n_type = NLE.n_type;
332 ListEntry.n_sect = NLE.n_sect;
333 ListEntry.n_desc = NLE.n_desc;
334 ListEntry.n_value = NLE.n_value;
335 OS.write(reinterpret_cast(&ListEntry), sizeof(NListType));
325336 }
326337
327338 Error MachOWriter::writeLinkEditData(raw_ostream &OS) {
356367 LinkEdit.LazyBindOpcodes);
357368
358369 ZeroToOffset(OS, DyldInfoOnlyCmd->export_off);
359 if(auto Err = writeExportTrie(OS))
370 if (auto Err = writeExportTrie(OS))
360371 return Err;
372
373 ZeroToOffset(OS, SymtabCmd->symoff);
374
375 for (auto NLE : LinkEdit.NameList) {
376 if (is64Bit)
377 writeNListEntry(NLE, OS);
378 else
379 writeNListEntry(NLE, OS);
380 }
381
382 auto currOffset = OS.tell() - fileStart;
383 if (currOffset < SymtabCmd->stroff)
384 Fill(OS, SymtabCmd->stroff - currOffset, 0xDEADBEEFu);
385
386 for (auto Str : LinkEdit.StringTable) {
387 OS.write(Str.data(), Str.size());
388 OS.write('\0');
389 }
361390
362391 // Fill to the end of the string table
363392 ZeroToOffset(OS, SymtabCmd->stroff + SymtabCmd->strsize);