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