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/compact_unwind_encoding.h>
35 #include <mach/machine.h>
38 #include "FileAbstraction.hpp"
40 #include "configure.h"
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 N_ARM_THUMB_DEF
58 #define N_ARM_THUMB_DEF 0x0008
60 #ifndef MH_DEAD_STRIPPABLE_DYLIB
61 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
63 #ifndef MH_KEXT_BUNDLE
64 #define MH_KEXT_BUNDLE 11
67 #define LC_DYLD_INFO 0x22 /* compressed dyld information */
68 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
70 struct dyld_info_command {
71 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
72 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
73 uint32_t rebase_off; /* file offset to rebase info */
74 uint32_t rebase_size; /* size of rebase info */
75 uint32_t bind_off; /* file offset to binding info */
76 uint32_t bind_size; /* size of binding info */
77 uint32_t weak_bind_off; /* file offset to weak binding info */
78 uint32_t weak_bind_size; /* size of weak binding info */
79 uint32_t lazy_bind_off; /* file offset to lazy binding info */
80 uint32_t lazy_bind_size; /* size of lazy binding infs */
81 uint32_t export_off; /* file offset to lazy binding info */
82 uint32_t export_size; /* size of lazy binding infs */
85 #define REBASE_TYPE_POINTER 1
86 #define REBASE_TYPE_TEXT_ABSOLUTE32 2
87 #define REBASE_TYPE_TEXT_PCREL32 3
89 #define REBASE_OPCODE_MASK 0xF0
90 #define REBASE_IMMEDIATE_MASK 0x0F
91 #define REBASE_OPCODE_DONE 0x00
92 #define REBASE_OPCODE_SET_TYPE_IMM 0x10
93 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
94 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
95 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
96 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
97 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
98 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
99 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
101 #define BIND_TYPE_POINTER 1
102 #define BIND_TYPE_TEXT_ABSOLUTE32 2
103 #define BIND_TYPE_TEXT_PCREL32 3
105 #define BIND_SPECIAL_DYLIB_SELF 0
106 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
107 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
109 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
110 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
112 #define BIND_OPCODE_MASK 0xF0
113 #define BIND_IMMEDIATE_MASK 0x0F
114 #define BIND_OPCODE_DONE 0x00
115 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
116 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
117 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
118 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
119 #define BIND_OPCODE_SET_TYPE_IMM 0x50
120 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60
121 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
122 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80
123 #define BIND_OPCODE_DO_BIND 0x90
124 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
125 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
126 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
128 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
129 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
130 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
131 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
132 #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
133 #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
137 #ifndef S_THREAD_LOCAL_REGULAR
138 #define S_THREAD_LOCAL_REGULAR 0x11
141 #ifndef S_THREAD_LOCAL_ZEROFILL
142 #define S_THREAD_LOCAL_ZEROFILL 0x12
145 #ifndef S_THREAD_LOCAL_VARIABLES
146 #define S_THREAD_LOCAL_VARIABLES 0x13
149 #ifndef S_THREAD_LOCAL_VARIABLE_POINTERS
150 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
153 #ifndef S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
154 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
157 #ifndef MH_HAS_TLV_DESCRIPTORS
158 #define MH_HAS_TLV_DESCRIPTORS 0x800000
161 #ifndef X86_64_RELOC_TLV
162 #define X86_64_RELOC_TLV 9
165 #define GENERIC_RLEOC_TLV 5
167 #ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
168 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
171 #ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
172 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
175 // type internal to linker
176 #define BIND_TYPE_OVERRIDE_OF_WEAKDEF_IN_DYLIB 0
178 #ifndef LC_VERSION_MIN_MACOSX
179 #define LC_VERSION_MIN_MACOSX 0x24
180 #define LC_VERSION_MIN_IPHONEOS 0x25
182 struct version_min_command {
183 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS */
184 uint32_t cmdsize; /* sizeof(struct min_version_command) */
185 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
186 uint32_t reserved; /* zero */
190 #ifndef N_SYMBOL_RESOLVER
191 #define N_SYMBOL_RESOLVER 0x100
194 #ifndef LC_FUNCTION_STARTS
195 #define LC_FUNCTION_STARTS 0x26
198 #ifndef MH_NO_HEAP_EXECUTION
199 #define MH_NO_HEAP_EXECUTION 0x1000000
202 #ifndef LC_DYLD_ENVIRONMENT
203 #define LC_DYLD_ENVIRONMENT 0x27
206 #ifndef LC_DATA_IN_CODE
207 #define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
208 struct data_in_code_entry {
215 #ifndef LC_DYLIB_CODE_SIGN_DRS
216 #define LC_DYLIB_CODE_SIGN_DRS 0x2B
219 #ifndef CPU_SUBTYPE_ARM_V7F
220 #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
222 #ifndef CPU_SUBTYPE_ARM_V7K
223 #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
227 #ifndef LC_SOURCE_VERSION
228 #define LC_SOURCE_VERSION 0x2A
229 struct source_version_command {
230 uint32_t cmd; /* LC_SOURCE_VERSION */
231 uint32_t cmdsize; /* 16 */
232 uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */
237 #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
238 struct entry_point_command {
239 uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */
240 uint32_t cmdsize; /* 24 */
241 uint64_t entryoff; /* file (__TEXT) offset of main() */
242 uint64_t stacksize;/* if not zero, initial stack size */
246 #ifndef LC_DYLIB_CODE_SIGN_DRS
247 #define LC_DYLIB_CODE_SIGN_DRS 0x2B
252 const char* archName;
254 cpu_subtype_t cpuSubType;
255 const char* llvmTriplePrefix;
256 const char* llvmTriplePrefixAlt;
261 static const ArchInfo archInfoArray[] = {
262 #if SUPPORT_ARCH_x86_64
263 { "x86_64", CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL, "x86_64-", "", false, false },
265 #if SUPPORT_ARCH_i386
266 { "i386", CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL, "i386-", "", false, false },
268 #if SUPPORT_ARCH_armv4t
269 { "armv4t", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V4T, "armv4t-", "", true, false },
270 #define SUPPORT_ARCH_arm_any 1
272 #if SUPPORT_ARCH_armv5
273 { "armv5", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V5TEJ, "armv5e-", "", true, false },
274 #define SUPPORT_ARCH_arm_any 1
276 #if SUPPORT_ARCH_armv6
277 { "armv6", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6, "armv6-", "", true, false },
278 #define SUPPORT_ARCH_arm_any 1
280 #if SUPPORT_ARCH_armv7
281 { "armv7", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7, "thumbv7-", "armv7-", true, true },
282 #define SUPPORT_ARCH_arm_any 1
284 { NULL, 0, 0, NULL, NULL, false, false }
288 // weird, but this include must wait until after SUPPORT_ARCH_arm_any is set up
289 #if SUPPORT_ARCH_arm_any
290 #include <mach-o/arm/reloc.h>
293 // hack until newer <mach-o/arm/reloc.h> everywhere
294 #define ARM_RELOC_HALF 8
295 #define ARM_RELOC_HALF_SECTDIFF 9
300 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
306 // mach-o file header
308 template <typename P> struct macho_header_content {};
309 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
310 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
311 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
312 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
314 template <typename P>
317 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
318 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
320 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
321 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
323 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
324 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
326 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
327 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
329 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
330 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
332 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
333 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
335 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
336 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
338 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
339 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
341 typedef typename P::E E;
343 macho_header_content<P> header;
348 // mach-o load command
350 template <typename P>
351 class macho_load_command {
353 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
354 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
356 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
357 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
359 typedef typename P::E E;
361 load_command command;
366 // mach-o segment load command
368 template <typename P> struct macho_segment_content {};
369 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
370 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
371 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
372 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
374 template <typename P>
375 class macho_segment_command {
377 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
378 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
380 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
381 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
383 const char* segname() const INLINE { return segment.fields.segname; }
384 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
386 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
387 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
389 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
390 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
392 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
393 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
395 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
396 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
398 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
399 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
401 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
402 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
404 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
405 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
407 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
408 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
411 CMD = macho_segment_content<P>::CMD
414 typedef typename P::E E;
416 macho_segment_content<P> segment;
423 template <typename P> struct macho_section_content {};
424 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
425 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
426 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
427 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
429 template <typename P>
430 class macho_section {
432 const char* sectname() const INLINE { return section.fields.sectname; }
433 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
435 const char* segname() const INLINE { return section.fields.segname; }
436 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
438 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
439 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
441 uint64_t size() const INLINE { return P::getP(section.fields.size); }
442 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
444 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
445 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
447 uint32_t align() const INLINE { return E::get32(section.fields.align); }
448 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
450 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
451 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
453 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
454 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
456 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
457 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
459 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
460 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
462 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
463 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
465 typedef typename P::E E;
467 macho_section_content<P> section;
472 // mach-o dylib load command
474 template <typename P>
475 class macho_dylib_command {
477 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
478 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
480 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
481 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
483 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
484 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
486 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
487 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
489 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
490 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
492 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
493 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
495 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
496 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
498 typedef typename P::E E;
500 dylib_command fields;
505 // mach-o dylinker load command
507 template <typename P>
508 class macho_dylinker_command {
510 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
511 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
513 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
514 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
516 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
517 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
519 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
520 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
522 typedef typename P::E E;
524 dylinker_command fields;
529 // mach-o sub_framework load command
531 template <typename P>
532 class macho_sub_framework_command {
534 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
535 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
537 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
538 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
540 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
541 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
543 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
544 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
546 typedef typename P::E E;
548 sub_framework_command fields;
553 // mach-o sub_client load command
555 template <typename P>
556 class macho_sub_client_command {
558 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
559 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
561 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
562 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
564 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
565 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
567 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
568 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
570 typedef typename P::E E;
572 sub_client_command fields;
577 // mach-o sub_umbrella load command
579 template <typename P>
580 class macho_sub_umbrella_command {
582 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
583 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
585 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
586 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
588 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
589 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
591 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
592 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
594 typedef typename P::E E;
596 sub_umbrella_command fields;
601 // mach-o sub_library load command
603 template <typename P>
604 class macho_sub_library_command {
606 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
607 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
609 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
610 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
612 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
613 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
615 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
616 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
618 typedef typename P::E E;
620 sub_library_command fields;
625 // mach-o uuid load command
627 template <typename P>
628 class macho_uuid_command {
630 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
631 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
633 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
634 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
636 const uint8_t* uuid() const INLINE { return fields.uuid; }
637 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
639 typedef typename P::E E;
646 // mach-o routines load command
648 template <typename P> struct macho_routines_content {};
649 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
650 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
651 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
652 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
654 template <typename P>
655 class macho_routines_command {
657 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
658 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
660 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
661 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
663 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
664 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
666 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
667 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
669 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
670 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
672 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
673 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
675 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
676 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
678 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
679 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
681 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
682 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
684 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
685 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
687 typedef typename P::E E;
689 CMD = macho_routines_content<P>::CMD
692 macho_routines_content<P> routines;
697 // mach-o symbol table load command
699 template <typename P>
700 class macho_symtab_command {
702 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
703 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
705 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
706 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
708 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
709 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
711 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
712 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
714 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
715 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
717 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
718 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
721 typedef typename P::E E;
723 symtab_command fields;
728 // mach-o dynamic symbol table load command
730 template <typename P>
731 class macho_dysymtab_command {
733 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
734 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
736 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
737 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
739 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
740 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
742 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
743 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
745 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
746 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
748 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
749 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
751 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
752 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
754 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
755 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
757 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
758 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
760 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
761 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
763 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
764 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
766 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
767 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
769 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
770 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
772 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
773 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
775 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
776 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
778 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
779 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
781 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
782 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
784 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
785 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
787 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
788 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
790 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
791 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
793 typedef typename P::E E;
795 dysymtab_command fields;
802 // mach-o module table entry (for compatibility with old ld/dyld)
804 template <typename P> struct macho_dylib_module_content {};
805 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
806 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
807 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
808 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
810 template <typename P>
811 class macho_dylib_module {
813 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
814 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
816 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
817 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
819 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
820 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
822 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
823 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
825 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
826 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
828 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
829 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
831 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
832 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
834 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
835 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
837 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
838 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
840 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
841 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
842 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
844 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
845 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
846 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
848 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
849 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
851 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
852 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
855 typedef typename P::E E;
857 macho_dylib_module_content<P> module;
862 // mach-o dylib_reference entry
864 template <typename P>
865 class macho_dylib_reference {
867 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
868 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
870 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
871 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
873 typedef typename P::E E;
881 // mach-o two-level hints load command
883 template <typename P>
884 class macho_dylib_table_of_contents {
886 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
887 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
889 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
890 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
892 typedef typename P::E E;
894 dylib_table_of_contents fields;
900 // mach-o two-level hints load command
902 template <typename P>
903 class macho_twolevel_hints_command {
905 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
906 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
908 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
909 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
911 uint32_t offset() const INLINE { return E::get32(fields.offset); }
912 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
914 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
915 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
917 typedef typename P::E E;
919 twolevel_hints_command fields;
924 // mach-o threads load command
926 template <typename P>
927 class macho_thread_command {
929 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
930 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
932 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
933 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
935 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
936 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
938 uint32_t count() const INLINE { return E::get32(fields_count); }
939 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
941 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
942 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
944 typedef typename P::E E;
945 typedef typename P::uint_t pint_t;
947 struct thread_command fields;
948 uint32_t fields_flavor;
949 uint32_t fields_count;
950 pint_t thread_registers[1];
957 template <typename P>
958 class macho_linkedit_data_command {
960 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
961 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
963 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
964 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
966 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
967 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
969 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
970 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
973 typedef typename P::E E;
975 struct linkedit_data_command fields;
982 template <typename P>
983 class macho_rpath_command {
985 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
986 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
988 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
989 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
991 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
992 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
994 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
995 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
998 typedef typename P::E E;
1000 struct rpath_command fields;
1006 // mach-o symbol table entry
1008 template <typename P> struct macho_nlist_content {};
1009 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
1010 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
1011 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
1012 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
1014 template <typename P>
1017 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
1018 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
1020 uint8_t n_type() const INLINE { return entry.fields.n_type; }
1021 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
1023 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
1024 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
1026 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
1027 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
1029 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
1030 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
1032 typedef typename P::E E;
1034 macho_nlist_content<P> entry;
1040 // mach-o relocation info
1042 template <typename P>
1043 class macho_relocation_info {
1045 uint32_t r_address() const INLINE { return E::get32(address); }
1046 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
1048 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
1049 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
1051 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
1052 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
1054 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
1055 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
1057 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
1058 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1060 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1061 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1063 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1065 typedef typename P::E E;
1073 // mach-o scattered relocation info
1074 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1076 template <typename P>
1077 class macho_scattered_relocation_info {
1079 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1080 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1082 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1083 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1085 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1086 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1088 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1089 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1091 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1092 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1093 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1095 uint32_t r_value() const INLINE { return E::get32(value); }
1096 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1098 uint32_t r_other() const INLINE { return other; }
1100 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1102 typedef typename P::E E;
1111 // mach-o encyrption info load command
1113 template <typename P>
1114 class macho_encryption_info_command {
1116 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1117 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1119 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1120 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1122 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
1123 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
1125 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
1126 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
1128 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
1129 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
1131 typedef typename P::E E;
1133 encryption_info_command fields;
1138 // start of __unwind_info section
1140 template <typename P>
1141 class macho_unwind_info_section_header {
1143 uint32_t version() const INLINE { return E::get32(fields.version); }
1144 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1146 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1147 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1149 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1150 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1152 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1153 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1155 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1156 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1158 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1159 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1161 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1162 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1164 typedef typename P::E E;
1166 unwind_info_section_header fields;
1172 // uwind first level index entry
1174 template <typename P>
1175 class macho_unwind_info_section_header_index_entry {
1177 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1178 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1180 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1181 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1183 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1184 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1186 typedef typename P::E E;
1188 unwind_info_section_header_index_entry fields;
1195 template <typename P>
1196 class macho_unwind_info_section_header_lsda_index_entry {
1198 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1199 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1201 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1202 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1204 typedef typename P::E E;
1206 unwind_info_section_header_lsda_index_entry fields;
1211 // regular second level entry
1213 template <typename P>
1214 class macho_unwind_info_regular_second_level_entry {
1216 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1217 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1219 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1220 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1222 typedef typename P::E E;
1224 unwind_info_regular_second_level_entry fields;
1229 // start of second level regular page
1231 template <typename P>
1232 class macho_unwind_info_regular_second_level_page_header {
1234 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1235 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1237 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1238 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1240 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1241 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1243 typedef typename P::E E;
1245 unwind_info_regular_second_level_page_header fields;
1250 // start of second level compressed page
1252 template <typename P>
1253 class macho_unwind_info_compressed_second_level_page_header {
1255 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1256 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1258 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1259 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1261 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1262 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1264 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1265 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1267 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1268 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1270 typedef typename P::E E;
1272 unwind_info_compressed_second_level_page_header fields;
1277 // compressed dyld info load command
1279 template <typename P>
1280 class macho_dyld_info_command {
1282 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1283 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1285 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1286 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1288 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1289 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1291 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1292 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1294 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1295 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1297 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1298 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1300 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1301 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1303 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1304 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1306 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1307 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1309 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1310 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1312 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1313 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1315 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1316 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1319 typedef typename P::E E;
1321 dyld_info_command fields;
1326 // mach-o version load command
1328 template <typename P>
1329 class macho_version_min_command {
1331 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1332 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1334 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1335 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1337 uint32_t version() const INLINE { return fields.version; }
1338 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1340 #ifdef DICE_KIND_DATA
1341 uint32_t sdk() const INLINE { return fields.sdk; }
1342 void set_sdk(uint32_t value) INLINE { E::set32(fields.sdk, value); }
1344 uint32_t sdk() const INLINE { return fields.reserved; }
1345 void set_sdk(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1348 typedef typename P::E E;
1350 version_min_command fields;
1355 // mach-o __LD, __compact_unwind section in object files
1357 template <typename P>
1358 class macho_compact_unwind_entry {
1360 typedef typename P::E E;
1361 typedef typename P::uint_t pint_t;
1363 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1364 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1366 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1367 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1369 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1370 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1372 pint_t personality() const INLINE { return P::getP(_personality); }
1373 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1375 pint_t lsda() const INLINE { return P::getP(_lsda); }
1376 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1378 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1379 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1380 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1385 uint32_t _compactUnwindInfo;
1386 pint_t _personality;
1392 // mach-o source version load command
1394 template <typename P>
1395 class macho_source_version_command {
1397 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1398 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1400 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1401 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1403 uint64_t version() const INLINE { return fields.version; }
1404 void set_version(uint64_t value) INLINE { E::set64(fields.version, value); }
1406 typedef typename P::E E;
1408 source_version_command fields;
1413 // mach-o source version load command
1415 template <typename P>
1416 class macho_entry_point_command {
1418 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1419 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1421 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1422 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1424 uint64_t entryoff() const INLINE { return fields.entryoff; }
1425 void set_entryoff(uint64_t value) INLINE { E::set64(fields.entryoff, value); }
1427 uint64_t stacksize() const INLINE { return fields.stacksize; }
1428 void set_stacksize(uint64_t value) INLINE { E::set64(fields.stacksize, value); }
1430 typedef typename P::E E;
1432 entry_point_command fields;
1437 template <typename P>
1438 class macho_data_in_code_entry {
1440 uint32_t offset() const INLINE { return E::get32(fields.offset); }
1441 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
1443 uint16_t length() const INLINE { return E::get16(fields.length); }
1444 void set_length(uint16_t value) INLINE { E::set16((uint16_t&)fields.length, value); }
1446 uint16_t kind() const INLINE { return E::get16(fields.kind); }
1447 void set_kind(uint16_t value) INLINE { E::set16((uint16_t&)fields.kind, value); }
1449 typedef typename P::E E;
1451 data_in_code_entry fields;
1455 #endif // __MACH_O_FILE_ABSTRACTION__