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