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