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