LLVM  10.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.
494 };
495 
496 // Values for tools enum in build_tool_version.
497 enum { TOOL_CLANG = 1, TOOL_SWIFT = 2, TOOL_LD = 3 };
498 
499 // Structs from <mach-o/loader.h>
500 
501 struct mach_header {
509 };
510 
520 };
521 
522 struct load_command {
525 };
526 
530  char segname[16];
539 };
540 
544  char segname[16];
545  uint64_t vmaddr;
546  uint64_t vmsize;
547  uint64_t fileoff;
548  uint64_t filesize;
553 };
554 
555 struct section {
556  char sectname[16];
557  char segname[16];
567 };
568 
569 struct section_64 {
570  char sectname[16];
571  char segname[16];
572  uint64_t addr;
573  uint64_t size;
582 };
583 
584 inline bool isVirtualSection(uint8_t type) {
585  return (type == MachO::S_ZEROFILL || type == MachO::S_GB_ZEROFILL ||
587 }
588 
589 struct fvmlib {
593 };
594 
595 // The fvmlib_command is obsolete and no longer supported.
599  struct fvmlib fvmlib;
600 };
601 
602 struct dylib {
607 };
608 
612  struct dylib dylib;
613 };
614 
619 };
620 
625 };
626 
631 };
632 
637 };
638 
639 // The prebound_dylib_command is obsolete and no longer supported.
646 };
647 
652 };
653 
657 };
658 
670 };
671 
675  uint64_t init_address;
676  uint64_t init_module;
677  uint64_t reserved1;
678  uint64_t reserved2;
679  uint64_t reserved3;
680  uint64_t reserved4;
681  uint64_t reserved5;
682  uint64_t reserved6;
683 };
684 
692 };
693 
715 };
716 
720 };
721 
722 struct dylib_module {
736 };
737 
752 };
753 
755  uint32_t isym : 24, flags : 8;
756 };
757 
758 // The twolevel_hints_command is obsolete and no longer supported.
764 };
765 
766 // The twolevel_hints_command is obsolete and no longer supported.
768  uint32_t isub_image : 8, itoc : 24;
769 };
770 
771 // The prebind_cksum_command is obsolete and no longer supported.
776 };
777 
778 struct uuid_command {
781  uint8_t uuid[16];
782 };
783 
788 };
789 
795 };
796 
799  uint16_t length;
800  uint16_t kind;
801 };
802 
806  uint64_t version;
807 };
808 
815 };
816 
824 };
825 
827  uint32_t cmd; // LC_VERSION_MIN_MACOSX or
828  // LC_VERSION_MIN_IPHONEOS
829  uint32_t cmdsize; // sizeof(struct version_min_command)
830  uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
831  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
832 };
833 
834 struct note_command {
835  uint32_t cmd; // LC_NOTE
836  uint32_t cmdsize; // sizeof(struct note_command)
837  char data_owner[16]; // owner name for this LC_NOTE
838  uint64_t offset; // file offset of this data
839  uint64_t size; // length of data region
840 };
841 
843  uint32_t tool; // enum for the tool
844  uint32_t version; // version of the tool
845 };
846 
848  uint32_t cmd; // LC_BUILD_VERSION
849  uint32_t cmdsize; // sizeof(struct build_version_command) +
850  // ntools * sizeof(struct build_tool_version)
851  uint32_t platform; // platform
852  uint32_t minos; // X.Y.Z is encoded in nibbles xxxx.yy.zz
853  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
854  uint32_t ntools; // number of tool entries following this
855 };
856 
870 };
871 
876 };
877 
878 // The symseg_command is obsolete and no longer supported.
884 };
885 
886 // The ident_command is obsolete and no longer supported.
890 };
891 
892 // The fvmfile_command is obsolete and no longer supported.
898 };
899 
904 };
905 
907  uint64_t thunk;
908  uint64_t key;
909  uint64_t offset;
910 };
911 
913  uintptr_t thunk;
914  uintptr_t key;
915  uintptr_t offset;
916 };
917 
921  uint64_t entryoff;
922  uint64_t stacksize;
923 };
924 
925 // Structs from <mach-o/fat.h>
926 struct fat_header {
929 };
930 
931 struct fat_arch {
937 };
938 
939 struct fat_arch_64 {
942  uint64_t offset;
943  uint64_t size;
946 };
947 
948 // Structs from <mach-o/reloc.h>
950  int32_t r_address;
951 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
952  uint32_t r_type : 4, r_extern : 1, r_length : 2, r_pcrel : 1,
953  r_symbolnum : 24;
954 #else
955  uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1,
956  r_type : 4;
957 #endif
958 };
959 
961 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
962  uint32_t r_scattered : 1, r_pcrel : 1, r_length : 2, r_type : 4,
963  r_address : 24;
964 #else
965  uint32_t r_address : 24, r_type : 4, r_length : 2, r_pcrel : 1,
966  r_scattered : 1;
967 #endif
968  int32_t r_value;
969 };
970 
971 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
973  uint32_t r_word0, r_word1;
974 };
975 
976 // Structs from <mach-o/nlist.h>
977 struct nlist_base {
979  uint8_t n_type;
980  uint8_t n_sect;
981  uint16_t n_desc;
982 };
983 
984 struct nlist {
986  uint8_t n_type;
987  uint8_t n_sect;
988  int16_t n_desc;
990 };
991 
992 struct nlist_64 {
994  uint8_t n_type;
995  uint8_t n_sect;
996  uint16_t n_desc;
997  uint64_t n_value;
998 };
999 
1000 // Byte order swapping functions for MachO structs
1001 
1002 inline void swapStruct(fat_header &mh) {
1005 }
1006 
1007 inline void swapStruct(fat_arch &mh) {
1013 }
1014 
1015 inline void swapStruct(fat_arch_64 &mh) {
1022 }
1023 
1024 inline void swapStruct(mach_header &mh) {
1032 }
1033 
1034 inline void swapStruct(mach_header_64 &H) {
1043 }
1044 
1045 inline void swapStruct(load_command &lc) {
1046  sys::swapByteOrder(lc.cmd);
1048 }
1049 
1050 inline void swapStruct(symtab_command &lc) {
1051  sys::swapByteOrder(lc.cmd);
1057 }
1058 
1059 inline void swapStruct(segment_command_64 &seg) {
1060  sys::swapByteOrder(seg.cmd);
1070 }
1071 
1072 inline void swapStruct(segment_command &seg) {
1073  sys::swapByteOrder(seg.cmd);
1083 }
1084 
1085 inline void swapStruct(section_64 &sect) {
1086  sys::swapByteOrder(sect.addr);
1087  sys::swapByteOrder(sect.size);
1088  sys::swapByteOrder(sect.offset);
1089  sys::swapByteOrder(sect.align);
1090  sys::swapByteOrder(sect.reloff);
1091  sys::swapByteOrder(sect.nreloc);
1092  sys::swapByteOrder(sect.flags);
1095 }
1096 
1097 inline void swapStruct(section &sect) {
1098  sys::swapByteOrder(sect.addr);
1099  sys::swapByteOrder(sect.size);
1100  sys::swapByteOrder(sect.offset);
1101  sys::swapByteOrder(sect.align);
1102  sys::swapByteOrder(sect.reloff);
1103  sys::swapByteOrder(sect.nreloc);
1104  sys::swapByteOrder(sect.flags);
1107 }
1108 
1110  sys::swapByteOrder(info.cmd);
1122 }
1123 
1124 inline void swapStruct(dylib_command &d) {
1131 }
1132 
1137 }
1138 
1143 }
1144 
1149 }
1150 
1155 }
1156 
1157 inline void swapStruct(routines_command &r) {
1168 }
1169 
1181 }
1182 
1183 inline void swapStruct(thread_command &t) {
1186 }
1187 
1188 inline void swapStruct(dylinker_command &d) {
1192 }
1193 
1194 inline void swapStruct(uuid_command &u) {
1197 }
1198 
1199 inline void swapStruct(rpath_command &r) {
1203 }
1204 
1209 }
1210 
1216 }
1217 
1224 }
1225 
1233 }
1234 
1235 inline void swapStruct(dysymtab_command &dst) {
1236  sys::swapByteOrder(dst.cmd);
1245  sys::swapByteOrder(dst.ntoc);
1256 }
1257 
1258 inline void swapStruct(any_relocation_info &reloc) {
1259  sys::swapByteOrder(reloc.r_word0);
1260  sys::swapByteOrder(reloc.r_word1);
1261 }
1262 
1263 inline void swapStruct(nlist_base &S) {
1266 }
1267 
1268 inline void swapStruct(nlist &sym) {
1272 }
1273 
1274 inline void swapStruct(nlist_64 &sym) {
1278 }
1279 
1285 }
1286 
1291 }
1292 
1298 }
1299 
1300 inline void swapStruct(note_command &C) {
1305 }
1306 
1314 }
1315 
1319 }
1320 
1325 }
1326 
1328 
1329 // The prebind_cksum_command is obsolete and no longer supported.
1334 }
1335 
1336 // The twolevel_hints_command is obsolete and no longer supported.
1342 }
1343 
1344 // The prebound_dylib_command is obsolete and no longer supported.
1351 }
1352 
1353 // The fvmfile_command is obsolete and no longer supported.
1359 }
1360 
1361 // The symseg_command is obsolete and no longer supported.
1362 inline void swapStruct(symseg_command &C) {
1367 }
1368 
1369 // The ident_command is obsolete and no longer supported.
1370 inline void swapStruct(ident_command &C) {
1373 }
1374 
1375 inline void swapStruct(fvmlib &C) {
1379 }
1380 
1381 // The fvmlib_command is obsolete and no longer supported.
1382 inline void swapStruct(fvmlib_command &C) {
1385  swapStruct(C.fvmlib);
1386 }
1387 
1388 // Get/Set functions from <mach-o/nlist.h>
1389 
1390 inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1391  return (((n_desc) >> 8u) & 0xffu);
1392 }
1393 
1394 inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1395  n_desc = (((n_desc)&0x00ff) | (((ordinal)&0xff) << 8));
1396 }
1397 
1398 inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) {
1399  return (n_desc >> 8u) & 0x0fu;
1400 }
1401 
1402 inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) {
1403  n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1404 }
1405 
1406 // Enums from <mach/machine.h>
1407 enum : uint32_t {
1408  // Capability bits used in the definition of cpu_type.
1409  CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1410  CPU_ARCH_ABI64 = 0x01000000, // 64 bit ABI
1411  CPU_ARCH_ABI64_32 = 0x02000000, // ILP32 ABI on 64-bit hardware
1412 };
1413 
1414 // Constants for the cputype field.
1415 enum CPUType {
1420  /* CPU_TYPE_MIPS = 8, */
1421  CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1428 };
1429 
1430 enum : uint32_t {
1431  // Capability bits used in the definition of cpusubtype.
1432  CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1433  CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1434 
1435  // Special CPU subtype constants.
1437 };
1438 
1439 // Constants for the cpusubtype field.
1462 
1467 };
1468 inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1469  return Family | (Model << 4);
1470 }
1472  return ((int)ST) & 0x0f;
1473 }
1474 inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) { return ((int)ST) >> 4; }
1476 
1485  // unused ARM_V7F = 10,
1491 };
1492 
1496 };
1497 
1499 
1501 
1516 
1519 };
1520 
1538 };
1539 
1541  uint64_t rax;
1542  uint64_t rbx;
1543  uint64_t rcx;
1544  uint64_t rdx;
1545  uint64_t rdi;
1546  uint64_t rsi;
1547  uint64_t rbp;
1548  uint64_t rsp;
1549  uint64_t r8;
1550  uint64_t r9;
1551  uint64_t r10;
1552  uint64_t r11;
1553  uint64_t r12;
1554  uint64_t r13;
1555  uint64_t r14;
1556  uint64_t r15;
1557  uint64_t rip;
1558  uint64_t rflags;
1559  uint64_t cs;
1560  uint64_t fs;
1561  uint64_t gs;
1562 };
1563 
1568 };
1569 
1575 };
1576 
1578  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1579  precis : 1, : 2, pc : 2, rc : 2, : 1, : 3;
1580 };
1581 
1582 struct fp_status_t {
1583  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1584  precis : 1, stkflt : 1, errsumm : 1, c0 : 1, c1 : 1, c2 : 1, tos : 3,
1585  c3 : 1, busy : 1;
1586 };
1587 
1588 struct mmst_reg_t {
1589  char mmst_reg[10];
1590  char mmst_rsrv[6];
1591 };
1592 
1593 struct xmm_reg_t {
1594  char xmm_reg[16];
1595 };
1596 
1598  int32_t fpu_reserved[2];
1601  uint8_t fpu_ftw;
1602  uint8_t fpu_rsrv1;
1603  uint16_t fpu_fop;
1605  uint16_t fpu_cs;
1606  uint16_t fpu_rsrv2;
1608  uint16_t fpu_ds;
1609  uint16_t fpu_rsrv3;
1636  char fpu_rsrv4[6 * 16];
1638 };
1639 
1641  uint16_t trapno;
1642  uint16_t cpu;
1644  uint64_t faultvaddr;
1645 };
1646 
1664 }
1665 
1688 }
1689 
1693  // TODO swap: fp_control_t fpu_fcw;
1694  // TODO swap: fp_status_t fpu_fsw;
1705 }
1706 
1712 }
1713 
1717 };
1718 
1721  union {
1724  } uts;
1725 };
1726 
1729  union {
1731  } ufs;
1732 };
1733 
1736  union {
1738  } ues;
1739 };
1740 
1741 inline void swapStruct(x86_state_hdr_t &x) {
1744 }
1745 
1759 };
1760 
1762  swapStruct(x.tsh);
1763  if (x.tsh.flavor == x86_THREAD_STATE64)
1764  swapStruct(x.uts.ts64);
1765 }
1766 
1768  swapStruct(x.fsh);
1769  if (x.fsh.flavor == x86_FLOAT_STATE64)
1770  swapStruct(x.ufs.fs64);
1771 }
1772 
1774  swapStruct(x.esh);
1775  if (x.esh.flavor == x86_EXCEPTION_STATE64)
1776  swapStruct(x.ues.es64);
1777 }
1778 
1780  sizeof(x86_thread_state32_t) / sizeof(uint32_t);
1781 
1783  sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1785  sizeof(x86_float_state64_t) / sizeof(uint32_t);
1787  sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1788 
1790  sizeof(x86_thread_state_t) / sizeof(uint32_t);
1792  sizeof(x86_float_state_t) / sizeof(uint32_t);
1794  sizeof(x86_exception_state_t) / sizeof(uint32_t);
1795 
1797  uint32_t r[13];
1802 };
1803 
1805  for (int i = 0; i < 13; i++)
1806  sys::swapByteOrder(x.r[i]);
1811 }
1812 
1814  uint64_t x[29];
1815  uint64_t fp;
1816  uint64_t lr;
1817  uint64_t sp;
1818  uint64_t pc;
1821 };
1822 
1824  for (int i = 0; i < 29; i++)
1825  sys::swapByteOrder(x.x[i]);
1831 }
1832 
1836 };
1837 
1840  union {
1842  } uts;
1843 };
1844 
1845 inline void swapStruct(arm_state_hdr_t &x) {
1848 }
1849 
1858 };
1859 
1861  swapStruct(x.tsh);
1862  if (x.tsh.flavor == ARM_THREAD_STATE)
1863  swapStruct(x.uts.ts32);
1864 }
1865 
1867  sizeof(arm_thread_state32_t) / sizeof(uint32_t);
1868 
1870  sizeof(arm_thread_state64_t) / sizeof(uint32_t);
1871 
1913 };
1914 
1956 }
1957 
1961 };
1962 
1965  union {
1967  } uts;
1968 };
1969 
1970 inline void swapStruct(ppc_state_hdr_t &x) {
1973 }
1974 
1983 };
1984 
1986  swapStruct(x.tsh);
1987  if (x.tsh.flavor == PPC_THREAD_STATE)
1988  swapStruct(x.uts.ts32);
1989 }
1990 
1992  sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
1993 
1994 // Define a union of all load command structs
1995 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1996 
1998 union alignas(4) macho_load_command {
1999 #include "llvm/BinaryFormat/MachO.def"
2000 };
2002 
2003 } // end namespace MachO
2004 } // end namespace llvm
2005 
2006 #endif
uint32_t align
Definition: MachO.h:936
uint64_t CallInst * C
void swapStruct(fat_header &mh)
Definition: MachO.h:1002
LoadCommandType
Definition: MachO.h:91
uint32_t header_addr
Definition: MachO.h:592
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:1791
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:612
uint64_t n_value
Definition: MachO.h:997
SectionOrdinal
Definition: MachO.h:311
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:181
void swapByteOrder(T &Value)
const uint32_t x86_EXCEPTION_STATE64_COUNT
Definition: MachO.h:1786
uint8_t n_sect
Definition: MachO.h:987
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isVirtualSection(uint8_t type)
Definition: MachO.h:584
int CPU_SUBTYPE_INTEL(int Family, int Model)
Definition: MachO.h:1468
ExportSymbolKind
Definition: MachO.h:286
uint32_t nfat_arch
Definition: MachO.h:928
Definition: MachO.h:797
uint32_t reserved1
Definition: MachO.h:565
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:187
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:1390
uint32_t reserved2
Definition: MachO.h:580
uint32_t size
Definition: MachO.h:559
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
Definition: MachO.h:1398
PPCThreadFlavors
Definition: MachO.h:1975
uint32_t cpusubtype
Definition: MachO.h:933
unsigned short zdiv
Definition: MachO.h:1583
S_ATTR_LOC_RELOC - Section has local relocation entries.
Definition: MachO.h:206
void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align)
Definition: MachO.h:1402
uint32_t name
Definition: MachO.h:603
void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
Definition: MachO.h:1394
uint32_t reloff
Definition: MachO.h:562
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:1866
union llvm::MachO::ppc_thread_state_t::@134 uts
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:125
const uint32_t x86_THREAD_STATE32_COUNT
Definition: MachO.h:1779
HeaderFileType
Definition: MachO.h:36
S_ATTR_EXT_RELOC - Section has external relocation entries.
Definition: MachO.h:204
uint32_t n_value
Definition: MachO.h:989
uint16_t length
Definition: MachO.h:799
S_8BYTE_LITERALS - Section with 8 byte literals.
Definition: MachO.h:127
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
Definition: MachO.h:194
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:734
ppc_thread_state32_t ts32
Definition: MachO.h:1966
union llvm::MachO::arm_thread_state_t::@133 uts
S_REGULAR - Regular section.
Definition: MachO.h:119
uint32_t flags
Definition: MachO.h:564
S_INTERPOSING - Section with only pairs of function pointers for interposing.
Definition: MachO.h:150
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:191
#define rc(i)
S_LITERAL_POINTERS - Section with pointers to literals.
Definition: MachO.h:129
x86_fp_control_rc
Definition: MachO.h:1570
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:579
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:161
const uint32_t x86_THREAD_STATE64_COUNT
Definition: MachO.h:1782
#define H(x, y, z)
Definition: MD5.cpp:57
uint32_t offset
Definition: MachO.h:798
X86ThreadFlavors
Definition: MachO.h:1746
CPUSubTypeARM64
Definition: MachO.h:1493
union llvm::MachO::x86_float_state_t::@131 ufs
uint64_t objc_module_info_addr
Definition: MachO.h:751
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:1500
uint16_t kind
Definition: MachO.h:800
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition: MachO.h:189
x86_exception_state64_t es64
Definition: MachO.h:1737
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:988
S_DTRACE_DOF - Section contains DTrace Object Format.
Definition: MachO.h:154
x86_fp_control_precis
Definition: MachO.h:1564
const uint32_t x86_FLOAT_STATE64_COUNT
Definition: MachO.h:1784
x86_thread_state64_t ts64
Definition: MachO.h:1722
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:167
union llvm::MachO::x86_thread_state_t::@130 uts
ARMThreadFlavors
Definition: MachO.h:1850
const uint32_t x86_THREAD_STATE_COUNT
Definition: MachO.h:1789
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:1471
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:152
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition: MachO.h:1793
uint32_t cputype
Definition: MachO.h:932
struct fvmlib fvmlib
Definition: MachO.h:599
x86_thread_state32_t ts32
Definition: MachO.h:1723
uint16_t n_desc
Definition: MachO.h:996
uint32_t n_strx
Definition: MachO.h:985
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
Definition: MachO.h:202
CPUSubTypePowerPC
Definition: MachO.h:1502
union llvm::MachO::x86_exception_state_t::@132 ues
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:196
uint32_t reserved3
Definition: MachO.h:581
#define LLVM_PACKED_START
Definition: Compiler.h:373
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:184
uint32_t offset
Definition: MachO.h:934
uint32_t objc_module_info_size
Definition: MachO.h:750
uint32_t n_strx
Definition: MachO.h:993
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:144
uint32_t addr
Definition: MachO.h:558
uint32_t objc_module_info_size
Definition: MachO.h:735
uint32_t nreloc
Definition: MachO.h:563
RelocationInfoType
Definition: MachO.h:392
unsigned short zdiv
Definition: MachO.h:1578
CPUSubTypeARM64_32
Definition: MachO.h:1498
uint32_t timestamp
Definition: MachO.h:604
uint32_t offset
Definition: MachO.h:560
const uint32_t ARM_THREAD_STATE64_COUNT
Definition: MachO.h:1869
uint8_t n_type
Definition: MachO.h:986
uint32_t reserved2
Definition: MachO.h:566
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:121
uint32_t minor_version
Definition: MachO.h:591
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition: MachO.h:139
uint32_t align
Definition: MachO.h:561
SectionType
These are the section type and attributes fields.
Definition: MachO.h:114
uint32_t current_version
Definition: MachO.h:605
uint32_t compatibility_version
Definition: MachO.h:606
uint32_t name
Definition: MachO.h:590
const uint32_t PPC_THREAD_STATE_COUNT
Definition: MachO.h:1991
x86_float_state64_t fs64
Definition: MachO.h:1730
int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST)
Definition: MachO.h:1474
arm_thread_state32_t ts32
Definition: MachO.h:1841
#define LLVM_PACKED_END
Definition: Compiler.h:374