LLVM  8.0.1
MachO.h
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- C++/-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines manifest constants for the MachO object file format.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_BINARYFORMAT_MACHO_H
15 #define LLVM_BINARYFORMAT_MACHO_H
16 
17 #include "llvm/Support/Compiler.h"
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Host.h"
20 
21 namespace llvm {
22 namespace MachO {
23 // Enums from <mach-o/loader.h>
24 enum : uint32_t {
25  // Constants for the "magic" field in llvm::MachO::mach_header and
26  // llvm::MachO::mach_header_64
27  MH_MAGIC = 0xFEEDFACEu,
28  MH_CIGAM = 0xCEFAEDFEu,
29  MH_MAGIC_64 = 0xFEEDFACFu,
30  MH_CIGAM_64 = 0xCFFAEDFEu,
31  FAT_MAGIC = 0xCAFEBABEu,
32  FAT_CIGAM = 0xBEBAFECAu,
33  FAT_MAGIC_64 = 0xCAFEBABFu,
34  FAT_CIGAM_64 = 0xBFBAFECAu
35 };
36 
38  // Constants for the "filetype" field in llvm::MachO::mach_header and
39  // llvm::MachO::mach_header_64
40  MH_OBJECT = 0x1u,
41  MH_EXECUTE = 0x2u,
42  MH_FVMLIB = 0x3u,
43  MH_CORE = 0x4u,
44  MH_PRELOAD = 0x5u,
45  MH_DYLIB = 0x6u,
46  MH_DYLINKER = 0x7u,
47  MH_BUNDLE = 0x8u,
48  MH_DYLIB_STUB = 0x9u,
49  MH_DSYM = 0xAu,
51 };
52 
53 enum {
54  // Constant bits for the "flags" field in llvm::MachO::mach_header and
55  // llvm::MachO::mach_header_64
56  MH_NOUNDEFS = 0x00000001u,
57  MH_INCRLINK = 0x00000002u,
58  MH_DYLDLINK = 0x00000004u,
59  MH_BINDATLOAD = 0x00000008u,
60  MH_PREBOUND = 0x00000010u,
61  MH_SPLIT_SEGS = 0x00000020u,
62  MH_LAZY_INIT = 0x00000040u,
63  MH_TWOLEVEL = 0x00000080u,
64  MH_FORCE_FLAT = 0x00000100u,
65  MH_NOMULTIDEFS = 0x00000200u,
66  MH_NOFIXPREBINDING = 0x00000400u,
67  MH_PREBINDABLE = 0x00000800u,
68  MH_ALLMODSBOUND = 0x00001000u,
70  MH_CANONICAL = 0x00004000u,
71  MH_WEAK_DEFINES = 0x00008000u,
72  MH_BINDS_TO_WEAK = 0x00010000u,
73  MH_ALLOW_STACK_EXECUTION = 0x00020000u,
74  MH_ROOT_SAFE = 0x00040000u,
75  MH_SETUID_SAFE = 0x00080000u,
76  MH_NO_REEXPORTED_DYLIBS = 0x00100000u,
77  MH_PIE = 0x00200000u,
78  MH_DEAD_STRIPPABLE_DYLIB = 0x00400000u,
79  MH_HAS_TLV_DESCRIPTORS = 0x00800000u,
80  MH_NO_HEAP_EXECUTION = 0x01000000u,
81  MH_APP_EXTENSION_SAFE = 0x02000000u,
83 };
84 
85 enum : uint32_t {
86  // Flags for the "cmd" field in llvm::MachO::load_command
87  LC_REQ_DYLD = 0x80000000u
88 };
89 
90 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) LCName = LCValue,
91 
93 #include "llvm/BinaryFormat/MachO.def"
94 };
95 
96 #undef HANDLE_LOAD_COMMAND
97 
98 enum : uint32_t {
99  // Constant bits for the "flags" field in llvm::MachO::segment_command
100  SG_HIGHVM = 0x1u,
101  SG_FVMLIB = 0x2u,
102  SG_NORELOC = 0x4u,
104 
105  // Constant masks for the "flags" field in llvm::MachO::section and
106  // llvm::MachO::section_64
107  SECTION_TYPE = 0x000000ffu, // SECTION_TYPE
108  SECTION_ATTRIBUTES = 0xffffff00u, // SECTION_ATTRIBUTES
109  SECTION_ATTRIBUTES_USR = 0xff000000u, // SECTION_ATTRIBUTES_USR
110  SECTION_ATTRIBUTES_SYS = 0x00ffff00u // SECTION_ATTRIBUTES_SYS
111 };
112 
113 /// These are the section type and attributes fields. A MachO section can
114 /// have only one Type, but can have any of the attributes specified.
116  // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
117  // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
118 
119  /// S_REGULAR - Regular section.
120  S_REGULAR = 0x00u,
121  /// S_ZEROFILL - Zero fill on demand section.
122  S_ZEROFILL = 0x01u,
123  /// S_CSTRING_LITERALS - Section with literal C strings.
125  /// S_4BYTE_LITERALS - Section with 4 byte literals.
127  /// S_8BYTE_LITERALS - Section with 8 byte literals.
129  /// S_LITERAL_POINTERS - Section with pointers to literals.
131  /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
133  /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
135  /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
136  /// the Reserved2 field.
137  S_SYMBOL_STUBS = 0x08u,
138  /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
139  /// initialization.
141  /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
142  /// termination.
144  /// S_COALESCED - Section contains symbols that are to be coalesced.
145  S_COALESCED = 0x0bu,
146  /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
147  /// gigabytes).
148  S_GB_ZEROFILL = 0x0cu,
149  /// S_INTERPOSING - Section with only pairs of function pointers for
150  /// interposing.
151  S_INTERPOSING = 0x0du,
152  /// S_16BYTE_LITERALS - Section with only 16 byte literals.
154  /// S_DTRACE_DOF - Section contains DTrace Object Format.
155  S_DTRACE_DOF = 0x0fu,
156  /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
157  /// lazy loaded dylibs.
159  /// S_THREAD_LOCAL_REGULAR - Thread local data section.
161  /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
163  /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
164  /// structure data.
166  /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
167  /// local structures.
169  /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
170  /// variable initialization pointers to functions.
172 
174 };
175 
176 enum : uint32_t {
177  // Constant masks for the "flags[31:24]" field in llvm::MachO::section and
178  // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR)
179 
180  /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
181  /// instructions.
183  /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
184  /// in a ranlib table of contents.
185  S_ATTR_NO_TOC = 0x40000000u,
186  /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
187  /// in files with the MY_DYLDLINK flag.
189  /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
190  S_ATTR_NO_DEAD_STRIP = 0x10000000u,
191  /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
192  S_ATTR_LIVE_SUPPORT = 0x08000000u,
193  /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
194  /// dyld.
196  /// S_ATTR_DEBUG - A debug section.
197  S_ATTR_DEBUG = 0x02000000u,
198 
199  // Constant masks for the "flags[23:8]" field in llvm::MachO::section and
200  // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS)
201 
202  /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
204  /// S_ATTR_EXT_RELOC - Section has external relocation entries.
205  S_ATTR_EXT_RELOC = 0x00000200u,
206  /// S_ATTR_LOC_RELOC - Section has local relocation entries.
207  S_ATTR_LOC_RELOC = 0x00000100u,
208 
209  // Constant masks for the value of an indirect symbol in an indirect
210  // symbol table
211  INDIRECT_SYMBOL_LOCAL = 0x80000000u,
212  INDIRECT_SYMBOL_ABS = 0x40000000u
213 };
214 
216  // Constants for the "kind" field in a data_in_code_entry structure
222 };
223 
228 };
229 
230 enum { REBASE_OPCODE_MASK = 0xF0u, REBASE_IMMEDIATE_MASK = 0x0Fu };
231 
242 };
243 
244 enum BindType {
248 };
249 
254 };
255 
256 enum {
259 
262 };
263 
278 };
279 
280 enum {
285 };
286 
291 };
292 
293 enum {
294  // Constant masks for the "n_type" field in llvm::MachO::nlist and
295  // llvm::MachO::nlist_64
296  N_STAB = 0xe0,
297  N_PEXT = 0x10,
298  N_TYPE = 0x0e,
299  N_EXT = 0x01
300 };
301 
302 enum NListType : uint8_t {
303  // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
304  // llvm::MachO::nlist_64
305  N_UNDF = 0x0u,
306  N_ABS = 0x2u,
307  N_SECT = 0xeu,
308  N_PBUD = 0xcu,
309  N_INDR = 0xau
310 };
311 
313  // Constants for the "n_sect" field in llvm::MachO::nlist and
314  // llvm::MachO::nlist_64
315  NO_SECT = 0u,
316  MAX_SECT = 0xffu
317 };
318 
319 enum {
320  // Constant masks for the "n_desc" field in llvm::MachO::nlist and
321  // llvm::MachO::nlist_64
322  // The low 3 bits are the for the REFERENCE_TYPE.
330  // Flag bits (some overlap with the library ordinal bits).
331  N_ARM_THUMB_DEF = 0x0008u,
333  N_NO_DEAD_STRIP = 0x0020u,
334  N_WEAK_REF = 0x0040u,
335  N_WEAK_DEF = 0x0080u,
336  N_SYMBOL_RESOLVER = 0x0100u,
337  N_ALT_ENTRY = 0x0200u,
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  uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1,
946  r_type : 4;
947 };
948 
950 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
951  uint32_t r_scattered : 1, r_pcrel : 1, r_length : 2, r_type : 4,
952  r_address : 24;
953 #else
954  uint32_t r_address : 24, r_type : 4, r_length : 2, r_pcrel : 1,
955  r_scattered : 1;
956 #endif
957  int32_t r_value;
958 };
959 
960 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
962  uint32_t r_word0, r_word1;
963 };
964 
965 // Structs from <mach-o/nlist.h>
966 struct nlist_base {
968  uint8_t n_type;
969  uint8_t n_sect;
970  uint16_t n_desc;
971 };
972 
973 struct nlist {
975  uint8_t n_type;
976  uint8_t n_sect;
977  int16_t n_desc;
979 };
980 
981 struct nlist_64 {
983  uint8_t n_type;
984  uint8_t n_sect;
985  uint16_t n_desc;
986  uint64_t n_value;
987 };
988 
989 // Byte order swapping functions for MachO structs
990 
991 inline void swapStruct(fat_header &mh) {
994 }
995 
996 inline void swapStruct(fat_arch &mh) {
1002 }
1003 
1004 inline void swapStruct(fat_arch_64 &mh) {
1011 }
1012 
1013 inline void swapStruct(mach_header &mh) {
1021 }
1022 
1023 inline void swapStruct(mach_header_64 &H) {
1032 }
1033 
1034 inline void swapStruct(load_command &lc) {
1035  sys::swapByteOrder(lc.cmd);
1037 }
1038 
1039 inline void swapStruct(symtab_command &lc) {
1040  sys::swapByteOrder(lc.cmd);
1046 }
1047 
1048 inline void swapStruct(segment_command_64 &seg) {
1049  sys::swapByteOrder(seg.cmd);
1059 }
1060 
1061 inline void swapStruct(segment_command &seg) {
1062  sys::swapByteOrder(seg.cmd);
1072 }
1073 
1074 inline void swapStruct(section_64 &sect) {
1075  sys::swapByteOrder(sect.addr);
1076  sys::swapByteOrder(sect.size);
1077  sys::swapByteOrder(sect.offset);
1078  sys::swapByteOrder(sect.align);
1079  sys::swapByteOrder(sect.reloff);
1080  sys::swapByteOrder(sect.nreloc);
1081  sys::swapByteOrder(sect.flags);
1084 }
1085 
1086 inline void swapStruct(section &sect) {
1087  sys::swapByteOrder(sect.addr);
1088  sys::swapByteOrder(sect.size);
1089  sys::swapByteOrder(sect.offset);
1090  sys::swapByteOrder(sect.align);
1091  sys::swapByteOrder(sect.reloff);
1092  sys::swapByteOrder(sect.nreloc);
1093  sys::swapByteOrder(sect.flags);
1096 }
1097 
1099  sys::swapByteOrder(info.cmd);
1111 }
1112 
1113 inline void swapStruct(dylib_command &d) {
1120 }
1121 
1126 }
1127 
1132 }
1133 
1138 }
1139 
1144 }
1145 
1146 inline void swapStruct(routines_command &r) {
1157 }
1158 
1170 }
1171 
1172 inline void swapStruct(thread_command &t) {
1175 }
1176 
1177 inline void swapStruct(dylinker_command &d) {
1181 }
1182 
1183 inline void swapStruct(uuid_command &u) {
1186 }
1187 
1188 inline void swapStruct(rpath_command &r) {
1192 }
1193 
1198 }
1199 
1205 }
1206 
1213 }
1214 
1222 }
1223 
1224 inline void swapStruct(dysymtab_command &dst) {
1225  sys::swapByteOrder(dst.cmd);
1234  sys::swapByteOrder(dst.ntoc);
1245 }
1246 
1247 inline void swapStruct(any_relocation_info &reloc) {
1248  sys::swapByteOrder(reloc.r_word0);
1249  sys::swapByteOrder(reloc.r_word1);
1250 }
1251 
1252 inline void swapStruct(nlist_base &S) {
1255 }
1256 
1257 inline void swapStruct(nlist &sym) {
1261 }
1262 
1263 inline void swapStruct(nlist_64 &sym) {
1267 }
1268 
1274 }
1275 
1280 }
1281 
1287 }
1288 
1289 inline void swapStruct(note_command &C) {
1294 }
1295 
1303 }
1304 
1308 }
1309 
1314 }
1315 
1317 
1318 // The prebind_cksum_command is obsolete and no longer supported.
1323 }
1324 
1325 // The twolevel_hints_command is obsolete and no longer supported.
1331 }
1332 
1333 // The prebound_dylib_command is obsolete and no longer supported.
1340 }
1341 
1342 // The fvmfile_command is obsolete and no longer supported.
1348 }
1349 
1350 // The symseg_command is obsolete and no longer supported.
1351 inline void swapStruct(symseg_command &C) {
1356 }
1357 
1358 // The ident_command is obsolete and no longer supported.
1359 inline void swapStruct(ident_command &C) {
1362 }
1363 
1364 inline void swapStruct(fvmlib &C) {
1368 }
1369 
1370 // The fvmlib_command is obsolete and no longer supported.
1371 inline void swapStruct(fvmlib_command &C) {
1374  swapStruct(C.fvmlib);
1375 }
1376 
1377 // Get/Set functions from <mach-o/nlist.h>
1378 
1379 inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1380  return (((n_desc) >> 8u) & 0xffu);
1381 }
1382 
1383 inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1384  n_desc = (((n_desc)&0x00ff) | (((ordinal)&0xff) << 8));
1385 }
1386 
1387 inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) {
1388  return (n_desc >> 8u) & 0x0fu;
1389 }
1390 
1391 inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) {
1392  n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1393 }
1394 
1395 // Enums from <mach/machine.h>
1396 enum : uint32_t {
1397  // Capability bits used in the definition of cpu_type.
1398  CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1399  CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI
1400 };
1401 
1402 // Constants for the cputype field.
1403 enum CPUType {
1408  /* CPU_TYPE_MIPS = 8, */
1409  CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1415 };
1416 
1417 enum : uint32_t {
1418  // Capability bits used in the definition of cpusubtype.
1419  CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1420  CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1421 
1422  // Special CPU subtype constants.
1424 };
1425 
1426 // Constants for the cpusubtype field.
1449 
1454 };
1455 inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1456  return Family | (Model << 4);
1457 }
1459  return ((int)ST) & 0x0f;
1460 }
1461 inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) { return ((int)ST) >> 4; }
1463 
1472  // unused ARM_V7F = 10,
1478 };
1479 
1481 
1483 
1498 
1501 };
1502 
1520 };
1521 
1523  uint64_t rax;
1524  uint64_t rbx;
1525  uint64_t rcx;
1526  uint64_t rdx;
1527  uint64_t rdi;
1528  uint64_t rsi;
1529  uint64_t rbp;
1530  uint64_t rsp;
1531  uint64_t r8;
1532  uint64_t r9;
1533  uint64_t r10;
1534  uint64_t r11;
1535  uint64_t r12;
1536  uint64_t r13;
1537  uint64_t r14;
1538  uint64_t r15;
1539  uint64_t rip;
1540  uint64_t rflags;
1541  uint64_t cs;
1542  uint64_t fs;
1543  uint64_t gs;
1544 };
1545 
1550 };
1551 
1557 };
1558 
1560  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1561  precis : 1, : 2, pc : 2, rc : 2, : 1, : 3;
1562 };
1563 
1564 struct fp_status_t {
1565  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1566  precis : 1, stkflt : 1, errsumm : 1, c0 : 1, c1 : 1, c2 : 1, tos : 3,
1567  c3 : 1, busy : 1;
1568 };
1569 
1570 struct mmst_reg_t {
1571  char mmst_reg[10];
1572  char mmst_rsrv[6];
1573 };
1574 
1575 struct xmm_reg_t {
1576  char xmm_reg[16];
1577 };
1578 
1580  int32_t fpu_reserved[2];
1583  uint8_t fpu_ftw;
1584  uint8_t fpu_rsrv1;
1585  uint16_t fpu_fop;
1587  uint16_t fpu_cs;
1588  uint16_t fpu_rsrv2;
1590  uint16_t fpu_ds;
1591  uint16_t fpu_rsrv3;
1618  char fpu_rsrv4[6 * 16];
1620 };
1621 
1623  uint16_t trapno;
1624  uint16_t cpu;
1626  uint64_t faultvaddr;
1627 };
1628 
1646 }
1647 
1670 }
1671 
1675  // TODO swap: fp_control_t fpu_fcw;
1676  // TODO swap: fp_status_t fpu_fsw;
1687 }
1688 
1694 }
1695 
1699 };
1700 
1703  union {
1706  } uts;
1707 };
1708 
1711  union {
1713  } ufs;
1714 };
1715 
1718  union {
1720  } ues;
1721 };
1722 
1723 inline void swapStruct(x86_state_hdr_t &x) {
1726 }
1727 
1741 };
1742 
1744  swapStruct(x.tsh);
1745  if (x.tsh.flavor == x86_THREAD_STATE64)
1746  swapStruct(x.uts.ts64);
1747 }
1748 
1750  swapStruct(x.fsh);
1751  if (x.fsh.flavor == x86_FLOAT_STATE64)
1752  swapStruct(x.ufs.fs64);
1753 }
1754 
1756  swapStruct(x.esh);
1757  if (x.esh.flavor == x86_EXCEPTION_STATE64)
1758  swapStruct(x.ues.es64);
1759 }
1760 
1762  sizeof(x86_thread_state32_t) / sizeof(uint32_t);
1763 
1765  sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1767  sizeof(x86_float_state64_t) / sizeof(uint32_t);
1769  sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1770 
1772  sizeof(x86_thread_state_t) / sizeof(uint32_t);
1774  sizeof(x86_float_state_t) / sizeof(uint32_t);
1776  sizeof(x86_exception_state_t) / sizeof(uint32_t);
1777 
1779  uint32_t r[13];
1784 };
1785 
1787  for (int i = 0; i < 13; i++)
1788  sys::swapByteOrder(x.r[i]);
1793 }
1794 
1796  uint64_t x[29];
1797  uint64_t fp;
1798  uint64_t lr;
1799  uint64_t sp;
1800  uint64_t pc;
1803 };
1804 
1806  for (int i = 0; i < 29; i++)
1807  sys::swapByteOrder(x.x[i]);
1813 }
1814 
1818 };
1819 
1822  union {
1824  } uts;
1825 };
1826 
1827 inline void swapStruct(arm_state_hdr_t &x) {
1830 }
1831 
1840 };
1841 
1843  swapStruct(x.tsh);
1844  if (x.tsh.flavor == ARM_THREAD_STATE)
1845  swapStruct(x.uts.ts32);
1846 }
1847 
1849  sizeof(arm_thread_state32_t) / sizeof(uint32_t);
1850 
1852  sizeof(arm_thread_state64_t) / sizeof(uint32_t);
1853 
1895 };
1896 
1938 }
1939 
1943 };
1944 
1947  union {
1949  } uts;
1950 };
1951 
1952 inline void swapStruct(ppc_state_hdr_t &x) {
1955 }
1956 
1965 };
1966 
1968  swapStruct(x.tsh);
1969  if (x.tsh.flavor == PPC_THREAD_STATE)
1970  swapStruct(x.uts.ts32);
1971 }
1972 
1974  sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
1975 
1976 // Define a union of all load command structs
1977 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1978 
1980 union alignas(4) macho_load_command {
1981 #include "llvm/BinaryFormat/MachO.def"
1982 };
1984 
1985 } // end namespace MachO
1986 } // end namespace llvm
1987 
1988 #endif
#define LLVM_PACKED_END
Definition: Compiler.h:366
uint32_t align
Definition: MachO.h:930
uint64_t CallInst * C
union llvm::MachO::arm_thread_state_t::@128 uts
void swapStruct(fat_header &mh)
Definition: MachO.h:991
LoadCommandType
Definition: MachO.h:92
uint32_t header_addr
Definition: MachO.h:586
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
Definition: MachO.h:132
const uint32_t x86_FLOAT_STATE_COUNT
Definition: MachO.h:1773
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
Definition: MachO.h:137
struct dylib dylib
Definition: MachO.h:606
uint64_t n_value
Definition: MachO.h:986
SectionOrdinal
Definition: MachO.h:312
void swapByteOrder(T &Value)
const uint32_t x86_EXCEPTION_STATE64_COUNT
Definition: MachO.h:1768
uint8_t n_sect
Definition: MachO.h:976
This class represents lattice values for constants.
Definition: AllocatorList.h:24
int CPU_SUBTYPE_INTEL(int Family, int Model)
Definition: MachO.h:1455
union llvm::MachO::x86_exception_state_t::@127 ues
#define LLVM_PACKED_START
Definition: Compiler.h:365
ExportSymbolKind
Definition: MachO.h:287
uint32_t nfat_arch
Definition: MachO.h:922
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
Definition: MachO.h:195
Definition: MachO.h:791
uint32_t reserved1
Definition: MachO.h:564
BindSpecialDylib
Definition: MachO.h:250
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
Definition: MachO.h:165
uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
Definition: MachO.h:1379
uint32_t reserved2
Definition: MachO.h:579
uint32_t size
Definition: MachO.h:558
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition: MachO.h:190
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
Definition: MachO.h:1387
PPCThreadFlavors
Definition: MachO.h:1957
uint32_t cpusubtype
Definition: MachO.h:927
unsigned short zdiv
Definition: MachO.h:1565
void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align)
Definition: MachO.h:1391
uint32_t name
Definition: MachO.h:597
void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
Definition: MachO.h:1383
uint32_t reloff
Definition: MachO.h:561
S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to lazy loaded dylibs.
Definition: MachO.h:158
const uint32_t ARM_THREAD_STATE_COUNT
Definition: MachO.h:1848
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:126
const uint32_t x86_THREAD_STATE32_COUNT
Definition: MachO.h:1761
HeaderFileType
Definition: MachO.h:37
uint32_t n_value
Definition: MachO.h:978
uint16_t length
Definition: MachO.h:793
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition: MachO.h:128
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
Definition: MachO.h:143
PlatformType
Definition: MachO.h:484
uint32_t objc_module_info_addr
Definition: MachO.h:728
union llvm::MachO::x86_float_state_t::@126 ufs
ppc_thread_state32_t ts32
Definition: MachO.h:1948
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:182
S_ATTR_EXT_RELOC - Section has external relocation entries.
Definition: MachO.h:205
S_REGULAR - Regular section.
Definition: MachO.h:120
uint32_t flags
Definition: MachO.h:563
S_INTERPOSING - Section with only pairs of function pointers for interposing.
Definition: MachO.h:151
#define rc(i)
S_LITERAL_POINTERS - Section with pointers to literals.
Definition: MachO.h:130
x86_fp_control_rc
Definition: MachO.h:1552
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
Definition: MachO.h:148
uint32_t reserved1
Definition: MachO.h:578
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:162
const uint32_t x86_THREAD_STATE64_COUNT
Definition: MachO.h:1764
#define H(x, y, z)
Definition: MD5.cpp:57
uint32_t offset
Definition: MachO.h:792
X86ThreadFlavors
Definition: MachO.h:1728
CPUSubTypeARM64
Definition: MachO.h:1480
uint64_t objc_module_info_addr
Definition: MachO.h:745
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:192
RebaseOpcode
Definition: MachO.h:232
S_THREAD_LOCAL_REGULAR - Thread local data section.
Definition: MachO.h:160
lazy value info
S_CSTRING_LITERALS - Section with literal C strings.
Definition: MachO.h:124
CPUSubTypeSPARC
Definition: MachO.h:1482
uint16_t kind
Definition: MachO.h:794
x86_exception_state64_t es64
Definition: MachO.h:1719
DataRegionType
Definition: MachO.h:215
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:134
int16_t n_desc
Definition: MachO.h:977
S_DTRACE_DOF - Section contains DTrace Object Format.
Definition: MachO.h:155
x86_fp_control_precis
Definition: MachO.h:1546
const uint32_t x86_FLOAT_STATE64_COUNT
Definition: MachO.h:1766
x86_thread_state64_t ts64
Definition: MachO.h:1704
S_ATTR_LOC_RELOC - Section has local relocation entries.
Definition: MachO.h:207
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:168
ARMThreadFlavors
Definition: MachO.h:1832
const uint32_t x86_THREAD_STATE_COUNT
Definition: MachO.h:1771
union llvm::MachO::ppc_thread_state_t::@129 uts
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition: MachO.h:171
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:185
int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST)
Definition: MachO.h:1458
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:153
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition: MachO.h:1775
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
Definition: MachO.h:203
uint32_t cputype
Definition: MachO.h:926
struct fvmlib fvmlib
Definition: MachO.h:593
x86_thread_state32_t ts32
Definition: MachO.h:1705
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:197
uint16_t n_desc
Definition: MachO.h:985
uint32_t n_strx
Definition: MachO.h:974
CPUSubTypePowerPC
Definition: MachO.h:1484
uint32_t reserved3
Definition: MachO.h:580
uint32_t offset
Definition: MachO.h:928
uint32_t objc_module_info_size
Definition: MachO.h:744
uint32_t n_strx
Definition: MachO.h:982
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:145
uint32_t addr
Definition: MachO.h:557
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:1560
union llvm::MachO::x86_thread_state_t::@125 uts
uint32_t timestamp
Definition: MachO.h:598
uint32_t offset
Definition: MachO.h:559
const uint32_t ARM_THREAD_STATE64_COUNT
Definition: MachO.h:1851
uint8_t n_type
Definition: MachO.h:975
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:188
uint32_t reserved2
Definition: MachO.h:565
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:122
uint32_t minor_version
Definition: MachO.h:585
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition: MachO.h:140
uint32_t align
Definition: MachO.h:560
SectionType
These are the section type and attributes fields.
Definition: MachO.h:115
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:1973
x86_float_state64_t fs64
Definition: MachO.h:1712
int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST)
Definition: MachO.h:1461
arm_thread_state32_t ts32
Definition: MachO.h:1823