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