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