]> git.saurik.com Git - apple/ld64.git/blob - src/abstraction/MachOFileAbstraction.hpp
50982a16b8ce8f8b1d586a4fed431feae13e95ab
[apple/ld64.git] / src / abstraction / MachOFileAbstraction.hpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005-2008 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 #ifndef __MACH_O_FILE_ABSTRACTION__
25 #define __MACH_O_FILE_ABSTRACTION__
26
27 #include <mach-o/loader.h>
28 #include <mach-o/nlist.h>
29 #include <mach-o/reloc.h>
30 #include <mach-o/fat.h>
31 #include <mach-o/stab.h>
32 #include <mach-o/reloc.h>
33 #include <mach-o/ppc/reloc.h>
34 #include <mach-o/x86_64/reloc.h>
35 #include <mach-o/arm/reloc.h>
36 #include <mach-o/compact_unwind_encoding.h>
37 #include <mach/machine.h>
38
39 #include "FileAbstraction.hpp"
40
41
42 // stuff that will eventually go away once newer cctools headers are widespread
43 #ifndef CPU_SUBTYPE_ARM_V5TEJ
44 #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
45 #endif
46 #ifndef CPU_SUBTYPE_ARM_XSCALE
47 #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
48 #endif
49 #ifndef CPU_SUBTYPE_ARM_V7
50 #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
51 #endif
52 #ifndef ARM_THUMB_32BIT_BRANCH
53 #define ARM_THUMB_32BIT_BRANCH 7
54 #endif
55 #ifndef N_ARM_THUMB_DEF
56 #define N_ARM_THUMB_DEF 0x0008
57 #endif
58 #ifndef MH_DEAD_STRIPPABLE_DYLIB
59 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
60 #endif
61 #ifndef MH_KEXT_BUNDLE
62 #define MH_KEXT_BUNDLE 11
63 #endif
64 #ifndef LC_DYLD_INFO
65 #define LC_DYLD_INFO 0x22 /* compressed dyld information */
66 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
67
68 struct dyld_info_command {
69 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
70 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
71 uint32_t rebase_off; /* file offset to rebase info */
72 uint32_t rebase_size; /* size of rebase info */
73 uint32_t bind_off; /* file offset to binding info */
74 uint32_t bind_size; /* size of binding info */
75 uint32_t weak_bind_off; /* file offset to weak binding info */
76 uint32_t weak_bind_size; /* size of weak binding info */
77 uint32_t lazy_bind_off; /* file offset to lazy binding info */
78 uint32_t lazy_bind_size; /* size of lazy binding infs */
79 uint32_t export_off; /* file offset to lazy binding info */
80 uint32_t export_size; /* size of lazy binding infs */
81 };
82
83 #define REBASE_TYPE_POINTER 1
84 #define REBASE_TYPE_TEXT_ABSOLUTE32 2
85 #define REBASE_TYPE_TEXT_PCREL32 3
86
87 #define REBASE_OPCODE_MASK 0xF0
88 #define REBASE_IMMEDIATE_MASK 0x0F
89 #define REBASE_OPCODE_DONE 0x00
90 #define REBASE_OPCODE_SET_TYPE_IMM 0x10
91 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
92 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
93 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
94 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
95 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
96 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
97 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
98
99 #define BIND_TYPE_POINTER 1
100 #define BIND_TYPE_TEXT_ABSOLUTE32 2
101 #define BIND_TYPE_TEXT_PCREL32 3
102
103 #define BIND_SPECIAL_DYLIB_SELF 0
104 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
105 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
106
107 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
108 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
109
110 #define BIND_OPCODE_MASK 0xF0
111 #define BIND_IMMEDIATE_MASK 0x0F
112 #define BIND_OPCODE_DONE 0x00
113 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
114 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
115 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
116 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
117 #define BIND_OPCODE_SET_TYPE_IMM 0x50
118 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60
119 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
120 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80
121 #define BIND_OPCODE_DO_BIND 0x90
122 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
123 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
124 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
125
126 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
127 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
128 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
129 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
130 #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
131 #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
132
133 #endif
134
135
136 //
137 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
138 //
139
140
141
142 //
143 // mach-o file header
144 //
145 template <typename P> struct macho_header_content {};
146 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
147 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
148 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
149 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
150
151 template <typename P>
152 class macho_header {
153 public:
154 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
155 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
156
157 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
158 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
159
160 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
161 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
162
163 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
164 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
165
166 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
167 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
168
169 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
170 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
171
172 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
173 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
174
175 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
176 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
177
178 typedef typename P::E E;
179 private:
180 macho_header_content<P> header;
181 };
182
183
184 //
185 // mach-o load command
186 //
187 template <typename P>
188 class macho_load_command {
189 public:
190 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
191 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
192
193 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
194 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
195
196 typedef typename P::E E;
197 private:
198 load_command command;
199 };
200
201
202 //
203 // mach-o segment load command
204 //
205 template <typename P> struct macho_segment_content {};
206 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
207 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
208 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
209 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
210
211 template <typename P>
212 class macho_segment_command {
213 public:
214 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
215 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
216
217 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
218 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
219
220 const char* segname() const INLINE { return segment.fields.segname; }
221 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
222
223 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
224 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
225
226 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
227 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
228
229 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
230 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
231
232 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
233 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
234
235 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
236 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
237
238 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
239 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
240
241 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
242 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
243
244 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
245 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
246
247 enum {
248 CMD = macho_segment_content<P>::CMD
249 };
250
251 typedef typename P::E E;
252 private:
253 macho_segment_content<P> segment;
254 };
255
256
257 //
258 // mach-o section
259 //
260 template <typename P> struct macho_section_content {};
261 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
262 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
263 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
264 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
265
266 template <typename P>
267 class macho_section {
268 public:
269 const char* sectname() const INLINE { return section.fields.sectname; }
270 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
271
272 const char* segname() const INLINE { return section.fields.segname; }
273 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
274
275 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
276 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
277
278 uint64_t size() const INLINE { return P::getP(section.fields.size); }
279 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
280
281 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
282 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
283
284 uint32_t align() const INLINE { return E::get32(section.fields.align); }
285 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
286
287 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
288 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
289
290 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
291 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
292
293 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
294 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
295
296 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
297 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
298
299 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
300 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
301
302 typedef typename P::E E;
303 private:
304 macho_section_content<P> section;
305 };
306
307
308 //
309 // mach-o dylib load command
310 //
311 template <typename P>
312 class macho_dylib_command {
313 public:
314 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
315 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
316
317 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
318 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
319
320 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
321 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
322
323 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
324 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
325
326 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
327 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
328
329 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
330 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
331
332 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
333 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
334
335 typedef typename P::E E;
336 private:
337 dylib_command fields;
338 };
339
340
341 //
342 // mach-o dylinker load command
343 //
344 template <typename P>
345 class macho_dylinker_command {
346 public:
347 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
348 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
349
350 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
351 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
352
353 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
354 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
355
356 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
357 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
358
359 typedef typename P::E E;
360 private:
361 dylinker_command fields;
362 };
363
364
365 //
366 // mach-o sub_framework load command
367 //
368 template <typename P>
369 class macho_sub_framework_command {
370 public:
371 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
372 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
373
374 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
375 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
376
377 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
378 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
379
380 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
381 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
382
383 typedef typename P::E E;
384 private:
385 sub_framework_command fields;
386 };
387
388
389 //
390 // mach-o sub_client load command
391 //
392 template <typename P>
393 class macho_sub_client_command {
394 public:
395 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
396 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
397
398 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
399 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
400
401 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
402 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
403
404 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
405 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
406
407 typedef typename P::E E;
408 private:
409 sub_client_command fields;
410 };
411
412
413 //
414 // mach-o sub_umbrella load command
415 //
416 template <typename P>
417 class macho_sub_umbrella_command {
418 public:
419 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
420 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
421
422 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
423 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
424
425 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
426 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
427
428 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
429 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
430
431 typedef typename P::E E;
432 private:
433 sub_umbrella_command fields;
434 };
435
436
437 //
438 // mach-o sub_library load command
439 //
440 template <typename P>
441 class macho_sub_library_command {
442 public:
443 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
444 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
445
446 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
447 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
448
449 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
450 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
451
452 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
453 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
454
455 typedef typename P::E E;
456 private:
457 sub_library_command fields;
458 };
459
460
461 //
462 // mach-o uuid load command
463 //
464 template <typename P>
465 class macho_uuid_command {
466 public:
467 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
468 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
469
470 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
471 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
472
473 const uint8_t* uuid() const INLINE { return fields.uuid; }
474 void set_uuid(uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
475
476 typedef typename P::E E;
477 private:
478 uuid_command fields;
479 };
480
481
482 //
483 // mach-o routines load command
484 //
485 template <typename P> struct macho_routines_content {};
486 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
487 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
488 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
489 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
490
491 template <typename P>
492 class macho_routines_command {
493 public:
494 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
495 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
496
497 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
498 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
499
500 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
501 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
502
503 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
504 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
505
506 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
507 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
508
509 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
510 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
511
512 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
513 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
514
515 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
516 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
517
518 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
519 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
520
521 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
522 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
523
524 typedef typename P::E E;
525 enum {
526 CMD = macho_routines_content<P>::CMD
527 };
528 private:
529 macho_routines_content<P> routines;
530 };
531
532
533 //
534 // mach-o symbol table load command
535 //
536 template <typename P>
537 class macho_symtab_command {
538 public:
539 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
540 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
541
542 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
543 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
544
545 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
546 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
547
548 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
549 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
550
551 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
552 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
553
554 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
555 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
556
557
558 typedef typename P::E E;
559 private:
560 symtab_command fields;
561 };
562
563
564 //
565 // mach-o dynamic symbol table load command
566 //
567 template <typename P>
568 class macho_dysymtab_command {
569 public:
570 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
571 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
572
573 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
574 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
575
576 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
577 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
578
579 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
580 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
581
582 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
583 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
584
585 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
586 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
587
588 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
589 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
590
591 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
592 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
593
594 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
595 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
596
597 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
598 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
599
600 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
601 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
602
603 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
604 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
605
606 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
607 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
608
609 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
610 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
611
612 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
613 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
614
615 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
616 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
617
618 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
619 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
620
621 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
622 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
623
624 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
625 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
626
627 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
628 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
629
630 typedef typename P::E E;
631 private:
632 dysymtab_command fields;
633 };
634
635
636
637
638 //
639 // mach-o module table entry (for compatibility with old ld/dyld)
640 //
641 template <typename P> struct macho_dylib_module_content {};
642 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
643 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
644 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
645 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
646
647 template <typename P>
648 class macho_dylib_module {
649 public:
650 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
651 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
652
653 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
654 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
655
656 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
657 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
658
659 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
660 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
661
662 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
663 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
664
665 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
666 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
667
668 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
669 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
670
671 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
672 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
673
674 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
675 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
676
677 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
678 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
679 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
680
681 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
682 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
683 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
684
685 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
686 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
687
688 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
689 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
690
691
692 typedef typename P::E E;
693 private:
694 macho_dylib_module_content<P> module;
695 };
696
697
698 //
699 // mach-o dylib_reference entry
700 //
701 template <typename P>
702 class macho_dylib_reference {
703 public:
704 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
705 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
706
707 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
708 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
709
710 typedef typename P::E E;
711 private:
712 uint32_t fields;
713 };
714
715
716
717 //
718 // mach-o two-level hints load command
719 //
720 template <typename P>
721 class macho_dylib_table_of_contents {
722 public:
723 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
724 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
725
726 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
727 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
728
729 typedef typename P::E E;
730 private:
731 dylib_table_of_contents fields;
732 };
733
734
735
736 //
737 // mach-o two-level hints load command
738 //
739 template <typename P>
740 class macho_twolevel_hints_command {
741 public:
742 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
743 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
744
745 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
746 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
747
748 uint32_t offset() const INLINE { return E::get32(fields.offset); }
749 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
750
751 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
752 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
753
754 typedef typename P::E E;
755 private:
756 twolevel_hints_command fields;
757 };
758
759
760 //
761 // mach-o threads load command
762 //
763 template <typename P>
764 class macho_thread_command {
765 public:
766 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
767 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
768
769 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
770 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
771
772 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
773 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
774
775 uint32_t count() const INLINE { return E::get32(fields_count); }
776 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
777
778 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
779 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
780
781 typedef typename P::E E;
782 typedef typename P::uint_t pint_t;
783 private:
784 struct thread_command fields;
785 uint32_t fields_flavor;
786 uint32_t fields_count;
787 pint_t thread_registers[1];
788 };
789
790
791 //
792 // mach-o misc data
793 //
794 template <typename P>
795 class macho_linkedit_data_command {
796 public:
797 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
798 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
799
800 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
801 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
802
803 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
804 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
805
806 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
807 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
808
809
810 typedef typename P::E E;
811 private:
812 struct linkedit_data_command fields;
813 };
814
815
816 //
817 // mach-o rpath
818 //
819 template <typename P>
820 class macho_rpath_command {
821 public:
822 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
823 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
824
825 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
826 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
827
828 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
829 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
830
831 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
832 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
833
834
835 typedef typename P::E E;
836 private:
837 struct rpath_command fields;
838 };
839
840
841
842 //
843 // mach-o symbol table entry
844 //
845 template <typename P> struct macho_nlist_content {};
846 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
847 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
848 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
849 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
850
851 template <typename P>
852 class macho_nlist {
853 public:
854 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
855 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
856
857 uint8_t n_type() const INLINE { return entry.fields.n_type; }
858 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
859
860 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
861 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
862
863 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
864 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
865
866 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
867 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
868
869 typedef typename P::E E;
870 private:
871 macho_nlist_content<P> entry;
872 };
873
874
875
876 //
877 // mach-o relocation info
878 //
879 template <typename P>
880 class macho_relocation_info {
881 public:
882 uint32_t r_address() const INLINE { return E::get32(address); }
883 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
884
885 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
886 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
887
888 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
889 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
890
891 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
892 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
893
894 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
895 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
896
897 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
898 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
899
900 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
901
902 typedef typename P::E E;
903 private:
904 uint32_t address;
905 uint32_t other;
906 };
907
908
909 //
910 // mach-o scattered relocation info
911 // The bit fields are always in big-endian order (see mach-o/reloc.h)
912 //
913 template <typename P>
914 class macho_scattered_relocation_info {
915 public:
916 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
917 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
918
919 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
920 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
921
922 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
923 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
924
925 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
926 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
927
928 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
929 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
930 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
931
932 uint32_t r_value() const INLINE { return E::get32(value); }
933 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
934
935 uint32_t r_other() const INLINE { return other; }
936
937 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
938
939 typedef typename P::E E;
940 private:
941 uint32_t other;
942 uint32_t value;
943 };
944
945
946
947 //
948 // mach-o encyrption info load command
949 //
950 template <typename P>
951 class macho_encryption_info_command {
952 public:
953 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
954 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
955
956 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
957 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
958
959 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
960 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
961
962 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
963 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
964
965 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
966 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
967
968 typedef typename P::E E;
969 private:
970 encryption_info_command fields;
971 };
972
973
974 //
975 // start of __unwind_info section
976 //
977 template <typename P>
978 class macho_unwind_info_section_header {
979 public:
980 uint32_t version() const INLINE { return E::get32(fields.version); }
981 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
982
983 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
984 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
985
986 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
987 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
988
989 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
990 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
991
992 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
993 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
994
995 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
996 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
997
998 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
999 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1000
1001 typedef typename P::E E;
1002 private:
1003 unwind_info_section_header fields;
1004 };
1005
1006
1007
1008 //
1009 // uwind first level index entry
1010 //
1011 template <typename P>
1012 class macho_unwind_info_section_header_index_entry {
1013 public:
1014 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1015 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1016
1017 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1018 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1019
1020 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1021 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1022
1023 typedef typename P::E E;
1024 private:
1025 unwind_info_section_header_index_entry fields;
1026 };
1027
1028
1029 //
1030 // LSDA table entry
1031 //
1032 template <typename P>
1033 class macho_unwind_info_section_header_lsda_index_entry {
1034 public:
1035 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1036 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1037
1038 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1039 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1040
1041 typedef typename P::E E;
1042 private:
1043 unwind_info_section_header_lsda_index_entry fields;
1044 };
1045
1046
1047 //
1048 // regular second level entry
1049 //
1050 template <typename P>
1051 class macho_unwind_info_regular_second_level_entry {
1052 public:
1053 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1054 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1055
1056 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1057 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1058
1059 typedef typename P::E E;
1060 private:
1061 unwind_info_regular_second_level_entry fields;
1062 };
1063
1064
1065 //
1066 // start of second level regular page
1067 //
1068 template <typename P>
1069 class macho_unwind_info_regular_second_level_page_header {
1070 public:
1071 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1072 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1073
1074 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1075 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1076
1077 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1078 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1079
1080 typedef typename P::E E;
1081 private:
1082 unwind_info_regular_second_level_page_header fields;
1083 };
1084
1085
1086 //
1087 // start of second level compressed page
1088 //
1089 template <typename P>
1090 class macho_unwind_info_compressed_second_level_page_header {
1091 public:
1092 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1093 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1094
1095 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1096 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1097
1098 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1099 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1100
1101 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1102 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1103
1104 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1105 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1106
1107 typedef typename P::E E;
1108 private:
1109 unwind_info_compressed_second_level_page_header fields;
1110 };
1111
1112
1113 //
1114 // compressed dyld info load command
1115 //
1116 template <typename P>
1117 class macho_dyld_info_command {
1118 public:
1119 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1120 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1121
1122 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1123 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1124
1125 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1126 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1127
1128 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1129 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1130
1131 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1132 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1133
1134 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1135 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1136
1137 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1138 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1139
1140 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1141 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1142
1143 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1144 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1145
1146 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1147 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1148
1149 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1150 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1151
1152 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1153 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1154
1155
1156 typedef typename P::E E;
1157 private:
1158 dyld_info_command fields;
1159 };
1160
1161
1162
1163
1164 #endif // __MACH_O_FILE_ABSTRACTION__
1165
1166