LLVM  8.0.0svn
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.
490 };
491 
492 // Values for tools enum in build_tool_version.
493 enum { TOOL_CLANG = 1, TOOL_SWIFT = 2, TOOL_LD = 3 };
494 
495 // Structs from <mach-o/loader.h>
496 
497 struct mach_header {
505 };
506 
516 };
517 
518 struct load_command {
521 };
522 
526  char segname[16];
535 };
536 
540  char segname[16];
541  uint64_t vmaddr;
542  uint64_t vmsize;
543  uint64_t fileoff;
544  uint64_t filesize;
549 };
550 
551 struct section {
552  char sectname[16];
553  char segname[16];
563 };
564 
565 struct section_64 {
566  char sectname[16];
567  char segname[16];
568  uint64_t addr;
569  uint64_t size;
578 };
579 
580 struct fvmlib {
584 };
585 
586 // The fvmlib_command is obsolete and no longer supported.
590  struct fvmlib fvmlib;
591 };
592 
593 struct dylib {
598 };
599 
603  struct dylib dylib;
604 };
605 
610 };
611 
616 };
617 
622 };
623 
628 };
629 
630 // The prebound_dylib_command is obsolete and no longer supported.
637 };
638 
643 };
644 
648 };
649 
661 };
662 
666  uint64_t init_address;
667  uint64_t init_module;
668  uint64_t reserved1;
669  uint64_t reserved2;
670  uint64_t reserved3;
671  uint64_t reserved4;
672  uint64_t reserved5;
673  uint64_t reserved6;
674 };
675 
683 };
684 
706 };
707 
711 };
712 
713 struct dylib_module {
727 };
728 
743 };
744 
746  uint32_t isym : 24, flags : 8;
747 };
748 
749 // The twolevel_hints_command is obsolete and no longer supported.
755 };
756 
757 // The twolevel_hints_command is obsolete and no longer supported.
759  uint32_t isub_image : 8, itoc : 24;
760 };
761 
762 // The prebind_cksum_command is obsolete and no longer supported.
767 };
768 
769 struct uuid_command {
772  uint8_t uuid[16];
773 };
774 
779 };
780 
786 };
787 
790  uint16_t length;
791  uint16_t kind;
792 };
793 
797  uint64_t version;
798 };
799 
806 };
807 
815 };
816 
818  uint32_t cmd; // LC_VERSION_MIN_MACOSX or
819  // LC_VERSION_MIN_IPHONEOS
820  uint32_t cmdsize; // sizeof(struct version_min_command)
821  uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
822  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
823 };
824 
825 struct note_command {
826  uint32_t cmd; // LC_NOTE
827  uint32_t cmdsize; // sizeof(struct note_command)
828  char data_owner[16]; // owner name for this LC_NOTE
829  uint64_t offset; // file offset of this data
830  uint64_t size; // length of data region
831 };
832 
834  uint32_t tool; // enum for the tool
835  uint32_t version; // version of the tool
836 };
837 
839  uint32_t cmd; // LC_BUILD_VERSION
840  uint32_t cmdsize; // sizeof(struct build_version_command) +
841  // ntools * sizeof(struct build_tool_version)
842  uint32_t platform; // platform
843  uint32_t minos; // X.Y.Z is encoded in nibbles xxxx.yy.zz
844  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
845  uint32_t ntools; // number of tool entries following this
846 };
847 
861 };
862 
867 };
868 
869 // The symseg_command is obsolete and no longer supported.
875 };
876 
877 // The ident_command is obsolete and no longer supported.
881 };
882 
883 // The fvmfile_command is obsolete and no longer supported.
889 };
890 
895 };
896 
898  uint64_t thunk;
899  uint64_t key;
900  uint64_t offset;
901 };
902 
904  uintptr_t thunk;
905  uintptr_t key;
906  uintptr_t offset;
907 };
908 
912  uint64_t entryoff;
913  uint64_t stacksize;
914 };
915 
916 // Structs from <mach-o/fat.h>
917 struct fat_header {
920 };
921 
922 struct fat_arch {
928 };
929 
930 struct fat_arch_64 {
933  uint64_t offset;
934  uint64_t size;
937 };
938 
939 // Structs from <mach-o/reloc.h>
941  int32_t r_address;
942  uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1,
943  r_type : 4;
944 };
945 
947 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
948  uint32_t r_scattered : 1, r_pcrel : 1, r_length : 2, r_type : 4,
949  r_address : 24;
950 #else
951  uint32_t r_address : 24, r_type : 4, r_length : 2, r_pcrel : 1,
952  r_scattered : 1;
953 #endif
954  int32_t r_value;
955 };
956 
957 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
959  uint32_t r_word0, r_word1;
960 };
961 
962 // Structs from <mach-o/nlist.h>
963 struct nlist_base {
965  uint8_t n_type;
966  uint8_t n_sect;
967  uint16_t n_desc;
968 };
969 
970 struct nlist {
972  uint8_t n_type;
973  uint8_t n_sect;
974  int16_t n_desc;
976 };
977 
978 struct nlist_64 {
980  uint8_t n_type;
981  uint8_t n_sect;
982  uint16_t n_desc;
983  uint64_t n_value;
984 };
985 
986 // Byte order swapping functions for MachO structs
987 
988 inline void swapStruct(fat_header &mh) {
991 }
992 
993 inline void swapStruct(fat_arch &mh) {
999 }
1000 
1001 inline void swapStruct(fat_arch_64 &mh) {
1008 }
1009 
1010 inline void swapStruct(mach_header &mh) {
1018 }
1019 
1020 inline void swapStruct(mach_header_64 &H) {
1029 }
1030 
1031 inline void swapStruct(load_command &lc) {
1032  sys::swapByteOrder(lc.cmd);
1034 }
1035 
1036 inline void swapStruct(symtab_command &lc) {
1037  sys::swapByteOrder(lc.cmd);
1043 }
1044 
1045 inline void swapStruct(segment_command_64 &seg) {
1046  sys::swapByteOrder(seg.cmd);
1056 }
1057 
1058 inline void swapStruct(segment_command &seg) {
1059  sys::swapByteOrder(seg.cmd);
1069 }
1070 
1071 inline void swapStruct(section_64 &sect) {
1072  sys::swapByteOrder(sect.addr);
1073  sys::swapByteOrder(sect.size);
1074  sys::swapByteOrder(sect.offset);
1075  sys::swapByteOrder(sect.align);
1076  sys::swapByteOrder(sect.reloff);
1077  sys::swapByteOrder(sect.nreloc);
1078  sys::swapByteOrder(sect.flags);
1081 }
1082 
1083 inline void swapStruct(section &sect) {
1084  sys::swapByteOrder(sect.addr);
1085  sys::swapByteOrder(sect.size);
1086  sys::swapByteOrder(sect.offset);
1087  sys::swapByteOrder(sect.align);
1088  sys::swapByteOrder(sect.reloff);
1089  sys::swapByteOrder(sect.nreloc);
1090  sys::swapByteOrder(sect.flags);
1093 }
1094 
1096  sys::swapByteOrder(info.cmd);
1108 }
1109 
1110 inline void swapStruct(dylib_command &d) {
1117 }
1118 
1123 }
1124 
1129 }
1130 
1135 }
1136 
1141 }
1142 
1143 inline void swapStruct(routines_command &r) {
1154 }
1155 
1167 }
1168 
1169 inline void swapStruct(thread_command &t) {
1172 }
1173 
1174 inline void swapStruct(dylinker_command &d) {
1178 }
1179 
1180 inline void swapStruct(uuid_command &u) {
1183 }
1184 
1185 inline void swapStruct(rpath_command &r) {
1189 }
1190 
1195 }
1196 
1202 }
1203 
1210 }
1211 
1219 }
1220 
1221 inline void swapStruct(dysymtab_command &dst) {
1222  sys::swapByteOrder(dst.cmd);
1231  sys::swapByteOrder(dst.ntoc);
1242 }
1243 
1244 inline void swapStruct(any_relocation_info &reloc) {
1245  sys::swapByteOrder(reloc.r_word0);
1246  sys::swapByteOrder(reloc.r_word1);
1247 }
1248 
1249 inline void swapStruct(nlist_base &S) {
1252 }
1253 
1254 inline void swapStruct(nlist &sym) {
1258 }
1259 
1260 inline void swapStruct(nlist_64 &sym) {
1264 }
1265 
1271 }
1272 
1277 }
1278 
1284 }
1285 
1286 inline void swapStruct(note_command &C) {
1291 }
1292 
1300 }
1301 
1305 }
1306 
1311 }
1312 
1314 
1315 // The prebind_cksum_command is obsolete and no longer supported.
1320 }
1321 
1322 // The twolevel_hints_command is obsolete and no longer supported.
1328 }
1329 
1330 // The prebound_dylib_command is obsolete and no longer supported.
1337 }
1338 
1339 // The fvmfile_command is obsolete and no longer supported.
1345 }
1346 
1347 // The symseg_command is obsolete and no longer supported.
1348 inline void swapStruct(symseg_command &C) {
1353 }
1354 
1355 // The ident_command is obsolete and no longer supported.
1356 inline void swapStruct(ident_command &C) {
1359 }
1360 
1361 inline void swapStruct(fvmlib &C) {
1365 }
1366 
1367 // The fvmlib_command is obsolete and no longer supported.
1368 inline void swapStruct(fvmlib_command &C) {
1371  swapStruct(C.fvmlib);
1372 }
1373 
1374 // Get/Set functions from <mach-o/nlist.h>
1375 
1376 inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1377  return (((n_desc) >> 8u) & 0xffu);
1378 }
1379 
1380 inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1381  n_desc = (((n_desc)&0x00ff) | (((ordinal)&0xff) << 8));
1382 }
1383 
1384 inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) {
1385  return (n_desc >> 8u) & 0x0fu;
1386 }
1387 
1388 inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) {
1389  n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1390 }
1391 
1392 // Enums from <mach/machine.h>
1393 enum : uint32_t {
1394  // Capability bits used in the definition of cpu_type.
1395  CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1396  CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI
1397 };
1398 
1399 // Constants for the cputype field.
1400 enum CPUType {
1405  /* CPU_TYPE_MIPS = 8, */
1406  CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1412 };
1413 
1414 enum : uint32_t {
1415  // Capability bits used in the definition of cpusubtype.
1416  CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1417  CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1418 
1419  // Special CPU subtype constants.
1421 };
1422 
1423 // Constants for the cpusubtype field.
1446 
1451 };
1452 inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1453  return Family | (Model << 4);
1454 }
1456  return ((int)ST) & 0x0f;
1457 }
1458 inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) { return ((int)ST) >> 4; }
1460 
1469  // unused ARM_V7F = 10,
1475 };
1476 
1478 
1480 
1495 
1498 };
1499 
1517 };
1518 
1520  uint64_t rax;
1521  uint64_t rbx;
1522  uint64_t rcx;
1523  uint64_t rdx;
1524  uint64_t rdi;
1525  uint64_t rsi;
1526  uint64_t rbp;
1527  uint64_t rsp;
1528  uint64_t r8;
1529  uint64_t r9;
1530  uint64_t r10;
1531  uint64_t r11;
1532  uint64_t r12;
1533  uint64_t r13;
1534  uint64_t r14;
1535  uint64_t r15;
1536  uint64_t rip;
1537  uint64_t rflags;
1538  uint64_t cs;
1539  uint64_t fs;
1540  uint64_t gs;
1541 };
1542 
1547 };
1548 
1554 };
1555 
1557  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1558  precis : 1, : 2, pc : 2, rc : 2, : 1, : 3;
1559 };
1560 
1561 struct fp_status_t {
1562  unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1,
1563  precis : 1, stkflt : 1, errsumm : 1, c0 : 1, c1 : 1, c2 : 1, tos : 3,
1564  c3 : 1, busy : 1;
1565 };
1566 
1567 struct mmst_reg_t {
1568  char mmst_reg[10];
1569  char mmst_rsrv[6];
1570 };
1571 
1572 struct xmm_reg_t {
1573  char xmm_reg[16];
1574 };
1575 
1577  int32_t fpu_reserved[2];
1580  uint8_t fpu_ftw;
1581  uint8_t fpu_rsrv1;
1582  uint16_t fpu_fop;
1584  uint16_t fpu_cs;
1585  uint16_t fpu_rsrv2;
1587  uint16_t fpu_ds;
1588  uint16_t fpu_rsrv3;
1615  char fpu_rsrv4[6 * 16];
1617 };
1618 
1620  uint16_t trapno;
1621  uint16_t cpu;
1623  uint64_t faultvaddr;
1624 };
1625 
1643 }
1644 
1667 }
1668 
1672  // TODO swap: fp_control_t fpu_fcw;
1673  // TODO swap: fp_status_t fpu_fsw;
1684 }
1685 
1691 }
1692 
1696 };
1697 
1700  union {
1703  } uts;
1704 };
1705 
1708  union {
1710  } ufs;
1711 };
1712 
1715  union {
1717  } ues;
1718 };
1719 
1720 inline void swapStruct(x86_state_hdr_t &x) {
1723 }
1724 
1738 };
1739 
1741  swapStruct(x.tsh);
1742  if (x.tsh.flavor == x86_THREAD_STATE64)
1743  swapStruct(x.uts.ts64);
1744 }
1745 
1747  swapStruct(x.fsh);
1748  if (x.fsh.flavor == x86_FLOAT_STATE64)
1749  swapStruct(x.ufs.fs64);
1750 }
1751 
1753  swapStruct(x.esh);
1754  if (x.esh.flavor == x86_EXCEPTION_STATE64)
1755  swapStruct(x.ues.es64);
1756 }
1757 
1759  sizeof(x86_thread_state32_t) / sizeof(uint32_t);
1760 
1762  sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1764  sizeof(x86_float_state64_t) / sizeof(uint32_t);
1766  sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1767 
1769  sizeof(x86_thread_state_t) / sizeof(uint32_t);
1771  sizeof(x86_float_state_t) / sizeof(uint32_t);
1773  sizeof(x86_exception_state_t) / sizeof(uint32_t);
1774 
1776  uint32_t r[13];
1781 };
1782 
1784  for (int i = 0; i < 13; i++)
1785  sys::swapByteOrder(x.r[i]);
1790 }
1791 
1793  uint64_t x[29];
1794  uint64_t fp;
1795  uint64_t lr;
1796  uint64_t sp;
1797  uint64_t pc;
1800 };
1801 
1803  for (int i = 0; i < 29; i++)
1804  sys::swapByteOrder(x.x[i]);
1810 }
1811 
1815 };
1816 
1819  union {
1821  } uts;
1822 };
1823 
1824 inline void swapStruct(arm_state_hdr_t &x) {
1827 }
1828 
1837 };
1838 
1840  swapStruct(x.tsh);
1841  if (x.tsh.flavor == ARM_THREAD_STATE)
1842  swapStruct(x.uts.ts32);
1843 }
1844 
1846  sizeof(arm_thread_state32_t) / sizeof(uint32_t);
1847 
1849  sizeof(arm_thread_state64_t) / sizeof(uint32_t);
1850 
1892 };
1893 
1935 }
1936 
1940 };
1941 
1944  union {
1946  } uts;
1947 };
1948 
1949 inline void swapStruct(ppc_state_hdr_t &x) {
1952 }
1953 
1962 };
1963 
1965  swapStruct(x.tsh);
1966  if (x.tsh.flavor == PPC_THREAD_STATE)
1967  swapStruct(x.uts.ts32);
1968 }
1969 
1971  sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
1972 
1973 // Define a union of all load command structs
1974 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1975 
1977 union alignas(4) macho_load_command {
1978 #include "llvm/BinaryFormat/MachO.def"
1979 };
1981 
1982 } // end namespace MachO
1983 } // end namespace llvm
1984 
1985 #endif
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
Definition: MachO.h:185
uint32_t align
Definition: MachO.h:927
uint64_t CallInst * C
void swapStruct(fat_header &mh)
Definition: MachO.h:988
LoadCommandType
Definition: MachO.h:92
uint32_t header_addr
Definition: MachO.h:583
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:1770
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:603
uint64_t n_value
Definition: MachO.h:983
SectionOrdinal
Definition: MachO.h:312
void swapByteOrder(T &Value)
const uint32_t x86_EXCEPTION_STATE64_COUNT
Definition: MachO.h:1765
uint8_t n_sect
Definition: MachO.h:973
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
int CPU_SUBTYPE_INTEL(int Family, int Model)
Definition: MachO.h:1452
ExportSymbolKind
Definition: MachO.h:287
uint32_t nfat_arch
Definition: MachO.h:919
Definition: MachO.h:788
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
Definition: MachO.h:192
uint32_t reserved1
Definition: MachO.h:561
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:1376
uint32_t reserved2
Definition: MachO.h:576
uint32_t size
Definition: MachO.h:555
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
Definition: MachO.h:188
uint8_t GET_COMM_ALIGN(uint16_t n_desc)
Definition: MachO.h:1384
PPCThreadFlavors
Definition: MachO.h:1954
uint32_t cpusubtype
Definition: MachO.h:924
unsigned short zdiv
Definition: MachO.h:1562
void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align)
Definition: MachO.h:1388
uint32_t name
Definition: MachO.h:594
void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
Definition: MachO.h:1380
uint32_t reloff
Definition: MachO.h:558
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:1845
S_4BYTE_LITERALS - Section with 4 byte literals.
Definition: MachO.h:126
const uint32_t x86_THREAD_STATE32_COUNT
Definition: MachO.h:1758
HeaderFileType
Definition: MachO.h:37
uint32_t n_value
Definition: MachO.h:975
uint16_t length
Definition: MachO.h:790
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:725
ppc_thread_state32_t ts32
Definition: MachO.h:1945
#define LLVM_PACKED_START
Definition: Compiler.h:352
#define LLVM_PACKED_END
Definition: Compiler.h:353
S_REGULAR - Regular section.
Definition: MachO.h:120
uint32_t flags
Definition: MachO.h:560
S_INTERPOSING - Section with only pairs of function pointers for interposing.
Definition: MachO.h:151
union llvm::MachO::x86_float_state_t::@122 ufs
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
Definition: MachO.h:195
#define rc(i)
S_LITERAL_POINTERS - Section with pointers to literals.
Definition: MachO.h:130
x86_fp_control_rc
Definition: MachO.h:1549
union llvm::MachO::ppc_thread_state_t::@125 uts
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:575
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
Definition: MachO.h:162
const uint32_t x86_THREAD_STATE64_COUNT
Definition: MachO.h:1761
#define H(x, y, z)
Definition: MD5.cpp:57
uint32_t offset
Definition: MachO.h:789
X86ThreadFlavors
Definition: MachO.h:1725
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
Definition: MachO.h:182
CPUSubTypeARM64
Definition: MachO.h:1477
uint64_t objc_module_info_addr
Definition: MachO.h:742
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:1479
uint16_t kind
Definition: MachO.h:791
x86_exception_state64_t es64
Definition: MachO.h:1716
DataRegionType
Definition: MachO.h:215
S_ATTR_NO_DEAD_STRIP - No dead stripping.
Definition: MachO.h:190
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
Definition: MachO.h:134
int16_t n_desc
Definition: MachO.h:974
S_ATTR_EXT_RELOC - Section has external relocation entries.
Definition: MachO.h:205
S_DTRACE_DOF - Section contains DTrace Object Format.
Definition: MachO.h:155
x86_fp_control_precis
Definition: MachO.h:1543
const uint32_t x86_FLOAT_STATE64_COUNT
Definition: MachO.h:1763
x86_thread_state64_t ts64
Definition: MachO.h:1701
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
Definition: MachO.h:168
ARMThreadFlavors
Definition: MachO.h:1829
const uint32_t x86_THREAD_STATE_COUNT
Definition: MachO.h:1768
S_ATTR_LOC_RELOC - Section has local relocation entries.
Definition: MachO.h:207
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
Definition: MachO.h:171
int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST)
Definition: MachO.h:1455
S_16BYTE_LITERALS - Section with only 16 byte literals.
Definition: MachO.h:153
const uint32_t x86_EXCEPTION_STATE_COUNT
Definition: MachO.h:1772
union llvm::MachO::x86_exception_state_t::@123 ues
uint32_t cputype
Definition: MachO.h:923
struct fvmlib fvmlib
Definition: MachO.h:590
x86_thread_state32_t ts32
Definition: MachO.h:1702
uint16_t n_desc
Definition: MachO.h:982
uint32_t n_strx
Definition: MachO.h:971
CPUSubTypePowerPC
Definition: MachO.h:1481
uint32_t reserved3
Definition: MachO.h:577
uint32_t offset
Definition: MachO.h:925
S_ATTR_DEBUG - A debug section.
Definition: MachO.h:197
uint32_t objc_module_info_size
Definition: MachO.h:741
uint32_t n_strx
Definition: MachO.h:979
S_COALESCED - Section contains symbols that are to be coalesced.
Definition: MachO.h:145
uint32_t addr
Definition: MachO.h:554
uint32_t objc_module_info_size
Definition: MachO.h:726
uint32_t nreloc
Definition: MachO.h:559
RelocationInfoType
Definition: MachO.h:392
unsigned short zdiv
Definition: MachO.h:1557
uint32_t timestamp
Definition: MachO.h:595
uint32_t offset
Definition: MachO.h:556
const uint32_t ARM_THREAD_STATE64_COUNT
Definition: MachO.h:1848
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
Definition: MachO.h:203
uint8_t n_type
Definition: MachO.h:972
union llvm::MachO::arm_thread_state_t::@124 uts
uint32_t reserved2
Definition: MachO.h:562
S_ZEROFILL - Zero fill on demand section.
Definition: MachO.h:122
uint32_t minor_version
Definition: MachO.h:582
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
Definition: MachO.h:140
uint32_t align
Definition: MachO.h:557
SectionType
These are the section type and attributes fields.
Definition: MachO.h:115
uint32_t current_version
Definition: MachO.h:596
uint32_t compatibility_version
Definition: MachO.h:597
union llvm::MachO::x86_thread_state_t::@121 uts
uint32_t name
Definition: MachO.h:581
const uint32_t PPC_THREAD_STATE_COUNT
Definition: MachO.h:1970
x86_float_state64_t fs64
Definition: MachO.h:1709
int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST)
Definition: MachO.h:1458
arm_thread_state32_t ts32
Definition: MachO.h:1820