llvm.org GIT mirror llvm / 923a9ba
Revert "[obj2yaml] [yaml2obj] Support for MachO load command structures" This reverts commit r269782 because it broke bots with -fpermissive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269785 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 3 years ago
7 changed file(s) with 33 addition(s) and 590 deletion(s). Raw diff Collapse all Expand all
3434
3535 struct LoadCommand {
3636 virtual ~LoadCommand();
37 llvm::MachO::macho_load_command load_command_data;
37 MachO::LoadCommandType cmd;
38 uint32_t cmdsize;
3839 };
3940
4041 struct Object {
4142 FileHeader Header;
42 std::vector<LoadCommand> LoadCommands;
43 std::vector<std::unique_ptr> LoadCommands;
4344 };
4445
4546 } // namespace llvm::MachOYAML
4647 } // namespace llvm
4748
48 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
49 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
4950
5051 namespace llvm {
5152 namespace yaml {
5859 static void mapping(IO &IO, MachOYAML::Object &Object);
5960 };
6061
61 template <> struct MappingTraits {
62 static void mapping(IO &IO, MachOYAML::LoadCommand &LoadCommand);
62 template <> struct MappingTraits> {
63 static void mapping(IO &IO,
64 std::unique_ptr &LoadCommand);
6365 };
6466
65 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
67 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
6668 io.enumCase(value, #LCName, MachO::LCName);
6769
6870 template <> struct ScalarEnumerationTraits {
7173 }
7274 };
7375
74 // This trait is used for 16-byte chars in Mach structures used for strings
75 typedef char char_16[16];
76
77 template <> struct ScalarTraits {
78 static void output(const char_16 &Val, void *, llvm::raw_ostream &Out);
79
80 static StringRef input(StringRef Scalar, void *, char_16 &Val);
81 static bool mustQuote(StringRef S);
82 };
83
84 // This trait is used for UUIDs. It reads and writes them matching otool's
85 // formatting style.
86 typedef uint8_t uuid_t[16];
87
88 template <> struct ScalarTraits {
89 static void output(const uuid_t &Val, void *, llvm::raw_ostream &Out);
90
91 static StringRef input(StringRef Scalar, void *, uuid_t &Val);
92 static bool mustQuote(StringRef S);
93 };
94
95 // Load Command struct mapping traits
96
97 #define LOAD_COMMAND_STRUCT(LCStruct) \
98 template <> struct MappingTraits { \
99 static void mapping(IO &IO, MachO::LCStruct &LoadCommand); \
100 };
101
102 #include "llvm/Support/MachO.def"
103
104 // Extra structures used by load commands
105 template <> struct MappingTraits {
106 static void mapping(IO &IO, MachO::dylib &LoadCommand);
107 };
108
109 template <> struct MappingTraits {
110 static void mapping(IO &IO, MachO::fvmlib &LoadCommand);
111 };
112
113 template <> struct MappingTraits {
114 static void mapping(IO &IO, MachO::section &LoadCommand);
115 };
116
117 template <> struct MappingTraits {
118 static void mapping(IO &IO, MachO::section_64 &LoadCommand);
119 };
76 #undef HANDLE_LOAD_COMMAND
12077
12178 } // namespace llvm::yaml
12279
1010 //
1111 //,,,----------------------------------------------------------------------,,,//
1212
13 #ifdef HANDLE_LOAD_COMMAND
13 #ifndef HANDLE_LOAD_COMMAND
14 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct)
15 #endif
1416
1517 HANDLE_LOAD_COMMAND(LC_SEGMENT, 0x00000001u, segment_command)
1618 HANDLE_LOAD_COMMAND(LC_SYMTAB, 0x00000002u, symtab_command)
6264 HANDLE_LOAD_COMMAND(LC_LINKER_OPTIMIZATION_HINT, 0x0000002Eu, linkedit_data_command)
6365 HANDLE_LOAD_COMMAND(LC_VERSION_MIN_TVOS, 0x0000002Fu, version_min_command)
6466 HANDLE_LOAD_COMMAND(LC_VERSION_MIN_WATCHOS, 0x00000030u, version_min_command)
65
66 #endif
67
68 #ifdef LOAD_COMMAND_STRUCT
69
70 LOAD_COMMAND_STRUCT(dyld_info_command)
71 LOAD_COMMAND_STRUCT(dylib_command)
72 LOAD_COMMAND_STRUCT(dylinker_command)
73 LOAD_COMMAND_STRUCT(dysymtab_command)
74 LOAD_COMMAND_STRUCT(encryption_info_command)
75 LOAD_COMMAND_STRUCT(encryption_info_command_64)
76 LOAD_COMMAND_STRUCT(entry_point_command)
77 LOAD_COMMAND_STRUCT(fvmfile_command)
78 LOAD_COMMAND_STRUCT(fvmlib_command)
79 LOAD_COMMAND_STRUCT(ident_command)
80 LOAD_COMMAND_STRUCT(linkedit_data_command)
81 LOAD_COMMAND_STRUCT(linker_option_command)
82 LOAD_COMMAND_STRUCT(load_command)
83 LOAD_COMMAND_STRUCT(prebind_cksum_command)
84 LOAD_COMMAND_STRUCT(prebound_dylib_command)
85 LOAD_COMMAND_STRUCT(routines_command)
86 LOAD_COMMAND_STRUCT(routines_command_64)
87 LOAD_COMMAND_STRUCT(rpath_command)
88 LOAD_COMMAND_STRUCT(segment_command)
89 LOAD_COMMAND_STRUCT(segment_command_64)
90 LOAD_COMMAND_STRUCT(source_version_command)
91 LOAD_COMMAND_STRUCT(sub_client_command)
92 LOAD_COMMAND_STRUCT(sub_framework_command)
93 LOAD_COMMAND_STRUCT(sub_library_command)
94 LOAD_COMMAND_STRUCT(sub_umbrella_command)
95 LOAD_COMMAND_STRUCT(symseg_command)
96 LOAD_COMMAND_STRUCT(symtab_command)
97 LOAD_COMMAND_STRUCT(thread_command)
98 LOAD_COMMAND_STRUCT(twolevel_hints_command)
99 LOAD_COMMAND_STRUCT(uuid_command)
100 LOAD_COMMAND_STRUCT(version_min_command)
101
102 #endif
103
104 #undef HANDLE_LOAD_COMMAND
105 #undef LOAD_COMMAND_STRUCT
16761676 const uint32_t x86_EXCEPTION_STATE_COUNT =
16771677 sizeof(x86_exception_state_t) / sizeof(uint32_t);
16781678
1679 // Define a union of all load command structs
1680 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct;
1681
1682 union macho_load_command {
1683 #include "llvm/Support/MachO.def"
1684 };
1685
16861679 } // end namespace MachO
16871680 } // end namespace llvm
16881681
1212
1313 #include "llvm/ObjectYAML/MachOYAML.h"
1414 #include "llvm/Support/Casting.h"
15 #include "llvm/Support/Format.h"
16
17 #include // For memcpy and memset.
1815
1916 namespace llvm {
2017
2118 MachOYAML::LoadCommand::~LoadCommand() {}
2219
2320 namespace yaml {
24
25 void ScalarTraits::output(const char_16 &Val, void *,
26 llvm::raw_ostream &Out) {
27 Out << Val;
28 }
29
30 StringRef ScalarTraits::input(StringRef Scalar, void *, char_16 &Val) {
31 size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
32 memcpy((void *)Val, Scalar.data(), CopySize);
33
34 if (Scalar.size() < 16) {
35 memset((void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
36 }
37
38 return StringRef();
39 }
40
41 bool ScalarTraits::mustQuote(StringRef S) { return needsQuotes(S); }
42
43 void ScalarTraits::output(const uuid_t &Val, void *,
44 llvm::raw_ostream &Out) {
45 for (int Idx = 0; Idx < 16; ++Idx) {
46 Out << format("%02" PRIX32, Val[Idx]);
47 if (Idx == 3 || Idx == 5 || Idx == 7 || Idx == 9)
48 Out << "-";
49 }
50 }
51
52 StringRef ScalarTraits::input(StringRef Scalar, void *, uuid_t &Val) {
53 size_t OutIdx = 0;
54 for (size_t Idx = 0; Idx < Scalar.size(); ++Idx) {
55 if (Scalar[Idx] == '-' || OutIdx >= 16)
56 continue;
57 unsigned long long TempInt;
58 if (getAsUnsignedInteger(Scalar.slice(Idx, Idx + 2), 16, TempInt))
59 return "invalid number";
60 if (TempInt > 0xFF)
61 return "out of range number";
62 Val[OutIdx] = static_cast(TempInt);
63 ++Idx; // increment idx an extra time because we're consuming 2 chars
64 ++OutIdx;
65 }
66 return StringRef();
67 }
68
69 bool ScalarTraits::mustQuote(StringRef S) { return needsQuotes(S); }
7021
7122 void MappingTraits::mapping(
7223 IO &IO, MachOYAML::FileHeader &FileHdr) {
9445 IO.setContext(nullptr);
9546 }
9647
97 void MappingTraits::mapping(
98 IO &IO, MachOYAML::LoadCommand &LoadCommand) {
99 IO.mapRequired(
100 "cmd",
101 (MachO::LoadCommandType &)LoadCommand.load_command_data.load_command.cmd);
102 IO.mapRequired("cmdsize", LoadCommand.load_command_data.load_command.cmdsize);
103
104 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
105 case MachO::LCName: \
106 MappingTraits::mapping( \
107 IO, LoadCommand.load_command_data.LCStruct); \
108 break;
109
110 switch (LoadCommand.load_command_data.load_command.cmd) {
111 #include "llvm/Support/MachO.def"
112 }
113 }
114
115 void MappingTraits::mapping(
116 IO &IO, MachO::dyld_info_command &LoadCommand) {
117 IO.mapRequired("rebase_off", LoadCommand.rebase_off);
118 IO.mapRequired("rebase_size", LoadCommand.rebase_size);
119 IO.mapRequired("bind_off", LoadCommand.bind_size);
120 IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
121 IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
122 IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_size);
123 IO.mapRequired("export_off", LoadCommand.export_off);
124 IO.mapRequired("export_size", LoadCommand.export_size);
125 }
126
127 void MappingTraits::mapping(IO &IO, MachO::dylib &DylibStruct) {
128 IO.mapRequired("name", DylibStruct.name);
129 IO.mapRequired("timestamp", DylibStruct.timestamp);
130 IO.mapRequired("current_version", DylibStruct.current_version);
131 IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
132 }
133
134 void MappingTraits::mapping(
135 IO &IO, MachO::dylib_command &LoadCommand) {
136 IO.mapRequired("dylib", LoadCommand.dylib);
137 }
138
139 void MappingTraits::mapping(
140 IO &IO, MachO::dylinker_command &LoadCommand) {
141
142 IO.mapRequired("name", LoadCommand.name);
143 }
144
145 void MappingTraits::mapping(
146 IO &IO, MachO::dysymtab_command &LoadCommand) {
147
148 IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
149 IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
150 IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
151 IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
152 IO.mapRequired("iundefsym", LoadCommand.iundefsym);
153 IO.mapRequired("nundefsym", LoadCommand.nundefsym);
154 IO.mapRequired("tocoff", LoadCommand.tocoff);
155 IO.mapRequired("ntoc", LoadCommand.ntoc);
156 IO.mapRequired("modtaboff", LoadCommand.modtaboff);
157 IO.mapRequired("nmodtab", LoadCommand.nmodtab);
158 IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
159 IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
160 IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
161 IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
162 IO.mapRequired("extreloff", LoadCommand.extreloff);
163 IO.mapRequired("nextrel", LoadCommand.nextrel);
164 IO.mapRequired("locreloff", LoadCommand.locreloff);
165 IO.mapRequired("nlocrel", LoadCommand.nlocrel);
166 }
167
168 void MappingTraits::mapping(
169 IO &IO, MachO::encryption_info_command &LoadCommand) {
170
171 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
172 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
173 IO.mapRequired("cryptid", LoadCommand.cryptid);
174 }
175
176 void MappingTraits::mapping(
177 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
178
179 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
180 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
181 IO.mapRequired("cryptid", LoadCommand.cryptid);
182 IO.mapRequired("pad", LoadCommand.pad);
183 }
184
185 void MappingTraits::mapping(
186 IO &IO, MachO::entry_point_command &LoadCommand) {
187
188 IO.mapRequired("entryoff", LoadCommand.entryoff);
189 IO.mapRequired("stacksize", LoadCommand.stacksize);
190 }
191
192 void MappingTraits::mapping(
193 IO &IO, MachO::fvmfile_command &LoadCommand) {
194
195 IO.mapRequired("name", LoadCommand.name);
196 IO.mapRequired("header_addr", LoadCommand.header_addr);
197 }
198
199 void MappingTraits::mapping(IO &IO, MachO::fvmlib &FVMLib) {
200 IO.mapRequired("name", FVMLib.name);
201 IO.mapRequired("minor_version", FVMLib.minor_version);
202 IO.mapRequired("header_addr", FVMLib.header_addr);
203 }
204
205 void MappingTraits::mapping(
206 IO &IO, MachO::fvmlib_command &LoadCommand) {
207
208 IO.mapRequired("fvmlib", LoadCommand.fvmlib);
209 }
210
211 void MappingTraits::mapping(
212 IO &IO, MachO::ident_command &LoadCommand) {}
213
214 void MappingTraits::mapping(
215 IO &IO, MachO::linkedit_data_command &LoadCommand) {
216
217 IO.mapRequired("dataoff", LoadCommand.dataoff);
218 IO.mapRequired("datasize", LoadCommand.datasize);
219 }
220
221 void MappingTraits::mapping(
222 IO &IO, MachO::linker_option_command &LoadCommand) {
223
224 IO.mapRequired("count", LoadCommand.count);
225 }
226
227 void MappingTraits::mapping(
228 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
229
230 IO.mapRequired("cksum", LoadCommand.cksum);
231 }
232
233 void MappingTraits::mapping(
234 IO &IO, MachO::load_command &LoadCommand) {}
235
236 void MappingTraits::mapping(
237 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
238
239 IO.mapRequired("name", LoadCommand.name);
240 IO.mapRequired("nmodules", LoadCommand.nmodules);
241 IO.mapRequired("linked_modules", LoadCommand.linked_modules);
242 }
243
244 void MappingTraits::mapping(
245 IO &IO, MachO::routines_command &LoadCommand) {
246
247 IO.mapRequired("init_address", LoadCommand.init_address);
248 IO.mapRequired("init_module", LoadCommand.init_module);
249 IO.mapRequired("reserved1", LoadCommand.reserved1);
250 IO.mapRequired("reserved2", LoadCommand.reserved2);
251 IO.mapRequired("reserved3", LoadCommand.reserved3);
252 IO.mapRequired("reserved4", LoadCommand.reserved4);
253 IO.mapRequired("reserved5", LoadCommand.reserved5);
254 IO.mapRequired("reserved6", LoadCommand.reserved6);
255 }
256
257 void MappingTraits::mapping(
258 IO &IO, MachO::routines_command_64 &LoadCommand) {
259
260 IO.mapRequired("init_address", LoadCommand.init_address);
261 IO.mapRequired("init_module", LoadCommand.init_module);
262 IO.mapRequired("reserved1", LoadCommand.reserved1);
263 IO.mapRequired("reserved2", LoadCommand.reserved2);
264 IO.mapRequired("reserved3", LoadCommand.reserved3);
265 IO.mapRequired("reserved4", LoadCommand.reserved4);
266 IO.mapRequired("reserved5", LoadCommand.reserved5);
267 IO.mapRequired("reserved6", LoadCommand.reserved6);
268 }
269
270 void MappingTraits::mapping(
271 IO &IO, MachO::rpath_command &LoadCommand) {
272
273 IO.mapRequired("path", LoadCommand.path);
274 }
275
276 void MappingTraits::mapping(IO &IO, MachO::section &Section) {
277 IO.mapRequired("sectname", Section.sectname);
278 IO.mapRequired("segname", Section.segname);
279 IO.mapRequired("addr", Section.addr);
280 IO.mapRequired("size", Section.size);
281 IO.mapRequired("offset", Section.offset);
282 IO.mapRequired("align", Section.align);
283 IO.mapRequired("reloff", Section.reloff);
284 IO.mapRequired("nreloc", Section.nreloc);
285 IO.mapRequired("flags", Section.flags);
286 IO.mapRequired("reserved1", Section.reserved1);
287 IO.mapRequired("reserved2", Section.reserved2);
288 }
289
290 void MappingTraits::mapping(IO &IO,
291 MachO::section_64 &Section) {
292 IO.mapRequired("sectname", Section.sectname);
293 IO.mapRequired("segname", Section.segname);
294 IO.mapRequired("addr", Section.addr);
295 IO.mapRequired("size", Section.size);
296 IO.mapRequired("offset", Section.offset);
297 IO.mapRequired("align", Section.align);
298 IO.mapRequired("reloff", Section.reloff);
299 IO.mapRequired("nreloc", Section.nreloc);
300 IO.mapRequired("flags", Section.flags);
301 IO.mapRequired("reserved1", Section.reserved1);
302 IO.mapRequired("reserved2", Section.reserved2);
303 IO.mapRequired("reserved3", Section.reserved3);
304 }
305
306 void MappingTraits::mapping(
307 IO &IO, MachO::segment_command &LoadCommand) {
308
309 IO.mapRequired("segname", LoadCommand.segname);
310 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
311 IO.mapRequired("vmsize", LoadCommand.vmsize);
312 IO.mapRequired("fileoff", LoadCommand.fileoff);
313 IO.mapRequired("filesize", LoadCommand.filesize);
314 IO.mapRequired("maxprot", LoadCommand.maxprot);
315 IO.mapRequired("initprot", LoadCommand.initprot);
316 IO.mapRequired("nsects", LoadCommand.nsects);
317 IO.mapRequired("flags", LoadCommand.flags);
318 }
319
320 void MappingTraits::mapping(
321 IO &IO, MachO::segment_command_64 &LoadCommand) {
322
323 IO.mapRequired("segname", LoadCommand.segname);
324 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
325 IO.mapRequired("vmsize", LoadCommand.vmsize);
326 IO.mapRequired("fileoff", LoadCommand.fileoff);
327 IO.mapRequired("filesize", LoadCommand.filesize);
328 IO.mapRequired("maxprot", LoadCommand.maxprot);
329 IO.mapRequired("initprot", LoadCommand.initprot);
330 IO.mapRequired("nsects", LoadCommand.nsects);
331 IO.mapRequired("flags", LoadCommand.flags);
332 }
333
334 void MappingTraits::mapping(
335 IO &IO, MachO::source_version_command &LoadCommand) {
336
337 IO.mapRequired("version", LoadCommand.version);
338 }
339
340 void MappingTraits::mapping(
341 IO &IO, MachO::sub_client_command &LoadCommand) {
342
343 IO.mapRequired("client", LoadCommand.client);
344 }
345
346 void MappingTraits::mapping(
347 IO &IO, MachO::sub_framework_command &LoadCommand) {
348
349 IO.mapRequired("umbrella", LoadCommand.umbrella);
350 }
351
352 void MappingTraits::mapping(
353 IO &IO, MachO::sub_library_command &LoadCommand) {
354
355 IO.mapRequired("sub_library", LoadCommand.sub_library);
356 }
357
358 void MappingTraits::mapping(
359 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
360
361 IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
362 }
363
364 void MappingTraits::mapping(
365 IO &IO, MachO::symseg_command &LoadCommand) {
366
367 IO.mapRequired("offset", LoadCommand.offset);
368 IO.mapRequired("size", LoadCommand.size);
369 }
370
371 void MappingTraits::mapping(
372 IO &IO, MachO::symtab_command &LoadCommand) {
373
374 IO.mapRequired("symoff", LoadCommand.symoff);
375 IO.mapRequired("nsyms", LoadCommand.nsyms);
376 IO.mapRequired("stroff", LoadCommand.stroff);
377 IO.mapRequired("strsize", LoadCommand.strsize);
378 }
379
380 void MappingTraits::mapping(
381 IO &IO, MachO::thread_command &LoadCommand) {}
382
383 void MappingTraits::mapping(
384 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
385
386 IO.mapRequired("offset", LoadCommand.offset);
387 IO.mapRequired("nhints", LoadCommand.nhints);
388 }
389
390 void MappingTraits::mapping(
391 IO &IO, MachO::uuid_command &LoadCommand) {
392
393 IO.mapRequired("cmdsize", LoadCommand.cmdsize);
394 IO.mapRequired("uuid", LoadCommand.uuid);
395 }
396
397 void MappingTraits::mapping(
398 IO &IO, MachO::version_min_command &LoadCommand) {
399
400 IO.mapRequired("version", LoadCommand.version);
401 IO.mapRequired("sdk", LoadCommand.sdk);
48 void MappingTraits>::mapping(
49 IO &IO, std::unique_ptr &LoadCommand) {
50 if (!IO.outputting())
51 LoadCommand.reset(new MachOYAML::LoadCommand());
52 IO.mapRequired("cmd", LoadCommand->cmd);
53 IO.mapRequired("cmdsize", LoadCommand->cmdsize);
40254 }
40355
40456 } // namespace llvm::yaml
1212 LoadCommands:
1313 - cmd: LC_SEGMENT_64
1414 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
2415 - cmd: LC_SEGMENT_64
2516 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
3517 - cmd: LC_SEGMENT_64
3618 cmdsize: 312
37 segname: __DATA
38 vmaddr: 4294975488
39 vmsize: 4096
40 fileoff: 8192
41 filesize: 4096
42 maxprot: 7
43 initprot: 3
44 nsects: 3
45 flags: 0
4619 - cmd: LC_SEGMENT_64
4720 cmdsize: 72
48 segname: __LINKEDIT
49 vmaddr: 4294979584
50 vmsize: 4096
51 fileoff: 12288
52 filesize: 2508
53 maxprot: 7
54 initprot: 1
55 nsects: 0
56 flags: 0
5721 - cmd: LC_DYLD_INFO_ONLY
5822 cmdsize: 48
59 rebase_off: 12288
60 rebase_size: 8
61 bind_off: 96
62 weak_bind_off: 0
63 weak_bind_size: 0
64 lazy_bind_off: 624
65 export_off: 13016
66 export_size: 48
6723 - cmd: LC_SYMTAB
6824 cmdsize: 24
69 symoff: 13080
70 nsyms: 30
71 stroff: 13700
72 strsize: 1096
7325 - cmd: LC_DYSYMTAB
7426 cmdsize: 80
75 ilocalsym: 0
76 nlocalsym: 9
77 iextdefsym: 9
78 nextdefsym: 2
79 iundefsym: 11
80 nundefsym: 19
81 tocoff: 0
82 ntoc: 0
83 modtaboff: 0
84 nmodtab: 0
85 extrefsymoff: 0
86 nextrefsyms: 0
87 indirectsymoff: 13560
88 nindirectsyms: 35
89 extreloff: 0
90 nextrel: 0
91 locreloff: 0
92 nlocrel: 0
9327 - cmd: LC_LOAD_DYLINKER
9428 cmdsize: 32
95 name: 12
9629 - cmd: LC_UUID
9730 cmdsize: 24
98 cmdsize: 24
99 uuid: 461A1B28-822F-3F38-B670-645419E636F5
10031 - cmd: LC_VERSION_MIN_MACOSX
10132 cmdsize: 16
102 version: 658176
103 sdk: 658176
10433 - cmd: LC_SOURCE_VERSION
10534 cmdsize: 16
106 version: 0
10735 - cmd: LC_MAIN
10836 cmdsize: 24
109 entryoff: 4448
110 stacksize: 0
11137 - cmd: LC_LOAD_DYLIB
11238 cmdsize: 48
113 dylib:
114 name: 24
115 timestamp: 2
116 current_version: 7864576
117 compatibility_version: 65536
11839 - cmd: LC_LOAD_DYLIB
11940 cmdsize: 56
120 dylib:
121 name: 24
122 timestamp: 2
123 current_version: 80349697
124 compatibility_version: 65536
12541 - cmd: LC_FUNCTION_STARTS
12642 cmdsize: 16
127 dataoff: 13064
128 datasize: 16
12943 - cmd: LC_DATA_IN_CODE
13044 cmdsize: 16
131 dataoff: 13080
132 datasize: 0
13345 ...
134
13546
13647
13748 # CHECK: LoadCommands:
88
99 #include "Error.h"
1010 #include "obj2yaml.h"
11 #include "llvm/Support/ErrorHandling.h"
1112 #include "llvm/Object/MachOUniversal.h"
1213 #include "llvm/ObjectYAML/MachOYAML.h"
13 #include "llvm/Support/ErrorHandling.h"
1414
1515 using namespace llvm;
1616
2323 Expected> dump();
2424 };
2525
26 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
27 case MachO::LCName: \
28 memcpy((void *) & (LC.load_command_data.LCStruct), LoadCmd.Ptr, \
29 sizeof(MachO::LCStruct)); \
30 if (Obj.isLittleEndian() != sys::IsLittleEndianHost) \
31 MachO::swapStruct(LC.load_command_data.LCStruct); \
32 break;
33
3426 Expected> MachODumper::dump() {
3527 auto Y = make_unique();
3628 Y->Header.magic = Obj.getHeader().magic;
4234 Y->Header.flags = Obj.getHeader().flags;
4335 Y->Header.reserved = 0;
4436
45 for (auto LoadCmd : Obj.load_commands()) {
46 MachOYAML::LoadCommand LC;
47 switch (LoadCmd.C.cmd) {
48 default:
49 memcpy((void *)&(LC.load_command_data.load_command), LoadCmd.Ptr,
50 sizeof(MachO::load_command));
51 if (Obj.isLittleEndian() != sys::IsLittleEndianHost)
52 MachO::swapStruct(LC.load_command_data.load_command);
53 break;
54 #include "llvm/Support/MachO.def"
55 }
37 for (auto load_command : Obj.load_commands()) {
38 auto LC = make_unique();
39 LC->cmd = static_cast(load_command.C.cmd);
40 LC->cmdsize = load_command.C.cmdsize;
5641 Y->LoadCommands.push_back(std::move(LC));
5742 }
5843
7878
7979 Error MachOWriter::writeLoadCommands(raw_ostream &OS) {
8080 for (auto &LC : Obj.LoadCommands) {
81 size_t BytesWritten = 0;
82 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
83 case MachO::LCName: \
84 OS.write(reinterpret_cast(&(LC.load_command_data.LCStruct)), \
85 sizeof(MachO::LCStruct)); \
86 BytesWritten = sizeof(MachO::LCStruct); \
87 break;
88
89 switch (LC.load_command_data.load_command.cmd) {
90 default:
91 OS.write(
92 reinterpret_cast(&(LC.load_command_data.load_command)),
93 sizeof(MachO::load_command));
94 BytesWritten = sizeof(MachO::load_command);
95 break;
96 #include "llvm/Support/MachO.def"
97 }
98
99 auto BytesRemaining =
100 LC.load_command_data.load_command.cmdsize - BytesWritten;
101 if (BytesRemaining > 0) {
81 MachO::load_command LCTemp;
82 LCTemp.cmd = LC->cmd;
83 LCTemp.cmdsize = LC->cmdsize;
84 OS.write(reinterpret_cast(&LCTemp),
85 sizeof(MachO::load_command));
86 auto remaining_size = LC->cmdsize - sizeof(MachO::load_command);
87 if (remaining_size > 0) {
10288 // TODO: Replace all this once the load command data is present in yaml.
103 // For now I fill with 0xDEADBEEF because it is easy to spot on a hex
104 // viewer.
105 std::vector FillData;
106 FillData.insert(FillData.begin(), BytesRemaining / 4 + 1, 0xDEADBEEFu);
107 OS.write(reinterpret_cast(FillData.data()), BytesRemaining);
89 std::vector fill_data;
90 fill_data.insert(fill_data.begin(), remaining_size, 0);
91 OS.write(fill_data.data(), remaining_size);
10892 }
10993 }
11094 return Error::success();