]> git.saurik.com Git - apple/ld64.git/blob - src/abstraction/MachOFileAbstraction.hpp
ld64-127.2.tar.gz
[apple/ld64.git] / src / abstraction / MachOFileAbstraction.hpp
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005-2010 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 #ifndef __MACH_O_FILE_ABSTRACTION__
25 #define __MACH_O_FILE_ABSTRACTION__
26
27 #include <mach-o/loader.h>
28 #include <mach-o/nlist.h>
29 #include <mach-o/reloc.h>
30 #include <mach-o/fat.h>
31 #include <mach-o/stab.h>
32 #include <mach-o/reloc.h>
33 #include <mach-o/ppc/reloc.h>
34 #include <mach-o/x86_64/reloc.h>
35 #include <mach-o/arm/reloc.h>
36 #include <mach-o/compact_unwind_encoding.h>
37 #include <mach/machine.h>
38 #include <stddef.h>
39
40 #include "FileAbstraction.hpp"
41
42
43 // stuff that will eventually go away once newer cctools headers are widespread
44 #ifndef LC_LOAD_UPWARD_DYLIB
45 #define LC_LOAD_UPWARD_DYLIB (0x23|LC_REQ_DYLD) /* load of dylib whose initializers run later */
46 #endif
47
48 #ifndef CPU_SUBTYPE_ARM_V5TEJ
49 #define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7)
50 #endif
51 #ifndef CPU_SUBTYPE_ARM_XSCALE
52 #define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8)
53 #endif
54 #ifndef CPU_SUBTYPE_ARM_V7
55 #define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9)
56 #endif
57
58 #ifndef ARM_THUMB_32BIT_BRANCH
59 #define ARM_THUMB_32BIT_BRANCH 7
60 #endif
61 #ifndef N_ARM_THUMB_DEF
62 #define N_ARM_THUMB_DEF 0x0008
63 #endif
64 #ifndef MH_DEAD_STRIPPABLE_DYLIB
65 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000
66 #endif
67 #ifndef MH_KEXT_BUNDLE
68 #define MH_KEXT_BUNDLE 11
69 #endif
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
139 #endif
140
141 #ifndef S_THREAD_LOCAL_REGULAR
142 #define S_THREAD_LOCAL_REGULAR 0x11
143 #endif
144
145 #ifndef S_THREAD_LOCAL_ZEROFILL
146 #define S_THREAD_LOCAL_ZEROFILL 0x12
147 #endif
148
149 #ifndef S_THREAD_LOCAL_VARIABLES
150 #define S_THREAD_LOCAL_VARIABLES 0x13
151 #endif
152
153 #ifndef S_THREAD_LOCAL_VARIABLE_POINTERS
154 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14
155 #endif
156
157 #ifndef S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
158 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15
159 #endif
160
161 #ifndef MH_HAS_TLV_DESCRIPTORS
162 #define MH_HAS_TLV_DESCRIPTORS 0x800000
163 #endif
164
165 #ifndef X86_64_RELOC_TLV
166 #define X86_64_RELOC_TLV 9
167 #endif
168
169 #define GENERIC_RLEOC_TLV 5
170
171 #ifndef EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
172 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10
173 #endif
174
175 #ifndef EXPORT_SYMBOL_FLAGS_REEXPORT
176 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08
177 #endif
178
179 // type internal to linker
180 #define BIND_TYPE_OVERRIDE_OF_WEAKDEF_IN_DYLIB 0
181
182 #ifndef LC_VERSION_MIN_MACOSX
183 #define LC_VERSION_MIN_MACOSX 0x24
184 #define LC_VERSION_MIN_IPHONEOS 0x25
185
186 struct version_min_command {
187 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS */
188 uint32_t cmdsize; /* sizeof(struct min_version_command) */
189 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
190 uint32_t reserved; /* zero */
191 };
192 #endif
193
194 #ifndef N_SYMBOL_RESOLVER
195 #define N_SYMBOL_RESOLVER 0x100
196 #endif
197
198 #ifndef LC_FUNCTION_STARTS
199 #define LC_FUNCTION_STARTS 0x26
200 #endif
201
202 #ifndef MH_NO_HEAP_EXECUTION
203 #define MH_NO_HEAP_EXECUTION 0x1000000
204 #endif
205
206 #ifndef LC_DYLD_ENVIRONMENT
207 #define LC_DYLD_ENVIRONMENT 0x27
208 #endif
209
210 // hack until newer <mach-o/arm/reloc.h> everywhere
211 #define ARM_RELOC_HALF 8
212 #define ARM_RELOC_HALF_SECTDIFF 9
213
214 #ifndef CPU_SUBTYPE_ARM_V7F
215 #define CPU_SUBTYPE_ARM_V7F ((cpu_subtype_t) 10)
216 #endif
217 #ifndef CPU_SUBTYPE_ARM_V7K
218 #define CPU_SUBTYPE_ARM_V7K ((cpu_subtype_t) 12)
219 #endif
220
221 struct ARMSubType {
222 const char* subTypeName;
223 const char* llvmTriplePrefix;
224 cpu_subtype_t subType;
225 bool supportsThumb2;
226 };
227
228 static const ARMSubType ARMSubTypes[] = {
229 { "armv4t","armv4t-", CPU_SUBTYPE_ARM_V4T, false },
230 { "armv5", "armv5e-", CPU_SUBTYPE_ARM_V5TEJ, false },
231 { "armv6", "armv6-", CPU_SUBTYPE_ARM_V6, false },
232 { "armv7", "thumbv7-", CPU_SUBTYPE_ARM_V7, true },
233 { "armv7f", "thumbv7f-", CPU_SUBTYPE_ARM_V7F, true },
234 { "armv7k", "thumbv7k-", CPU_SUBTYPE_ARM_V7K, true },
235 { 0, NULL, false }
236 };
237
238
239
240
241 //
242 // This abstraction layer makes every mach-o file look like a 64-bit mach-o file with native endianness
243 //
244
245
246
247 //
248 // mach-o file header
249 //
250 template <typename P> struct macho_header_content {};
251 template <> struct macho_header_content<Pointer32<BigEndian> > { mach_header fields; };
252 template <> struct macho_header_content<Pointer64<BigEndian> > { mach_header_64 fields; };
253 template <> struct macho_header_content<Pointer32<LittleEndian> > { mach_header fields; };
254 template <> struct macho_header_content<Pointer64<LittleEndian> > { mach_header_64 fields; };
255
256 template <typename P>
257 class macho_header {
258 public:
259 uint32_t magic() const INLINE { return E::get32(header.fields.magic); }
260 void set_magic(uint32_t value) INLINE { E::set32(header.fields.magic, value); }
261
262 uint32_t cputype() const INLINE { return E::get32(header.fields.cputype); }
263 void set_cputype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cputype, value); }
264
265 uint32_t cpusubtype() const INLINE { return E::get32(header.fields.cpusubtype); }
266 void set_cpusubtype(uint32_t value) INLINE { E::set32((uint32_t&)header.fields.cpusubtype, value); }
267
268 uint32_t filetype() const INLINE { return E::get32(header.fields.filetype); }
269 void set_filetype(uint32_t value) INLINE { E::set32(header.fields.filetype, value); }
270
271 uint32_t ncmds() const INLINE { return E::get32(header.fields.ncmds); }
272 void set_ncmds(uint32_t value) INLINE { E::set32(header.fields.ncmds, value); }
273
274 uint32_t sizeofcmds() const INLINE { return E::get32(header.fields.sizeofcmds); }
275 void set_sizeofcmds(uint32_t value) INLINE { E::set32(header.fields.sizeofcmds, value); }
276
277 uint32_t flags() const INLINE { return E::get32(header.fields.flags); }
278 void set_flags(uint32_t value) INLINE { E::set32(header.fields.flags, value); }
279
280 uint32_t reserved() const INLINE { return E::get32(header.fields.reserved); }
281 void set_reserved(uint32_t value) INLINE { E::set32(header.fields.reserved, value); }
282
283 typedef typename P::E E;
284 private:
285 macho_header_content<P> header;
286 };
287
288
289 //
290 // mach-o load command
291 //
292 template <typename P>
293 class macho_load_command {
294 public:
295 uint32_t cmd() const INLINE { return E::get32(command.cmd); }
296 void set_cmd(uint32_t value) INLINE { E::set32(command.cmd, value); }
297
298 uint32_t cmdsize() const INLINE { return E::get32(command.cmdsize); }
299 void set_cmdsize(uint32_t value) INLINE { E::set32(command.cmdsize, value); }
300
301 typedef typename P::E E;
302 private:
303 load_command command;
304 };
305
306
307 //
308 // mach-o segment load command
309 //
310 template <typename P> struct macho_segment_content {};
311 template <> struct macho_segment_content<Pointer32<BigEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
312 template <> struct macho_segment_content<Pointer64<BigEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
313 template <> struct macho_segment_content<Pointer32<LittleEndian> > { segment_command fields; enum { CMD = LC_SEGMENT }; };
314 template <> struct macho_segment_content<Pointer64<LittleEndian> > { segment_command_64 fields; enum { CMD = LC_SEGMENT_64 }; };
315
316 template <typename P>
317 class macho_segment_command {
318 public:
319 uint32_t cmd() const INLINE { return E::get32(segment.fields.cmd); }
320 void set_cmd(uint32_t value) INLINE { E::set32(segment.fields.cmd, value); }
321
322 uint32_t cmdsize() const INLINE { return E::get32(segment.fields.cmdsize); }
323 void set_cmdsize(uint32_t value) INLINE { E::set32(segment.fields.cmdsize, value); }
324
325 const char* segname() const INLINE { return segment.fields.segname; }
326 void set_segname(const char* value) INLINE { strncpy(segment.fields.segname, value, 16); }
327
328 uint64_t vmaddr() const INLINE { return P::getP(segment.fields.vmaddr); }
329 void set_vmaddr(uint64_t value) INLINE { P::setP(segment.fields.vmaddr, value); }
330
331 uint64_t vmsize() const INLINE { return P::getP(segment.fields.vmsize); }
332 void set_vmsize(uint64_t value) INLINE { P::setP(segment.fields.vmsize, value); }
333
334 uint64_t fileoff() const INLINE { return P::getP(segment.fields.fileoff); }
335 void set_fileoff(uint64_t value) INLINE { P::setP(segment.fields.fileoff, value); }
336
337 uint64_t filesize() const INLINE { return P::getP(segment.fields.filesize); }
338 void set_filesize(uint64_t value) INLINE { P::setP(segment.fields.filesize, value); }
339
340 uint32_t maxprot() const INLINE { return E::get32(segment.fields.maxprot); }
341 void set_maxprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.maxprot, value); }
342
343 uint32_t initprot() const INLINE { return E::get32(segment.fields.initprot); }
344 void set_initprot(uint32_t value) INLINE { E::set32((uint32_t&)segment.fields.initprot, value); }
345
346 uint32_t nsects() const INLINE { return E::get32(segment.fields.nsects); }
347 void set_nsects(uint32_t value) INLINE { E::set32(segment.fields.nsects, value); }
348
349 uint32_t flags() const INLINE { return E::get32(segment.fields.flags); }
350 void set_flags(uint32_t value) INLINE { E::set32(segment.fields.flags, value); }
351
352 enum {
353 CMD = macho_segment_content<P>::CMD
354 };
355
356 typedef typename P::E E;
357 private:
358 macho_segment_content<P> segment;
359 };
360
361
362 //
363 // mach-o section
364 //
365 template <typename P> struct macho_section_content {};
366 template <> struct macho_section_content<Pointer32<BigEndian> > { section fields; };
367 template <> struct macho_section_content<Pointer64<BigEndian> > { section_64 fields; };
368 template <> struct macho_section_content<Pointer32<LittleEndian> > { section fields; };
369 template <> struct macho_section_content<Pointer64<LittleEndian> > { section_64 fields; };
370
371 template <typename P>
372 class macho_section {
373 public:
374 const char* sectname() const INLINE { return section.fields.sectname; }
375 void set_sectname(const char* value) INLINE { strncpy(section.fields.sectname, value, 16); }
376
377 const char* segname() const INLINE { return section.fields.segname; }
378 void set_segname(const char* value) INLINE { strncpy(section.fields.segname, value, 16); }
379
380 uint64_t addr() const INLINE { return P::getP(section.fields.addr); }
381 void set_addr(uint64_t value) INLINE { P::setP(section.fields.addr, value); }
382
383 uint64_t size() const INLINE { return P::getP(section.fields.size); }
384 void set_size(uint64_t value) INLINE { P::setP(section.fields.size, value); }
385
386 uint32_t offset() const INLINE { return E::get32(section.fields.offset); }
387 void set_offset(uint32_t value) INLINE { E::set32(section.fields.offset, value); }
388
389 uint32_t align() const INLINE { return E::get32(section.fields.align); }
390 void set_align(uint32_t value) INLINE { E::set32(section.fields.align, value); }
391
392 uint32_t reloff() const INLINE { return E::get32(section.fields.reloff); }
393 void set_reloff(uint32_t value) INLINE { E::set32(section.fields.reloff, value); }
394
395 uint32_t nreloc() const INLINE { return E::get32(section.fields.nreloc); }
396 void set_nreloc(uint32_t value) INLINE { E::set32(section.fields.nreloc, value); }
397
398 uint32_t flags() const INLINE { return E::get32(section.fields.flags); }
399 void set_flags(uint32_t value) INLINE { E::set32(section.fields.flags, value); }
400
401 uint32_t reserved1() const INLINE { return E::get32(section.fields.reserved1); }
402 void set_reserved1(uint32_t value) INLINE { E::set32(section.fields.reserved1, value); }
403
404 uint32_t reserved2() const INLINE { return E::get32(section.fields.reserved2); }
405 void set_reserved2(uint32_t value) INLINE { E::set32(section.fields.reserved2, value); }
406
407 typedef typename P::E E;
408 private:
409 macho_section_content<P> section;
410 };
411
412
413 //
414 // mach-o dylib load command
415 //
416 template <typename P>
417 class macho_dylib_command {
418 public:
419 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
420 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
421
422 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
423 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
424
425 uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
426 void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
427
428 uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
429 void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
430
431 uint32_t current_version() const INLINE { return E::get32(fields.dylib.current_version); }
432 void set_current_version(uint32_t value) INLINE { E::set32(fields.dylib.current_version, value); }
433
434 uint32_t compatibility_version() const INLINE { return E::get32(fields.dylib.compatibility_version); }
435 void set_compatibility_version(uint32_t value) INLINE { E::set32(fields.dylib.compatibility_version, value); }
436
437 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
438 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
439
440 typedef typename P::E E;
441 private:
442 dylib_command fields;
443 };
444
445
446 //
447 // mach-o dylinker load command
448 //
449 template <typename P>
450 class macho_dylinker_command {
451 public:
452 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
453 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
454
455 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
456 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
457
458 uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
459 void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
460
461 const char* name() const INLINE { return (const char*)&fields + name_offset(); }
462 void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
463
464 typedef typename P::E E;
465 private:
466 dylinker_command fields;
467 };
468
469
470 //
471 // mach-o sub_framework load command
472 //
473 template <typename P>
474 class macho_sub_framework_command {
475 public:
476 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
477 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
478
479 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
480 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
481
482 uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
483 void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
484
485 const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
486 void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
487
488 typedef typename P::E E;
489 private:
490 sub_framework_command fields;
491 };
492
493
494 //
495 // mach-o sub_client load command
496 //
497 template <typename P>
498 class macho_sub_client_command {
499 public:
500 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
501 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
502
503 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
504 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
505
506 uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
507 void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
508
509 const char* client() const INLINE { return (const char*)&fields + client_offset(); }
510 void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
511
512 typedef typename P::E E;
513 private:
514 sub_client_command fields;
515 };
516
517
518 //
519 // mach-o sub_umbrella load command
520 //
521 template <typename P>
522 class macho_sub_umbrella_command {
523 public:
524 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
525 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
526
527 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
528 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
529
530 uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
531 void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
532
533 const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
534 void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
535
536 typedef typename P::E E;
537 private:
538 sub_umbrella_command fields;
539 };
540
541
542 //
543 // mach-o sub_library load command
544 //
545 template <typename P>
546 class macho_sub_library_command {
547 public:
548 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
549 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
550
551 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
552 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
553
554 uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
555 void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
556
557 const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
558 void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
559
560 typedef typename P::E E;
561 private:
562 sub_library_command fields;
563 };
564
565
566 //
567 // mach-o uuid load command
568 //
569 template <typename P>
570 class macho_uuid_command {
571 public:
572 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
573 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
574
575 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
576 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
577
578 const uint8_t* uuid() const INLINE { return fields.uuid; }
579 void set_uuid(const uint8_t u[16]) INLINE { memcpy(&fields.uuid, u, 16); }
580
581 typedef typename P::E E;
582 private:
583 uuid_command fields;
584 };
585
586
587 //
588 // mach-o routines load command
589 //
590 template <typename P> struct macho_routines_content {};
591 template <> struct macho_routines_content<Pointer32<BigEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
592 template <> struct macho_routines_content<Pointer64<BigEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
593 template <> struct macho_routines_content<Pointer32<LittleEndian> > { routines_command fields; enum { CMD = LC_ROUTINES }; };
594 template <> struct macho_routines_content<Pointer64<LittleEndian> > { routines_command_64 fields; enum { CMD = LC_ROUTINES_64 }; };
595
596 template <typename P>
597 class macho_routines_command {
598 public:
599 uint32_t cmd() const INLINE { return E::get32(routines.fields.cmd); }
600 void set_cmd(uint32_t value) INLINE { E::set32(routines.fields.cmd, value); }
601
602 uint32_t cmdsize() const INLINE { return E::get32(routines.fields.cmdsize); }
603 void set_cmdsize(uint32_t value) INLINE { E::set32(routines.fields.cmdsize, value); }
604
605 uint64_t init_address() const INLINE { return P::getP(routines.fields.init_address); }
606 void set_init_address(uint64_t value) INLINE { P::setP(routines.fields.init_address, value); }
607
608 uint64_t init_module() const INLINE { return P::getP(routines.fields.init_module); }
609 void set_init_module(uint64_t value) INLINE { P::setP(routines.fields.init_module, value); }
610
611 uint64_t reserved1() const INLINE { return P::getP(routines.fields.reserved1); }
612 void set_reserved1(uint64_t value) INLINE { P::setP(routines.fields.reserved1, value); }
613
614 uint64_t reserved2() const INLINE { return P::getP(routines.fields.reserved2); }
615 void set_reserved2(uint64_t value) INLINE { P::setP(routines.fields.reserved2, value); }
616
617 uint64_t reserved3() const INLINE { return P::getP(routines.fields.reserved3); }
618 void set_reserved3(uint64_t value) INLINE { P::setP(routines.fields.reserved3, value); }
619
620 uint64_t reserved4() const INLINE { return P::getP(routines.fields.reserved4); }
621 void set_reserved4(uint64_t value) INLINE { P::setP(routines.fields.reserved4, value); }
622
623 uint64_t reserved5() const INLINE { return P::getP(routines.fields.reserved5); }
624 void set_reserved5(uint64_t value) INLINE { P::setP(routines.fields.reserved5, value); }
625
626 uint64_t reserved6() const INLINE { return P::getP(routines.fields.reserved6); }
627 void set_reserved6(uint64_t value) INLINE { P::setP(routines.fields.reserved6, value); }
628
629 typedef typename P::E E;
630 enum {
631 CMD = macho_routines_content<P>::CMD
632 };
633 private:
634 macho_routines_content<P> routines;
635 };
636
637
638 //
639 // mach-o symbol table load command
640 //
641 template <typename P>
642 class macho_symtab_command {
643 public:
644 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
645 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
646
647 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
648 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
649
650 uint32_t symoff() const INLINE { return E::get32(fields.symoff); }
651 void set_symoff(uint32_t value) INLINE { E::set32(fields.symoff, value); }
652
653 uint32_t nsyms() const INLINE { return E::get32(fields.nsyms); }
654 void set_nsyms(uint32_t value) INLINE { E::set32(fields.nsyms, value); }
655
656 uint32_t stroff() const INLINE { return E::get32(fields.stroff); }
657 void set_stroff(uint32_t value) INLINE { E::set32(fields.stroff, value); }
658
659 uint32_t strsize() const INLINE { return E::get32(fields.strsize); }
660 void set_strsize(uint32_t value) INLINE { E::set32(fields.strsize, value); }
661
662
663 typedef typename P::E E;
664 private:
665 symtab_command fields;
666 };
667
668
669 //
670 // mach-o dynamic symbol table load command
671 //
672 template <typename P>
673 class macho_dysymtab_command {
674 public:
675 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
676 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
677
678 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
679 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
680
681 uint32_t ilocalsym() const INLINE { return E::get32(fields.ilocalsym); }
682 void set_ilocalsym(uint32_t value) INLINE { E::set32(fields.ilocalsym, value); }
683
684 uint32_t nlocalsym() const INLINE { return E::get32(fields.nlocalsym); }
685 void set_nlocalsym(uint32_t value) INLINE { E::set32(fields.nlocalsym, value); }
686
687 uint32_t iextdefsym() const INLINE { return E::get32(fields.iextdefsym); }
688 void set_iextdefsym(uint32_t value) INLINE { E::set32(fields.iextdefsym, value); }
689
690 uint32_t nextdefsym() const INLINE { return E::get32(fields.nextdefsym); }
691 void set_nextdefsym(uint32_t value) INLINE { E::set32(fields.nextdefsym, value); }
692
693 uint32_t iundefsym() const INLINE { return E::get32(fields.iundefsym); }
694 void set_iundefsym(uint32_t value) INLINE { E::set32(fields.iundefsym, value); }
695
696 uint32_t nundefsym() const INLINE { return E::get32(fields.nundefsym); }
697 void set_nundefsym(uint32_t value) INLINE { E::set32(fields.nundefsym, value); }
698
699 uint32_t tocoff() const INLINE { return E::get32(fields.tocoff); }
700 void set_tocoff(uint32_t value) INLINE { E::set32(fields.tocoff, value); }
701
702 uint32_t ntoc() const INLINE { return E::get32(fields.ntoc); }
703 void set_ntoc(uint32_t value) INLINE { E::set32(fields.ntoc, value); }
704
705 uint32_t modtaboff() const INLINE { return E::get32(fields.modtaboff); }
706 void set_modtaboff(uint32_t value) INLINE { E::set32(fields.modtaboff, value); }
707
708 uint32_t nmodtab() const INLINE { return E::get32(fields.nmodtab); }
709 void set_nmodtab(uint32_t value) INLINE { E::set32(fields.nmodtab, value); }
710
711 uint32_t extrefsymoff() const INLINE { return E::get32(fields.extrefsymoff); }
712 void set_extrefsymoff(uint32_t value) INLINE { E::set32(fields.extrefsymoff, value); }
713
714 uint32_t nextrefsyms() const INLINE { return E::get32(fields.nextrefsyms); }
715 void set_nextrefsyms(uint32_t value) INLINE { E::set32(fields.nextrefsyms, value); }
716
717 uint32_t indirectsymoff() const INLINE { return E::get32(fields.indirectsymoff); }
718 void set_indirectsymoff(uint32_t value) INLINE { E::set32(fields.indirectsymoff, value); }
719
720 uint32_t nindirectsyms() const INLINE { return E::get32(fields.nindirectsyms); }
721 void set_nindirectsyms(uint32_t value) INLINE { E::set32(fields.nindirectsyms, value); }
722
723 uint32_t extreloff() const INLINE { return E::get32(fields.extreloff); }
724 void set_extreloff(uint32_t value) INLINE { E::set32(fields.extreloff, value); }
725
726 uint32_t nextrel() const INLINE { return E::get32(fields.nextrel); }
727 void set_nextrel(uint32_t value) INLINE { E::set32(fields.nextrel, value); }
728
729 uint32_t locreloff() const INLINE { return E::get32(fields.locreloff); }
730 void set_locreloff(uint32_t value) INLINE { E::set32(fields.locreloff, value); }
731
732 uint32_t nlocrel() const INLINE { return E::get32(fields.nlocrel); }
733 void set_nlocrel(uint32_t value) INLINE { E::set32(fields.nlocrel, value); }
734
735 typedef typename P::E E;
736 private:
737 dysymtab_command fields;
738 };
739
740
741
742
743 //
744 // mach-o module table entry (for compatibility with old ld/dyld)
745 //
746 template <typename P> struct macho_dylib_module_content {};
747 template <> struct macho_dylib_module_content<Pointer32<BigEndian> > { struct dylib_module fields; };
748 template <> struct macho_dylib_module_content<Pointer32<LittleEndian> > { struct dylib_module fields; };
749 template <> struct macho_dylib_module_content<Pointer64<BigEndian> > { struct dylib_module_64 fields; };
750 template <> struct macho_dylib_module_content<Pointer64<LittleEndian> > { struct dylib_module_64 fields; };
751
752 template <typename P>
753 class macho_dylib_module {
754 public:
755 uint32_t module_name() const INLINE { return E::get32(module.fields.module_name); }
756 void set_module_name(uint32_t value) INLINE { E::set32(module.fields.module_name, value); }
757
758 uint32_t iextdefsym() const INLINE { return E::get32(module.fields.iextdefsym); }
759 void set_iextdefsym(uint32_t value) INLINE { E::set32(module.fields.iextdefsym, value); }
760
761 uint32_t nextdefsym() const INLINE { return E::get32(module.fields.nextdefsym); }
762 void set_nextdefsym(uint32_t value) INLINE { E::set32(module.fields.nextdefsym, value); }
763
764 uint32_t irefsym() const INLINE { return E::get32(module.fields.irefsym); }
765 void set_irefsym(uint32_t value) INLINE { E::set32(module.fields.irefsym, value); }
766
767 uint32_t nrefsym() const INLINE { return E::get32(module.fields.nrefsym); }
768 void set_nrefsym(uint32_t value) INLINE { E::set32(module.fields.nrefsym, value); }
769
770 uint32_t ilocalsym() const INLINE { return E::get32(module.fields.ilocalsym); }
771 void set_ilocalsym(uint32_t value) INLINE { E::set32(module.fields.ilocalsym, value); }
772
773 uint32_t nlocalsym() const INLINE { return E::get32(module.fields.nlocalsym); }
774 void set_nlocalsym(uint32_t value) INLINE { E::set32(module.fields.nlocalsym, value); }
775
776 uint32_t iextrel() const INLINE { return E::get32(module.fields.iextrel); }
777 void set_iextrel(uint32_t value) INLINE { E::set32(module.fields.iextrel, value); }
778
779 uint32_t nextrel() const INLINE { return E::get32(module.fields.nextrel); }
780 void set_nextrel(uint32_t value) INLINE { E::set32(module.fields.nextrel, value); }
781
782 uint16_t iinit() const INLINE { return E::get32(module.fields.iinit_iterm) & 0xFFFF; }
783 uint16_t iterm() const INLINE { return E::get32(module.fields.iinit_iterm) > 16; }
784 void set_iinit_iterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.iinit_iterm, (term<<16) | (init &0xFFFF)); }
785
786 uint16_t ninit() const INLINE { return E::get32(module.fields.ninit_nterm) & 0xFFFF; }
787 uint16_t nterm() const INLINE { return E::get32(module.fields.ninit_nterm) > 16; }
788 void set_ninit_nterm(uint16_t init, uint16_t term) INLINE { E::set32(module.fields.ninit_nterm, (term<<16) | (init &0xFFFF)); }
789
790 uint64_t objc_module_info_addr() const INLINE { return P::getP(module.fields.objc_module_info_addr); }
791 void set_objc_module_info_addr(uint64_t value) INLINE { P::setP(module.fields.objc_module_info_addr, value); }
792
793 uint32_t objc_module_info_size() const INLINE { return E::get32(module.fields.objc_module_info_size); }
794 void set_objc_module_info_size(uint32_t value) INLINE { E::set32(module.fields.objc_module_info_size, value); }
795
796
797 typedef typename P::E E;
798 private:
799 macho_dylib_module_content<P> module;
800 };
801
802
803 //
804 // mach-o dylib_reference entry
805 //
806 template <typename P>
807 class macho_dylib_reference {
808 public:
809 uint32_t isym() const INLINE { return E::getBits(fields, 0, 24); }
810 void set_isym(uint32_t value) INLINE { E::setBits(fields, value, 0, 24); }
811
812 uint8_t flags() const INLINE { return E::getBits(fields, 24, 8); }
813 void set_flags(uint8_t value) INLINE { E::setBits(fields, value, 24, 8); }
814
815 typedef typename P::E E;
816 private:
817 uint32_t fields;
818 };
819
820
821
822 //
823 // mach-o two-level hints load command
824 //
825 template <typename P>
826 class macho_dylib_table_of_contents {
827 public:
828 uint32_t symbol_index() const INLINE { return E::get32(fields.symbol_index); }
829 void set_symbol_index(uint32_t value) INLINE { E::set32(fields.symbol_index, value); }
830
831 uint32_t module_index() const INLINE { return E::get32(fields.module_index); }
832 void set_module_index(uint32_t value) INLINE { E::set32(fields.module_index, value); }
833
834 typedef typename P::E E;
835 private:
836 dylib_table_of_contents fields;
837 };
838
839
840
841 //
842 // mach-o two-level hints load command
843 //
844 template <typename P>
845 class macho_twolevel_hints_command {
846 public:
847 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
848 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
849
850 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
851 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
852
853 uint32_t offset() const INLINE { return E::get32(fields.offset); }
854 void set_offset(uint32_t value) INLINE { E::set32(fields.offset, value); }
855
856 uint32_t nhints() const INLINE { return E::get32(fields.nhints); }
857 void set_nhints(uint32_t value) INLINE { E::set32(fields.nhints, value); }
858
859 typedef typename P::E E;
860 private:
861 twolevel_hints_command fields;
862 };
863
864
865 //
866 // mach-o threads load command
867 //
868 template <typename P>
869 class macho_thread_command {
870 public:
871 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
872 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
873
874 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
875 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
876
877 uint32_t flavor() const INLINE { return E::get32(fields_flavor); }
878 void set_flavor(uint32_t value) INLINE { E::set32(fields_flavor, value); }
879
880 uint32_t count() const INLINE { return E::get32(fields_count); }
881 void set_count(uint32_t value) INLINE { E::set32(fields_count, value); }
882
883 uint64_t thread_register(uint32_t index) const INLINE { return P::getP(thread_registers[index]); }
884 void set_thread_register(uint32_t index, uint64_t value) INLINE { P::setP(thread_registers[index], value); }
885
886 typedef typename P::E E;
887 typedef typename P::uint_t pint_t;
888 private:
889 struct thread_command fields;
890 uint32_t fields_flavor;
891 uint32_t fields_count;
892 pint_t thread_registers[1];
893 };
894
895
896 //
897 // mach-o misc data
898 //
899 template <typename P>
900 class macho_linkedit_data_command {
901 public:
902 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
903 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
904
905 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
906 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
907
908 uint32_t dataoff() const INLINE { return E::get32(fields.dataoff); }
909 void set_dataoff(uint32_t value) INLINE { E::set32(fields.dataoff, value); }
910
911 uint32_t datasize() const INLINE { return E::get32(fields.datasize); }
912 void set_datasize(uint32_t value)INLINE { E::set32(fields.datasize, value); }
913
914
915 typedef typename P::E E;
916 private:
917 struct linkedit_data_command fields;
918 };
919
920
921 //
922 // mach-o rpath
923 //
924 template <typename P>
925 class macho_rpath_command {
926 public:
927 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
928 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
929
930 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
931 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
932
933 uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
934 void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
935
936 const char* path() const INLINE { return (const char*)&fields + path_offset(); }
937 void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
938
939
940 typedef typename P::E E;
941 private:
942 struct rpath_command fields;
943 };
944
945
946
947 //
948 // mach-o symbol table entry
949 //
950 template <typename P> struct macho_nlist_content {};
951 template <> struct macho_nlist_content<Pointer32<BigEndian> > { struct nlist fields; };
952 template <> struct macho_nlist_content<Pointer64<BigEndian> > { struct nlist_64 fields; };
953 template <> struct macho_nlist_content<Pointer32<LittleEndian> > { struct nlist fields; };
954 template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_64 fields; };
955
956 template <typename P>
957 class macho_nlist {
958 public:
959 uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
960 void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
961
962 uint8_t n_type() const INLINE { return entry.fields.n_type; }
963 void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
964
965 uint8_t n_sect() const INLINE { return entry.fields.n_sect; }
966 void set_n_sect(uint8_t value) INLINE { entry.fields.n_sect = value; }
967
968 uint16_t n_desc() const INLINE { return E::get16(entry.fields.n_desc); }
969 void set_n_desc(uint16_t value) INLINE { E::set16((uint16_t&)entry.fields.n_desc, value); }
970
971 uint64_t n_value() const INLINE { return P::getP(entry.fields.n_value); }
972 void set_n_value(uint64_t value) INLINE { P::setP(entry.fields.n_value, value); }
973
974 typedef typename P::E E;
975 private:
976 macho_nlist_content<P> entry;
977 };
978
979
980
981 //
982 // mach-o relocation info
983 //
984 template <typename P>
985 class macho_relocation_info {
986 public:
987 uint32_t r_address() const INLINE { return E::get32(address); }
988 void set_r_address(uint32_t value) INLINE { E::set32(address, value); }
989
990 uint32_t r_symbolnum() const INLINE { return E::getBits(other, 0, 24); }
991 void set_r_symbolnum(uint32_t value) INLINE { E::setBits(other, value, 0, 24); }
992
993 bool r_pcrel() const INLINE { return E::getBits(other, 24, 1); }
994 void set_r_pcrel(bool value) INLINE { E::setBits(other, value, 24, 1); }
995
996 uint8_t r_length() const INLINE { return E::getBits(other, 25, 2); }
997 void set_r_length(uint8_t value) INLINE { E::setBits(other, value, 25, 2); }
998
999 bool r_extern() const INLINE { return E::getBits(other, 27, 1); }
1000 void set_r_extern(bool value) INLINE { E::setBits(other, value, 27, 1); }
1001
1002 uint8_t r_type() const INLINE { return E::getBits(other, 28, 4); }
1003 void set_r_type(uint8_t value) INLINE { E::setBits(other, value, 28, 4); }
1004
1005 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1006
1007 typedef typename P::E E;
1008 private:
1009 uint32_t address;
1010 uint32_t other;
1011 };
1012
1013
1014 //
1015 // mach-o scattered relocation info
1016 // The bit fields are always in big-endian order (see mach-o/reloc.h)
1017 //
1018 template <typename P>
1019 class macho_scattered_relocation_info {
1020 public:
1021 bool r_scattered() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 0, 1); }
1022 void set_r_scattered(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 0, 1); E::set32(other, temp); }
1023
1024 bool r_pcrel() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 1, 1); }
1025 void set_r_pcrel(bool x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 1, 1); E::set32(other, temp); }
1026
1027 uint8_t r_length() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 2, 2); }
1028 void set_r_length(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 2, 2); E::set32(other, temp); }
1029
1030 uint8_t r_type() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 4, 4); }
1031 void set_r_type(uint8_t x) INLINE { uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 4, 4); E::set32(other, temp); }
1032
1033 uint32_t r_address() const INLINE { return BigEndian::getBitsRaw(E::get32(other), 8, 24); }
1034 void set_r_address(uint32_t x) { if ( x > 0x00FFFFFF ) throw "scattered reloc r_address too large";
1035 uint32_t temp = E::get32(other); BigEndian::setBitsRaw(temp, x, 8, 24); E::set32(other, temp); }
1036
1037 uint32_t r_value() const INLINE { return E::get32(value); }
1038 void set_r_value(uint32_t x) INLINE { E::set32(value, x); }
1039
1040 uint32_t r_other() const INLINE { return other; }
1041
1042 void set_r_length() INLINE { set_r_length((sizeof(typename P::uint_t)==8) ? 3 : 2); }
1043
1044 typedef typename P::E E;
1045 private:
1046 uint32_t other;
1047 uint32_t value;
1048 };
1049
1050
1051
1052 //
1053 // mach-o encyrption info load command
1054 //
1055 template <typename P>
1056 class macho_encryption_info_command {
1057 public:
1058 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1059 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1060
1061 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1062 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1063
1064 uint32_t cryptoff() const INLINE { return E::get32(fields.cryptoff); }
1065 void set_cryptoff(uint32_t value) INLINE { E::set32(fields.cryptoff, value); }
1066
1067 uint32_t cryptsize() const INLINE { return E::get32(fields.cryptsize); }
1068 void set_cryptsize(uint32_t value) INLINE { E::set32(fields.cryptsize, value); }
1069
1070 uint32_t cryptid() const INLINE { return E::get32(fields.cryptid); }
1071 void set_cryptid(uint32_t value) INLINE { E::set32(fields.cryptid, value); }
1072
1073 typedef typename P::E E;
1074 private:
1075 encryption_info_command fields;
1076 };
1077
1078
1079 //
1080 // start of __unwind_info section
1081 //
1082 template <typename P>
1083 class macho_unwind_info_section_header {
1084 public:
1085 uint32_t version() const INLINE { return E::get32(fields.version); }
1086 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1087
1088 uint32_t commonEncodingsArraySectionOffset() const INLINE { return E::get32(fields.commonEncodingsArraySectionOffset); }
1089 void set_commonEncodingsArraySectionOffset(uint32_t value) INLINE { E::set32(fields.commonEncodingsArraySectionOffset, value); }
1090
1091 uint32_t commonEncodingsArrayCount() const INLINE { return E::get32(fields.commonEncodingsArrayCount); }
1092 void set_commonEncodingsArrayCount(uint32_t value) INLINE { E::set32(fields.commonEncodingsArrayCount, value); }
1093
1094 uint32_t personalityArraySectionOffset() const INLINE { return E::get32(fields.personalityArraySectionOffset); }
1095 void set_personalityArraySectionOffset(uint32_t value) INLINE { E::set32(fields.personalityArraySectionOffset, value); }
1096
1097 uint32_t personalityArrayCount() const INLINE { return E::get32(fields.personalityArrayCount); }
1098 void set_personalityArrayCount(uint32_t value) INLINE { E::set32(fields.personalityArrayCount, value); }
1099
1100 uint32_t indexSectionOffset() const INLINE { return E::get32(fields.indexSectionOffset); }
1101 void set_indexSectionOffset(uint32_t value) INLINE { E::set32(fields.indexSectionOffset, value); }
1102
1103 uint32_t indexCount() const INLINE { return E::get32(fields.indexCount); }
1104 void set_indexCount(uint32_t value) INLINE { E::set32(fields.indexCount, value); }
1105
1106 typedef typename P::E E;
1107 private:
1108 unwind_info_section_header fields;
1109 };
1110
1111
1112
1113 //
1114 // uwind first level index entry
1115 //
1116 template <typename P>
1117 class macho_unwind_info_section_header_index_entry {
1118 public:
1119 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1120 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1121
1122 uint32_t secondLevelPagesSectionOffset() const INLINE { return E::get32(fields.secondLevelPagesSectionOffset); }
1123 void set_secondLevelPagesSectionOffset(uint32_t value) INLINE { E::set32(fields.secondLevelPagesSectionOffset, value); }
1124
1125 uint32_t lsdaIndexArraySectionOffset() const INLINE { return E::get32(fields.lsdaIndexArraySectionOffset); }
1126 void set_lsdaIndexArraySectionOffset(uint32_t value) INLINE { E::set32(fields.lsdaIndexArraySectionOffset, value); }
1127
1128 typedef typename P::E E;
1129 private:
1130 unwind_info_section_header_index_entry fields;
1131 };
1132
1133
1134 //
1135 // LSDA table entry
1136 //
1137 template <typename P>
1138 class macho_unwind_info_section_header_lsda_index_entry {
1139 public:
1140 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1141 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1142
1143 uint32_t lsdaOffset() const INLINE { return E::get32(fields.lsdaOffset); }
1144 void set_lsdaOffset(uint32_t value) INLINE { E::set32(fields.lsdaOffset, value); }
1145
1146 typedef typename P::E E;
1147 private:
1148 unwind_info_section_header_lsda_index_entry fields;
1149 };
1150
1151
1152 //
1153 // regular second level entry
1154 //
1155 template <typename P>
1156 class macho_unwind_info_regular_second_level_entry {
1157 public:
1158 uint32_t functionOffset() const INLINE { return E::get32(fields.functionOffset); }
1159 void set_functionOffset(uint32_t value) INLINE { E::set32(fields.functionOffset, value); }
1160
1161 uint32_t encoding() const INLINE { return E::get32(fields.encoding); }
1162 void set_encoding(uint32_t value) INLINE { E::set32(fields.encoding, value); }
1163
1164 typedef typename P::E E;
1165 private:
1166 unwind_info_regular_second_level_entry fields;
1167 };
1168
1169
1170 //
1171 // start of second level regular page
1172 //
1173 template <typename P>
1174 class macho_unwind_info_regular_second_level_page_header {
1175 public:
1176 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1177 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1178
1179 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1180 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1181
1182 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1183 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1184
1185 typedef typename P::E E;
1186 private:
1187 unwind_info_regular_second_level_page_header fields;
1188 };
1189
1190
1191 //
1192 // start of second level compressed page
1193 //
1194 template <typename P>
1195 class macho_unwind_info_compressed_second_level_page_header {
1196 public:
1197 uint32_t kind() const INLINE { return E::get32(fields.kind); }
1198 void set_kind(uint32_t value) INLINE { E::set32(fields.kind, value); }
1199
1200 uint16_t entryPageOffset() const INLINE { return E::get16(fields.entryPageOffset); }
1201 void set_entryPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryPageOffset, value); }
1202
1203 uint16_t entryCount() const INLINE { return E::get16(fields.entryCount); }
1204 void set_entryCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.entryCount, value); }
1205
1206 uint16_t encodingsPageOffset() const INLINE { return E::get16(fields.encodingsPageOffset); }
1207 void set_encodingsPageOffset(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsPageOffset, value); }
1208
1209 uint16_t encodingsCount() const INLINE { return E::get16(fields.encodingsCount); }
1210 void set_encodingsCount(uint16_t value) INLINE { E::set16((uint16_t&)fields.encodingsCount, value); }
1211
1212 typedef typename P::E E;
1213 private:
1214 unwind_info_compressed_second_level_page_header fields;
1215 };
1216
1217
1218 //
1219 // compressed dyld info load command
1220 //
1221 template <typename P>
1222 class macho_dyld_info_command {
1223 public:
1224 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1225 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1226
1227 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1228 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1229
1230 uint32_t rebase_off() const INLINE { return E::get32(fields.rebase_off); }
1231 void set_rebase_off(uint32_t value) INLINE { E::set32(fields.rebase_off, value); }
1232
1233 uint32_t rebase_size() const INLINE { return E::get32(fields.rebase_size); }
1234 void set_rebase_size(uint32_t value) INLINE { E::set32(fields.rebase_size, value); }
1235
1236 uint32_t bind_off() const INLINE { return E::get32(fields.bind_off); }
1237 void set_bind_off(uint32_t value) INLINE { E::set32(fields.bind_off, value); }
1238
1239 uint32_t bind_size() const INLINE { return E::get32(fields.bind_size); }
1240 void set_bind_size(uint32_t value) INLINE { E::set32(fields.bind_size, value); }
1241
1242 uint32_t weak_bind_off() const INLINE { return E::get32(fields.weak_bind_off); }
1243 void set_weak_bind_off(uint32_t value) INLINE { E::set32(fields.weak_bind_off, value); }
1244
1245 uint32_t weak_bind_size() const INLINE { return E::get32(fields.weak_bind_size); }
1246 void set_weak_bind_size(uint32_t value) INLINE { E::set32(fields.weak_bind_size, value); }
1247
1248 uint32_t lazy_bind_off() const INLINE { return E::get32(fields.lazy_bind_off); }
1249 void set_lazy_bind_off(uint32_t value) INLINE { E::set32(fields.lazy_bind_off, value); }
1250
1251 uint32_t lazy_bind_size() const INLINE { return E::get32(fields.lazy_bind_size); }
1252 void set_lazy_bind_size(uint32_t value) INLINE { E::set32(fields.lazy_bind_size, value); }
1253
1254 uint32_t export_off() const INLINE { return E::get32(fields.export_off); }
1255 void set_export_off(uint32_t value) INLINE { E::set32(fields.export_off, value); }
1256
1257 uint32_t export_size() const INLINE { return E::get32(fields.export_size); }
1258 void set_export_size(uint32_t value) INLINE { E::set32(fields.export_size, value); }
1259
1260
1261 typedef typename P::E E;
1262 private:
1263 dyld_info_command fields;
1264 };
1265
1266
1267 //
1268 // mach-o version load command
1269 //
1270 template <typename P>
1271 class macho_version_min_command {
1272 public:
1273 uint32_t cmd() const INLINE { return E::get32(fields.cmd); }
1274 void set_cmd(uint32_t value) INLINE { E::set32(fields.cmd, value); }
1275
1276 uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
1277 void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
1278
1279 uint32_t version() const INLINE { return fields.version; }
1280 void set_version(uint32_t value) INLINE { E::set32(fields.version, value); }
1281
1282 uint32_t reserved() const INLINE { return fields.reserved; }
1283 void set_reserved(uint32_t value) INLINE { E::set32(fields.reserved, value); }
1284
1285 typedef typename P::E E;
1286 private:
1287 version_min_command fields;
1288 };
1289
1290
1291 //
1292 // mach-o __LD, __compact_unwind section in object files
1293 //
1294 template <typename P>
1295 class macho_compact_unwind_entry {
1296 public:
1297 typedef typename P::E E;
1298 typedef typename P::uint_t pint_t;
1299
1300 pint_t codeStart() const INLINE { return P::getP(_codeStart); }
1301 void set_codeStart(pint_t value) INLINE { P::setP(_codeStart, value); }
1302
1303 uint32_t codeLen() const INLINE { return E::get32(_codeLen); }
1304 void set_codeLen(uint32_t value) INLINE { E::set32(_codeLen, value); }
1305
1306 uint32_t compactUnwindInfo() const INLINE { return E::get32(_compactUnwindInfo); }
1307 void set_compactUnwindInfo(uint32_t value) INLINE { E::set32(_compactUnwindInfo, value); }
1308
1309 pint_t personality() const INLINE { return P::getP(_personality); }
1310 void set_personality(pint_t value) INLINE { P::setP(_personality, value); }
1311
1312 pint_t lsda() const INLINE { return P::getP(_lsda); }
1313 void set_lsda(pint_t value) INLINE { P::setP(_lsda, value); }
1314
1315 static uint32_t codeStartFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_codeStart); }
1316 static uint32_t personalityFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_personality); }
1317 static uint32_t lsdaFieldOffset() INLINE { return offsetof(macho_compact_unwind_entry<P>,_lsda); }
1318
1319 private:
1320 pint_t _codeStart;
1321 uint32_t _codeLen;
1322 uint32_t _compactUnwindInfo;
1323 pint_t _personality;
1324 pint_t _lsda;
1325 };
1326
1327
1328 #endif // __MACH_O_FILE_ABSTRACTION__
1329
1330