1 //===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- C++/-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines manifest constants for the MachO object file format.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_BINARYFORMAT_MACHO_H
14 #define LLVM_BINARYFORMAT_MACHO_H
16 #include "llvm/Support/Compiler.h"
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/Host.h"
22 // Enums from <mach-o/loader.h>
24 // Constants for the "magic" field in llvm::MachO::mach_header and
25 // llvm::MachO::mach_header_64
26 MH_MAGIC
= 0xFEEDFACEu
,
27 MH_CIGAM
= 0xCEFAEDFEu
,
28 MH_MAGIC_64
= 0xFEEDFACFu
,
29 MH_CIGAM_64
= 0xCFFAEDFEu
,
30 FAT_MAGIC
= 0xCAFEBABEu
,
31 FAT_CIGAM
= 0xBEBAFECAu
,
32 FAT_MAGIC_64
= 0xCAFEBABFu
,
33 FAT_CIGAM_64
= 0xBFBAFECAu
37 // Constants for the "filetype" field in llvm::MachO::mach_header and
38 // llvm::MachO::mach_header_64
53 // Constant bits for the "flags" field in llvm::MachO::mach_header and
54 // llvm::MachO::mach_header_64
55 MH_NOUNDEFS
= 0x00000001u
,
56 MH_INCRLINK
= 0x00000002u
,
57 MH_DYLDLINK
= 0x00000004u
,
58 MH_BINDATLOAD
= 0x00000008u
,
59 MH_PREBOUND
= 0x00000010u
,
60 MH_SPLIT_SEGS
= 0x00000020u
,
61 MH_LAZY_INIT
= 0x00000040u
,
62 MH_TWOLEVEL
= 0x00000080u
,
63 MH_FORCE_FLAT
= 0x00000100u
,
64 MH_NOMULTIDEFS
= 0x00000200u
,
65 MH_NOFIXPREBINDING
= 0x00000400u
,
66 MH_PREBINDABLE
= 0x00000800u
,
67 MH_ALLMODSBOUND
= 0x00001000u
,
68 MH_SUBSECTIONS_VIA_SYMBOLS
= 0x00002000u
,
69 MH_CANONICAL
= 0x00004000u
,
70 MH_WEAK_DEFINES
= 0x00008000u
,
71 MH_BINDS_TO_WEAK
= 0x00010000u
,
72 MH_ALLOW_STACK_EXECUTION
= 0x00020000u
,
73 MH_ROOT_SAFE
= 0x00040000u
,
74 MH_SETUID_SAFE
= 0x00080000u
,
75 MH_NO_REEXPORTED_DYLIBS
= 0x00100000u
,
77 MH_DEAD_STRIPPABLE_DYLIB
= 0x00400000u
,
78 MH_HAS_TLV_DESCRIPTORS
= 0x00800000u
,
79 MH_NO_HEAP_EXECUTION
= 0x01000000u
,
80 MH_APP_EXTENSION_SAFE
= 0x02000000u
,
81 MH_NLIST_OUTOFSYNC_WITH_DYLDINFO
= 0x04000000u
85 // Flags for the "cmd" field in llvm::MachO::load_command
86 LC_REQ_DYLD
= 0x80000000u
89 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) LCName = LCValue,
91 enum LoadCommandType
: uint32_t {
92 #include "llvm/BinaryFormat/MachO.def"
95 #undef HANDLE_LOAD_COMMAND
98 // Constant bits for the "flags" field in llvm::MachO::segment_command
102 SG_PROTECTED_VERSION_1
= 0x8u
,
104 // Constant masks for the "flags" field in llvm::MachO::section and
105 // llvm::MachO::section_64
106 SECTION_TYPE
= 0x000000ffu
, // SECTION_TYPE
107 SECTION_ATTRIBUTES
= 0xffffff00u
, // SECTION_ATTRIBUTES
108 SECTION_ATTRIBUTES_USR
= 0xff000000u
, // SECTION_ATTRIBUTES_USR
109 SECTION_ATTRIBUTES_SYS
= 0x00ffff00u
// SECTION_ATTRIBUTES_SYS
112 /// These are the section type and attributes fields. A MachO section can
113 /// have only one Type, but can have any of the attributes specified.
114 enum SectionType
: uint32_t {
115 // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
116 // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
118 /// S_REGULAR - Regular section.
120 /// S_ZEROFILL - Zero fill on demand section.
122 /// S_CSTRING_LITERALS - Section with literal C strings.
123 S_CSTRING_LITERALS
= 0x02u
,
124 /// S_4BYTE_LITERALS - Section with 4 byte literals.
125 S_4BYTE_LITERALS
= 0x03u
,
126 /// S_8BYTE_LITERALS - Section with 8 byte literals.
127 S_8BYTE_LITERALS
= 0x04u
,
128 /// S_LITERAL_POINTERS - Section with pointers to literals.
129 S_LITERAL_POINTERS
= 0x05u
,
130 /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
131 S_NON_LAZY_SYMBOL_POINTERS
= 0x06u
,
132 /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
133 S_LAZY_SYMBOL_POINTERS
= 0x07u
,
134 /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
135 /// the Reserved2 field.
136 S_SYMBOL_STUBS
= 0x08u
,
137 /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
139 S_MOD_INIT_FUNC_POINTERS
= 0x09u
,
140 /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
142 S_MOD_TERM_FUNC_POINTERS
= 0x0au
,
143 /// S_COALESCED - Section contains symbols that are to be coalesced.
145 /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
147 S_GB_ZEROFILL
= 0x0cu
,
148 /// S_INTERPOSING - Section with only pairs of function pointers for
150 S_INTERPOSING
= 0x0du
,
151 /// S_16BYTE_LITERALS - Section with only 16 byte literals.
152 S_16BYTE_LITERALS
= 0x0eu
,
153 /// S_DTRACE_DOF - Section contains DTrace Object Format.
154 S_DTRACE_DOF
= 0x0fu
,
155 /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
156 /// lazy loaded dylibs.
157 S_LAZY_DYLIB_SYMBOL_POINTERS
= 0x10u
,
158 /// S_THREAD_LOCAL_REGULAR - Thread local data section.
159 S_THREAD_LOCAL_REGULAR
= 0x11u
,
160 /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
161 S_THREAD_LOCAL_ZEROFILL
= 0x12u
,
162 /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
164 S_THREAD_LOCAL_VARIABLES
= 0x13u
,
165 /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
166 /// local structures.
167 S_THREAD_LOCAL_VARIABLE_POINTERS
= 0x14u
,
168 /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
169 /// variable initialization pointers to functions.
170 S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
= 0x15u
,
172 LAST_KNOWN_SECTION_TYPE
= S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
176 // Constant masks for the "flags[31:24]" field in llvm::MachO::section and
177 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR)
179 /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
181 S_ATTR_PURE_INSTRUCTIONS
= 0x80000000u
,
182 /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
183 /// in a ranlib table of contents.
184 S_ATTR_NO_TOC
= 0x40000000u
,
185 /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
186 /// in files with the MY_DYLDLINK flag.
187 S_ATTR_STRIP_STATIC_SYMS
= 0x20000000u
,
188 /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
189 S_ATTR_NO_DEAD_STRIP
= 0x10000000u
,
190 /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
191 S_ATTR_LIVE_SUPPORT
= 0x08000000u
,
192 /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
194 S_ATTR_SELF_MODIFYING_CODE
= 0x04000000u
,
195 /// S_ATTR_DEBUG - A debug section.
196 S_ATTR_DEBUG
= 0x02000000u
,
198 // Constant masks for the "flags[23:8]" field in llvm::MachO::section and
199 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS)
201 /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
202 S_ATTR_SOME_INSTRUCTIONS
= 0x00000400u
,
203 /// S_ATTR_EXT_RELOC - Section has external relocation entries.
204 S_ATTR_EXT_RELOC
= 0x00000200u
,
205 /// S_ATTR_LOC_RELOC - Section has local relocation entries.
206 S_ATTR_LOC_RELOC
= 0x00000100u
,
208 // Constant masks for the value of an indirect symbol in an indirect
210 INDIRECT_SYMBOL_LOCAL
= 0x80000000u
,
211 INDIRECT_SYMBOL_ABS
= 0x40000000u
214 enum DataRegionType
{
215 // Constants for the "kind" field in a data_in_code_entry structure
217 DICE_KIND_JUMP_TABLE8
= 2u,
218 DICE_KIND_JUMP_TABLE16
= 3u,
219 DICE_KIND_JUMP_TABLE32
= 4u,
220 DICE_KIND_ABS_JUMP_TABLE32
= 5u
224 REBASE_TYPE_POINTER
= 1u,
225 REBASE_TYPE_TEXT_ABSOLUTE32
= 2u,
226 REBASE_TYPE_TEXT_PCREL32
= 3u
229 enum { REBASE_OPCODE_MASK
= 0xF0u
, REBASE_IMMEDIATE_MASK
= 0x0Fu
};
232 REBASE_OPCODE_DONE
= 0x00u
,
233 REBASE_OPCODE_SET_TYPE_IMM
= 0x10u
,
234 REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
= 0x20u
,
235 REBASE_OPCODE_ADD_ADDR_ULEB
= 0x30u
,
236 REBASE_OPCODE_ADD_ADDR_IMM_SCALED
= 0x40u
,
237 REBASE_OPCODE_DO_REBASE_IMM_TIMES
= 0x50u
,
238 REBASE_OPCODE_DO_REBASE_ULEB_TIMES
= 0x60u
,
239 REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
= 0x70u
,
240 REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
= 0x80u
244 BIND_TYPE_POINTER
= 1u,
245 BIND_TYPE_TEXT_ABSOLUTE32
= 2u,
246 BIND_TYPE_TEXT_PCREL32
= 3u
249 enum BindSpecialDylib
{
250 BIND_SPECIAL_DYLIB_SELF
= 0,
251 BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE
= -1,
252 BIND_SPECIAL_DYLIB_FLAT_LOOKUP
= -2
256 BIND_SYMBOL_FLAGS_WEAK_IMPORT
= 0x1u
,
257 BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION
= 0x8u
,
259 BIND_OPCODE_MASK
= 0xF0u
,
260 BIND_IMMEDIATE_MASK
= 0x0Fu
264 BIND_OPCODE_DONE
= 0x00u
,
265 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
= 0x10u
,
266 BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB
= 0x20u
,
267 BIND_OPCODE_SET_DYLIB_SPECIAL_IMM
= 0x30u
,
268 BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
= 0x40u
,
269 BIND_OPCODE_SET_TYPE_IMM
= 0x50u
,
270 BIND_OPCODE_SET_ADDEND_SLEB
= 0x60u
,
271 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
= 0x70u
,
272 BIND_OPCODE_ADD_ADDR_ULEB
= 0x80u
,
273 BIND_OPCODE_DO_BIND
= 0x90u
,
274 BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
= 0xA0u
,
275 BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
= 0xB0u
,
276 BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
= 0xC0u
280 EXPORT_SYMBOL_FLAGS_KIND_MASK
= 0x03u
,
281 EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION
= 0x04u
,
282 EXPORT_SYMBOL_FLAGS_REEXPORT
= 0x08u
,
283 EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER
= 0x10u
286 enum ExportSymbolKind
{
287 EXPORT_SYMBOL_FLAGS_KIND_REGULAR
= 0x00u
,
288 EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
= 0x01u
,
289 EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE
= 0x02u
293 // Constant masks for the "n_type" field in llvm::MachO::nlist and
294 // llvm::MachO::nlist_64
301 enum NListType
: uint8_t {
302 // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
303 // llvm::MachO::nlist_64
311 enum SectionOrdinal
{
312 // Constants for the "n_sect" field in llvm::MachO::nlist and
313 // llvm::MachO::nlist_64
319 // Constant masks for the "n_desc" field in llvm::MachO::nlist and
320 // llvm::MachO::nlist_64
321 // The low 3 bits are the for the REFERENCE_TYPE.
322 REFERENCE_TYPE
= 0x7,
323 REFERENCE_FLAG_UNDEFINED_NON_LAZY
= 0,
324 REFERENCE_FLAG_UNDEFINED_LAZY
= 1,
325 REFERENCE_FLAG_DEFINED
= 2,
326 REFERENCE_FLAG_PRIVATE_DEFINED
= 3,
327 REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY
= 4,
328 REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY
= 5,
329 // Flag bits (some overlap with the library ordinal bits).
330 N_ARM_THUMB_DEF
= 0x0008u
,
331 REFERENCED_DYNAMICALLY
= 0x0010u
,
332 N_NO_DEAD_STRIP
= 0x0020u
,
333 N_WEAK_REF
= 0x0040u
,
334 N_WEAK_DEF
= 0x0080u
,
335 N_SYMBOL_RESOLVER
= 0x0100u
,
336 N_ALT_ENTRY
= 0x0200u
,
337 N_COLD_FUNC
= 0x0400u
,
338 // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL()
339 // as these are in the top 8 bits.
340 SELF_LIBRARY_ORDINAL
= 0x0,
341 MAX_LIBRARY_ORDINAL
= 0xfd,
342 DYNAMIC_LOOKUP_ORDINAL
= 0xfe,
343 EXECUTABLE_ORDINAL
= 0xff
347 // Constant values for the "n_type" field in llvm::MachO::nlist and
348 // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
383 // Constant values for the r_symbolnum field in an
384 // llvm::MachO::relocation_info structure when r_extern is 0.
387 // Constant bits for the r_address field in an
388 // llvm::MachO::relocation_info structure.
389 R_SCATTERED
= 0x80000000
392 enum RelocationInfoType
{
393 // Constant values for the r_type field in an
394 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
396 GENERIC_RELOC_VANILLA
= 0,
397 GENERIC_RELOC_PAIR
= 1,
398 GENERIC_RELOC_SECTDIFF
= 2,
399 GENERIC_RELOC_PB_LA_PTR
= 3,
400 GENERIC_RELOC_LOCAL_SECTDIFF
= 4,
401 GENERIC_RELOC_TLV
= 5,
403 // Constant values for the r_type field in a PowerPC architecture
404 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
406 PPC_RELOC_VANILLA
= GENERIC_RELOC_VANILLA
,
407 PPC_RELOC_PAIR
= GENERIC_RELOC_PAIR
,
414 PPC_RELOC_SECTDIFF
= 8,
415 PPC_RELOC_PB_LA_PTR
= 9,
416 PPC_RELOC_HI16_SECTDIFF
= 10,
417 PPC_RELOC_LO16_SECTDIFF
= 11,
418 PPC_RELOC_HA16_SECTDIFF
= 12,
420 PPC_RELOC_LO14_SECTDIFF
= 14,
421 PPC_RELOC_LOCAL_SECTDIFF
= 15,
423 // Constant values for the r_type field in an ARM architecture
424 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
426 ARM_RELOC_VANILLA
= GENERIC_RELOC_VANILLA
,
427 ARM_RELOC_PAIR
= GENERIC_RELOC_PAIR
,
428 ARM_RELOC_SECTDIFF
= GENERIC_RELOC_SECTDIFF
,
429 ARM_RELOC_LOCAL_SECTDIFF
= 3,
430 ARM_RELOC_PB_LA_PTR
= 4,
432 ARM_THUMB_RELOC_BR22
= 6,
433 ARM_THUMB_32BIT_BRANCH
= 7, // obsolete
435 ARM_RELOC_HALF_SECTDIFF
= 9,
437 // Constant values for the r_type field in an ARM64 architecture
438 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
442 ARM64_RELOC_UNSIGNED
= 0,
443 // Must be followed by an ARM64_RELOC_UNSIGNED
444 ARM64_RELOC_SUBTRACTOR
= 1,
445 // A B/BL instruction with 26-bit displacement.
446 ARM64_RELOC_BRANCH26
= 2,
447 // PC-rel distance to page of target.
448 ARM64_RELOC_PAGE21
= 3,
449 // Offset within page, scaled by r_length.
450 ARM64_RELOC_PAGEOFF12
= 4,
451 // PC-rel distance to page of GOT slot.
452 ARM64_RELOC_GOT_LOAD_PAGE21
= 5,
453 // Offset within page of GOT slot, scaled by r_length.
454 ARM64_RELOC_GOT_LOAD_PAGEOFF12
= 6,
455 // For pointers to GOT slots.
456 ARM64_RELOC_POINTER_TO_GOT
= 7,
457 // PC-rel distance to page of TLVP slot.
458 ARM64_RELOC_TLVP_LOAD_PAGE21
= 8,
459 // Offset within page of TLVP slot, scaled by r_length.
460 ARM64_RELOC_TLVP_LOAD_PAGEOFF12
= 9,
461 // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
462 ARM64_RELOC_ADDEND
= 10,
464 // Constant values for the r_type field in an x86_64 architecture
465 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
467 X86_64_RELOC_UNSIGNED
= 0,
468 X86_64_RELOC_SIGNED
= 1,
469 X86_64_RELOC_BRANCH
= 2,
470 X86_64_RELOC_GOT_LOAD
= 3,
471 X86_64_RELOC_GOT
= 4,
472 X86_64_RELOC_SUBTRACTOR
= 5,
473 X86_64_RELOC_SIGNED_1
= 6,
474 X86_64_RELOC_SIGNED_2
= 7,
475 X86_64_RELOC_SIGNED_4
= 8,
479 // Values for segment_command.initprot.
480 // From <mach/vm_prot.h>
481 enum { VM_PROT_READ
= 0x1, VM_PROT_WRITE
= 0x2, VM_PROT_EXECUTE
= 0x4 };
483 // Values for platform field in build_version_command.
488 PLATFORM_WATCHOS
= 4,
489 PLATFORM_BRIDGEOS
= 5,
490 PLATFORM_MACCATALYST
= 6,
491 PLATFORM_IOSSIMULATOR
= 7,
492 PLATFORM_TVOSSIMULATOR
= 8,
493 PLATFORM_WATCHOSSIMULATOR
= 9
496 // Values for tools enum in build_tool_version.
497 enum { TOOL_CLANG
= 1, TOOL_SWIFT
= 2, TOOL_LD
= 3 };
499 // Structs from <mach-o/loader.h>
511 struct mach_header_64
{
522 struct load_command
{
527 struct segment_command
{
541 struct segment_command_64
{
584 inline bool isVirtualSection(uint8_t type
) {
585 return (type
== MachO::S_ZEROFILL
|| type
== MachO::S_GB_ZEROFILL
||
586 type
== MachO::S_THREAD_LOCAL_ZEROFILL
);
591 uint32_t minor_version
;
592 uint32_t header_addr
;
595 // The fvmlib_command is obsolete and no longer supported.
596 struct fvmlib_command
{
599 struct fvmlib fvmlib
;
605 uint32_t current_version
;
606 uint32_t compatibility_version
;
609 struct dylib_command
{
615 struct sub_framework_command
{
621 struct sub_client_command
{
627 struct sub_umbrella_command
{
630 uint32_t sub_umbrella
;
633 struct sub_library_command
{
636 uint32_t sub_library
;
639 // The prebound_dylib_command is obsolete and no longer supported.
640 struct prebound_dylib_command
{
645 uint32_t linked_modules
;
648 struct dylinker_command
{
654 struct thread_command
{
659 struct routines_command
{
662 uint32_t init_address
;
663 uint32_t init_module
;
672 struct routines_command_64
{
675 uint64_t init_address
;
676 uint64_t init_module
;
685 struct symtab_command
{
694 struct dysymtab_command
{
707 uint32_t extrefsymoff
;
708 uint32_t nextrefsyms
;
709 uint32_t indirectsymoff
;
710 uint32_t nindirectsyms
;
717 struct dylib_table_of_contents
{
718 uint32_t symbol_index
;
719 uint32_t module_index
;
722 struct dylib_module
{
723 uint32_t module_name
;
732 uint32_t iinit_iterm
;
733 uint32_t ninit_nterm
;
734 uint32_t objc_module_info_addr
;
735 uint32_t objc_module_info_size
;
738 struct dylib_module_64
{
739 uint32_t module_name
;
748 uint32_t iinit_iterm
;
749 uint32_t ninit_nterm
;
750 uint32_t objc_module_info_size
;
751 uint64_t objc_module_info_addr
;
754 struct dylib_reference
{
755 uint32_t isym
: 24, flags
: 8;
758 // The twolevel_hints_command is obsolete and no longer supported.
759 struct twolevel_hints_command
{
766 // The twolevel_hints_command is obsolete and no longer supported.
767 struct twolevel_hint
{
768 uint32_t isub_image
: 8, itoc
: 24;
771 // The prebind_cksum_command is obsolete and no longer supported.
772 struct prebind_cksum_command
{
778 struct uuid_command
{
784 struct rpath_command
{
790 struct linkedit_data_command
{
797 struct data_in_code_entry
{
803 struct source_version_command
{
809 struct encryption_info_command
{
817 struct encryption_info_command_64
{
826 struct version_min_command
{
827 uint32_t cmd
; // LC_VERSION_MIN_MACOSX or
828 // LC_VERSION_MIN_IPHONEOS
829 uint32_t cmdsize
; // sizeof(struct version_min_command)
830 uint32_t version
; // X.Y.Z is encoded in nibbles xxxx.yy.zz
831 uint32_t sdk
; // X.Y.Z is encoded in nibbles xxxx.yy.zz
834 struct note_command
{
835 uint32_t cmd
; // LC_NOTE
836 uint32_t cmdsize
; // sizeof(struct note_command)
837 char data_owner
[16]; // owner name for this LC_NOTE
838 uint64_t offset
; // file offset of this data
839 uint64_t size
; // length of data region
842 struct build_tool_version
{
843 uint32_t tool
; // enum for the tool
844 uint32_t version
; // version of the tool
847 struct build_version_command
{
848 uint32_t cmd
; // LC_BUILD_VERSION
849 uint32_t cmdsize
; // sizeof(struct build_version_command) +
850 // ntools * sizeof(struct build_tool_version)
851 uint32_t platform
; // platform
852 uint32_t minos
; // X.Y.Z is encoded in nibbles xxxx.yy.zz
853 uint32_t sdk
; // X.Y.Z is encoded in nibbles xxxx.yy.zz
854 uint32_t ntools
; // number of tool entries following this
857 struct dyld_info_command
{
861 uint32_t rebase_size
;
864 uint32_t weak_bind_off
;
865 uint32_t weak_bind_size
;
866 uint32_t lazy_bind_off
;
867 uint32_t lazy_bind_size
;
869 uint32_t export_size
;
872 struct linker_option_command
{
878 // The symseg_command is obsolete and no longer supported.
879 struct symseg_command
{
886 // The ident_command is obsolete and no longer supported.
887 struct ident_command
{
892 // The fvmfile_command is obsolete and no longer supported.
893 struct fvmfile_command
{
897 uint32_t header_addr
;
900 struct tlv_descriptor_32
{
906 struct tlv_descriptor_64
{
912 struct tlv_descriptor
{
918 struct entry_point_command
{
925 // Structs from <mach-o/fat.h>
948 // Structs from <mach-o/reloc.h>
949 struct relocation_info
{
951 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
952 uint32_t r_type
: 4, r_extern
: 1, r_length
: 2, r_pcrel
: 1,
955 uint32_t r_symbolnum
: 24, r_pcrel
: 1, r_length
: 2, r_extern
: 1,
960 struct scattered_relocation_info
{
961 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
962 uint32_t r_scattered
: 1, r_pcrel
: 1, r_length
: 2, r_type
: 4,
965 uint32_t r_address
: 24, r_type
: 4, r_length
: 2, r_pcrel
: 1,
971 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
972 struct any_relocation_info
{
973 uint32_t r_word0
, r_word1
;
976 // Structs from <mach-o/nlist.h>
1000 // Byte order swapping functions for MachO structs
1002 inline void swapStruct(fat_header
&mh
) {
1003 sys::swapByteOrder(mh
.magic
);
1004 sys::swapByteOrder(mh
.nfat_arch
);
1007 inline void swapStruct(fat_arch
&mh
) {
1008 sys::swapByteOrder(mh
.cputype
);
1009 sys::swapByteOrder(mh
.cpusubtype
);
1010 sys::swapByteOrder(mh
.offset
);
1011 sys::swapByteOrder(mh
.size
);
1012 sys::swapByteOrder(mh
.align
);
1015 inline void swapStruct(fat_arch_64
&mh
) {
1016 sys::swapByteOrder(mh
.cputype
);
1017 sys::swapByteOrder(mh
.cpusubtype
);
1018 sys::swapByteOrder(mh
.offset
);
1019 sys::swapByteOrder(mh
.size
);
1020 sys::swapByteOrder(mh
.align
);
1021 sys::swapByteOrder(mh
.reserved
);
1024 inline void swapStruct(mach_header
&mh
) {
1025 sys::swapByteOrder(mh
.magic
);
1026 sys::swapByteOrder(mh
.cputype
);
1027 sys::swapByteOrder(mh
.cpusubtype
);
1028 sys::swapByteOrder(mh
.filetype
);
1029 sys::swapByteOrder(mh
.ncmds
);
1030 sys::swapByteOrder(mh
.sizeofcmds
);
1031 sys::swapByteOrder(mh
.flags
);
1034 inline void swapStruct(mach_header_64
&H
) {
1035 sys::swapByteOrder(H
.magic
);
1036 sys::swapByteOrder(H
.cputype
);
1037 sys::swapByteOrder(H
.cpusubtype
);
1038 sys::swapByteOrder(H
.filetype
);
1039 sys::swapByteOrder(H
.ncmds
);
1040 sys::swapByteOrder(H
.sizeofcmds
);
1041 sys::swapByteOrder(H
.flags
);
1042 sys::swapByteOrder(H
.reserved
);
1045 inline void swapStruct(load_command
&lc
) {
1046 sys::swapByteOrder(lc
.cmd
);
1047 sys::swapByteOrder(lc
.cmdsize
);
1050 inline void swapStruct(symtab_command
&lc
) {
1051 sys::swapByteOrder(lc
.cmd
);
1052 sys::swapByteOrder(lc
.cmdsize
);
1053 sys::swapByteOrder(lc
.symoff
);
1054 sys::swapByteOrder(lc
.nsyms
);
1055 sys::swapByteOrder(lc
.stroff
);
1056 sys::swapByteOrder(lc
.strsize
);
1059 inline void swapStruct(segment_command_64
&seg
) {
1060 sys::swapByteOrder(seg
.cmd
);
1061 sys::swapByteOrder(seg
.cmdsize
);
1062 sys::swapByteOrder(seg
.vmaddr
);
1063 sys::swapByteOrder(seg
.vmsize
);
1064 sys::swapByteOrder(seg
.fileoff
);
1065 sys::swapByteOrder(seg
.filesize
);
1066 sys::swapByteOrder(seg
.maxprot
);
1067 sys::swapByteOrder(seg
.initprot
);
1068 sys::swapByteOrder(seg
.nsects
);
1069 sys::swapByteOrder(seg
.flags
);
1072 inline void swapStruct(segment_command
&seg
) {
1073 sys::swapByteOrder(seg
.cmd
);
1074 sys::swapByteOrder(seg
.cmdsize
);
1075 sys::swapByteOrder(seg
.vmaddr
);
1076 sys::swapByteOrder(seg
.vmsize
);
1077 sys::swapByteOrder(seg
.fileoff
);
1078 sys::swapByteOrder(seg
.filesize
);
1079 sys::swapByteOrder(seg
.maxprot
);
1080 sys::swapByteOrder(seg
.initprot
);
1081 sys::swapByteOrder(seg
.nsects
);
1082 sys::swapByteOrder(seg
.flags
);
1085 inline void swapStruct(section_64
§
) {
1086 sys::swapByteOrder(sect
.addr
);
1087 sys::swapByteOrder(sect
.size
);
1088 sys::swapByteOrder(sect
.offset
);
1089 sys::swapByteOrder(sect
.align
);
1090 sys::swapByteOrder(sect
.reloff
);
1091 sys::swapByteOrder(sect
.nreloc
);
1092 sys::swapByteOrder(sect
.flags
);
1093 sys::swapByteOrder(sect
.reserved1
);
1094 sys::swapByteOrder(sect
.reserved2
);
1097 inline void swapStruct(section
§
) {
1098 sys::swapByteOrder(sect
.addr
);
1099 sys::swapByteOrder(sect
.size
);
1100 sys::swapByteOrder(sect
.offset
);
1101 sys::swapByteOrder(sect
.align
);
1102 sys::swapByteOrder(sect
.reloff
);
1103 sys::swapByteOrder(sect
.nreloc
);
1104 sys::swapByteOrder(sect
.flags
);
1105 sys::swapByteOrder(sect
.reserved1
);
1106 sys::swapByteOrder(sect
.reserved2
);
1109 inline void swapStruct(dyld_info_command
&info
) {
1110 sys::swapByteOrder(info
.cmd
);
1111 sys::swapByteOrder(info
.cmdsize
);
1112 sys::swapByteOrder(info
.rebase_off
);
1113 sys::swapByteOrder(info
.rebase_size
);
1114 sys::swapByteOrder(info
.bind_off
);
1115 sys::swapByteOrder(info
.bind_size
);
1116 sys::swapByteOrder(info
.weak_bind_off
);
1117 sys::swapByteOrder(info
.weak_bind_size
);
1118 sys::swapByteOrder(info
.lazy_bind_off
);
1119 sys::swapByteOrder(info
.lazy_bind_size
);
1120 sys::swapByteOrder(info
.export_off
);
1121 sys::swapByteOrder(info
.export_size
);
1124 inline void swapStruct(dylib_command
&d
) {
1125 sys::swapByteOrder(d
.cmd
);
1126 sys::swapByteOrder(d
.cmdsize
);
1127 sys::swapByteOrder(d
.dylib
.name
);
1128 sys::swapByteOrder(d
.dylib
.timestamp
);
1129 sys::swapByteOrder(d
.dylib
.current_version
);
1130 sys::swapByteOrder(d
.dylib
.compatibility_version
);
1133 inline void swapStruct(sub_framework_command
&s
) {
1134 sys::swapByteOrder(s
.cmd
);
1135 sys::swapByteOrder(s
.cmdsize
);
1136 sys::swapByteOrder(s
.umbrella
);
1139 inline void swapStruct(sub_umbrella_command
&s
) {
1140 sys::swapByteOrder(s
.cmd
);
1141 sys::swapByteOrder(s
.cmdsize
);
1142 sys::swapByteOrder(s
.sub_umbrella
);
1145 inline void swapStruct(sub_library_command
&s
) {
1146 sys::swapByteOrder(s
.cmd
);
1147 sys::swapByteOrder(s
.cmdsize
);
1148 sys::swapByteOrder(s
.sub_library
);
1151 inline void swapStruct(sub_client_command
&s
) {
1152 sys::swapByteOrder(s
.cmd
);
1153 sys::swapByteOrder(s
.cmdsize
);
1154 sys::swapByteOrder(s
.client
);
1157 inline void swapStruct(routines_command
&r
) {
1158 sys::swapByteOrder(r
.cmd
);
1159 sys::swapByteOrder(r
.cmdsize
);
1160 sys::swapByteOrder(r
.init_address
);
1161 sys::swapByteOrder(r
.init_module
);
1162 sys::swapByteOrder(r
.reserved1
);
1163 sys::swapByteOrder(r
.reserved2
);
1164 sys::swapByteOrder(r
.reserved3
);
1165 sys::swapByteOrder(r
.reserved4
);
1166 sys::swapByteOrder(r
.reserved5
);
1167 sys::swapByteOrder(r
.reserved6
);
1170 inline void swapStruct(routines_command_64
&r
) {
1171 sys::swapByteOrder(r
.cmd
);
1172 sys::swapByteOrder(r
.cmdsize
);
1173 sys::swapByteOrder(r
.init_address
);
1174 sys::swapByteOrder(r
.init_module
);
1175 sys::swapByteOrder(r
.reserved1
);
1176 sys::swapByteOrder(r
.reserved2
);
1177 sys::swapByteOrder(r
.reserved3
);
1178 sys::swapByteOrder(r
.reserved4
);
1179 sys::swapByteOrder(r
.reserved5
);
1180 sys::swapByteOrder(r
.reserved6
);
1183 inline void swapStruct(thread_command
&t
) {
1184 sys::swapByteOrder(t
.cmd
);
1185 sys::swapByteOrder(t
.cmdsize
);
1188 inline void swapStruct(dylinker_command
&d
) {
1189 sys::swapByteOrder(d
.cmd
);
1190 sys::swapByteOrder(d
.cmdsize
);
1191 sys::swapByteOrder(d
.name
);
1194 inline void swapStruct(uuid_command
&u
) {
1195 sys::swapByteOrder(u
.cmd
);
1196 sys::swapByteOrder(u
.cmdsize
);
1199 inline void swapStruct(rpath_command
&r
) {
1200 sys::swapByteOrder(r
.cmd
);
1201 sys::swapByteOrder(r
.cmdsize
);
1202 sys::swapByteOrder(r
.path
);
1205 inline void swapStruct(source_version_command
&s
) {
1206 sys::swapByteOrder(s
.cmd
);
1207 sys::swapByteOrder(s
.cmdsize
);
1208 sys::swapByteOrder(s
.version
);
1211 inline void swapStruct(entry_point_command
&e
) {
1212 sys::swapByteOrder(e
.cmd
);
1213 sys::swapByteOrder(e
.cmdsize
);
1214 sys::swapByteOrder(e
.entryoff
);
1215 sys::swapByteOrder(e
.stacksize
);
1218 inline void swapStruct(encryption_info_command
&e
) {
1219 sys::swapByteOrder(e
.cmd
);
1220 sys::swapByteOrder(e
.cmdsize
);
1221 sys::swapByteOrder(e
.cryptoff
);
1222 sys::swapByteOrder(e
.cryptsize
);
1223 sys::swapByteOrder(e
.cryptid
);
1226 inline void swapStruct(encryption_info_command_64
&e
) {
1227 sys::swapByteOrder(e
.cmd
);
1228 sys::swapByteOrder(e
.cmdsize
);
1229 sys::swapByteOrder(e
.cryptoff
);
1230 sys::swapByteOrder(e
.cryptsize
);
1231 sys::swapByteOrder(e
.cryptid
);
1232 sys::swapByteOrder(e
.pad
);
1235 inline void swapStruct(dysymtab_command
&dst
) {
1236 sys::swapByteOrder(dst
.cmd
);
1237 sys::swapByteOrder(dst
.cmdsize
);
1238 sys::swapByteOrder(dst
.ilocalsym
);
1239 sys::swapByteOrder(dst
.nlocalsym
);
1240 sys::swapByteOrder(dst
.iextdefsym
);
1241 sys::swapByteOrder(dst
.nextdefsym
);
1242 sys::swapByteOrder(dst
.iundefsym
);
1243 sys::swapByteOrder(dst
.nundefsym
);
1244 sys::swapByteOrder(dst
.tocoff
);
1245 sys::swapByteOrder(dst
.ntoc
);
1246 sys::swapByteOrder(dst
.modtaboff
);
1247 sys::swapByteOrder(dst
.nmodtab
);
1248 sys::swapByteOrder(dst
.extrefsymoff
);
1249 sys::swapByteOrder(dst
.nextrefsyms
);
1250 sys::swapByteOrder(dst
.indirectsymoff
);
1251 sys::swapByteOrder(dst
.nindirectsyms
);
1252 sys::swapByteOrder(dst
.extreloff
);
1253 sys::swapByteOrder(dst
.nextrel
);
1254 sys::swapByteOrder(dst
.locreloff
);
1255 sys::swapByteOrder(dst
.nlocrel
);
1258 inline void swapStruct(any_relocation_info
&reloc
) {
1259 sys::swapByteOrder(reloc
.r_word0
);
1260 sys::swapByteOrder(reloc
.r_word1
);
1263 inline void swapStruct(nlist_base
&S
) {
1264 sys::swapByteOrder(S
.n_strx
);
1265 sys::swapByteOrder(S
.n_desc
);
1268 inline void swapStruct(nlist
&sym
) {
1269 sys::swapByteOrder(sym
.n_strx
);
1270 sys::swapByteOrder(sym
.n_desc
);
1271 sys::swapByteOrder(sym
.n_value
);
1274 inline void swapStruct(nlist_64
&sym
) {
1275 sys::swapByteOrder(sym
.n_strx
);
1276 sys::swapByteOrder(sym
.n_desc
);
1277 sys::swapByteOrder(sym
.n_value
);
1280 inline void swapStruct(linkedit_data_command
&C
) {
1281 sys::swapByteOrder(C
.cmd
);
1282 sys::swapByteOrder(C
.cmdsize
);
1283 sys::swapByteOrder(C
.dataoff
);
1284 sys::swapByteOrder(C
.datasize
);
1287 inline void swapStruct(linker_option_command
&C
) {
1288 sys::swapByteOrder(C
.cmd
);
1289 sys::swapByteOrder(C
.cmdsize
);
1290 sys::swapByteOrder(C
.count
);
1293 inline void swapStruct(version_min_command
&C
) {
1294 sys::swapByteOrder(C
.cmd
);
1295 sys::swapByteOrder(C
.cmdsize
);
1296 sys::swapByteOrder(C
.version
);
1297 sys::swapByteOrder(C
.sdk
);
1300 inline void swapStruct(note_command
&C
) {
1301 sys::swapByteOrder(C
.cmd
);
1302 sys::swapByteOrder(C
.cmdsize
);
1303 sys::swapByteOrder(C
.offset
);
1304 sys::swapByteOrder(C
.size
);
1307 inline void swapStruct(build_version_command
&C
) {
1308 sys::swapByteOrder(C
.cmd
);
1309 sys::swapByteOrder(C
.cmdsize
);
1310 sys::swapByteOrder(C
.platform
);
1311 sys::swapByteOrder(C
.minos
);
1312 sys::swapByteOrder(C
.sdk
);
1313 sys::swapByteOrder(C
.ntools
);
1316 inline void swapStruct(build_tool_version
&C
) {
1317 sys::swapByteOrder(C
.tool
);
1318 sys::swapByteOrder(C
.version
);
1321 inline void swapStruct(data_in_code_entry
&C
) {
1322 sys::swapByteOrder(C
.offset
);
1323 sys::swapByteOrder(C
.length
);
1324 sys::swapByteOrder(C
.kind
);
1327 inline void swapStruct(uint32_t &C
) { sys::swapByteOrder(C
); }
1329 // The prebind_cksum_command is obsolete and no longer supported.
1330 inline void swapStruct(prebind_cksum_command
&C
) {
1331 sys::swapByteOrder(C
.cmd
);
1332 sys::swapByteOrder(C
.cmdsize
);
1333 sys::swapByteOrder(C
.cksum
);
1336 // The twolevel_hints_command is obsolete and no longer supported.
1337 inline void swapStruct(twolevel_hints_command
&C
) {
1338 sys::swapByteOrder(C
.cmd
);
1339 sys::swapByteOrder(C
.cmdsize
);
1340 sys::swapByteOrder(C
.offset
);
1341 sys::swapByteOrder(C
.nhints
);
1344 // The prebound_dylib_command is obsolete and no longer supported.
1345 inline void swapStruct(prebound_dylib_command
&C
) {
1346 sys::swapByteOrder(C
.cmd
);
1347 sys::swapByteOrder(C
.cmdsize
);
1348 sys::swapByteOrder(C
.name
);
1349 sys::swapByteOrder(C
.nmodules
);
1350 sys::swapByteOrder(C
.linked_modules
);
1353 // The fvmfile_command is obsolete and no longer supported.
1354 inline void swapStruct(fvmfile_command
&C
) {
1355 sys::swapByteOrder(C
.cmd
);
1356 sys::swapByteOrder(C
.cmdsize
);
1357 sys::swapByteOrder(C
.name
);
1358 sys::swapByteOrder(C
.header_addr
);
1361 // The symseg_command is obsolete and no longer supported.
1362 inline void swapStruct(symseg_command
&C
) {
1363 sys::swapByteOrder(C
.cmd
);
1364 sys::swapByteOrder(C
.cmdsize
);
1365 sys::swapByteOrder(C
.offset
);
1366 sys::swapByteOrder(C
.size
);
1369 // The ident_command is obsolete and no longer supported.
1370 inline void swapStruct(ident_command
&C
) {
1371 sys::swapByteOrder(C
.cmd
);
1372 sys::swapByteOrder(C
.cmdsize
);
1375 inline void swapStruct(fvmlib
&C
) {
1376 sys::swapByteOrder(C
.name
);
1377 sys::swapByteOrder(C
.minor_version
);
1378 sys::swapByteOrder(C
.header_addr
);
1381 // The fvmlib_command is obsolete and no longer supported.
1382 inline void swapStruct(fvmlib_command
&C
) {
1383 sys::swapByteOrder(C
.cmd
);
1384 sys::swapByteOrder(C
.cmdsize
);
1385 swapStruct(C
.fvmlib
);
1388 // Get/Set functions from <mach-o/nlist.h>
1390 inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc
) {
1391 return (((n_desc
) >> 8u) & 0xffu
);
1394 inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc
, uint8_t ordinal
) {
1395 n_desc
= (((n_desc
)&0x00ff) | (((ordinal
)&0xff) << 8));
1398 inline uint8_t GET_COMM_ALIGN(uint16_t n_desc
) {
1399 return (n_desc
>> 8u) & 0x0fu
;
1402 inline void SET_COMM_ALIGN(uint16_t &n_desc
, uint8_t align
) {
1403 n_desc
= ((n_desc
& 0xf0ffu
) | ((align
& 0x0fu
) << 8u));
1406 // Enums from <mach/machine.h>
1408 // Capability bits used in the definition of cpu_type.
1409 CPU_ARCH_MASK
= 0xff000000, // Mask for architecture bits
1410 CPU_ARCH_ABI64
= 0x01000000, // 64 bit ABI
1411 CPU_ARCH_ABI64_32
= 0x02000000, // ILP32 ABI on 64-bit hardware
1414 // Constants for the cputype field.
1418 CPU_TYPE_I386
= CPU_TYPE_X86
,
1419 CPU_TYPE_X86_64
= CPU_TYPE_X86
| CPU_ARCH_ABI64
,
1420 /* CPU_TYPE_MIPS = 8, */
1421 CPU_TYPE_MC98000
= 10, // Old Motorola PowerPC
1423 CPU_TYPE_ARM64
= CPU_TYPE_ARM
| CPU_ARCH_ABI64
,
1424 CPU_TYPE_ARM64_32
= CPU_TYPE_ARM
| CPU_ARCH_ABI64_32
,
1425 CPU_TYPE_SPARC
= 14,
1426 CPU_TYPE_POWERPC
= 18,
1427 CPU_TYPE_POWERPC64
= CPU_TYPE_POWERPC
| CPU_ARCH_ABI64
1431 // Capability bits used in the definition of cpusubtype.
1432 CPU_SUBTYPE_MASK
= 0xff000000, // Mask for architecture bits
1433 CPU_SUBTYPE_LIB64
= 0x80000000, // 64 bit libraries
1435 // Special CPU subtype constants.
1436 CPU_SUBTYPE_MULTIPLE
= ~0u
1439 // Constants for the cpusubtype field.
1440 enum CPUSubTypeX86
{
1441 CPU_SUBTYPE_I386_ALL
= 3,
1442 CPU_SUBTYPE_386
= 3,
1443 CPU_SUBTYPE_486
= 4,
1444 CPU_SUBTYPE_486SX
= 0x84,
1445 CPU_SUBTYPE_586
= 5,
1446 CPU_SUBTYPE_PENT
= CPU_SUBTYPE_586
,
1447 CPU_SUBTYPE_PENTPRO
= 0x16,
1448 CPU_SUBTYPE_PENTII_M3
= 0x36,
1449 CPU_SUBTYPE_PENTII_M5
= 0x56,
1450 CPU_SUBTYPE_CELERON
= 0x67,
1451 CPU_SUBTYPE_CELERON_MOBILE
= 0x77,
1452 CPU_SUBTYPE_PENTIUM_3
= 0x08,
1453 CPU_SUBTYPE_PENTIUM_3_M
= 0x18,
1454 CPU_SUBTYPE_PENTIUM_3_XEON
= 0x28,
1455 CPU_SUBTYPE_PENTIUM_M
= 0x09,
1456 CPU_SUBTYPE_PENTIUM_4
= 0x0a,
1457 CPU_SUBTYPE_PENTIUM_4_M
= 0x1a,
1458 CPU_SUBTYPE_ITANIUM
= 0x0b,
1459 CPU_SUBTYPE_ITANIUM_2
= 0x1b,
1460 CPU_SUBTYPE_XEON
= 0x0c,
1461 CPU_SUBTYPE_XEON_MP
= 0x1c,
1463 CPU_SUBTYPE_X86_ALL
= 3,
1464 CPU_SUBTYPE_X86_64_ALL
= 3,
1465 CPU_SUBTYPE_X86_ARCH1
= 4,
1466 CPU_SUBTYPE_X86_64_H
= 8
1468 inline int CPU_SUBTYPE_INTEL(int Family
, int Model
) {
1469 return Family
| (Model
<< 4);
1471 inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST
) {
1472 return ((int)ST
) & 0x0f;
1474 inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST
) { return ((int)ST
) >> 4; }
1475 enum { CPU_SUBTYPE_INTEL_FAMILY_MAX
= 15, CPU_SUBTYPE_INTEL_MODEL_ALL
= 0 };
1477 enum CPUSubTypeARM
{
1478 CPU_SUBTYPE_ARM_ALL
= 0,
1479 CPU_SUBTYPE_ARM_V4T
= 5,
1480 CPU_SUBTYPE_ARM_V6
= 6,
1481 CPU_SUBTYPE_ARM_V5
= 7,
1482 CPU_SUBTYPE_ARM_V5TEJ
= 7,
1483 CPU_SUBTYPE_ARM_XSCALE
= 8,
1484 CPU_SUBTYPE_ARM_V7
= 9,
1485 // unused ARM_V7F = 10,
1486 CPU_SUBTYPE_ARM_V7S
= 11,
1487 CPU_SUBTYPE_ARM_V7K
= 12,
1488 CPU_SUBTYPE_ARM_V6M
= 14,
1489 CPU_SUBTYPE_ARM_V7M
= 15,
1490 CPU_SUBTYPE_ARM_V7EM
= 16
1493 enum CPUSubTypeARM64
{
1494 CPU_SUBTYPE_ARM64_ALL
= 0,
1495 CPU_SUBTYPE_ARM64E
= 2,
1498 enum CPUSubTypeARM64_32
{ CPU_SUBTYPE_ARM64_32_V8
= 1 };
1500 enum CPUSubTypeSPARC
{ CPU_SUBTYPE_SPARC_ALL
= 0 };
1502 enum CPUSubTypePowerPC
{
1503 CPU_SUBTYPE_POWERPC_ALL
= 0,
1504 CPU_SUBTYPE_POWERPC_601
= 1,
1505 CPU_SUBTYPE_POWERPC_602
= 2,
1506 CPU_SUBTYPE_POWERPC_603
= 3,
1507 CPU_SUBTYPE_POWERPC_603e
= 4,
1508 CPU_SUBTYPE_POWERPC_603ev
= 5,
1509 CPU_SUBTYPE_POWERPC_604
= 6,
1510 CPU_SUBTYPE_POWERPC_604e
= 7,
1511 CPU_SUBTYPE_POWERPC_620
= 8,
1512 CPU_SUBTYPE_POWERPC_750
= 9,
1513 CPU_SUBTYPE_POWERPC_7400
= 10,
1514 CPU_SUBTYPE_POWERPC_7450
= 11,
1515 CPU_SUBTYPE_POWERPC_970
= 100,
1517 CPU_SUBTYPE_MC980000_ALL
= CPU_SUBTYPE_POWERPC_ALL
,
1518 CPU_SUBTYPE_MC98601
= CPU_SUBTYPE_POWERPC_601
1521 struct x86_thread_state32_t
{
1540 struct x86_thread_state64_t
{
1564 enum x86_fp_control_precis
{
1565 x86_FP_PREC_24B
= 0,
1566 x86_FP_PREC_53B
= 2,
1570 enum x86_fp_control_rc
{
1571 x86_FP_RND_NEAR
= 0,
1572 x86_FP_RND_DOWN
= 1,
1577 struct fp_control_t
{
1578 unsigned short invalid
: 1, denorm
: 1, zdiv
: 1, ovrfl
: 1, undfl
: 1,
1579 precis
: 1, : 2, pc
: 2, rc
: 2, : 1, : 3;
1582 struct fp_status_t
{
1583 unsigned short invalid
: 1, denorm
: 1, zdiv
: 1, ovrfl
: 1, undfl
: 1,
1584 precis
: 1, stkflt
: 1, errsumm
: 1, c0
: 1, c1
: 1, c2
: 1, tos
: 3,
1597 struct x86_float_state64_t
{
1598 int32_t fpu_reserved
[2];
1599 fp_control_t fpu_fcw
;
1600 fp_status_t fpu_fsw
;
1611 uint32_t fpu_mxcsrmask
;
1612 mmst_reg_t fpu_stmm0
;
1613 mmst_reg_t fpu_stmm1
;
1614 mmst_reg_t fpu_stmm2
;
1615 mmst_reg_t fpu_stmm3
;
1616 mmst_reg_t fpu_stmm4
;
1617 mmst_reg_t fpu_stmm5
;
1618 mmst_reg_t fpu_stmm6
;
1619 mmst_reg_t fpu_stmm7
;
1630 xmm_reg_t fpu_xmm10
;
1631 xmm_reg_t fpu_xmm11
;
1632 xmm_reg_t fpu_xmm12
;
1633 xmm_reg_t fpu_xmm13
;
1634 xmm_reg_t fpu_xmm14
;
1635 xmm_reg_t fpu_xmm15
;
1636 char fpu_rsrv4
[6 * 16];
1637 uint32_t fpu_reserved1
;
1640 struct x86_exception_state64_t
{
1644 uint64_t faultvaddr
;
1647 inline void swapStruct(x86_thread_state32_t
&x
) {
1648 sys::swapByteOrder(x
.eax
);
1649 sys::swapByteOrder(x
.ebx
);
1650 sys::swapByteOrder(x
.ecx
);
1651 sys::swapByteOrder(x
.edx
);
1652 sys::swapByteOrder(x
.edi
);
1653 sys::swapByteOrder(x
.esi
);
1654 sys::swapByteOrder(x
.ebp
);
1655 sys::swapByteOrder(x
.esp
);
1656 sys::swapByteOrder(x
.ss
);
1657 sys::swapByteOrder(x
.eflags
);
1658 sys::swapByteOrder(x
.eip
);
1659 sys::swapByteOrder(x
.cs
);
1660 sys::swapByteOrder(x
.ds
);
1661 sys::swapByteOrder(x
.es
);
1662 sys::swapByteOrder(x
.fs
);
1663 sys::swapByteOrder(x
.gs
);
1666 inline void swapStruct(x86_thread_state64_t
&x
) {
1667 sys::swapByteOrder(x
.rax
);
1668 sys::swapByteOrder(x
.rbx
);
1669 sys::swapByteOrder(x
.rcx
);
1670 sys::swapByteOrder(x
.rdx
);
1671 sys::swapByteOrder(x
.rdi
);
1672 sys::swapByteOrder(x
.rsi
);
1673 sys::swapByteOrder(x
.rbp
);
1674 sys::swapByteOrder(x
.rsp
);
1675 sys::swapByteOrder(x
.r8
);
1676 sys::swapByteOrder(x
.r9
);
1677 sys::swapByteOrder(x
.r10
);
1678 sys::swapByteOrder(x
.r11
);
1679 sys::swapByteOrder(x
.r12
);
1680 sys::swapByteOrder(x
.r13
);
1681 sys::swapByteOrder(x
.r14
);
1682 sys::swapByteOrder(x
.r15
);
1683 sys::swapByteOrder(x
.rip
);
1684 sys::swapByteOrder(x
.rflags
);
1685 sys::swapByteOrder(x
.cs
);
1686 sys::swapByteOrder(x
.fs
);
1687 sys::swapByteOrder(x
.gs
);
1690 inline void swapStruct(x86_float_state64_t
&x
) {
1691 sys::swapByteOrder(x
.fpu_reserved
[0]);
1692 sys::swapByteOrder(x
.fpu_reserved
[1]);
1693 // TODO swap: fp_control_t fpu_fcw;
1694 // TODO swap: fp_status_t fpu_fsw;
1695 sys::swapByteOrder(x
.fpu_fop
);
1696 sys::swapByteOrder(x
.fpu_ip
);
1697 sys::swapByteOrder(x
.fpu_cs
);
1698 sys::swapByteOrder(x
.fpu_rsrv2
);
1699 sys::swapByteOrder(x
.fpu_dp
);
1700 sys::swapByteOrder(x
.fpu_ds
);
1701 sys::swapByteOrder(x
.fpu_rsrv3
);
1702 sys::swapByteOrder(x
.fpu_mxcsr
);
1703 sys::swapByteOrder(x
.fpu_mxcsrmask
);
1704 sys::swapByteOrder(x
.fpu_reserved1
);
1707 inline void swapStruct(x86_exception_state64_t
&x
) {
1708 sys::swapByteOrder(x
.trapno
);
1709 sys::swapByteOrder(x
.cpu
);
1710 sys::swapByteOrder(x
.err
);
1711 sys::swapByteOrder(x
.faultvaddr
);
1714 struct x86_state_hdr_t
{
1719 struct x86_thread_state_t
{
1720 x86_state_hdr_t tsh
;
1722 x86_thread_state64_t ts64
;
1723 x86_thread_state32_t ts32
;
1727 struct x86_float_state_t
{
1728 x86_state_hdr_t fsh
;
1730 x86_float_state64_t fs64
;
1734 struct x86_exception_state_t
{
1735 x86_state_hdr_t esh
;
1737 x86_exception_state64_t es64
;
1741 inline void swapStruct(x86_state_hdr_t
&x
) {
1742 sys::swapByteOrder(x
.flavor
);
1743 sys::swapByteOrder(x
.count
);
1746 enum X86ThreadFlavors
{
1747 x86_THREAD_STATE32
= 1,
1748 x86_FLOAT_STATE32
= 2,
1749 x86_EXCEPTION_STATE32
= 3,
1750 x86_THREAD_STATE64
= 4,
1751 x86_FLOAT_STATE64
= 5,
1752 x86_EXCEPTION_STATE64
= 6,
1753 x86_THREAD_STATE
= 7,
1754 x86_FLOAT_STATE
= 8,
1755 x86_EXCEPTION_STATE
= 9,
1756 x86_DEBUG_STATE32
= 10,
1757 x86_DEBUG_STATE64
= 11,
1758 x86_DEBUG_STATE
= 12
1761 inline void swapStruct(x86_thread_state_t
&x
) {
1763 if (x
.tsh
.flavor
== x86_THREAD_STATE64
)
1764 swapStruct(x
.uts
.ts64
);
1767 inline void swapStruct(x86_float_state_t
&x
) {
1769 if (x
.fsh
.flavor
== x86_FLOAT_STATE64
)
1770 swapStruct(x
.ufs
.fs64
);
1773 inline void swapStruct(x86_exception_state_t
&x
) {
1775 if (x
.esh
.flavor
== x86_EXCEPTION_STATE64
)
1776 swapStruct(x
.ues
.es64
);
1779 const uint32_t x86_THREAD_STATE32_COUNT
=
1780 sizeof(x86_thread_state32_t
) / sizeof(uint32_t);
1782 const uint32_t x86_THREAD_STATE64_COUNT
=
1783 sizeof(x86_thread_state64_t
) / sizeof(uint32_t);
1784 const uint32_t x86_FLOAT_STATE64_COUNT
=
1785 sizeof(x86_float_state64_t
) / sizeof(uint32_t);
1786 const uint32_t x86_EXCEPTION_STATE64_COUNT
=
1787 sizeof(x86_exception_state64_t
) / sizeof(uint32_t);
1789 const uint32_t x86_THREAD_STATE_COUNT
=
1790 sizeof(x86_thread_state_t
) / sizeof(uint32_t);
1791 const uint32_t x86_FLOAT_STATE_COUNT
=
1792 sizeof(x86_float_state_t
) / sizeof(uint32_t);
1793 const uint32_t x86_EXCEPTION_STATE_COUNT
=
1794 sizeof(x86_exception_state_t
) / sizeof(uint32_t);
1796 struct arm_thread_state32_t
{
1804 inline void swapStruct(arm_thread_state32_t
&x
) {
1805 for (int i
= 0; i
< 13; i
++)
1806 sys::swapByteOrder(x
.r
[i
]);
1807 sys::swapByteOrder(x
.sp
);
1808 sys::swapByteOrder(x
.lr
);
1809 sys::swapByteOrder(x
.pc
);
1810 sys::swapByteOrder(x
.cpsr
);
1813 struct arm_thread_state64_t
{
1823 inline void swapStruct(arm_thread_state64_t
&x
) {
1824 for (int i
= 0; i
< 29; i
++)
1825 sys::swapByteOrder(x
.x
[i
]);
1826 sys::swapByteOrder(x
.fp
);
1827 sys::swapByteOrder(x
.lr
);
1828 sys::swapByteOrder(x
.sp
);
1829 sys::swapByteOrder(x
.pc
);
1830 sys::swapByteOrder(x
.cpsr
);
1833 struct arm_state_hdr_t
{
1838 struct arm_thread_state_t
{
1839 arm_state_hdr_t tsh
;
1841 arm_thread_state32_t ts32
;
1845 inline void swapStruct(arm_state_hdr_t
&x
) {
1846 sys::swapByteOrder(x
.flavor
);
1847 sys::swapByteOrder(x
.count
);
1850 enum ARMThreadFlavors
{
1851 ARM_THREAD_STATE
= 1,
1853 ARM_EXCEPTION_STATE
= 3,
1854 ARM_DEBUG_STATE
= 4,
1855 ARN_THREAD_STATE_NONE
= 5,
1856 ARM_THREAD_STATE64
= 6,
1857 ARM_EXCEPTION_STATE64
= 7
1860 inline void swapStruct(arm_thread_state_t
&x
) {
1862 if (x
.tsh
.flavor
== ARM_THREAD_STATE
)
1863 swapStruct(x
.uts
.ts32
);
1866 const uint32_t ARM_THREAD_STATE_COUNT
=
1867 sizeof(arm_thread_state32_t
) / sizeof(uint32_t);
1869 const uint32_t ARM_THREAD_STATE64_COUNT
=
1870 sizeof(arm_thread_state64_t
) / sizeof(uint32_t);
1872 struct ppc_thread_state32_t
{
1915 inline void swapStruct(ppc_thread_state32_t
&x
) {
1916 sys::swapByteOrder(x
.srr0
);
1917 sys::swapByteOrder(x
.srr1
);
1918 sys::swapByteOrder(x
.r0
);
1919 sys::swapByteOrder(x
.r1
);
1920 sys::swapByteOrder(x
.r2
);
1921 sys::swapByteOrder(x
.r3
);
1922 sys::swapByteOrder(x
.r4
);
1923 sys::swapByteOrder(x
.r5
);
1924 sys::swapByteOrder(x
.r6
);
1925 sys::swapByteOrder(x
.r7
);
1926 sys::swapByteOrder(x
.r8
);
1927 sys::swapByteOrder(x
.r9
);
1928 sys::swapByteOrder(x
.r10
);
1929 sys::swapByteOrder(x
.r11
);
1930 sys::swapByteOrder(x
.r12
);
1931 sys::swapByteOrder(x
.r13
);
1932 sys::swapByteOrder(x
.r14
);
1933 sys::swapByteOrder(x
.r15
);
1934 sys::swapByteOrder(x
.r16
);
1935 sys::swapByteOrder(x
.r17
);
1936 sys::swapByteOrder(x
.r18
);
1937 sys::swapByteOrder(x
.r19
);
1938 sys::swapByteOrder(x
.r20
);
1939 sys::swapByteOrder(x
.r21
);
1940 sys::swapByteOrder(x
.r22
);
1941 sys::swapByteOrder(x
.r23
);
1942 sys::swapByteOrder(x
.r24
);
1943 sys::swapByteOrder(x
.r25
);
1944 sys::swapByteOrder(x
.r26
);
1945 sys::swapByteOrder(x
.r27
);
1946 sys::swapByteOrder(x
.r28
);
1947 sys::swapByteOrder(x
.r29
);
1948 sys::swapByteOrder(x
.r30
);
1949 sys::swapByteOrder(x
.r31
);
1950 sys::swapByteOrder(x
.ct
);
1951 sys::swapByteOrder(x
.xer
);
1952 sys::swapByteOrder(x
.lr
);
1953 sys::swapByteOrder(x
.ctr
);
1954 sys::swapByteOrder(x
.mq
);
1955 sys::swapByteOrder(x
.vrsave
);
1958 struct ppc_state_hdr_t
{
1963 struct ppc_thread_state_t
{
1964 ppc_state_hdr_t tsh
;
1966 ppc_thread_state32_t ts32
;
1970 inline void swapStruct(ppc_state_hdr_t
&x
) {
1971 sys::swapByteOrder(x
.flavor
);
1972 sys::swapByteOrder(x
.count
);
1975 enum PPCThreadFlavors
{
1976 PPC_THREAD_STATE
= 1,
1977 PPC_FLOAT_STATE
= 2,
1978 PPC_EXCEPTION_STATE
= 3,
1979 PPC_VECTOR_STATE
= 4,
1980 PPC_THREAD_STATE64
= 5,
1981 PPC_EXCEPTION_STATE64
= 6,
1982 PPC_THREAD_STATE_NONE
= 7
1985 inline void swapStruct(ppc_thread_state_t
&x
) {
1987 if (x
.tsh
.flavor
== PPC_THREAD_STATE
)
1988 swapStruct(x
.uts
.ts32
);
1991 const uint32_t PPC_THREAD_STATE_COUNT
=
1992 sizeof(ppc_thread_state32_t
) / sizeof(uint32_t);
1994 // Define a union of all load command structs
1995 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1998 union alignas(4) macho_load_command
{
1999 #include "llvm/BinaryFormat/MachO.def"
2003 } // end namespace MachO
2004 } // end namespace llvm