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)
225 #ifndef CPU_SUBTYPE_ARM_V7S
226 #define CPU_SUBTYPE_ARM_V7S ((cpu_subtype_t) 11)
230 #ifndef LC_SOURCE_VERSION
231 #define LC_SOURCE_VERSION 0x2A
232 struct source_version_command {
233 uint32_t cmd; /* LC_SOURCE_VERSION */
234 uint32_t cmdsize; /* 16 */
235 uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */
240 #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
241 struct entry_point_command {
242 uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */
243 uint32_t cmdsize; /* 24 */
244 uint64_t entryoff; /* file (__TEXT) offset of main() */
245 uint64_t stacksize;/* if not zero, initial stack size */
249 #ifndef LC_DYLIB_CODE_SIGN_DRS
250 #define LC_DYLIB_CODE_SIGN_DRS 0x2B
255 const char* archName;
257 cpu_subtype_t cpuSubType;
258 const char* llvmTriplePrefix;
259 const char* llvmTriplePrefixAlt;
264 static const ArchInfo archInfoArray[] = {
265 #if SUPPORT_ARCH_x86_64
266 { "x86_64", CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL, "x86_64-", "", false, false },
268 #if SUPPORT_ARCH_i386
269 { "i386", CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL, "i386-", "", false, false },
271 #if SUPPORT_ARCH_armv4t
272 { "armv4t", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V4T, "armv4t-", "", true, false },
273 #define SUPPORT_ARCH_arm_any 1
275 #if SUPPORT_ARCH_armv5
276 { "armv5", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V5TEJ, "armv5e-", "", true, false },
277 #define SUPPORT_ARCH_arm_any 1
279 #if SUPPORT_ARCH_armv6
280 { "armv6", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6, "armv6-", "", true, false },
281 #define SUPPORT_ARCH_arm_any 1
283 #if SUPPORT_ARCH_armv7
284 { "armv7", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7, "thumbv7-", "armv7-", true, true },
285 #define SUPPORT_ARCH_arm_any 1
287 #if SUPPORT_ARCH_armv7f
288 { "armv7f", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7F, "thumbv7f-", "", true, true },
289 #define SUPPORT_ARCH_arm_any 1
291 #if SUPPORT_ARCH_armv7k
292 { "armv7k", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7K, "thumbv7k-", "", true, true },
293 #define SUPPORT_ARCH_arm_any 1
295 #if SUPPORT_ARCH_armv7s
296 { "armv7s", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7S, "thumbv7s-", "armv7s", true, true },
297 #define SUPPORT_ARCH_arm_any 1
299 { NULL, 0, 0, NULL, NULL, false, false }
303 // weird, but this include must wait until after SUPPORT_ARCH_arm_any is set up
304 #if SUPPORT_ARCH_arm_any
305 #include <mach-o/arm/reloc.h>
308 // hack until newer <mach-o/arm/reloc.h> everywhere
309 #define ARM_RELOC_HALF 8
310 #define ARM_RELOC_HALF_SECTDIFF 9
315 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
321 // mach-o file header
323 template <typename P> struct macho_header_content {};
324 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
325 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
326 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
327 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
329 template <typename P>
332 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
333 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
335 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
336 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
338 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
339 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
341 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
342 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
344 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
345 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
347 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
348 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
350 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
351 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
353 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
354 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
356 typedef typename P::E E;
358 macho_header_content<P> header;
363 // mach-o load command
365 template <typename P>
366 class macho_load_command {
368 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
369 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
371 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
372 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
374 typedef typename P::E E;
376 load_command command;
381 // mach-o segment load command
383 template <typename P> struct macho_segment_content {};
384 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
385 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
386 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
387 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
389 template <typename P>
390 class macho_segment_command {
392 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
393 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
395 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
396 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
398 const char* segname() const INLINE { return segment.fields.segname; }
399 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
401 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
402 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
404 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
405 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
407 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
408 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
410 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
411 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
413 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
414 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
416 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
417 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
419 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
420 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
422 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
423 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
426 CMD = macho_segment_content<P>::CMD
429 typedef typename P::E E;
431 macho_segment_content<P> segment;
438 template <typename P> struct macho_section_content {};
439 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
440 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
441 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
442 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
444 template <typename P>
445 class macho_section {
447 const char* sectname() const INLINE { return section.fields.sectname; }
448 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
450 const char* segname() const INLINE { return section.fields.segname; }
451 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
453 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
454 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
456 uint64_t size() const INLINE { return P::getP(section.fields.size); }
457 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
459 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
460 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
462 uint32_t align() const INLINE { return E::get32(section.fields.align); }
463 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
465 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
466 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
468 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
469 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
471 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
472 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
474 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
475 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
477 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
478 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
480 typedef typename P::E E;
482 macho_section_content<P> section;
487 // mach-o dylib load command
489 template <typename P>
490 class macho_dylib_command {
492 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
493 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
495 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
496 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
498 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
499 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
501 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
502 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
504 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
505 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
507 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
508 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
510 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
511 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
513 typedef typename P::E E;
515 dylib_command fields;
520 // mach-o dylinker load command
522 template <typename P>
523 class macho_dylinker_command {
525 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
526 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
528 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
529 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
531 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
532 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
534 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
535 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
537 typedef typename P::E E;
539 dylinker_command fields;
544 // mach-o sub_framework load command
546 template <typename P>
547 class macho_sub_framework_command {
549 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
550 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
552 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
553 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
555 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
556 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
558 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
559 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
561 typedef typename P::E E;
563 sub_framework_command fields;
568 // mach-o sub_client load command
570 template <typename P>
571 class macho_sub_client_command {
573 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
574 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
576 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
577 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
579 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
580 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
582 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
583 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
585 typedef typename P::E E;
587 sub_client_command fields;
592 // mach-o sub_umbrella load command
594 template <typename P>
595 class macho_sub_umbrella_command {
597 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
598 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
600 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
601 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
603 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
604 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
606 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
607 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
609 typedef typename P::E E;
611 sub_umbrella_command fields;
616 // mach-o sub_library load command
618 template <typename P>
619 class macho_sub_library_command {
621 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
622 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
624 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
625 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
627 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
628 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
630 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
631 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
633 typedef typename P::E E;
635 sub_library_command fields;
640 // mach-o uuid load command
642 template <typename P>
643 class macho_uuid_command {
645 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
646 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
648 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
649 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
651 const uint8_t* uuid() const INLINE { return fields.uuid; }
652 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
654 typedef typename P::E E;
661 // mach-o routines load command
663 template <typename P> struct macho_routines_content {};
664 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
665 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
666 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
667 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
669 template <typename P>
670 class macho_routines_command {
672 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
673 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
675 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
676 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
678 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
679 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
681 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
682 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
684 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
685 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
687 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
688 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
690 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
691 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
693 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
694 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
696 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
697 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
699 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
700 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
702 typedef typename P::E E;
704 CMD = macho_routines_content<P>::CMD
707 macho_routines_content<P> routines;
712 // mach-o symbol table load command
714 template <typename P>
715 class macho_symtab_command {
717 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
718 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
720 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
721 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
723 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
724 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
726 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
727 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
729 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
730 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
732 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
733 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
736 typedef typename P::E E;
738 symtab_command fields;
743 // mach-o dynamic symbol table load command
745 template <typename P>
746 class macho_dysymtab_command {
748 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
749 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
751 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
752 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
754 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
755 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
757 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
758 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
760 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
761 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
763 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
764 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
766 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
767 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
769 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
770 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
772 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
773 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
775 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
776 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
778 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
779 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
781 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
782 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
784 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
785 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
787 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
788 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
790 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
791 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
793 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
794 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
796 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
797 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
799 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
800 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
802 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
803 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
805 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
806 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
808 typedef typename P::E E;
810 dysymtab_command fields;
817 // mach-o module table entry (for compatibility with old ld/dyld)
819 template <typename P> struct macho_dylib_module_content {};
820 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
821 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
822 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
823 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
825 template <typename P>
826 class macho_dylib_module {
828 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
829 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
831 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
832 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
834 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
835 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
837 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
838 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
840 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
841 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
843 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
844 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
846 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
847 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
849 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
850 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
852 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
853 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
855 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
856 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
857 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
859 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
860 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
861 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
863 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
864 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
866 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
867 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
870 typedef typename P::E E;
872 macho_dylib_module_content<P> module;
877 // mach-o dylib_reference entry
879 template <typename P>
880 class macho_dylib_reference {
882 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
883 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
885 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
886 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
888 typedef typename P::E E;
896 // mach-o two-level hints load command
898 template <typename P>
899 class macho_dylib_table_of_contents {
901 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
902 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
904 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
905 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
907 typedef typename P::E E;
909 dylib_table_of_contents fields;
915 // mach-o two-level hints load command
917 template <typename P>
918 class macho_twolevel_hints_command {
920 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
921 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
923 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
924 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
926 uint32_t offset() const INLINE { return E::get32(fields.offset); }
927 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
929 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
930 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
932 typedef typename P::E E;
934 twolevel_hints_command fields;
939 // mach-o threads load command
941 template <typename P>
942 class macho_thread_command {
944 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
945 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
947 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
948 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
950 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
951 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
953 uint32_t count() const INLINE { return E::get32(fields_count); }
954 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
956 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
957 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
959 typedef typename P::E E;
960 typedef typename P::uint_t pint_t;
962 struct thread_command fields;
963 uint32_t fields_flavor;
964 uint32_t fields_count;
965 pint_t thread_registers[1];
972 template <typename P>
973 class macho_linkedit_data_command {
975 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
976 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
978 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
979 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
981 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
982 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
984 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
985 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
988 typedef typename P::E E;
990 struct linkedit_data_command fields;
997 template <typename P>
998 class macho_rpath_command {
1000 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1001 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1003 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1004 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1006 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
1007 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
1009 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
1010 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
1013 typedef typename P::E E;
1015 struct rpath_command fields;
1021 // mach-o symbol table entry
1023 template <typename P> struct macho_nlist_content {};
1024 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
1025 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
1026 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
1027 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
1029 template <typename P>
1032 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
1033 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
1035 uint8_t n_type() const INLINE { return entry.fields.n_type; }
1036 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
1038 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
1039 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
1041 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
1042 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
1044 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
1045 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
1047 typedef typename P::E E;
1049 macho_nlist_content<P> entry;
1055 // mach-o relocation info
1057 template <typename P>
1058 class macho_relocation_info {
1060 uint32_t r_address() const INLINE { return E::get32(address); }
1061 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
1063 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
1064 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
1066 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
1067 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
1069 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
1070 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
1072 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
1073 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1075 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1076 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1078 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1080 typedef typename P::E E;
1088 // mach-o scattered relocation info
1089 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1091 template <typename P>
1092 class macho_scattered_relocation_info {
1094 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1095 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1097 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1098 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1100 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1101 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1103 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1104 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1106 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1107 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1108 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1110 uint32_t r_value() const INLINE { return E::get32(value); }
1111 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1113 uint32_t r_other() const INLINE { return other; }
1115 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1117 typedef typename P::E E;
1126 // mach-o encyrption info load command
1128 template <typename P>
1129 class macho_encryption_info_command {
1131 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1132 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1134 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1135 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1137 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
1138 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
1140 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
1141 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
1143 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
1144 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
1146 typedef typename P::E E;
1148 encryption_info_command fields;
1153 // start of __unwind_info section
1155 template <typename P>
1156 class macho_unwind_info_section_header {
1158 uint32_t version() const INLINE { return E::get32(fields.version); }
1159 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1161 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1162 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1164 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1165 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1167 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1168 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1170 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1171 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1173 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1174 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1176 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1177 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1179 typedef typename P::E E;
1181 unwind_info_section_header fields;
1187 // uwind first level index entry
1189 template <typename P>
1190 class macho_unwind_info_section_header_index_entry {
1192 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1193 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1195 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1196 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1198 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1199 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1201 typedef typename P::E E;
1203 unwind_info_section_header_index_entry fields;
1210 template <typename P>
1211 class macho_unwind_info_section_header_lsda_index_entry {
1213 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1214 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1216 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1217 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1219 typedef typename P::E E;
1221 unwind_info_section_header_lsda_index_entry fields;
1226 // regular second level entry
1228 template <typename P>
1229 class macho_unwind_info_regular_second_level_entry {
1231 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1232 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1234 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1235 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1237 typedef typename P::E E;
1239 unwind_info_regular_second_level_entry fields;
1244 // start of second level regular page
1246 template <typename P>
1247 class macho_unwind_info_regular_second_level_page_header {
1249 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1250 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1252 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1253 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1255 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1256 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1258 typedef typename P::E E;
1260 unwind_info_regular_second_level_page_header fields;
1265 // start of second level compressed page
1267 template <typename P>
1268 class macho_unwind_info_compressed_second_level_page_header {
1270 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1271 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1273 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1274 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1276 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1277 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1279 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1280 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1282 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1283 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1285 typedef typename P::E E;
1287 unwind_info_compressed_second_level_page_header fields;
1292 // compressed dyld info load command
1294 template <typename P>
1295 class macho_dyld_info_command {
1297 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1298 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1300 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1301 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1303 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1304 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1306 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1307 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1309 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1310 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1312 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1313 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1315 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1316 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1318 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1319 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1321 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1322 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1324 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1325 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1327 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1328 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1330 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1331 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1334 typedef typename P::E E;
1336 dyld_info_command fields;
1341 // mach-o version load command
1343 template <typename P>
1344 class macho_version_min_command {
1346 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1347 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1349 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1350 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1352 uint32_t version() const INLINE { return fields.version; }
1353 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1355 #ifdef DICE_KIND_DATA
1356 uint32_t sdk() const INLINE { return fields.sdk; }
1357 void set_sdk(uint32_t value) INLINE { E::set32(fields.sdk, value); }
1359 uint32_t sdk() const INLINE { return fields.reserved; }
1360 void set_sdk(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1363 typedef typename P::E E;
1365 version_min_command fields;
1370 // mach-o __LD, __compact_unwind section in object files
1372 template <typename P>
1373 class macho_compact_unwind_entry {
1375 typedef typename P::E E;
1376 typedef typename P::uint_t pint_t;
1378 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1379 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1381 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1382 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1384 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1385 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1387 pint_t personality() const INLINE { return P::getP(_personality); }
1388 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1390 pint_t lsda() const INLINE { return P::getP(_lsda); }
1391 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1393 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1394 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1395 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1400 uint32_t _compactUnwindInfo;
1401 pint_t _personality;
1407 // mach-o source version load command
1409 template <typename P>
1410 class macho_source_version_command {
1412 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1413 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1415 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1416 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1418 uint64_t version() const INLINE { return fields.version; }
1419 void set_version(uint64_t value) INLINE { E::set64(fields.version, value); }
1421 typedef typename P::E E;
1423 source_version_command fields;
1428 // mach-o source version load command
1430 template <typename P>
1431 class macho_entry_point_command {
1433 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1434 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1436 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1437 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1439 uint64_t entryoff() const INLINE { return fields.entryoff; }
1440 void set_entryoff(uint64_t value) INLINE { E::set64(fields.entryoff, value); }
1442 uint64_t stacksize() const INLINE { return fields.stacksize; }
1443 void set_stacksize(uint64_t value) INLINE { E::set64(fields.stacksize, value); }
1445 typedef typename P::E E;
1447 entry_point_command fields;
1452 template <typename P>
1453 class macho_data_in_code_entry {
1455 uint32_t offset() const INLINE { return E::get32(fields.offset); }
1456 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
1458 uint16_t length() const INLINE { return E::get16(fields.length); }
1459 void set_length(uint16_t value) INLINE { E::set16((uint16_t&)fields.length, value); }
1461 uint16_t kind() const INLINE { return E::get16(fields.kind); }
1462 void set_kind(uint16_t value) INLINE { E::set16((uint16_t&)fields.kind, value); }
1464 typedef typename P::E E;
1466 data_in_code_entry fields;
1471 #endif // __MACH_O_FILE_ABSTRACTION__