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  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
uint32_t align
Definition: MachO.h:930
uint64_t CallInst * C
void swapStruct(fat_header &mh)
Definition: MachO.h:991
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:1773
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:986
SectionOrdinal
Definition: MachO.h:311
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:23
int CPU_SUBTYPE_INTEL(int Family, int Model)
Definition: MachO.h:1455
union llvm::MachO::x86_exception_state_t::@131 ues
ExportSymbolKind
Definition: MachO.h:286
uint32_t nfat_arch
Definition: MachO.h:922
Definition: MachO.h:791
uint32_t reserved1
Definition: MachO.h:564
BindSpecialDylib
Definition: MachO.h:249
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:1379
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: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:157
const uint32_t ARM_THREAD_STATE_COUNT
Definition: MachO.h:1848
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:125
const uint32_t x86_THREAD_STATE32_COUNT
Definition: MachO.h:1761
HeaderFileType
Definition: MachO.h:36
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:127
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:1948
union llvm::MachO::x86_thread_state_t::@129 uts
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:196
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_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
Definition: MachO.h:194
S_LITERAL_POINTERS - Section with pointers to literals.
Definition: MachO.h:129
x86_fp_control_rc
Definition: MachO.h:1552
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition: MachO.h:189
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: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
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
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
Definition: MachO.h:202
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:191
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:214
union llvm::MachO::x86_float_state_t::@130 ufs
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:133
int16_t n_desc
Definition: MachO.h:977
S_DTRACE_DOF - Section contains DTrace Object Format.
Definition: MachO.h:154
union llvm::MachO::ppc_thread_state_t::@133 uts
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_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:167
ARMThreadFlavors
Definition: MachO.h:1832
const uint32_t x86_THREAD_STATE_COUNT
Definition: MachO.h:1771
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:1458
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:152
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition: MachO.h:1775
union llvm::MachO::arm_thread_state_t::@132 uts
uint32_t cputype
Definition: MachO.h:926
struct fvmlib fvmlib
Definition: MachO.h:593
x86_thread_state32_t ts32
Definition: MachO.h:1705
uint16_t n_desc
Definition: MachO.h:985
uint32_t n_strx
Definition: MachO.h:974
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:187
CPUSubTypePowerPC
Definition: MachO.h:1484
uint32_t reserved3
Definition: MachO.h:580
#define LLVM_PACKED_START
Definition: Compiler.h:364
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:144
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
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
S_ATTR_EXT_RELOC - Section has external relocation entries.
Definition: MachO.h:204
S_ATTR_LOC_RELOC - Section has local relocation entries.
Definition: MachO.h:206
uint8_t n_type
Definition: MachO.h:975
uint32_t reserved2
Definition: MachO.h:565
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
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:181
uint32_t name
Definition: MachO.h:584
const uint32_t PPC_THREAD_STATE_COUNT
Definition: MachO.h:1973
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:184
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
#define LLVM_PACKED_END
Definition: Compiler.h:365