]> git.saurik.com Git - apple/ld64.git/blob - src/abstraction/MachOFileAbstraction.hpp
8b58efd2357e3d6b7f83012634bf8914fcb3dec7
[apple/ld64.git] / src / abstraction / MachOFileAbstraction.hpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 #ifndef __MACH_O_FILE_ABSTRACTION__
25 #define __MACH_O_FILE_ABSTRACTION__
26
27 #include <mach-o/loader.h>
28 #include <mach-o/nlist.h>
29 #include <mach-o/reloc.h>
30 #include <mach-o/fat.h>
31 #include <mach-o/stab.h>
32 #include <mach-o/reloc.h>
33 #include <mach-o/x86_64/reloc.h>
34 #include <mach-o/compact_unwind_encoding.h>
35 #include <mach/machine.h>
36 #include <stddef.h>
37 #include <libunwind.h>
38
39 #include "FileAbstraction.hpp"
40
41 #include "configure.h"
42
43 // stuff that will eventually go away once newer cctools headers are widespread
44 #ifndef LC_LOAD_UPWARD_DYLIB
45 #define LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD) /* load of dylib whose initializers run later */
46 #endif
47
48 #ifndef CPU_SUBTYPE_ARM_V5TEJ
49 #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
50 #endif
51 #ifndef CPU_SUBTYPE_ARM_XSCALE
52 #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
53 #endif
54 #ifndef CPU_SUBTYPE_ARM_V7
55 #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
56 #endif
57
58 #ifndef N_ARM_THUMB_DEF
59 #define N_ARM_THUMB_DEF 0x0008
60 #endif
61 #ifndef MH_DEAD_STRIPPABLE_DYLIB
62 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
63 #endif
64 #ifndef MH_KEXT_BUNDLE
65 #define MH_KEXT_BUNDLE 11
66 #endif
67 #ifndef LC_DYLD_INFO
68 #define LC_DYLD_INFO 0x22 /* compressed dyld information */
69 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
70
71 struct dyld_info_command {
72 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
73 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
74 uint32_t rebase_off; /* file offset to rebase info */
75 uint32_t rebase_size; /* size of rebase info */
76 uint32_t bind_off; /* file offset to binding info */
77 uint32_t bind_size; /* size of binding info */
78 uint32_t weak_bind_off; /* file offset to weak binding info */
79 uint32_t weak_bind_size; /* size of weak binding info */
80 uint32_t lazy_bind_off; /* file offset to lazy binding info */
81 uint32_t lazy_bind_size; /* size of lazy binding infs */
82 uint32_t export_off; /* file offset to lazy binding info */
83 uint32_t export_size; /* size of lazy binding infs */
84 };
85
86 #define REBASE_TYPE_POINTER 1
87 #define REBASE_TYPE_TEXT_ABSOLUTE32 2
88 #define REBASE_TYPE_TEXT_PCREL32 3
89
90 #define REBASE_OPCODE_MASK 0xF0
91 #define REBASE_IMMEDIATE_MASK 0x0F
92 #define REBASE_OPCODE_DONE 0x00
93 #define REBASE_OPCODE_SET_TYPE_IMM 0x10
94 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
95 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
96 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
97 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
98 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
99 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
100 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
101
102 #define BIND_TYPE_POINTER 1
103 #define BIND_TYPE_TEXT_ABSOLUTE32 2
104 #define BIND_TYPE_TEXT_PCREL32 3
105
106 #define BIND_SPECIAL_DYLIB_SELF 0
107 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
108 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
109
110 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
111 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
112
113 #define BIND_OPCODE_MASK 0xF0
114 #define BIND_IMMEDIATE_MASK 0x0F
115 #define BIND_OPCODE_DONE 0x00
116 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
117 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
118 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
119 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
120 #define BIND_OPCODE_SET_TYPE_IMM 0x50
121 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60
122 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
123 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80
124 #define BIND_OPCODE_DO_BIND 0x90
125 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
126 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
127 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
128
129 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
130 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
131 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
132 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
133 #define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
134 #define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
135
136 #endif
137
138 #ifndef S_THREAD_LOCAL_REGULAR
139 #define S_THREAD_LOCAL_REGULAR 0x11
140 #endif
141
142 #ifndef S_THREAD_LOCAL_ZEROFILL
143 #define S_THREAD_LOCAL_ZEROFILL 0x12
144 #endif
145
146 #ifndef S_THREAD_LOCAL_VARIABLES
147 #define S_THREAD_LOCAL_VARIABLES 0x13
148 #endif
149
150 #ifndef S_THREAD_LOCAL_VARIABLE_POINTERS
151 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
152 #endif
153
154 #ifndef S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
155 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
156 #endif
157
158 #ifndef MH_HAS_TLV_DESCRIPTORS
159 #define MH_HAS_TLV_DESCRIPTORS 0x800000
160 #endif
161
162 #ifndef X86_64_RELOC_TLV
163 #define X86_64_RELOC_TLV 9
164 #endif
165
166 #define GENERIC_RLEOC_TLV 5
167
168 #ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
169 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
170 #endif
171
172 #ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
173 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
174 #endif
175
176 // type internal to linker
177 #define BIND_TYPE_OVERRIDE_OF_WEAKDEF_IN_DYLIB 0
178
179 #ifndef LC_VERSION_MIN_MACOSX
180 #define LC_VERSION_MIN_MACOSX 0x24
181 #define LC_VERSION_MIN_IPHONEOS 0x25
182
183 struct version_min_command {
184 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS */
185 uint32_t cmdsize; /* sizeof(struct min_version_command) */
186 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
187 uint32_t reserved; /* zero */
188 };
189 #endif
190
191 #ifndef N_SYMBOL_RESOLVER
192 #define N_SYMBOL_RESOLVER 0x100
193 #endif
194
195 #ifndef N_AST
196 #define N_AST 0x32
197 #endif
198
199 #ifndef LC_FUNCTION_STARTS
200 #define LC_FUNCTION_STARTS 0x26
201 #endif
202
203 #ifndef MH_NO_HEAP_EXECUTION
204 #define MH_NO_HEAP_EXECUTION 0x1000000
205 #endif
206
207 #ifndef LC_DYLD_ENVIRONMENT
208 #define LC_DYLD_ENVIRONMENT 0x27
209 #endif
210
211 #ifndef LC_DATA_IN_CODE
212 #define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */
213 struct data_in_code_entry {
214 uint32_t offset;
215 uint16_t length;
216 uint16_t kind;
217 };
218 #endif
219
220 #ifndef LC_DYLIB_CODE_SIGN_DRS
221 #define LC_DYLIB_CODE_SIGN_DRS 0x2B
222 #endif
223
224 #ifndef LC_ENCRYPTION_INFO_64
225 #define LC_ENCRYPTION_INFO_64 0x2C
226 struct encryption_info_command_64 {
227 uint32_t cmd;
228 uint32_t cmdsize;
229 uint32_t cryptoff;
230 uint32_t cryptsize;
231 uint32_t cryptid;
232 uint32_t pad;
233 };
234 #endif
235
236 #ifndef MH_APP_EXTENSION_SAFE
237 #define MH_APP_EXTENSION_SAFE 0x02000000
238 #endif
239
240 #ifndef N_ALT_ENTRY
241 #define N_ALT_ENTRY 0x0200
242 #endif
243
244 #ifndef CPU_SUBTYPE_ARM_V7F
245 #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
246 #endif
247 #ifndef CPU_SUBTYPE_ARM_V7K
248 #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
249 #endif
250 #ifndef CPU_SUBTYPE_ARM_V7S
251 #define CPU_SUBTYPE_ARM_V7S ((cpu_subtype_t) 11)
252 #endif
253
254
255
256 // hack until arm64 headers are worked out
257 #define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
258 #define CPU_SUBTYPE_ARM64_ALL 0
259 #define CPU_SUBTYPE_ARM64_V8 1
260
261 #define ARM64_RELOC_UNSIGNED 0 // for pointers
262 #define ARM64_RELOC_SUBTRACTOR 1 // must be followed by a ARM64_RELOC_UNSIGNED
263 #define ARM64_RELOC_BRANCH26 2 // a B/BL instruction with 26-bit displacement
264 #define ARM64_RELOC_PAGE21 3 // pc-rel distance to page of target
265 #define ARM64_RELOC_PAGEOFF12 4 // offset within page, scaled by r_length
266 #define ARM64_RELOC_GOT_LOAD_PAGE21 5 // pc-rel distance to page of GOT slot
267 #define ARM64_RELOC_GOT_LOAD_PAGEOFF12 6 // offset within page of GOT slot, scaled by r_length
268 #define ARM64_RELOC_POINTER_TO_GOT 7 // for pointers to GOT slots
269 #define ARM64_RELOC_TLVP_LOAD_PAGE21 8 // pc-rel distance to page of TLVP slot
270 #define ARM64_RELOC_TLVP_LOAD_PAGEOFF12 9 // offset within page of TLVP slot, scaled by r_length
271 #define ARM64_RELOC_ADDEND 10 // r_symbolnum is addend for next reloc
272
273
274
275 #define UNW_ARM64_X0 0
276 #define UNW_ARM64_X1 1
277 #define UNW_ARM64_X2 2
278 #define UNW_ARM64_X3 3
279 #define UNW_ARM64_X4 4
280 #define UNW_ARM64_X5 5
281 #define UNW_ARM64_X6 6
282 #define UNW_ARM64_X7 7
283 #define UNW_ARM64_X8 8
284 #define UNW_ARM64_X9 9
285 #define UNW_ARM64_X10 10
286 #define UNW_ARM64_X11 11
287 #define UNW_ARM64_X12 12
288 #define UNW_ARM64_X13 13
289 #define UNW_ARM64_X14 14
290 #define UNW_ARM64_X15 15
291 #define UNW_ARM64_X16 16
292 #define UNW_ARM64_X17 17
293 #define UNW_ARM64_X18 18
294 #define UNW_ARM64_X19 19
295 #define UNW_ARM64_X20 20
296 #define UNW_ARM64_X21 21
297 #define UNW_ARM64_X22 22
298 #define UNW_ARM64_X23 23
299 #define UNW_ARM64_X24 24
300 #define UNW_ARM64_X25 25
301 #define UNW_ARM64_X26 26
302 #define UNW_ARM64_X27 27
303 #define UNW_ARM64_X28 28
304 #define UNW_ARM64_X29 29
305 #define UNW_ARM64_FP 29
306 #define UNW_ARM64_X30 30
307 #define UNW_ARM64_LR 30
308 #define UNW_ARM64_X31 31
309 #define UNW_ARM64_SP 31
310 #define UNW_ARM64_D0 64
311 #define UNW_ARM64_D1 65
312 #define UNW_ARM64_D2 66
313 #define UNW_ARM64_D3 67
314 #define UNW_ARM64_D4 68
315 #define UNW_ARM64_D5 69
316 #define UNW_ARM64_D6 70
317 #define UNW_ARM64_D7 71
318 #define UNW_ARM64_D8 72
319 #define UNW_ARM64_D9 73
320 #define UNW_ARM64_D10 74
321 #define UNW_ARM64_D11 75
322 #define UNW_ARM64_D12 76
323 #define UNW_ARM64_D13 77
324 #define UNW_ARM64_D14 78
325 #define UNW_ARM64_D15 79
326 #define UNW_ARM64_D16 80
327 #define UNW_ARM64_D17 81
328 #define UNW_ARM64_D18 82
329 #define UNW_ARM64_D19 83
330 #define UNW_ARM64_D20 84
331 #define UNW_ARM64_D21 85
332 #define UNW_ARM64_D22 86
333 #define UNW_ARM64_D23 87
334 #define UNW_ARM64_D24 88
335 #define UNW_ARM64_D25 89
336 #define UNW_ARM64_D26 90
337 #define UNW_ARM64_D27 91
338 #define UNW_ARM64_D28 92
339 #define UNW_ARM64_D29 93
340 #define UNW_ARM64_D30 94
341 #define UNW_ARM64_D31 95
342
343 #define UNWIND_ARM64_MODE_MASK 0x0F000000
344 #define UNWIND_ARM64_MODE_FRAME_OLD 0x01000000
345 #define UNWIND_ARM64_MODE_FRAMELESS 0x02000000
346 #define UNWIND_ARM64_MODE_DWARF 0x03000000
347 #define UNWIND_ARM64_MODE_FRAME 0x04000000
348
349 #define UNWIND_ARM64_FRAME_X19_X20_PAIR 0x00000001
350 #define UNWIND_ARM64_FRAME_X21_X22_PAIR 0x00000002
351 #define UNWIND_ARM64_FRAME_X23_X24_PAIR 0x00000004
352 #define UNWIND_ARM64_FRAME_X25_X26_PAIR 0x00000008
353 #define UNWIND_ARM64_FRAME_X27_X28_PAIR 0x00000010
354 #define UNWIND_ARM64_FRAME_D8_D9_PAIR 0x00000100
355 #define UNWIND_ARM64_FRAME_D10_D11_PAIR 0x00000200
356 #define UNWIND_ARM64_FRAME_D12_D13_PAIR 0x00000400
357 #define UNWIND_ARM64_FRAME_D14_D15_PAIR 0x00000800
358
359 #define UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK 0x00FFF000
360
361 #define UNWIND_ARM64_FRAME_X21_X22_PAIR_OLD 0x00000001
362 #define UNWIND_ARM64_FRAME_X23_X24_PAIR_OLD 0x00000002
363 #define UNWIND_ARM64_FRAME_X25_X26_PAIR_OLD 0x00000004
364 #define UNWIND_ARM64_FRAME_X27_X28_PAIR_OLD 0x00000008
365 #define UNWIND_ARM64_FRAME_D8_D9_PAIR_OLD 0x00000010
366 #define UNWIND_ARM64_FRAME_D10_D11_PAIR_OLD 0x00000020
367 #define UNWIND_ARM64_FRAME_D12_D13_PAIR_OLD 0x00000040
368 #define UNWIND_ARM64_FRAME_D14_D15_PAIR_OLD 0x00000080
369
370
371 #define UNWIND_ARM64_DWARF_SECTION_OFFSET 0x00FFFFFF
372
373
374 #ifndef LC_SOURCE_VERSION
375 #define LC_SOURCE_VERSION 0x2A
376 struct source_version_command {
377 uint32_t cmd; /* LC_SOURCE_VERSION */
378 uint32_t cmdsize; /* 16 */
379 uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */
380 };
381 #endif
382
383 #ifndef LC_MAIN
384 #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */
385 struct entry_point_command {
386 uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */
387 uint32_t cmdsize; /* 24 */
388 uint64_t entryoff; /* file (__TEXT) offset of main() */
389 uint64_t stacksize;/* if not zero, initial stack size */
390 };
391 #endif
392
393 #ifndef LC_DYLIB_CODE_SIGN_DRS
394 #define LC_DYLIB_CODE_SIGN_DRS 0x2B
395 #endif
396
397 #ifndef LC_LINKER_OPTION
398 #define LC_LINKER_OPTION 0x2D
399
400 struct linker_option_command {
401 uint32_t cmd; /*LC_LINKER_OPTION only used in MH_OBJECT filetypes */
402 uint32_t cmdsize;
403 uint32_t count; /* number of strings */
404 /* concatenation of zero terminated UTF8 strings. Zero filled at end to align */
405 };
406 #endif
407
408 #ifndef LC_LINKER_OPTIMIZATION_HINTS
409 #define LC_LINKER_OPTIMIZATION_HINTS 0x2E
410 #define LOH_ARM64_ADRP_ADRP 1
411 #define LOH_ARM64_ADRP_LDR 2
412 #define LOH_ARM64_ADRP_ADD_LDR 3
413 #define LOH_ARM64_ADRP_LDR_GOT_LDR 4
414 #define LOH_ARM64_ADRP_ADD_STR 5
415 #define LOH_ARM64_ADRP_LDR_GOT_STR 6
416 #define LOH_ARM64_ADRP_ADD 7
417 #define LOH_ARM64_ADRP_LDR_GOT 8
418 #endif
419
420 #ifndef EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE
421 #define EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE 0x02
422 #endif
423
424
425 #ifndef CPU_SUBTYPE_ARM_V8
426 #define CPU_SUBTYPE_ARM_V8 ((cpu_subtype_t) 13)
427 #endif
428
429 #ifndef CPU_SUBTYPE_ARM_V6M
430 #define CPU_SUBTYPE_ARM_V6M ((cpu_subtype_t) 14)
431 #endif
432
433 #ifndef CPU_SUBTYPE_ARM_V7M
434 #define CPU_SUBTYPE_ARM_V7M ((cpu_subtype_t) 15)
435 #endif
436
437 #ifndef CPU_SUBTYPE_ARM_V7EM
438 #define CPU_SUBTYPE_ARM_V7EM ((cpu_subtype_t) 16)
439 #endif
440
441 #ifndef CPU_SUBTYPE_X86_64_H
442 #define CPU_SUBTYPE_X86_64_H ((cpu_subtype_t) 8)
443 #endif
444
445
446 struct ArchInfo {
447 const char* archName;
448 cpu_type_t cpuType;
449 cpu_subtype_t cpuSubType;
450 const char* llvmTriplePrefix;
451 const char* llvmTriplePrefixAlt;
452 bool isSubType;
453 bool supportsThumb2;
454 };
455
456 static const ArchInfo archInfoArray[] = {
457 #if SUPPORT_ARCH_x86_64
458 { "x86_64", CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL, "x86_64-", "", true, false },
459 #endif
460 #if SUPPORT_ARCH_x86_64h
461 { "x86_64h", CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_H, "x86_64h-", "", true, false },
462 #endif
463 #if SUPPORT_ARCH_i386
464 { "i386", CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL, "i386-", "", false, false },
465 #endif
466 #if SUPPORT_ARCH_armv4t
467 { "armv4t", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V4T, "armv4t-", "", true, false },
468 #define SUPPORT_ARCH_arm_any 1
469 #endif
470 #if SUPPORT_ARCH_armv5
471 { "armv5", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V5TEJ, "armv5e-", "", true, false },
472 #define SUPPORT_ARCH_arm_any 1
473 #endif
474 #if SUPPORT_ARCH_armv6
475 { "armv6", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6, "armv6-", "", true, false },
476 #define SUPPORT_ARCH_arm_any 1
477 #endif
478 #if SUPPORT_ARCH_armv7
479 { "armv7", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7, "thumbv7-", "armv7-", true, true },
480 #define SUPPORT_ARCH_arm_any 1
481 #endif
482 #if SUPPORT_ARCH_armv7f
483 { "armv7f", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7F, "thumbv7f-", "", true, true },
484 #define SUPPORT_ARCH_arm_any 1
485 #endif
486 #if SUPPORT_ARCH_armv7k
487 { "armv7k", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7K, "thumbv7k-", "", true, true },
488 #define SUPPORT_ARCH_arm_any 1
489 #endif
490 #if SUPPORT_ARCH_armv7s
491 { "armv7s", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7S, "thumbv7s-", "armv7s", true, true },
492 #define SUPPORT_ARCH_arm_any 1
493 #endif
494 #if SUPPORT_ARCH_armv6m
495 { "armv6m", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6M, "thumbv6m-", "", true, false },
496 #define SUPPORT_ARCH_arm_any 1
497 #endif
498 #if SUPPORT_ARCH_armv7m
499 { "armv7m", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7M, "thumbv7m-", "armv7m", true, true },
500 #define SUPPORT_ARCH_arm_any 1
501 #endif
502 #if SUPPORT_ARCH_armv7em
503 { "armv7em", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7EM, "thumbv7em-", "armv7em", true, true },
504 #define SUPPORT_ARCH_arm_any 1
505 #endif
506 #if SUPPORT_ARCH_armv8
507 { "armv8", CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V8, "thumbv8-", "armv8", true, true },
508 #define SUPPORT_ARCH_arm_any 1
509 #endif
510 #if SUPPORT_ARCH_arm64
511 { "arm64", CPU_TYPE_ARM64, CPU_SUBTYPE_ARM64_ALL, "arm64-", "", false, false },
512 #endif
513 #if SUPPORT_ARCH_arm64v8
514 { "arm64v8", CPU_TYPE_ARM64, CPU_SUBTYPE_ARM64_V8, "arm64v8-", "", true, false },
515 #endif
516 { NULL, 0, 0, NULL, NULL, false, false }
517 };
518
519
520 // weird, but this include must wait until after SUPPORT_ARCH_arm_any is set up
521 #if SUPPORT_ARCH_arm_any
522 #include <mach-o/arm/reloc.h>
523 #endif
524
525 // hack until newer <mach-o/arm/reloc.h> everywhere
526 #define ARM_RELOC_HALF 8
527 #define ARM_RELOC_HALF_SECTDIFF 9
528
529
530
531 //
532 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
533 //
534
535
536
537 //
538 // mach-o file header
539 //
540 template <typename P> struct macho_header_content {};
541 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
542 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
543 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
544 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
545
546 template <typename P>
547 class macho_header {
548 public:
549 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
550 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
551
552 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
553 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
554
555 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
556 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
557
558 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
559 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
560
561 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
562 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
563
564 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
565 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
566
567 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
568 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
569
570 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
571 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
572
573 typedef typename P::E E;
574 private:
575 macho_header_content<P> header;
576 };
577
578
579 //
580 // mach-o load command
581 //
582 template <typename P>
583 class macho_load_command {
584 public:
585 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
586 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
587
588 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
589 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
590
591 typedef typename P::E E;
592 private:
593 load_command command;
594 };
595
596
597 //
598 // mach-o segment load command
599 //
600 template <typename P> struct macho_segment_content {};
601 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
602 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
603 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
604 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
605
606 template <typename P>
607 class macho_segment_command {
608 public:
609 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
610 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
611
612 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
613 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
614
615 const char* segname() const INLINE { return segment.fields.segname; }
616 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
617
618 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
619 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
620
621 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
622 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
623
624 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
625 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
626
627 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
628 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
629
630 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
631 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
632
633 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
634 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
635
636 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
637 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
638
639 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
640 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
641
642 enum {
643 CMD = macho_segment_content<P>::CMD
644 };
645
646 typedef typename P::E E;
647 private:
648 macho_segment_content<P> segment;
649 };
650
651
652 //
653 // mach-o section
654 //
655 template <typename P> struct macho_section_content {};
656 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
657 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
658 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
659 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
660
661 template <typename P>
662 class macho_section {
663 public:
664 const char* sectname() const INLINE { return section.fields.sectname; }
665 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
666
667 const char* segname() const INLINE { return section.fields.segname; }
668 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
669
670 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
671 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
672
673 uint64_t size() const INLINE { return P::getP(section.fields.size); }
674 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
675
676 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
677 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
678
679 uint32_t align() const INLINE { return E::get32(section.fields.align); }
680 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
681
682 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
683 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
684
685 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
686 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
687
688 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
689 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
690
691 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
692 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
693
694 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
695 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
696
697 typedef typename P::E E;
698 private:
699 macho_section_content<P> section;
700 };
701
702
703 //
704 // mach-o dylib load command
705 //
706 template <typename P>
707 class macho_dylib_command {
708 public:
709 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
710 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
711
712 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
713 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
714
715 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
716 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
717
718 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
719 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
720
721 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
722 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
723
724 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
725 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
726
727 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
728 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
729
730 typedef typename P::E E;
731 private:
732 dylib_command fields;
733 };
734
735
736 //
737 // mach-o dylinker load command
738 //
739 template <typename P>
740 class macho_dylinker_command {
741 public:
742 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
743 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
744
745 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
746 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
747
748 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
749 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
750
751 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
752 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
753
754 typedef typename P::E E;
755 private:
756 dylinker_command fields;
757 };
758
759
760 //
761 // mach-o sub_framework load command
762 //
763 template <typename P>
764 class macho_sub_framework_command {
765 public:
766 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
767 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
768
769 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
770 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
771
772 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
773 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
774
775 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
776 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
777
778 typedef typename P::E E;
779 private:
780 sub_framework_command fields;
781 };
782
783
784 //
785 // mach-o sub_client load command
786 //
787 template <typename P>
788 class macho_sub_client_command {
789 public:
790 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
791 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
792
793 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
794 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
795
796 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
797 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
798
799 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
800 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
801
802 typedef typename P::E E;
803 private:
804 sub_client_command fields;
805 };
806
807
808 //
809 // mach-o sub_umbrella load command
810 //
811 template <typename P>
812 class macho_sub_umbrella_command {
813 public:
814 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
815 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
816
817 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
818 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
819
820 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
821 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
822
823 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
824 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
825
826 typedef typename P::E E;
827 private:
828 sub_umbrella_command fields;
829 };
830
831
832 //
833 // mach-o sub_library load command
834 //
835 template <typename P>
836 class macho_sub_library_command {
837 public:
838 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
839 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
840
841 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
842 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
843
844 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
845 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
846
847 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
848 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
849
850 typedef typename P::E E;
851 private:
852 sub_library_command fields;
853 };
854
855
856 //
857 // mach-o uuid load command
858 //
859 template <typename P>
860 class macho_uuid_command {
861 public:
862 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
863 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
864
865 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
866 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
867
868 const uint8_t* uuid() const INLINE { return fields.uuid; }
869 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
870
871 typedef typename P::E E;
872 private:
873 uuid_command fields;
874 };
875
876
877 //
878 // mach-o routines load command
879 //
880 template <typename P> struct macho_routines_content {};
881 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
882 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
883 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
884 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
885
886 template <typename P>
887 class macho_routines_command {
888 public:
889 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
890 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
891
892 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
893 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
894
895 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
896 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
897
898 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
899 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
900
901 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
902 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
903
904 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
905 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
906
907 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
908 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
909
910 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
911 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
912
913 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
914 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
915
916 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
917 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
918
919 typedef typename P::E E;
920 enum {
921 CMD = macho_routines_content<P>::CMD
922 };
923 private:
924 macho_routines_content<P> routines;
925 };
926
927
928 //
929 // mach-o symbol table load command
930 //
931 template <typename P>
932 class macho_symtab_command {
933 public:
934 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
935 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
936
937 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
938 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
939
940 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
941 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
942
943 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
944 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
945
946 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
947 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
948
949 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
950 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
951
952
953 typedef typename P::E E;
954 private:
955 symtab_command fields;
956 };
957
958
959 //
960 // mach-o dynamic symbol table load command
961 //
962 template <typename P>
963 class macho_dysymtab_command {
964 public:
965 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
966 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
967
968 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
969 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
970
971 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
972 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
973
974 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
975 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
976
977 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
978 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
979
980 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
981 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
982
983 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
984 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
985
986 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
987 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
988
989 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
990 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
991
992 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
993 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
994
995 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
996 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
997
998 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
999 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
1000
1001 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
1002 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
1003
1004 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
1005 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
1006
1007 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
1008 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
1009
1010 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
1011 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
1012
1013 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
1014 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
1015
1016 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
1017 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
1018
1019 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
1020 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
1021
1022 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
1023 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
1024
1025 typedef typename P::E E;
1026 private:
1027 dysymtab_command fields;
1028 };
1029
1030
1031
1032
1033 //
1034 // mach-o module table entry (for compatibility with old ld/dyld)
1035 //
1036 template <typename P> struct macho_dylib_module_content {};
1037 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
1038 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
1039 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
1040 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
1041
1042 template <typename P>
1043 class macho_dylib_module {
1044 public:
1045 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
1046 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
1047
1048 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
1049 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
1050
1051 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
1052 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
1053
1054 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
1055 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
1056
1057 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
1058 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
1059
1060 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
1061 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
1062
1063 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
1064 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
1065
1066 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
1067 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
1068
1069 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
1070 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
1071
1072 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
1073 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
1074 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
1075
1076 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
1077 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
1078 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
1079
1080 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
1081 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
1082
1083 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
1084 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
1085
1086
1087 typedef typename P::E E;
1088 private:
1089 macho_dylib_module_content<P> module;
1090 };
1091
1092
1093 //
1094 // mach-o dylib_reference entry
1095 //
1096 template <typename P>
1097 class macho_dylib_reference {
1098 public:
1099 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
1100 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
1101
1102 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
1103 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
1104
1105 typedef typename P::E E;
1106 private:
1107 uint32_t fields;
1108 };
1109
1110
1111
1112 //
1113 // mach-o two-level hints load command
1114 //
1115 template <typename P>
1116 class macho_dylib_table_of_contents {
1117 public:
1118 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
1119 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
1120
1121 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
1122 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
1123
1124 typedef typename P::E E;
1125 private:
1126 dylib_table_of_contents fields;
1127 };
1128
1129
1130
1131 //
1132 // mach-o two-level hints load command
1133 //
1134 template <typename P>
1135 class macho_twolevel_hints_command {
1136 public:
1137 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1138 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1139
1140 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1141 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1142
1143 uint32_t offset() const INLINE { return E::get32(fields.offset); }
1144 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
1145
1146 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
1147 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
1148
1149 typedef typename P::E E;
1150 private:
1151 twolevel_hints_command fields;
1152 };
1153
1154
1155 //
1156 // mach-o threads load command
1157 //
1158 template <typename P>
1159 class macho_thread_command {
1160 public:
1161 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1162 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1163
1164 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1165 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1166
1167 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
1168 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
1169
1170 uint32_t count() const INLINE { return E::get32(fields_count); }
1171 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
1172
1173 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
1174 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
1175
1176 typedef typename P::E E;
1177 typedef typename P::uint_t pint_t;
1178 private:
1179 struct thread_command fields;
1180 uint32_t fields_flavor;
1181 uint32_t fields_count;
1182 pint_t thread_registers[1];
1183 };
1184
1185
1186 //
1187 // mach-o misc data
1188 //
1189 template <typename P>
1190 class macho_linkedit_data_command {
1191 public:
1192 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1193 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1194
1195 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1196 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1197
1198 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
1199 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
1200
1201 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
1202 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
1203
1204
1205 typedef typename P::E E;
1206 private:
1207 struct linkedit_data_command fields;
1208 };
1209
1210
1211 //
1212 // mach-o rpath
1213 //
1214 template <typename P>
1215 class macho_rpath_command {
1216 public:
1217 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1218 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1219
1220 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1221 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1222
1223 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
1224 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
1225
1226 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
1227 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
1228
1229
1230 typedef typename P::E E;
1231 private:
1232 struct rpath_command fields;
1233 };
1234
1235
1236
1237 //
1238 // mach-o symbol table entry
1239 //
1240 template <typename P> struct macho_nlist_content {};
1241 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
1242 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
1243 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
1244 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
1245
1246 template <typename P>
1247 class macho_nlist {
1248 public:
1249 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
1250 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
1251
1252 uint8_t n_type() const INLINE { return entry.fields.n_type; }
1253 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
1254
1255 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
1256 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
1257
1258 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
1259 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
1260
1261 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
1262 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
1263
1264 typedef typename P::E E;
1265 private:
1266 macho_nlist_content<P> entry;
1267 };
1268
1269
1270
1271 //
1272 // mach-o relocation info
1273 //
1274 template <typename P>
1275 class macho_relocation_info {
1276 public:
1277 uint32_t r_address() const INLINE { return E::get32(address); }
1278 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
1279
1280 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
1281 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
1282
1283 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
1284 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
1285
1286 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
1287 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
1288
1289 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
1290 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1291
1292 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1293 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1294
1295 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1296
1297 typedef typename P::E E;
1298 private:
1299 uint32_t address;
1300 uint32_t other;
1301 };
1302
1303
1304 //
1305 // mach-o scattered relocation info
1306 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1307 //
1308 template <typename P>
1309 class macho_scattered_relocation_info {
1310 public:
1311 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1312 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1313
1314 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1315 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1316
1317 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1318 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1319
1320 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1321 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1322
1323 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1324 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1325 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1326
1327 uint32_t r_value() const INLINE { return E::get32(value); }
1328 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1329
1330 uint32_t r_other() const INLINE { return other; }
1331
1332 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1333
1334 typedef typename P::E E;
1335 private:
1336 uint32_t other;
1337 uint32_t value;
1338 };
1339
1340
1341
1342 //
1343 // mach-o encyrption info load command
1344 //
1345 template <typename P> struct macho_encryption_info_content {};
1346 template <> struct macho_encryption_info_content<Pointer32<BigEndian> > { struct encryption_info_command fields; };
1347 template <> struct macho_encryption_info_content<Pointer64<BigEndian> > { struct encryption_info_command_64 fields; };
1348 template <> struct macho_encryption_info_content<Pointer32<LittleEndian> > { struct encryption_info_command fields; };
1349 template <> struct macho_encryption_info_content<Pointer64<LittleEndian> > { struct encryption_info_command_64 fields; };
1350
1351
1352 template <typename P>
1353 class macho_encryption_info_command {
1354 public:
1355 uint32_t cmd() const INLINE { return E::get32(entry.fields.cmd); }
1356 void set_cmd(uint32_t value) INLINE { E::set32(entry.fields.cmd, value); }
1357
1358 uint32_t cmdsize() const INLINE { return E::get32(entry.fields.cmdsize); }
1359 void set_cmdsize(uint32_t value) INLINE { E::set32(entry.fields.cmdsize, value); }
1360
1361 uint32_t cryptoff() const INLINE { return E::get32(entry.fields.cryptoff); }
1362 void set_cryptoff(uint32_t value) INLINE { E::set32(entry.fields.cryptoff, value); }
1363
1364 uint32_t cryptsize() const INLINE { return E::get32(entry.fields.cryptsize); }
1365 void set_cryptsize(uint32_t value) INLINE { E::set32(entry.fields.cryptsize, value); }
1366
1367 uint32_t cryptid() const INLINE { return E::get32(entry.fields.cryptid); }
1368 void set_cryptid(uint32_t value) INLINE { E::set32(entry.fields.cryptid, value); }
1369
1370 uint32_t pad() const INLINE { return E::get32(entry.fields.pad); }
1371 void set_pad(uint32_t value) INLINE { E::set32(entry.fields.pad, value); }
1372
1373 typedef typename P::E E;
1374 private:
1375 macho_encryption_info_content<P> entry;
1376 };
1377
1378
1379 //
1380 // start of __unwind_info section
1381 //
1382 template <typename P>
1383 class macho_unwind_info_section_header {
1384 public:
1385 uint32_t version() const INLINE { return E::get32(fields.version); }
1386 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1387
1388 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1389 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1390
1391 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1392 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1393
1394 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1395 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1396
1397 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1398 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1399
1400 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1401 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1402
1403 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1404 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1405
1406 typedef typename P::E E;
1407 private:
1408 unwind_info_section_header fields;
1409 };
1410
1411
1412
1413 //
1414 // uwind first level index entry
1415 //
1416 template <typename P>
1417 class macho_unwind_info_section_header_index_entry {
1418 public:
1419 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1420 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1421
1422 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1423 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1424
1425 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1426 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1427
1428 typedef typename P::E E;
1429 private:
1430 unwind_info_section_header_index_entry fields;
1431 };
1432
1433
1434 //
1435 // LSDA table entry
1436 //
1437 template <typename P>
1438 class macho_unwind_info_section_header_lsda_index_entry {
1439 public:
1440 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1441 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1442
1443 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1444 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1445
1446 typedef typename P::E E;
1447 private:
1448 unwind_info_section_header_lsda_index_entry fields;
1449 };
1450
1451
1452 //
1453 // regular second level entry
1454 //
1455 template <typename P>
1456 class macho_unwind_info_regular_second_level_entry {
1457 public:
1458 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1459 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1460
1461 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1462 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1463
1464 typedef typename P::E E;
1465 private:
1466 unwind_info_regular_second_level_entry fields;
1467 };
1468
1469
1470 //
1471 // start of second level regular page
1472 //
1473 template <typename P>
1474 class macho_unwind_info_regular_second_level_page_header {
1475 public:
1476 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1477 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1478
1479 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1480 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1481
1482 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1483 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1484
1485 typedef typename P::E E;
1486 private:
1487 unwind_info_regular_second_level_page_header fields;
1488 };
1489
1490
1491 //
1492 // start of second level compressed page
1493 //
1494 template <typename P>
1495 class macho_unwind_info_compressed_second_level_page_header {
1496 public:
1497 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1498 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1499
1500 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1501 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1502
1503 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1504 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1505
1506 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1507 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1508
1509 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1510 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1511
1512 typedef typename P::E E;
1513 private:
1514 unwind_info_compressed_second_level_page_header fields;
1515 };
1516
1517
1518 //
1519 // compressed dyld info load command
1520 //
1521 template <typename P>
1522 class macho_dyld_info_command {
1523 public:
1524 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1525 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1526
1527 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1528 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1529
1530 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1531 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1532
1533 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1534 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1535
1536 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1537 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1538
1539 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1540 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1541
1542 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1543 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1544
1545 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1546 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1547
1548 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1549 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1550
1551 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1552 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1553
1554 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1555 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1556
1557 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1558 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1559
1560
1561 typedef typename P::E E;
1562 private:
1563 dyld_info_command fields;
1564 };
1565
1566
1567 //
1568 // mach-o version load command
1569 //
1570 template <typename P>
1571 class macho_version_min_command {
1572 public:
1573 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1574 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1575
1576 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1577 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1578
1579 uint32_t version() const INLINE { return fields.version; }
1580 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1581
1582 #ifdef DICE_KIND_DATA
1583 uint32_t sdk() const INLINE { return fields.sdk; }
1584 void set_sdk(uint32_t value) INLINE { E::set32(fields.sdk, value); }
1585 #else
1586 uint32_t sdk() const INLINE { return fields.reserved; }
1587 void set_sdk(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1588 #endif
1589
1590 typedef typename P::E E;
1591 private:
1592 version_min_command fields;
1593 };
1594
1595
1596 //
1597 // mach-o __LD, __compact_unwind section in object files
1598 //
1599 template <typename P>
1600 class macho_compact_unwind_entry {
1601 public:
1602 typedef typename P::E E;
1603 typedef typename P::uint_t pint_t;
1604
1605 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1606 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1607
1608 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1609 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1610
1611 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1612 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1613
1614 pint_t personality() const INLINE { return P::getP(_personality); }
1615 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1616
1617 pint_t lsda() const INLINE { return P::getP(_lsda); }
1618 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1619
1620 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1621 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1622 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1623
1624 private:
1625 pint_t _codeStart;
1626 uint32_t _codeLen;
1627 uint32_t _compactUnwindInfo;
1628 pint_t _personality;
1629 pint_t _lsda;
1630 };
1631
1632
1633 //
1634 // mach-o source version load command
1635 //
1636 template <typename P>
1637 class macho_source_version_command {
1638 public:
1639 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1640 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1641
1642 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1643 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1644
1645 uint64_t version() const INLINE { return fields.version; }
1646 void set_version(uint64_t value) INLINE { E::set64(fields.version, value); }
1647
1648 typedef typename P::E E;
1649 private:
1650 source_version_command fields;
1651 };
1652
1653
1654 //
1655 // mach-o source version load command
1656 //
1657 template <typename P>
1658 class macho_entry_point_command {
1659 public:
1660 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1661 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1662
1663 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1664 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1665
1666 uint64_t entryoff() const INLINE { return fields.entryoff; }
1667 void set_entryoff(uint64_t value) INLINE { E::set64(fields.entryoff, value); }
1668
1669 uint64_t stacksize() const INLINE { return fields.stacksize; }
1670 void set_stacksize(uint64_t value) INLINE { E::set64(fields.stacksize, value); }
1671
1672 typedef typename P::E E;
1673 private:
1674 entry_point_command fields;
1675 };
1676
1677
1678
1679 template <typename P>
1680 class macho_data_in_code_entry {
1681 public:
1682 uint32_t offset() const INLINE { return E::get32(fields.offset); }
1683 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
1684
1685 uint16_t length() const INLINE { return E::get16(fields.length); }
1686 void set_length(uint16_t value) INLINE { E::set16((uint16_t&)fields.length, value); }
1687
1688 uint16_t kind() const INLINE { return E::get16(fields.kind); }
1689 void set_kind(uint16_t value) INLINE { E::set16((uint16_t&)fields.kind, value); }
1690
1691 typedef typename P::E E;
1692 private:
1693 data_in_code_entry fields;
1694 };
1695
1696 #ifndef DICE_KIND_DATA
1697 #define DICE_KIND_DATA 0x0001
1698 #define DICE_KIND_JUMP_TABLE8 0x0002
1699 #define DICE_KIND_JUMP_TABLE16 0x0003
1700 #define DICE_KIND_JUMP_TABLE32 0x0004
1701 #define DICE_KIND_ABS_JUMP_TABLE32 0x0005
1702 #endif
1703
1704 template <typename P>
1705 class macho_linker_option_command {
1706 public:
1707 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1708 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1709
1710 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1711 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1712
1713 uint64_t count() const INLINE { return fields.count; }
1714 void set_count(uint32_t value) INLINE { E::set32(fields.count, value); }
1715
1716 const char* buffer() const INLINE { return ((char*)&fields) + sizeof(linker_option_command); }
1717 char* buffer() INLINE { return ((char*)&fields) + sizeof(linker_option_command); }
1718
1719 typedef typename P::E E;
1720 private:
1721 linker_option_command fields;
1722 };
1723
1724
1725
1726
1727
1728 #endif // __MACH_O_FILE_ABSTRACTION__
1729
1730