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/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>
40 #include "FileAbstraction.hpp"
43 // stuff that will eventually go away once newer cctools headers are widespread
44 #ifndef LC_LOAD_UPWARD_DYLIB
45 #define LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD) /* load of dylib whose initializers run later */
48 #ifndef CPU_SUBTYPE_ARM_V5TEJ
49 #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
51 #ifndef CPU_SUBTYPE_ARM_XSCALE
52 #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
54 #ifndef CPU_SUBTYPE_ARM_V7
55 #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
58 #ifndef ARM_THUMB_32BIT_BRANCH
59 #define ARM_THUMB_32BIT_BRANCH 7
61 #ifndef N_ARM_THUMB_DEF
62 #define N_ARM_THUMB_DEF 0x0008
64 #ifndef MH_DEAD_STRIPPABLE_DYLIB
65 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
67 #ifndef MH_KEXT_BUNDLE
68 #define MH_KEXT_BUNDLE 11
71 #define LC_DYLD_INFO 0x22 /* compressed dyld information */
72 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
74 struct dyld_info_command {
75 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
76 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
77 uint32_t rebase_off; /* file offset to rebase info */
78 uint32_t rebase_size; /* size of rebase info */
79 uint32_t bind_off; /* file offset to binding info */
80 uint32_t bind_size; /* size of binding info */
81 uint32_t weak_bind_off; /* file offset to weak binding info */
82 uint32_t weak_bind_size; /* size of weak binding info */
83 uint32_t lazy_bind_off; /* file offset to lazy binding info */
84 uint32_t lazy_bind_size; /* size of lazy binding infs */
85 uint32_t export_off; /* file offset to lazy binding info */
86 uint32_t export_size; /* size of lazy binding infs */
89 #define REBASE_TYPE_POINTER 1
90 #define REBASE_TYPE_TEXT_ABSOLUTE32 2
91 #define REBASE_TYPE_TEXT_PCREL32 3
93 #define REBASE_OPCODE_MASK 0xF0
94 #define REBASE_IMMEDIATE_MASK 0x0F
95 #define REBASE_OPCODE_DONE 0x00
96 #define REBASE_OPCODE_SET_TYPE_IMM 0x10
97 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
98 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
99 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
100 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
101 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
102 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
103 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
105 #define BIND_TYPE_POINTER 1
106 #define BIND_TYPE_TEXT_ABSOLUTE32 2
107 #define BIND_TYPE_TEXT_PCREL32 3
109 #define BIND_SPECIAL_DYLIB_SELF 0
110 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
111 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
113 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
114 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
116 #define BIND_OPCODE_MASK 0xF0
117 #define BIND_IMMEDIATE_MASK 0x0F
118 #define BIND_OPCODE_DONE 0x00
119 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
120 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
121 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
122 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
123 #define BIND_OPCODE_SET_TYPE_IMM 0x50
124 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60
125 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
126 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80
127 #define BIND_OPCODE_DO_BIND 0x90
128 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
129 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
130 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
132 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
133 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
134 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
135 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
136 #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
137 #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
141 #ifndef S_THREAD_LOCAL_REGULAR
142 #define S_THREAD_LOCAL_REGULAR 0x11
145 #ifndef S_THREAD_LOCAL_ZEROFILL
146 #define S_THREAD_LOCAL_ZEROFILL 0x12
149 #ifndef S_THREAD_LOCAL_VARIABLES
150 #define S_THREAD_LOCAL_VARIABLES 0x13
153 #ifndef S_THREAD_LOCAL_VARIABLE_POINTERS
154 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
157 #ifndef S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
158 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
161 #ifndef MH_HAS_TLV_DESCRIPTORS
162 #define MH_HAS_TLV_DESCRIPTORS 0x800000
165 #ifndef X86_64_RELOC_TLV
166 #define X86_64_RELOC_TLV 9
169 #define GENERIC_RLEOC_TLV 5
171 #ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
172 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
175 #ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
176 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
179 // type internal to linker
180 #define BIND_TYPE_OVERRIDE_OF_WEAKDEF_IN_DYLIB 0
182 #ifndef LC_VERSION_MIN_MACOSX
183 #define LC_VERSION_MIN_MACOSX 0x24
184 #define LC_VERSION_MIN_IPHONEOS 0x25
186 struct version_min_command {
187 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS */
188 uint32_t cmdsize; /* sizeof(struct min_version_command) */
189 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
190 uint32_t reserved; /* zero */
194 #ifndef N_SYMBOL_RESOLVER
195 #define N_SYMBOL_RESOLVER 0x100
198 #ifndef LC_FUNCTION_STARTS
199 #define LC_FUNCTION_STARTS 0x26
202 #ifndef MH_NO_HEAP_EXECUTION
203 #define MH_NO_HEAP_EXECUTION 0x1000000
206 #ifndef LC_DYLD_ENVIRONMENT
207 #define LC_DYLD_ENVIRONMENT 0x27
210 // hack until newer <mach-o/arm/reloc.h> everywhere
211 #define ARM_RELOC_HALF 8
212 #define ARM_RELOC_HALF_SECTDIFF 9
214 #ifndef CPU_SUBTYPE_ARM_V7F
215 #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
217 #ifndef CPU_SUBTYPE_ARM_V7K
218 #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
222 const char* subTypeName;
223 const char* llvmTriplePrefix;
224 cpu_subtype_t subType;
228 static const ARMSubType ARMSubTypes[] = {
229 { "armv4t","armv4t-", CPU_SUBTYPE_ARM_V4T, false },
230 { "armv5", "armv5e-", CPU_SUBTYPE_ARM_V5TEJ, false },
231 { "armv6", "armv6-", CPU_SUBTYPE_ARM_V6, false },
232 { "armv7", "thumbv7-", CPU_SUBTYPE_ARM_V7, true },
233 { "armv7f", "thumbv7f-", CPU_SUBTYPE_ARM_V7F, true },
234 { "armv7k", "thumbv7k-", CPU_SUBTYPE_ARM_V7K, true },
242 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
248 // mach-o file header
250 template <typename P> struct macho_header_content {};
251 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
252 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
253 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
254 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
256 template <typename P>
259 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
260 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
262 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
263 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
265 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
266 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
268 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
269 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
271 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
272 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
274 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
275 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
277 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
278 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
280 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
281 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
283 typedef typename P::E E;
285 macho_header_content<P> header;
290 // mach-o load command
292 template <typename P>
293 class macho_load_command {
295 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
296 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
298 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
299 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
301 typedef typename P::E E;
303 load_command command;
308 // mach-o segment load command
310 template <typename P> struct macho_segment_content {};
311 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
312 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
313 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
314 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
316 template <typename P>
317 class macho_segment_command {
319 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
320 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
322 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
323 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
325 const char* segname() const INLINE { return segment.fields.segname; }
326 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
328 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
329 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
331 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
332 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
334 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
335 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
337 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
338 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
340 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
341 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
343 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
344 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
346 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
347 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
349 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
350 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
353 CMD = macho_segment_content<P>::CMD
356 typedef typename P::E E;
358 macho_segment_content<P> segment;
365 template <typename P> struct macho_section_content {};
366 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
367 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
368 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
369 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
371 template <typename P>
372 class macho_section {
374 const char* sectname() const INLINE { return section.fields.sectname; }
375 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
377 const char* segname() const INLINE { return section.fields.segname; }
378 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
380 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
381 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
383 uint64_t size() const INLINE { return P::getP(section.fields.size); }
384 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
386 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
387 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
389 uint32_t align() const INLINE { return E::get32(section.fields.align); }
390 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
392 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
393 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
395 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
396 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
398 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
399 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
401 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
402 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
404 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
405 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
407 typedef typename P::E E;
409 macho_section_content<P> section;
414 // mach-o dylib load command
416 template <typename P>
417 class macho_dylib_command {
419 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
420 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
422 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
423 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
425 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
426 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
428 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
429 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
431 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
432 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
434 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
435 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
437 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
438 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
440 typedef typename P::E E;
442 dylib_command fields;
447 // mach-o dylinker load command
449 template <typename P>
450 class macho_dylinker_command {
452 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
453 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
455 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
456 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
458 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
459 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
461 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
462 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
464 typedef typename P::E E;
466 dylinker_command fields;
471 // mach-o sub_framework load command
473 template <typename P>
474 class macho_sub_framework_command {
476 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
477 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
479 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
480 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
482 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
483 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
485 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
486 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
488 typedef typename P::E E;
490 sub_framework_command fields;
495 // mach-o sub_client load command
497 template <typename P>
498 class macho_sub_client_command {
500 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
501 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
503 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
504 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
506 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
507 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
509 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
510 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
512 typedef typename P::E E;
514 sub_client_command fields;
519 // mach-o sub_umbrella load command
521 template <typename P>
522 class macho_sub_umbrella_command {
524 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
525 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
527 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
528 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
530 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
531 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
533 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
534 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
536 typedef typename P::E E;
538 sub_umbrella_command fields;
543 // mach-o sub_library load command
545 template <typename P>
546 class macho_sub_library_command {
548 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
549 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
551 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
552 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
554 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
555 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
557 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
558 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
560 typedef typename P::E E;
562 sub_library_command fields;
567 // mach-o uuid load command
569 template <typename P>
570 class macho_uuid_command {
572 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
573 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
575 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
576 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
578 const uint8_t* uuid() const INLINE { return fields.uuid; }
579 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
581 typedef typename P::E E;
588 // mach-o routines load command
590 template <typename P> struct macho_routines_content {};
591 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
592 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
593 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
594 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
596 template <typename P>
597 class macho_routines_command {
599 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
600 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
602 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
603 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
605 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
606 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
608 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
609 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
611 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
612 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
614 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
615 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
617 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
618 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
620 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
621 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
623 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
624 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
626 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
627 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
629 typedef typename P::E E;
631 CMD = macho_routines_content<P>::CMD
634 macho_routines_content<P> routines;
639 // mach-o symbol table load command
641 template <typename P>
642 class macho_symtab_command {
644 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
645 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
647 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
648 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
650 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
651 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
653 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
654 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
656 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
657 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
659 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
660 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
663 typedef typename P::E E;
665 symtab_command fields;
670 // mach-o dynamic symbol table load command
672 template <typename P>
673 class macho_dysymtab_command {
675 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
676 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
678 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
679 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
681 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
682 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
684 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
685 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
687 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
688 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
690 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
691 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
693 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
694 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
696 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
697 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
699 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
700 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
702 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
703 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
705 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
706 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
708 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
709 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
711 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
712 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
714 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
715 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
717 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
718 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
720 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
721 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
723 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
724 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
726 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
727 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
729 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
730 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
732 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
733 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
735 typedef typename P::E E;
737 dysymtab_command fields;
744 // mach-o module table entry (for compatibility with old ld/dyld)
746 template <typename P> struct macho_dylib_module_content {};
747 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
748 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
749 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
750 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
752 template <typename P>
753 class macho_dylib_module {
755 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
756 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
758 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
759 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
761 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
762 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
764 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
765 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
767 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
768 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
770 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
771 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
773 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
774 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
776 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
777 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
779 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
780 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
782 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
783 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
784 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
786 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
787 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
788 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
790 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
791 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
793 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
794 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
797 typedef typename P::E E;
799 macho_dylib_module_content<P> module;
804 // mach-o dylib_reference entry
806 template <typename P>
807 class macho_dylib_reference {
809 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
810 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
812 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
813 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
815 typedef typename P::E E;
823 // mach-o two-level hints load command
825 template <typename P>
826 class macho_dylib_table_of_contents {
828 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
829 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
831 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
832 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
834 typedef typename P::E E;
836 dylib_table_of_contents fields;
842 // mach-o two-level hints load command
844 template <typename P>
845 class macho_twolevel_hints_command {
847 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
848 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
850 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
851 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
853 uint32_t offset() const INLINE { return E::get32(fields.offset); }
854 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
856 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
857 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
859 typedef typename P::E E;
861 twolevel_hints_command fields;
866 // mach-o threads load command
868 template <typename P>
869 class macho_thread_command {
871 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
872 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
874 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
875 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
877 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
878 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
880 uint32_t count() const INLINE { return E::get32(fields_count); }
881 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
883 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
884 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
886 typedef typename P::E E;
887 typedef typename P::uint_t pint_t;
889 struct thread_command fields;
890 uint32_t fields_flavor;
891 uint32_t fields_count;
892 pint_t thread_registers[1];
899 template <typename P>
900 class macho_linkedit_data_command {
902 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
903 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
905 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
906 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
908 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
909 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
911 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
912 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
915 typedef typename P::E E;
917 struct linkedit_data_command fields;
924 template <typename P>
925 class macho_rpath_command {
927 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
928 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
930 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
931 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
933 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
934 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
936 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
937 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
940 typedef typename P::E E;
942 struct rpath_command fields;
948 // mach-o symbol table entry
950 template <typename P> struct macho_nlist_content {};
951 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
952 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
953 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
954 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
956 template <typename P>
959 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
960 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
962 uint8_t n_type() const INLINE { return entry.fields.n_type; }
963 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
965 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
966 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
968 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
969 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
971 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
972 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
974 typedef typename P::E E;
976 macho_nlist_content<P> entry;
982 // mach-o relocation info
984 template <typename P>
985 class macho_relocation_info {
987 uint32_t r_address() const INLINE { return E::get32(address); }
988 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
990 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
991 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
993 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
994 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
996 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
997 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
999 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
1000 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1002 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1003 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1005 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1007 typedef typename P::E E;
1015 // mach-o scattered relocation info
1016 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1018 template <typename P>
1019 class macho_scattered_relocation_info {
1021 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1022 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1024 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1025 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1027 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1028 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1030 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1031 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1033 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1034 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1035 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1037 uint32_t r_value() const INLINE { return E::get32(value); }
1038 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1040 uint32_t r_other() const INLINE { return other; }
1042 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1044 typedef typename P::E E;
1053 // mach-o encyrption info load command
1055 template <typename P>
1056 class macho_encryption_info_command {
1058 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1059 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1061 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1062 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1064 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
1065 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
1067 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
1068 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
1070 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
1071 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
1073 typedef typename P::E E;
1075 encryption_info_command fields;
1080 // start of __unwind_info section
1082 template <typename P>
1083 class macho_unwind_info_section_header {
1085 uint32_t version() const INLINE { return E::get32(fields.version); }
1086 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1088 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1089 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1091 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1092 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1094 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1095 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1097 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1098 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1100 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1101 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1103 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1104 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1106 typedef typename P::E E;
1108 unwind_info_section_header fields;
1114 // uwind first level index entry
1116 template <typename P>
1117 class macho_unwind_info_section_header_index_entry {
1119 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1120 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1122 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1123 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1125 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1126 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1128 typedef typename P::E E;
1130 unwind_info_section_header_index_entry fields;
1137 template <typename P>
1138 class macho_unwind_info_section_header_lsda_index_entry {
1140 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1141 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1143 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1144 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1146 typedef typename P::E E;
1148 unwind_info_section_header_lsda_index_entry fields;
1153 // regular second level entry
1155 template <typename P>
1156 class macho_unwind_info_regular_second_level_entry {
1158 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1159 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1161 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1162 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1164 typedef typename P::E E;
1166 unwind_info_regular_second_level_entry fields;
1171 // start of second level regular page
1173 template <typename P>
1174 class macho_unwind_info_regular_second_level_page_header {
1176 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1177 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1179 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1180 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1182 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1183 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1185 typedef typename P::E E;
1187 unwind_info_regular_second_level_page_header fields;
1192 // start of second level compressed page
1194 template <typename P>
1195 class macho_unwind_info_compressed_second_level_page_header {
1197 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1198 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1200 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1201 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1203 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1204 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1206 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1207 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1209 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1210 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1212 typedef typename P::E E;
1214 unwind_info_compressed_second_level_page_header fields;
1219 // compressed dyld info load command
1221 template <typename P>
1222 class macho_dyld_info_command {
1224 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1225 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1227 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1228 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1230 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1231 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1233 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1234 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1236 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1237 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1239 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1240 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1242 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1243 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1245 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1246 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1248 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1249 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1251 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1252 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1254 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1255 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1257 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1258 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1261 typedef typename P::E E;
1263 dyld_info_command fields;
1268 // mach-o version load command
1270 template <typename P>
1271 class macho_version_min_command {
1273 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1274 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1276 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1277 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1279 uint32_t version() const INLINE { return fields.version; }
1280 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1282 uint32_t reserved() const INLINE { return fields.reserved; }
1283 void set_reserved(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1285 typedef typename P::E E;
1287 version_min_command fields;
1292 // mach-o __LD, __compact_unwind section in object files
1294 template <typename P>
1295 class macho_compact_unwind_entry {
1297 typedef typename P::E E;
1298 typedef typename P::uint_t pint_t;
1300 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1301 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1303 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1304 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1306 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1307 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1309 pint_t personality() const INLINE { return P::getP(_personality); }
1310 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1312 pint_t lsda() const INLINE { return P::getP(_lsda); }
1313 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1315 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1316 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1317 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1322 uint32_t _compactUnwindInfo;
1323 pint_t _personality;
1328 #endif // __MACH_O_FILE_ABSTRACTION__