1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __MACH_O_FILE_ABSTRACTION__
25 #define __MACH_O_FILE_ABSTRACTION__
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/x86_64/reloc.h>
34 #include <mach-o/arm/reloc.h>
35 #include <mach-o/compact_unwind_encoding.h>
36 #include <mach/machine.h>
39 #include "FileAbstraction.hpp"
42 // stuff that will eventually go away once newer cctools headers are widespread
43 #ifndef LC_LOAD_UPWARD_DYLIB
44 #define LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD) /* load of dylib whose initializers run later */
47 #ifndef CPU_SUBTYPE_ARM_V5TEJ
48 #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
50 #ifndef CPU_SUBTYPE_ARM_XSCALE
51 #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
53 #ifndef CPU_SUBTYPE_ARM_V7
54 #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
57 #ifndef ARM_THUMB_32BIT_BRANCH
58 #define ARM_THUMB_32BIT_BRANCH 7
60 #ifndef N_ARM_THUMB_DEF
61 #define N_ARM_THUMB_DEF 0x0008
63 #ifndef MH_DEAD_STRIPPABLE_DYLIB
64 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
66 #ifndef MH_KEXT_BUNDLE
67 #define MH_KEXT_BUNDLE 11
70 #define LC_DYLD_INFO 0x22 /* compressed dyld information */
71 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
73 struct dyld_info_command {
74 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
75 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
76 uint32_t rebase_off; /* file offset to rebase info */
77 uint32_t rebase_size; /* size of rebase info */
78 uint32_t bind_off; /* file offset to binding info */
79 uint32_t bind_size; /* size of binding info */
80 uint32_t weak_bind_off; /* file offset to weak binding info */
81 uint32_t weak_bind_size; /* size of weak binding info */
82 uint32_t lazy_bind_off; /* file offset to lazy binding info */
83 uint32_t lazy_bind_size; /* size of lazy binding infs */
84 uint32_t export_off; /* file offset to lazy binding info */
85 uint32_t export_size; /* size of lazy binding infs */
88 #define REBASE_TYPE_POINTER 1
89 #define REBASE_TYPE_TEXT_ABSOLUTE32 2
90 #define REBASE_TYPE_TEXT_PCREL32 3
92 #define REBASE_OPCODE_MASK 0xF0
93 #define REBASE_IMMEDIATE_MASK 0x0F
94 #define REBASE_OPCODE_DONE 0x00
95 #define REBASE_OPCODE_SET_TYPE_IMM 0x10
96 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
97 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
98 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
99 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
100 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
101 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
102 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
104 #define BIND_TYPE_POINTER 1
105 #define BIND_TYPE_TEXT_ABSOLUTE32 2
106 #define BIND_TYPE_TEXT_PCREL32 3
108 #define BIND_SPECIAL_DYLIB_SELF 0
109 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
110 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
112 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
113 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
115 #define BIND_OPCODE_MASK 0xF0
116 #define BIND_IMMEDIATE_MASK 0x0F
117 #define BIND_OPCODE_DONE 0x00
118 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
119 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
120 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
121 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
122 #define BIND_OPCODE_SET_TYPE_IMM 0x50
123 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60
124 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
125 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80
126 #define BIND_OPCODE_DO_BIND 0x90
127 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
128 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
129 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
131 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
132 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
133 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
134 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
135 #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
136 #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
140 #ifndef S_THREAD_LOCAL_REGULAR
141 #define S_THREAD_LOCAL_REGULAR 0x11
144 #ifndef S_THREAD_LOCAL_ZEROFILL
145 #define S_THREAD_LOCAL_ZEROFILL 0x12
148 #ifndef S_THREAD_LOCAL_VARIABLES
149 #define S_THREAD_LOCAL_VARIABLES 0x13
152 #ifndef S_THREAD_LOCAL_VARIABLE_POINTERS
153 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
156 #ifndef S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
157 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
160 #ifndef MH_HAS_TLV_DESCRIPTORS
161 #define MH_HAS_TLV_DESCRIPTORS 0x800000
164 #ifndef X86_64_RELOC_TLV
165 #define X86_64_RELOC_TLV 9
168 #define GENERIC_RLEOC_TLV 5
170 #ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
171 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
174 #ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
175 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
178 // type internal to linker
179 #define BIND_TYPE_OVERRIDE_OF_WEAKDEF_IN_DYLIB 0
181 #ifndef LC_VERSION_MIN_MACOSX
182 #define LC_VERSION_MIN_MACOSX 0x24
183 #define LC_VERSION_MIN_IPHONEOS 0x25
185 struct version_min_command {
186 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS */
187 uint32_t cmdsize; /* sizeof(struct min_version_command) */
188 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
189 uint32_t reserved; /* zero */
193 #ifndef N_SYMBOL_RESOLVER
194 #define N_SYMBOL_RESOLVER 0x100
197 #ifndef LC_FUNCTION_STARTS
198 #define LC_FUNCTION_STARTS 0x26
201 #ifndef MH_NO_HEAP_EXECUTION
202 #define MH_NO_HEAP_EXECUTION 0x1000000
205 #ifndef LC_DYLD_ENVIRONMENT
206 #define LC_DYLD_ENVIRONMENT 0x27
209 // hack until newer <mach-o/arm/reloc.h> everywhere
210 #define ARM_RELOC_HALF 8
211 #define ARM_RELOC_HALF_SECTDIFF 9
213 #ifndef CPU_SUBTYPE_ARM_V7F
214 #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
216 #ifndef CPU_SUBTYPE_ARM_V7K
217 #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
221 const char* subTypeName;
222 const char* llvmTriplePrefix;
223 cpu_subtype_t subType;
227 static const ARMSubType ARMSubTypes[] = {
228 { "armv4t","armv4t-", CPU_SUBTYPE_ARM_V4T, false },
229 { "armv5", "armv5e-", CPU_SUBTYPE_ARM_V5TEJ, false },
230 { "armv6", "armv6-", CPU_SUBTYPE_ARM_V6, false },
231 { "armv7", "thumbv7-", CPU_SUBTYPE_ARM_V7, true },
232 { "armv7f", "thumbv7f-", CPU_SUBTYPE_ARM_V7F, true },
233 { "armv7k", "thumbv7k-", CPU_SUBTYPE_ARM_V7K, true },
241 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
247 // mach-o file header
249 template <typename P> struct macho_header_content {};
250 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
251 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
252 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
253 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
255 template <typename P>
258 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
259 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
261 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
262 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
264 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
265 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
267 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
268 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
270 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
271 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
273 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
274 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
276 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
277 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
279 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
280 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
282 typedef typename P::E E;
284 macho_header_content<P> header;
289 // mach-o load command
291 template <typename P>
292 class macho_load_command {
294 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
295 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
297 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
298 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
300 typedef typename P::E E;
302 load_command command;
307 // mach-o segment load command
309 template <typename P> struct macho_segment_content {};
310 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
311 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
312 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
313 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
315 template <typename P>
316 class macho_segment_command {
318 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
319 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
321 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
322 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
324 const char* segname() const INLINE { return segment.fields.segname; }
325 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
327 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
328 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
330 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
331 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
333 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
334 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
336 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
337 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
339 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
340 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
342 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
343 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
345 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
346 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
348 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
349 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
352 CMD = macho_segment_content<P>::CMD
355 typedef typename P::E E;
357 macho_segment_content<P> segment;
364 template <typename P> struct macho_section_content {};
365 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
366 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
367 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
368 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
370 template <typename P>
371 class macho_section {
373 const char* sectname() const INLINE { return section.fields.sectname; }
374 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
376 const char* segname() const INLINE { return section.fields.segname; }
377 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
379 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
380 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
382 uint64_t size() const INLINE { return P::getP(section.fields.size); }
383 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
385 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
386 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
388 uint32_t align() const INLINE { return E::get32(section.fields.align); }
389 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
391 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
392 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
394 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
395 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
397 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
398 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
400 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
401 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
403 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
404 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
406 typedef typename P::E E;
408 macho_section_content<P> section;
413 // mach-o dylib load command
415 template <typename P>
416 class macho_dylib_command {
418 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
419 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
421 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
422 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
424 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
425 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
427 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
428 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
430 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
431 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
433 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
434 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
436 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
437 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
439 typedef typename P::E E;
441 dylib_command fields;
446 // mach-o dylinker load command
448 template <typename P>
449 class macho_dylinker_command {
451 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
452 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
454 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
455 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
457 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
458 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
460 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
461 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
463 typedef typename P::E E;
465 dylinker_command fields;
470 // mach-o sub_framework load command
472 template <typename P>
473 class macho_sub_framework_command {
475 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
476 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
478 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
479 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
481 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
482 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
484 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
485 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
487 typedef typename P::E E;
489 sub_framework_command fields;
494 // mach-o sub_client load command
496 template <typename P>
497 class macho_sub_client_command {
499 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
500 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
502 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
503 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
505 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
506 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
508 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
509 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
511 typedef typename P::E E;
513 sub_client_command fields;
518 // mach-o sub_umbrella load command
520 template <typename P>
521 class macho_sub_umbrella_command {
523 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
524 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
526 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
527 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
529 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
530 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
532 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
533 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
535 typedef typename P::E E;
537 sub_umbrella_command fields;
542 // mach-o sub_library load command
544 template <typename P>
545 class macho_sub_library_command {
547 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
548 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
550 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
551 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
553 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
554 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
556 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
557 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
559 typedef typename P::E E;
561 sub_library_command fields;
566 // mach-o uuid load command
568 template <typename P>
569 class macho_uuid_command {
571 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
572 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
574 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
575 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
577 const uint8_t* uuid() const INLINE { return fields.uuid; }
578 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
580 typedef typename P::E E;
587 // mach-o routines load command
589 template <typename P> struct macho_routines_content {};
590 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
591 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
592 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
593 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
595 template <typename P>
596 class macho_routines_command {
598 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
599 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
601 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
602 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
604 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
605 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
607 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
608 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
610 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
611 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
613 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
614 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
616 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
617 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
619 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
620 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
622 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
623 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
625 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
626 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
628 typedef typename P::E E;
630 CMD = macho_routines_content<P>::CMD
633 macho_routines_content<P> routines;
638 // mach-o symbol table load command
640 template <typename P>
641 class macho_symtab_command {
643 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
644 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
646 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
647 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
649 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
650 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
652 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
653 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
655 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
656 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
658 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
659 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
662 typedef typename P::E E;
664 symtab_command fields;
669 // mach-o dynamic symbol table load command
671 template <typename P>
672 class macho_dysymtab_command {
674 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
675 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
677 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
678 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
680 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
681 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
683 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
684 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
686 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
687 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
689 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
690 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
692 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
693 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
695 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
696 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
698 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
699 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
701 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
702 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
704 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
705 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
707 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
708 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
710 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
711 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
713 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
714 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
716 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
717 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
719 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
720 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
722 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
723 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
725 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
726 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
728 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
729 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
731 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
732 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
734 typedef typename P::E E;
736 dysymtab_command fields;
743 // mach-o module table entry (for compatibility with old ld/dyld)
745 template <typename P> struct macho_dylib_module_content {};
746 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
747 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
748 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
749 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
751 template <typename P>
752 class macho_dylib_module {
754 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
755 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
757 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
758 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
760 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
761 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
763 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
764 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
766 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
767 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
769 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
770 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
772 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
773 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
775 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
776 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
778 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
779 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
781 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
782 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
783 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
785 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
786 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
787 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
789 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
790 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
792 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
793 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
796 typedef typename P::E E;
798 macho_dylib_module_content<P> module;
803 // mach-o dylib_reference entry
805 template <typename P>
806 class macho_dylib_reference {
808 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
809 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
811 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
812 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
814 typedef typename P::E E;
822 // mach-o two-level hints load command
824 template <typename P>
825 class macho_dylib_table_of_contents {
827 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
828 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
830 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
831 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
833 typedef typename P::E E;
835 dylib_table_of_contents fields;
841 // mach-o two-level hints load command
843 template <typename P>
844 class macho_twolevel_hints_command {
846 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
847 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
849 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
850 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
852 uint32_t offset() const INLINE { return E::get32(fields.offset); }
853 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
855 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
856 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
858 typedef typename P::E E;
860 twolevel_hints_command fields;
865 // mach-o threads load command
867 template <typename P>
868 class macho_thread_command {
870 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
871 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
873 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
874 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
876 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
877 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
879 uint32_t count() const INLINE { return E::get32(fields_count); }
880 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
882 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
883 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
885 typedef typename P::E E;
886 typedef typename P::uint_t pint_t;
888 struct thread_command fields;
889 uint32_t fields_flavor;
890 uint32_t fields_count;
891 pint_t thread_registers[1];
898 template <typename P>
899 class macho_linkedit_data_command {
901 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
902 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
904 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
905 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
907 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
908 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
910 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
911 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
914 typedef typename P::E E;
916 struct linkedit_data_command fields;
923 template <typename P>
924 class macho_rpath_command {
926 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
927 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
929 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
930 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
932 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
933 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
935 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
936 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
939 typedef typename P::E E;
941 struct rpath_command fields;
947 // mach-o symbol table entry
949 template <typename P> struct macho_nlist_content {};
950 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
951 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
952 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
953 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
955 template <typename P>
958 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
959 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
961 uint8_t n_type() const INLINE { return entry.fields.n_type; }
962 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
964 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
965 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
967 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
968 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
970 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
971 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
973 typedef typename P::E E;
975 macho_nlist_content<P> entry;
981 // mach-o relocation info
983 template <typename P>
984 class macho_relocation_info {
986 uint32_t r_address() const INLINE { return E::get32(address); }
987 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
989 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
990 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
992 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
993 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
995 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
996 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
998 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
999 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1001 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1002 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1004 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1006 typedef typename P::E E;
1014 // mach-o scattered relocation info
1015 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1017 template <typename P>
1018 class macho_scattered_relocation_info {
1020 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1021 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1023 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1024 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1026 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1027 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1029 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1030 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1032 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1033 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1034 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1036 uint32_t r_value() const INLINE { return E::get32(value); }
1037 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1039 uint32_t r_other() const INLINE { return other; }
1041 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1043 typedef typename P::E E;
1052 // mach-o encyrption info load command
1054 template <typename P>
1055 class macho_encryption_info_command {
1057 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1058 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1060 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1061 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1063 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
1064 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
1066 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
1067 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
1069 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
1070 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
1072 typedef typename P::E E;
1074 encryption_info_command fields;
1079 // start of __unwind_info section
1081 template <typename P>
1082 class macho_unwind_info_section_header {
1084 uint32_t version() const INLINE { return E::get32(fields.version); }
1085 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1087 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1088 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1090 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1091 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1093 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1094 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1096 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1097 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1099 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1100 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1102 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1103 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1105 typedef typename P::E E;
1107 unwind_info_section_header fields;
1113 // uwind first level index entry
1115 template <typename P>
1116 class macho_unwind_info_section_header_index_entry {
1118 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1119 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1121 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1122 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1124 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1125 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1127 typedef typename P::E E;
1129 unwind_info_section_header_index_entry fields;
1136 template <typename P>
1137 class macho_unwind_info_section_header_lsda_index_entry {
1139 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1140 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1142 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1143 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1145 typedef typename P::E E;
1147 unwind_info_section_header_lsda_index_entry fields;
1152 // regular second level entry
1154 template <typename P>
1155 class macho_unwind_info_regular_second_level_entry {
1157 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1158 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1160 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1161 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1163 typedef typename P::E E;
1165 unwind_info_regular_second_level_entry fields;
1170 // start of second level regular page
1172 template <typename P>
1173 class macho_unwind_info_regular_second_level_page_header {
1175 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1176 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1178 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1179 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1181 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1182 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1184 typedef typename P::E E;
1186 unwind_info_regular_second_level_page_header fields;
1191 // start of second level compressed page
1193 template <typename P>
1194 class macho_unwind_info_compressed_second_level_page_header {
1196 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1197 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1199 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1200 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1202 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1203 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1205 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1206 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1208 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1209 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1211 typedef typename P::E E;
1213 unwind_info_compressed_second_level_page_header fields;
1218 // compressed dyld info load command
1220 template <typename P>
1221 class macho_dyld_info_command {
1223 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1224 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1226 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1227 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1229 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1230 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1232 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1233 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1235 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1236 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1238 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1239 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1241 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1242 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1244 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1245 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1247 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1248 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1250 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1251 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1253 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1254 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1256 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1257 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1260 typedef typename P::E E;
1262 dyld_info_command fields;
1267 // mach-o version load command
1269 template <typename P>
1270 class macho_version_min_command {
1272 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1273 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1275 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1276 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1278 uint32_t version() const INLINE { return fields.version; }
1279 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1281 #ifdef LC_SOURCE_VERSION
1282 uint32_t sdk() const INLINE { return fields.sdk; }
1283 void set_sdk(uint32_t value) INLINE { E::set32(fields.sdk, value); }
1285 uint32_t sdk() const INLINE { return fields.reserved; }
1286 void set_sdk(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1289 typedef typename P::E E;
1291 version_min_command fields;
1296 // mach-o __LD, __compact_unwind section in object files
1298 template <typename P>
1299 class macho_compact_unwind_entry {
1301 typedef typename P::E E;
1302 typedef typename P::uint_t pint_t;
1304 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1305 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1307 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1308 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1310 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1311 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1313 pint_t personality() const INLINE { return P::getP(_personality); }
1314 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1316 pint_t lsda() const INLINE { return P::getP(_lsda); }
1317 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1319 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1320 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1321 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1326 uint32_t _compactUnwindInfo;
1327 pint_t _personality;
1332 #endif // __MACH_O_FILE_ABSTRACTION__