LLVM  9.0.0svn
MachO.h
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- C++/-*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines manifest constants for the MachO object file format.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_BINARYFORMAT_MACHO_H
14 #define LLVM_BINARYFORMAT_MACHO_H
15 
16 #include "llvm/Support/Compiler.h"
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/Host.h"
19 
20 namespace llvm {
21 namespace MachO {
22 // Enums from <mach-o/loader.h>
23 enum : uint32_t {
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
34 };
35 
37  // Constants for the "filetype" field in llvm::MachO::mach_header and
38  // llvm::MachO::mach_header_64
39  MH_OBJECT = 0x1u,
40  MH_EXECUTE = 0x2u,
41  MH_FVMLIB = 0x3u,
42  MH_CORE = 0x4u,
43  MH_PRELOAD = 0x5u,
44  MH_DYLIB = 0x6u,
45  MH_DYLINKER = 0x7u,
46  MH_BUNDLE = 0x8u,
47  MH_DYLIB_STUB = 0x9u,
48  MH_DSYM = 0xAu,
50 };
51 
52 enum {
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,
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,
76  MH_PIE = 0x00200000u,
77  MH_DEAD_STRIPPABLE_DYLIB = 0x00400000u,
78  MH_HAS_TLV_DESCRIPTORS = 0x00800000u,
79  MH_NO_HEAP_EXECUTION = 0x01000000u,
80  MH_APP_EXTENSION_SAFE = 0x02000000u,
82 };
83 
84 enum : uint32_t {
85  // Flags for the "cmd" field in llvm::MachO::load_command
86  LC_REQ_DYLD = 0x80000000u
87 };
88 
89 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) LCName = LCValue,
90 
92 #include "llvm/BinaryFormat/MachO.def"
93 };
94 
95 #undef HANDLE_LOAD_COMMAND
96 
97 enum : uint32_t {
98  // Constant bits for the "flags" field in llvm::MachO::segment_command
99  SG_HIGHVM = 0x1u,
100  SG_FVMLIB = 0x2u,
101  SG_NORELOC = 0x4u,
103 
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
110 };
111 
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.
115  // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
116  // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
117 
118  /// S_REGULAR - Regular section.
119  S_REGULAR = 0x00u,
120  /// S_ZEROFILL - Zero fill on demand section.
121  S_ZEROFILL = 0x01u,
122  /// S_CSTRING_LITERALS - Section with literal C strings.
124  /// S_4BYTE_LITERALS - Section with 4 byte literals.
126  /// S_8BYTE_LITERALS - Section with 8 byte literals.
128  /// S_LITERAL_POINTERS - Section with pointers to literals.
130  /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
132  /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
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
138  /// initialization.
140  /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
141  /// termination.
143  /// S_COALESCED - Section contains symbols that are to be coalesced.
144  S_COALESCED = 0x0bu,
145  /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
146  /// gigabytes).
147  S_GB_ZEROFILL = 0x0cu,
148  /// S_INTERPOSING - Section with only pairs of function pointers for
149  /// interposing.
150  S_INTERPOSING = 0x0du,
151  /// S_16BYTE_LITERALS - Section with only 16 byte literals.
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.
158  /// S_THREAD_LOCAL_REGULAR - Thread local data section.
160  /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
162  /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
163  /// structure data.
165  /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
166  /// local structures.
168  /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
169  /// variable initialization pointers to functions.
171 
173 };
174 
175 enum : uint32_t {
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)
178 
179  /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
180  /// instructions.
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.
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
193  /// dyld.
195  /// S_ATTR_DEBUG - A debug section.
196  S_ATTR_DEBUG = 0x02000000u,
197 
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)
200 
201  /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
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,
207 
208  // Constant masks for the value of an indirect symbol in an indirect
209  // symbol table
210  INDIRECT_SYMBOL_LOCAL = 0x80000000u,
211  INDIRECT_SYMBOL_ABS = 0x40000000u
212 };
213 
215  // Constants for the "kind" field in a data_in_code_entry structure
221 };
222 
227 };
228 
229 enum { REBASE_OPCODE_MASK = 0xF0u, REBASE_IMMEDIATE_MASK = 0x0Fu };
230 
241 };
242 
243 enum BindType {
247 };
248 
253 };
254 
255 enum {
258 
261 };
262 
277 };
278 
279 enum {
284 };
285 
290 };
291 
292 enum {
293  // Constant masks for the "n_type" field in llvm::MachO::nlist and
294  // llvm::MachO::nlist_64
295  N_STAB = 0xe0,
296  N_PEXT = 0x10,
297  N_TYPE = 0x0e,
298  N_EXT = 0x01
299 };
300 
301 enum NListType : uint8_t {
302  // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
303  // llvm::MachO::nlist_64
304  N_UNDF = 0x0u,
305  N_ABS = 0x2u,
306  N_SECT = 0xeu,
307  N_PBUD = 0xcu,
308  N_INDR = 0xau
309 };
310 
312  // Constants for the "n_sect" field in llvm::MachO::nlist and
313  // llvm::MachO::nlist_64
314  NO_SECT = 0u,
315  MAX_SECT = 0xffu
316 };
317 
318 enum {
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.
329  // Flag bits (some overlap with the library ordinal bits).
330  N_ARM_THUMB_DEF = 0x0008u,
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.
344 };
345 
346 enum StabType {
347  // Constant values for the "n_type" field in llvm::MachO::nlist and
348  // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
349  N_GSYM = 0x20u,
350  N_FNAME = 0x22u,
351  N_FUN = 0x24u,
352  N_STSYM = 0x26u,
353  N_LCSYM = 0x28u,
354  N_BNSYM = 0x2Eu,
355  N_PC = 0x30u,
356  N_AST = 0x32u,
357  N_OPT = 0x3Cu,
358  N_RSYM = 0x40u,
359  N_SLINE = 0x44u,
360  N_ENSYM = 0x4Eu,
361  N_SSYM = 0x60u,
362  N_SO = 0x64u,
363  N_OSO = 0x66u,
364  N_LSYM = 0x80u,
365  N_BINCL = 0x82u,
366  N_SOL = 0x84u,
367  N_PARAMS = 0x86u,
368  N_VERSION = 0x88u,
369  N_OLEVEL = 0x8Au,
370  N_PSYM = 0xA0u,
371  N_EINCL = 0xA2u,
372  N_ENTRY = 0xA4u,
373  N_LBRAC = 0xC0u,
374  N_EXCL = 0xC2u,
375  N_RBRAC = 0xE0u,
376  N_BCOMM = 0xE2u,
377  N_ECOMM = 0xE4u,
378  N_ECOML = 0xE8u,
379  N_LENG = 0xFEu
380 };
381 
382 enum : uint32_t {
383  // Constant values for the r_symbolnum field in an
384  // llvm::MachO::relocation_info structure when r_extern is 0.
385  R_ABS = 0,
386 
387  // Constant bits for the r_address field in an
388  // llvm::MachO::relocation_info structure.
389  R_SCATTERED = 0x80000000
390 };
391 
393  // Constant values for the r_type field in an
394  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
395  // structure.
402 
403  // Constant values for the r_type field in a PowerPC architecture
404  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
405  // structure.
422 
423  // Constant values for the r_type field in an ARM architecture
424  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
425  // structure.
433  ARM_THUMB_32BIT_BRANCH = 7, // obsolete
436 
437  // Constant values for the r_type field in an ARM64 architecture
438  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
439  // structure.
440 
441  // For pointers.
443  // Must be followed by an ARM64_RELOC_UNSIGNED
445  // A B/BL instruction with 26-bit displacement.
447  // PC-rel distance to page of target.
449  // Offset within page, scaled by r_length.
451  // PC-rel distance to page of GOT slot.
453  // Offset within page of GOT slot, scaled by r_length.
455  // For pointers to GOT slots.
457  // PC-rel distance to page of TLVP slot.
459  // Offset within page of TLVP slot, scaled by r_length.
461  // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
463 
464  // Constant values for the r_type field in an x86_64 architecture
465  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
466  // structure
477 };
478 
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 };
482 
483 // Values for platform field in build_version_command.
493 };
494 
495 // Values for tools enum in build_tool_version.
496 enum { TOOL_CLANG = 1, TOOL_SWIFT = 2, TOOL_LD = 3 };
497 
498 // Structs from <mach-o/loader.h>
499 
500 struct mach_header {
508 };
509 
519 };
520 
521 struct load_command {
524 };
525 
529  char segname[16];
538 };
539 
543  char segname[16];
544  uint64_t vmaddr;
545  uint64_t vmsize;
546  uint64_t fileoff;
547  uint64_t filesize;
552 };
553 
554 struct section {
555  char sectname[16];
556  char segname[16];
566 };
567 
568 struct section_64 {
569  char sectname[16];
570  char segname[16];
571  uint64_t addr;
572  uint64_t size;
581 };
582 
583 struct fvmlib {
587 };
588 
589 // The fvmlib_command is obsolete and no longer supported.
593  struct fvmlib fvmlib;
594 };
595 
596 struct dylib {
601 };
602 
606  struct dylib dylib;
607 };
608 
613 };
614 
619 };
620 
625 };
626 
631 };
632 
633 // The prebound_dylib_command is obsolete and no longer supported.
640 };
641 
646 };
647 
651 };
652 
664 };
665 
669  uint64_t init_address;
670  uint64_t init_module;
671  uint64_t reserved1;
672  uint64_t reserved2;
673  uint64_t reserved3;
674  uint64_t reserved4;
675  uint64_t reserved5;
676  uint64_t reserved6;
677 };
678 
686 };
687 
709 };
710 
714 };
715 
716 struct dylib_module {
730 };
731 
746 };
747 
749  uint32_t isym : 24, flags : 8;
750 };
751 
752 // The twolevel_hints_command is obsolete and no longer supported.
758 };
759 
760 // The twolevel_hints_command is obsolete and no longer supported.
762  uint32_t isub_image : 8, itoc : 24;
763 };
764 
765 // The prebind_cksum_command is obsolete and no longer supported.
770 };
771 
772 struct uuid_command {
775  uint8_t uuid[16];
776 };
777 
782 };
783 
789 };
790 
793  uint16_t length;
794  uint16_t kind;
795 };
796 
800  uint64_t version;
801 };
802 
809 };
810 
818 };
819 
821  uint32_t cmd; // LC_VERSION_MIN_MACOSX or
822  // LC_VERSION_MIN_IPHONEOS
823  uint32_t cmdsize; // sizeof(struct version_min_command)
824  uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
825  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
826 };
827 
828 struct note_command {
829  uint32_t cmd; // LC_NOTE
830  uint32_t cmdsize; // sizeof(struct note_command)
831  char data_owner[16]; // owner name for this LC_NOTE
832  uint64_t offset; // file offset of this data
833  uint64_t size; // length of data region
834 };
835 
837  uint32_t tool; // enum for the tool
838  uint32_t version; // version of the tool
839 };
840 
842  uint32_t cmd; // LC_BUILD_VERSION
843  uint32_t cmdsize; // sizeof(struct build_version_command) +
844  // ntools * sizeof(struct build_tool_version)
845  uint32_t platform; // platform
846  uint32_t minos; // X.Y.Z is encoded in nibbles xxxx.yy.zz
847  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
848  uint32_t ntools; // number of tool entries following this
849 };
850 
864 };
865 
870 };
871 
872 // The symseg_command is obsolete and no longer supported.
878 };
879 
880 // The ident_command is obsolete and no longer supported.
884 };
885 
886 // The fvmfile_command is obsolete and no longer supported.
892 };
893 
898 };
899 
901  uint64_t thunk;
902  uint64_t key;
903  uint64_t offset;
904 };
905 
907  uintptr_t thunk;
908  uintptr_t key;
909  uintptr_t offset;
910 };
911 
915  uint64_t entryoff;
916  uint64_t stacksize;
917 };
918 
919 // Structs from <mach-o/fat.h>
920 struct fat_header {
923 };
924 
925 struct fat_arch {
931 };
932 
933 struct fat_arch_64 {
936  uint64_t offset;
937  uint64_t size;
940 };
941 
942 // Structs from <mach-o/reloc.h>
944  int32_t r_address;
945 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
946  uint32_t r_type : 4, r_extern : 1, r_length : 2, r_pcrel : 1,
947  r_symbolnum : 24;
948 #else
949  uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1,
950  r_type : 4;
951 #endif
952 };
953 
955 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
956  uint32_t r_scattered : 1, r_pcrel : 1, r_length : 2, r_type : 4,
957  r_address : 24;
958 #else
959  uint32_t r_address : 24, r_type : 4, r_length : 2, r_pcrel : 1,
960  r_scattered : 1;
961 #endif
962  int32_t r_value;
963 };
964 
965 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
967  uint32_t r_word0, r_word1;
968 };
969 
970 // Structs from <mach-o/nlist.h>
971 struct nlist_base {
973  uint8_t n_type;
974  uint8_t n_sect;
975  uint16_t n_desc;
976 };
977 
978 struct nlist {
980  uint8_t n_type;
981  uint8_t n_sect;
982  int16_t n_desc;
984 };
985 
986 struct nlist_64 {
988  uint8_t n_type;
989  uint8_t n_sect;
990  uint16_t n_desc;
991  uint64_t n_value;
992 };
993 
994 // Byte order swapping functions for MachO structs
995 
996 inline void swapStruct(fat_header &mh) {
999 }
1000 
1001 inline void swapStruct(fat_arch &mh) {
1007 }
1008 
1009 inline void swapStruct(fat_arch_64 &mh) {
1016 }
1017 
1018 inline void swapStruct(mach_header &mh) {
1026 }
1027 
1028 inline void swapStruct(mach_header_64 &H) {
1037 }
1038 
1039 inline void swapStruct(load_command &lc) {
1040  sys::swapByteOrder(lc.cmd);
1042 }
1043 
1044 inline void swapStruct(symtab_command &lc) {
1045  sys::swapByteOrder(lc.cmd);
1051 }
1052 
1053 inline void swapStruct(segment_command_64 &seg) {
1054  sys::swapByteOrder(seg.cmd);
1064 }
1065 
1066 inline void swapStruct(segment_command &seg) {
1067  sys::swapByteOrder(seg.cmd);
1077 }
1078 
1079 inline void swapStruct(section_64 &sect) {
1080  sys::swapByteOrder(sect.addr);
1081  sys::swapByteOrder(sect.size);
1082  sys::swapByteOrder(sect.offset);
1083  sys::swapByteOrder(sect.align);
1084  sys::swapByteOrder(sect.reloff);
1085  sys::swapByteOrder(sect.nreloc);
1086  sys::swapByteOrder(sect.flags);
1089 }
1090 
1091 inline void swapStruct(section &sect) {
1092  sys::swapByteOrder(sect.addr);
1093  sys::swapByteOrder(sect.size);
1094  sys::swapByteOrder(sect.offset);
1095  sys::swapByteOrder(sect.align);
1096  sys::swapByteOrder(sect.reloff);
1097  sys::swapByteOrder(sect.nreloc);
1098  sys::swapByteOrder(sect.flags);
1101 }
1102 
1104  sys::swapByteOrder(info.cmd);
1116 }
1117 
1118 inline void swapStruct(dylib_command &d) {
1125 }
1126 
1131 }
1132 
1137 }
1138 
1143 }
1144 
1149 }
1150 
1151 inline void swapStruct(routines_command &r) {
1162 }
1163 
1175 }
1176 
1177 inline void swapStruct(thread_command &t) {
1180 }
1181 
1182 inline void swapStruct(dylinker_command &d) {
1186 }
1187 
1188 inline void swapStruct(uuid_command &u) {
1191 }
1192 
1193 inline void swapStruct(rpath_command &r) {
1197 }
1198 
1203 }
1204 
1210 }
1211 
1218 }
1219 
1227 }
1228 
1229 inline void swapStruct(dysymtab_command &dst) {
1230  sys::swapByteOrder(dst.cmd);
1239  sys::swapByteOrder(dst.ntoc);
1250 }
1251 
1252 inline void swapStruct(any_relocation_info &reloc) {
1253  sys::swapByteOrder(reloc.r_word0);
1254  sys::swapByteOrder(reloc.r_word1);
1255 }
1256 
1257 inline void swapStruct(nlist_base &S) {
1260 }
1261 
1262 inline void swapStruct(nlist &sym) {
1266 }
1267 
1268 inline void swapStruct(nlist_64 &sym) {
1272 }
1273 
1279 }
1280 
1285 }
1286 
1292 }
1293 
1294 inline void swapStruct(note_command &C) {
1299 }
1300 
1308 }
1309 
1313 }
1314 
1319 }
1320 
1322 
1323 // The prebind_cksum_command is obsolete and no longer supported.
1328 }
1329 
1330 // The twolevel_hints_command is obsolete and no longer supported.
1336 }
1337 
1338 // The prebound_dylib_command is obsolete and no longer supported.
1345 }
1346 
1347 // The fvmfile_command is obsolete and no longer supported.
1353 }
1354 
1355 // The symseg_command is obsolete and no longer supported.
1356 inline void swapStruct(symseg_command &C) {
1361 }
1362 
1363 // The ident_command is obsolete and no longer supported.
1364 inline void swapStruct(ident_command &C) {
1367 }
1368 
1369 inline void swapStruct(fvmlib &C) {
1373 }
1374 
1375 // The fvmlib_command is obsolete and no longer supported.
1376 inline void swapStruct(fvmlib_command &C) {
1379  swapStruct(C.fvmlib);
1380 }
1381 
1382 // Get/Set functions from <mach-o/nlist.h>
1383 
1384 inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1385  return (((n_desc) >> 8u) & 0xffu);
1386 }
1387 
1388 inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1389  n_desc = (((n_desc)&0x00ff) | (((ordinal)&0xff) << 8));
1390 }
1391 
1392 inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) {
1393  return (n_desc >> 8u) & 0x0fu;
1394 }
1395 
1396 inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) {
1397  n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1398 }
1399 
1400 // Enums from <mach/machine.h>
1401 enum : uint32_t {
1402  // Capability bits used in the definition of cpu_type.
1403  CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1404  CPU_ARCH_ABI64 = 0x01000000, // 64 bit ABI
1405  CPU_ARCH_ABI64_32 = 0x02000000, // ILP32 ABI on 64-bit hardware
1406 };
1407 
1408 // Constants for the cputype field.
1409 enum CPUType {
1414  /* CPU_TYPE_MIPS = 8, */
1415  CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1422 };
1423 
1424 enum : uint32_t {
1425  // Capability bits used in the definition of cpusubtype.
1426  CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1427  CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1428 
1429  // Special CPU subtype constants.
1431 };
1432 
1433 // Constants for the cpusubtype field.
1456 
1461 };
1462 inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1463  return Family | (Model << 4);
1464 }
1466  return ((int)ST) & 0x0f;
1467 }
1468 inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) { return ((int)ST) >> 4; }
1470 
1479  // unused ARM_V7F = 10,
1485 };
1486 
1490 };
1491 
1493 
1495 
1510 
1513 };
1514 
1532 };
1533 
1535  uint64_t rax;
1536  uint64_t rbx;
1537  uint64_t rcx;
1538  uint64_t rdx;
1539  uint64_t rdi;
1540  uint64_t rsi;
1541  uint64_t rbp;
1542  uint64_t rsp;
1543  uint64_t r8;
1544  uint64_t r9;
1545  uint64_t r10;
1546  uint64_t r11;
1547  uint64_t r12;
1548  uint64_t r13;
1549  uint64_t r14;
1550  uint64_t r15;
1551  uint64_t rip;
1552  uint64_t rflags;
1553  uint64_t cs;
1554  uint64_t fs;
1555  uint64_t gs;
1556 };
1557 
1562 };
1563 
1569 };
1570 
1572  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1573  precis : 1, : 2, pc : 2, rc : 2, : 1, : 3;
1574 };
1575 
1576 struct fp_status_t {
1577  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1578  precis : 1, stkflt : 1, errsumm : 1, c0 : 1, c1 : 1, c2 : 1, tos : 3,
1579  c3 : 1, busy : 1;
1580 };
1581 
1582 struct mmst_reg_t {
1583  char mmst_reg[10];
1584  char mmst_rsrv[6];
1585 };
1586 
1587 struct xmm_reg_t {
1588  char xmm_reg[16];
1589 };
1590 
1592  int32_t fpu_reserved[2];
1595  uint8_t fpu_ftw;
1596  uint8_t fpu_rsrv1;
1597  uint16_t fpu_fop;
1599  uint16_t fpu_cs;
1600  uint16_t fpu_rsrv2;
1602  uint16_t fpu_ds;
1603  uint16_t fpu_rsrv3;
1630  char fpu_rsrv4[6 * 16];
1632 };
1633 
1635  uint16_t trapno;
1636  uint16_t cpu;
1638  uint64_t faultvaddr;
1639 };
1640 
1658 }
1659 
1682 }
1683 
1687  // TODO swap: fp_control_t fpu_fcw;
1688  // TODO swap: fp_status_t fpu_fsw;
1699 }
1700 
1706 }
1707 
1711 };
1712 
1715  union {
1718  } uts;
1719 };
1720 
1723  union {
1725  } ufs;
1726 };
1727 
1730  union {
1732  } ues;
1733 };
1734 
1735 inline void swapStruct(x86_state_hdr_t &x) {
1738 }
1739 
1753 };
1754 
1756  swapStruct(x.tsh);
1757  if (x.tsh.flavor == x86_THREAD_STATE64)
1758  swapStruct(x.uts.ts64);
1759 }
1760 
1762  swapStruct(x.fsh);
1763  if (x.fsh.flavor == x86_FLOAT_STATE64)
1764  swapStruct(x.ufs.fs64);
1765 }
1766 
1768  swapStruct(x.esh);
1769  if (x.esh.flavor == x86_EXCEPTION_STATE64)
1770  swapStruct(x.ues.es64);
1771 }
1772 
1774  sizeof(x86_thread_state32_t) / sizeof(uint32_t);
1775 
1777  sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1779  sizeof(x86_float_state64_t) / sizeof(uint32_t);
1781  sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1782 
1784  sizeof(x86_thread_state_t) / sizeof(uint32_t);
1786  sizeof(x86_float_state_t) / sizeof(uint32_t);
1788  sizeof(x86_exception_state_t) / sizeof(uint32_t);
1789 
1791  uint32_t r[13];
1796 };
1797 
1799  for (int i = 0; i < 13; i++)
1800  sys::swapByteOrder(x.r[i]);
1805 }
1806 
1808  uint64_t x[29];
1809  uint64_t fp;
1810  uint64_t lr;
1811  uint64_t sp;
1812  uint64_t pc;
1815 };
1816 
1818  for (int i = 0; i < 29; i++)
1819  sys::swapByteOrder(x.x[i]);
1825 }
1826 
1830 };
1831 
1834  union {
1836  } uts;
1837 };
1838 
1839 inline void swapStruct(arm_state_hdr_t &x) {
1842 }
1843 
1852 };
1853 
1855  swapStruct(x.tsh);
1856  if (x.tsh.flavor == ARM_THREAD_STATE)
1857  swapStruct(x.uts.ts32);
1858 }
1859 
1861  sizeof(arm_thread_state32_t) / sizeof(uint32_t);
1862 
1864  sizeof(arm_thread_state64_t) / sizeof(uint32_t);
1865 
1907 };
1908 
1950 }
1951 
1955 };
1956 
1959  union {
1961  } uts;
1962 };
1963 
1964 inline void swapStruct(ppc_state_hdr_t &x) {
1967 }
1968 
1977 };
1978 
1980  swapStruct(x.tsh);
1981  if (x.tsh.flavor == PPC_THREAD_STATE)
1982  swapStruct(x.uts.ts32);
1983 }
1984 
1986  sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
1987 
1988 // Define a union of all load command structs
1989 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1990 
1992 union alignas(4) macho_load_command {
1993 #include "llvm/BinaryFormat/MachO.def"
1994 };
1996 
1997 } // end namespace MachO
1998 } // end namespace llvm
1999 
2000 #endif
uint32_t align
Definition: MachO.h:930
uint64_t CallInst * C
void swapStruct(fat_header &mh)
Definition: MachO.h:996
LoadCommandType
Definition: MachO.h:91
uint32_t header_addr
Definition: MachO.h:586
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition: MachO.h:131
const uint32_t x86_FLOAT_STATE_COUNT
Definition: MachO.h:1785
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
Definition: MachO.h:136
struct dylib dylib
Definition: MachO.h:606
uint64_t n_value
Definition: MachO.h:991
SectionOrdinal
Definition: MachO.h:311
void swapByteOrder(T &Value)
const uint32_t x86_EXCEPTION_STATE64_COUNT
Definition: MachO.h:1780
uint8_t n_sect
Definition: MachO.h:981
This class represents lattice values for constants.
Definition: AllocatorList.h:23
int CPU_SUBTYPE_INTEL(int Family, int Model)
Definition: MachO.h:1462
ExportSymbolKind
Definition: MachO.h:286
union llvm::MachO::x86_float_state_t::@128 ufs
uint32_t nfat_arch
Definition: MachO.h:922
Definition: MachO.h:791
uint32_t reserved1
Definition: MachO.h:564
BindSpecialDylib
Definition: MachO.h:249
union llvm::MachO::x86_thread_state_t::@127 uts
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition: MachO.h:164
uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
Definition: MachO.h:1384
uint32_t reserved2
Definition: MachO.h:579
uint32_t size
Definition: MachO.h:558
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
Definition: MachO.h:1392
PPCThreadFlavors
Definition: MachO.h:1969
uint32_t cpusubtype
Definition: MachO.h:927
unsigned short zdiv
Definition: MachO.h:1577
void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align)
Definition: MachO.h:1396
uint32_t name
Definition: MachO.h:597
void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
Definition: MachO.h:1388
uint32_t reloff
Definition: MachO.h:561
S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to lazy loaded dylibs.
Definition: MachO.h:157
const uint32_t ARM_THREAD_STATE_COUNT
Definition: MachO.h:1860
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:125
const uint32_t x86_THREAD_STATE32_COUNT
Definition: MachO.h:1773
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:187
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:181
HeaderFileType
Definition: MachO.h:36
uint32_t n_value
Definition: MachO.h:983
uint16_t length
Definition: MachO.h:793
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition: MachO.h:127
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:184
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
Definition: MachO.h:194
S_ATTR_EXT_RELOC - Section has external relocation entries.
Definition: MachO.h:204
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition: MachO.h:142
PlatformType
Definition: MachO.h:484
uint32_t objc_module_info_addr
Definition: MachO.h:728
ppc_thread_state32_t ts32
Definition: MachO.h:1960
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition: MachO.h:189
union llvm::MachO::ppc_thread_state_t::@131 uts
S_REGULAR - Regular section.
Definition: MachO.h:119
uint32_t flags
Definition: MachO.h:563
S_INTERPOSING - Section with only pairs of function pointers for interposing.
Definition: MachO.h:150
#define rc(i)
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
Definition: MachO.h:202
S_LITERAL_POINTERS - Section with pointers to literals.
Definition: MachO.h:129
x86_fp_control_rc
Definition: MachO.h:1564
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
Definition: MachO.h:147
uint32_t reserved1
Definition: MachO.h:578
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:161
const uint32_t x86_THREAD_STATE64_COUNT
Definition: MachO.h:1776
#define H(x, y, z)
Definition: MD5.cpp:57
uint32_t offset
Definition: MachO.h:792
X86ThreadFlavors
Definition: MachO.h:1740
CPUSubTypeARM64
Definition: MachO.h:1487
uint64_t objc_module_info_addr
Definition: MachO.h:745
RebaseOpcode
Definition: MachO.h:231
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition: MachO.h:159
lazy value info
S_CSTRING_LITERALS - Section with literal C strings.
Definition: MachO.h:123
CPUSubTypeSPARC
Definition: MachO.h:1494
uint16_t kind
Definition: MachO.h:794
x86_exception_state64_t es64
Definition: MachO.h:1731
DataRegionType
Definition: MachO.h:214
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:133
int16_t n_desc
Definition: MachO.h:982
S_DTRACE_DOF - Section contains DTrace Object Format.
Definition: MachO.h:154
x86_fp_control_precis
Definition: MachO.h:1558
const uint32_t x86_FLOAT_STATE64_COUNT
Definition: MachO.h:1778
x86_thread_state64_t ts64
Definition: MachO.h:1716
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:167
ARMThreadFlavors
Definition: MachO.h:1844
const uint32_t x86_THREAD_STATE_COUNT
Definition: MachO.h:1783
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition: MachO.h:170
int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST)
Definition: MachO.h:1465
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:152
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition: MachO.h:1787
uint32_t cputype
Definition: MachO.h:926
S_ATTR_LOC_RELOC - Section has local relocation entries.
Definition: MachO.h:206
struct fvmlib fvmlib
Definition: MachO.h:593
x86_thread_state32_t ts32
Definition: MachO.h:1717
uint16_t n_desc
Definition: MachO.h:990
uint32_t n_strx
Definition: MachO.h:979
CPUSubTypePowerPC
Definition: MachO.h:1496
uint32_t reserved3
Definition: MachO.h:580
#define LLVM_PACKED_START
Definition: Compiler.h:373
uint32_t offset
Definition: MachO.h:928
uint32_t objc_module_info_size
Definition: MachO.h:744
uint32_t n_strx
Definition: MachO.h:987
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:144
uint32_t addr
Definition: MachO.h:557
union llvm::MachO::arm_thread_state_t::@130 uts
uint32_t objc_module_info_size
Definition: MachO.h:729
uint32_t nreloc
Definition: MachO.h:562
RelocationInfoType
Definition: MachO.h:392
unsigned short zdiv
Definition: MachO.h:1572
CPUSubTypeARM64_32
Definition: MachO.h:1492
uint32_t timestamp
Definition: MachO.h:598
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:191
uint32_t offset
Definition: MachO.h:559
const uint32_t ARM_THREAD_STATE64_COUNT
Definition: MachO.h:1863
uint8_t n_type
Definition: MachO.h:980
uint32_t reserved2
Definition: MachO.h:565
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:196
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:121
uint32_t minor_version
Definition: MachO.h:585
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition: MachO.h:139
uint32_t align
Definition: MachO.h:560
SectionType
These are the section type and attributes fields.
Definition: MachO.h:114
uint32_t current_version
Definition: MachO.h:599
uint32_t compatibility_version
Definition: MachO.h:600
uint32_t name
Definition: MachO.h:584
const uint32_t PPC_THREAD_STATE_COUNT
Definition: MachO.h:1985
x86_float_state64_t fs64
Definition: MachO.h:1724
int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST)
Definition: MachO.h:1468
arm_thread_state32_t ts32
Definition: MachO.h:1835
#define LLVM_PACKED_END
Definition: Compiler.h:374
union llvm::MachO::x86_exception_state_t::@129 ues