LLVM  4.0.0
Support/MachO.h
Go to the documentation of this file.
1 //===-- llvm/Support/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_SUPPORT_MACHO_H
15 #define LLVM_SUPPORT_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
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) \
90  LCName = LCValue,
91 
93  #include "llvm/Support/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 
224  enum RebaseType {
228  };
229 
230  enum {
233  };
234 
245  };
246 
247  enum BindType {
251  };
252 
257  };
258 
259  enum {
262 
265  };
266 
267  enum BindOpcode {
281  };
282 
283  enum {
288  };
289 
294  };
295 
296  enum {
297  // Constant masks for the "n_type" field in llvm::MachO::nlist and
298  // llvm::MachO::nlist_64
299  N_STAB = 0xe0,
300  N_PEXT = 0x10,
301  N_TYPE = 0x0e,
302  N_EXT = 0x01
303  };
304 
305  enum NListType : uint8_t {
306  // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
307  // llvm::MachO::nlist_64
308  N_UNDF = 0x0u,
309  N_ABS = 0x2u,
310  N_SECT = 0xeu,
311  N_PBUD = 0xcu,
312  N_INDR = 0xau
313  };
314 
316  // Constants for the "n_sect" field in llvm::MachO::nlist and
317  // llvm::MachO::nlist_64
318  NO_SECT = 0u,
319  MAX_SECT = 0xffu
320  };
321 
322  enum {
323  // Constant masks for the "n_desc" field in llvm::MachO::nlist and
324  // llvm::MachO::nlist_64
325  // The low 3 bits are the for the REFERENCE_TYPE.
333  // Flag bits (some overlap with the library ordinal bits).
334  N_ARM_THUMB_DEF = 0x0008u,
336  N_NO_DEAD_STRIP = 0x0020u,
337  N_WEAK_REF = 0x0040u,
338  N_WEAK_DEF = 0x0080u,
339  N_SYMBOL_RESOLVER = 0x0100u,
340  N_ALT_ENTRY = 0x0200u,
341  // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL()
342  // as these are in the top 8 bits.
347  };
348 
349  enum StabType {
350  // Constant values for the "n_type" field in llvm::MachO::nlist and
351  // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
352  N_GSYM = 0x20u,
353  N_FNAME = 0x22u,
354  N_FUN = 0x24u,
355  N_STSYM = 0x26u,
356  N_LCSYM = 0x28u,
357  N_BNSYM = 0x2Eu,
358  N_PC = 0x30u,
359  N_AST = 0x32u,
360  N_OPT = 0x3Cu,
361  N_RSYM = 0x40u,
362  N_SLINE = 0x44u,
363  N_ENSYM = 0x4Eu,
364  N_SSYM = 0x60u,
365  N_SO = 0x64u,
366  N_OSO = 0x66u,
367  N_LSYM = 0x80u,
368  N_BINCL = 0x82u,
369  N_SOL = 0x84u,
370  N_PARAMS = 0x86u,
371  N_VERSION = 0x88u,
372  N_OLEVEL = 0x8Au,
373  N_PSYM = 0xA0u,
374  N_EINCL = 0xA2u,
375  N_ENTRY = 0xA4u,
376  N_LBRAC = 0xC0u,
377  N_EXCL = 0xC2u,
378  N_RBRAC = 0xE0u,
379  N_BCOMM = 0xE2u,
380  N_ECOMM = 0xE4u,
381  N_ECOML = 0xE8u,
382  N_LENG = 0xFEu
383  };
384 
385  enum : uint32_t {
386  // Constant values for the r_symbolnum field in an
387  // llvm::MachO::relocation_info structure when r_extern is 0.
388  R_ABS = 0,
389 
390  // Constant bits for the r_address field in an
391  // llvm::MachO::relocation_info structure.
392  R_SCATTERED = 0x80000000
393  };
394 
396  // Constant values for the r_type field in an
397  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
398  // structure.
405 
406  // Constant values for the r_type field in a PowerPC architecture
407  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
408  // structure.
425 
426  // Constant values for the r_type field in an ARM architecture
427  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
428  // structure.
436  ARM_THUMB_32BIT_BRANCH = 7, // obsolete
439 
440  // Constant values for the r_type field in an ARM64 architecture
441  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
442  // structure.
443 
444  // For pointers.
446  // Must be followed by an ARM64_RELOC_UNSIGNED
448  // A B/BL instruction with 26-bit displacement.
450  // PC-rel distance to page of target.
452  // Offset within page, scaled by r_length.
454  // PC-rel distance to page of GOT slot.
456  // Offset within page of GOT slot, scaled by r_length.
458  // For pointers to GOT slots.
460  // PC-rel distance to page of TLVP slot.
462  // Offset within page of TLVP slot, scaled by r_length.
464  // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
466 
467  // Constant values for the r_type field in an x86_64 architecture
468  // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
469  // structure
480  };
481 
482  // Values for segment_command.initprot.
483  // From <mach/vm_prot.h>
484  enum {
488  };
489 
490  // Structs from <mach-o/loader.h>
491 
492  struct mach_header {
500  };
501 
502  struct mach_header_64 {
511  };
512 
513  struct load_command {
516  };
517 
521  char segname[16];
530  };
531 
535  char segname[16];
536  uint64_t vmaddr;
537  uint64_t vmsize;
538  uint64_t fileoff;
539  uint64_t filesize;
544  };
545 
546  struct section {
547  char sectname[16];
548  char segname[16];
558  };
559 
560  struct section_64 {
561  char sectname[16];
562  char segname[16];
563  uint64_t addr;
564  uint64_t size;
573  };
574 
575  struct fvmlib {
579  };
580 
581  // The fvmlib_command is obsolete and no longer supported.
582  struct fvmlib_command {
585  struct fvmlib fvmlib;
586  };
587 
588  struct dylib {
593  };
594 
595  struct dylib_command {
598  struct dylib dylib;
599  };
600 
605  };
606 
611  };
612 
617  };
618 
623  };
624 
625  // The prebound_dylib_command is obsolete and no longer supported.
632  };
633 
638  };
639 
640  struct thread_command {
643  };
644 
656  };
657 
661  uint64_t init_address;
662  uint64_t init_module;
663  uint64_t reserved1;
664  uint64_t reserved2;
665  uint64_t reserved3;
666  uint64_t reserved4;
667  uint64_t reserved5;
668  uint64_t reserved6;
669  };
670 
671  struct symtab_command {
678  };
679 
701  };
702 
706  };
707 
708  struct dylib_module {
722  };
723 
738  };
739 
742  flags:8;
743  };
744 
745  // The twolevel_hints_command is obsolete and no longer supported.
751  };
752 
753  // The twolevel_hints_command is obsolete and no longer supported.
754  struct twolevel_hint {
756  itoc:24;
757  };
758 
759  // The prebind_cksum_command is obsolete and no longer supported.
764  };
765 
766  struct uuid_command {
769  uint8_t uuid[16];
770  };
771 
772  struct rpath_command {
776  };
777 
783  };
784 
787  uint16_t length;
788  uint16_t kind;
789  };
790 
794  uint64_t version;
795  };
796 
803  };
804 
812  };
813 
815  uint32_t cmd; // LC_VERSION_MIN_MACOSX or
816  // LC_VERSION_MIN_IPHONEOS
817  uint32_t cmdsize; // sizeof(struct version_min_command)
818  uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
819  uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
820  };
821 
835  };
836 
841  };
842 
843  // The symseg_command is obsolete and no longer supported.
844  struct symseg_command {
849  };
850 
851  // The ident_command is obsolete and no longer supported.
852  struct ident_command {
855  };
856 
857  // The fvmfile_command is obsolete and no longer supported.
863  };
864 
869  };
870 
872  uint64_t thunk;
873  uint64_t key;
874  uint64_t offset;
875  };
876 
877  struct tlv_descriptor {
878  uintptr_t thunk;
879  uintptr_t key;
880  uintptr_t offset;
881  };
882 
886  uint64_t entryoff;
887  uint64_t stacksize;
888  };
889 
890  // Structs from <mach-o/fat.h>
891  struct fat_header {
894  };
895 
896  struct fat_arch {
902  };
903 
904  struct fat_arch_64 {
907  uint64_t offset;
908  uint64_t size;
911  };
912 
913  // Structs from <mach-o/reloc.h>
915  int32_t r_address;
917  r_pcrel:1,
918  r_length:2,
919  r_extern:1,
920  r_type:4;
921  };
922 
924 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
926  r_pcrel:1,
927  r_length:2,
928  r_type:4,
929  r_address:24;
930 #else
932  r_type:4,
933  r_length:2,
934  r_pcrel:1,
935  r_scattered:1;
936 #endif
937  int32_t r_value;
938  };
939 
940  // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
943  };
944 
945  // Structs from <mach-o/nlist.h>
946  struct nlist_base {
948  uint8_t n_type;
949  uint8_t n_sect;
950  uint16_t n_desc;
951  };
952 
953  struct nlist {
955  uint8_t n_type;
956  uint8_t n_sect;
957  int16_t n_desc;
959  };
960 
961  struct nlist_64 {
963  uint8_t n_type;
964  uint8_t n_sect;
965  uint16_t n_desc;
966  uint64_t n_value;
967  };
968 
969  // Byte order swapping functions for MachO structs
970 
971  inline void swapStruct(fat_header &mh) {
974  }
975 
976  inline void swapStruct(fat_arch &mh) {
982  }
983 
984  inline void swapStruct(fat_arch_64 &mh) {
991  }
992 
993  inline void swapStruct(mach_header &mh) {
1001  }
1002 
1003  inline void swapStruct(mach_header_64 &H) {
1012  }
1013 
1014  inline void swapStruct(load_command &lc) {
1015  sys::swapByteOrder(lc.cmd);
1017  }
1018 
1019  inline void swapStruct(symtab_command &lc) {
1020  sys::swapByteOrder(lc.cmd);
1026  }
1027 
1028  inline void swapStruct(segment_command_64 &seg) {
1029  sys::swapByteOrder(seg.cmd);
1039  }
1040 
1041  inline void swapStruct(segment_command &seg) {
1042  sys::swapByteOrder(seg.cmd);
1052  }
1053 
1054  inline void swapStruct(section_64 &sect) {
1055  sys::swapByteOrder(sect.addr);
1056  sys::swapByteOrder(sect.size);
1057  sys::swapByteOrder(sect.offset);
1058  sys::swapByteOrder(sect.align);
1059  sys::swapByteOrder(sect.reloff);
1060  sys::swapByteOrder(sect.nreloc);
1061  sys::swapByteOrder(sect.flags);
1064  }
1065 
1066  inline void swapStruct(section &sect) {
1067  sys::swapByteOrder(sect.addr);
1068  sys::swapByteOrder(sect.size);
1069  sys::swapByteOrder(sect.offset);
1070  sys::swapByteOrder(sect.align);
1071  sys::swapByteOrder(sect.reloff);
1072  sys::swapByteOrder(sect.nreloc);
1073  sys::swapByteOrder(sect.flags);
1076  }
1077 
1079  sys::swapByteOrder(info.cmd);
1091  }
1092 
1093  inline void swapStruct(dylib_command &d) {
1100  }
1101 
1106  }
1107 
1112  }
1113 
1118  }
1119 
1120  inline void swapStruct(sub_client_command &s) {
1124  }
1125 
1126  inline void swapStruct(routines_command &r) {
1137  }
1138 
1150  }
1151 
1152  inline void swapStruct(thread_command &t) {
1155  }
1156 
1157  inline void swapStruct(dylinker_command &d) {
1161  }
1162 
1163  inline void swapStruct(uuid_command &u) {
1166  }
1167 
1168  inline void swapStruct(rpath_command &r) {
1172  }
1173 
1178  }
1179 
1185  }
1186 
1193  }
1194 
1202  }
1203 
1204  inline void swapStruct(dysymtab_command &dst) {
1205  sys::swapByteOrder(dst.cmd);
1214  sys::swapByteOrder(dst.ntoc);
1225  }
1226 
1227  inline void swapStruct(any_relocation_info &reloc) {
1228  sys::swapByteOrder(reloc.r_word0);
1229  sys::swapByteOrder(reloc.r_word1);
1230  }
1231 
1232  inline void swapStruct(nlist_base &S) {
1235  }
1236 
1237  inline void swapStruct(nlist &sym) {
1241  }
1242 
1243  inline void swapStruct(nlist_64 &sym) {
1247  }
1248 
1254  }
1255 
1260  }
1261 
1267  }
1268 
1273  }
1274 
1275  inline void swapStruct(uint32_t &C) {
1276  sys::swapByteOrder(C);
1277  }
1278 
1279  // The prebind_cksum_command is obsolete and no longer supported.
1284  }
1285 
1286  // The twolevel_hints_command is obsolete and no longer supported.
1292  }
1293 
1294  // The prebound_dylib_command is obsolete and no longer supported.
1301  }
1302 
1303  // The fvmfile_command is obsolete and no longer supported.
1304  inline void swapStruct(fvmfile_command &C) {
1309  }
1310 
1311  // The symseg_command is obsolete and no longer supported.
1312  inline void swapStruct(symseg_command &C) {
1317  }
1318 
1319  // The ident_command is obsolete and no longer supported.
1320  inline void swapStruct(ident_command &C) {
1323  }
1324 
1325  inline void swapStruct(fvmlib &C) {
1329  }
1330 
1331  // The fvmlib_command is obsolete and no longer supported.
1332  inline void swapStruct(fvmlib_command &C) {
1335  swapStruct(C.fvmlib);
1336  }
1337 
1338  // Get/Set functions from <mach-o/nlist.h>
1339 
1340  static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1341  return (((n_desc) >> 8u) & 0xffu);
1342  }
1343 
1344  static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1345  n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8));
1346  }
1347 
1348  static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) {
1349  return (n_desc >> 8u) & 0x0fu;
1350  }
1351 
1352  static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) {
1353  n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1354  }
1355 
1356  // Enums from <mach/machine.h>
1357  enum : uint32_t {
1358  // Capability bits used in the definition of cpu_type.
1359  CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1360  CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI
1361  };
1362 
1363  // Constants for the cputype field.
1364  enum CPUType {
1369  /* CPU_TYPE_MIPS = 8, */
1370  CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1376  };
1377 
1378  enum : uint32_t {
1379  // Capability bits used in the definition of cpusubtype.
1380  CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1381  CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1382 
1383  // Special CPU subtype constants.
1385  };
1386 
1387  // Constants for the cpusubtype field.
1410 
1415  };
1416  static inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1417  return Family | (Model << 4);
1418  }
1420  return ((int)ST) & 0x0f;
1421  }
1423  return ((int)ST) >> 4;
1424  }
1425  enum {
1428  };
1429 
1438  // unused ARM_V7F = 10,
1444  };
1445 
1448  };
1449 
1452  };
1453 
1468 
1471  };
1472 
1474  uint64_t rax;
1475  uint64_t rbx;
1476  uint64_t rcx;
1477  uint64_t rdx;
1478  uint64_t rdi;
1479  uint64_t rsi;
1480  uint64_t rbp;
1481  uint64_t rsp;
1482  uint64_t r8;
1483  uint64_t r9;
1484  uint64_t r10;
1485  uint64_t r11;
1486  uint64_t r12;
1487  uint64_t r13;
1488  uint64_t r14;
1489  uint64_t r15;
1490  uint64_t rip;
1491  uint64_t rflags;
1492  uint64_t cs;
1493  uint64_t fs;
1494  uint64_t gs;
1495  };
1496 
1501  };
1502 
1508  };
1509 
1510  struct fp_control_t {
1511  unsigned short
1513  denorm :1,
1514  zdiv :1,
1515  ovrfl :1,
1516  undfl :1,
1517  precis :1,
1518  :2,
1519  pc :2,
1520  rc :2,
1521  :1,
1522  :3;
1523  };
1524 
1525  struct fp_status_t {
1526  unsigned short
1528  denorm :1,
1529  zdiv :1,
1530  ovrfl :1,
1531  undfl :1,
1532  precis :1,
1533  stkflt :1,
1534  errsumm :1,
1535  c0 :1,
1536  c1 :1,
1537  c2 :1,
1538  tos :3,
1539  c3 :1,
1540  busy :1;
1541  };
1542 
1543  struct mmst_reg_t {
1544  char mmst_reg[10];
1545  char mmst_rsrv[6];
1546  };
1547 
1548  struct xmm_reg_t {
1549  char xmm_reg[16];
1550  };
1551 
1553  int32_t fpu_reserved[2];
1556  uint8_t fpu_ftw;
1557  uint8_t fpu_rsrv1;
1558  uint16_t fpu_fop;
1560  uint16_t fpu_cs;
1561  uint16_t fpu_rsrv2;
1563  uint16_t fpu_ds;
1564  uint16_t fpu_rsrv3;
1591  char fpu_rsrv4[6*16];
1593  };
1594 
1596  uint16_t trapno;
1597  uint16_t cpu;
1599  uint64_t faultvaddr;
1600  };
1601 
1624  }
1625 
1629  // TODO swap: fp_control_t fpu_fcw;
1630  // TODO swap: fp_status_t fpu_fsw;
1641  }
1642 
1648  }
1649 
1653  };
1654 
1657  union {
1659  } uts;
1660  };
1661 
1664  union {
1666  } ufs;
1667  };
1668 
1671  union {
1673  } ues;
1674  };
1675 
1676  inline void swapStruct(x86_state_hdr_t &x) {
1679  }
1680 
1694  };
1695 
1696  inline void swapStruct(x86_thread_state_t &x) {
1697  swapStruct(x.tsh);
1698  if (x.tsh.flavor == x86_THREAD_STATE64)
1699  swapStruct(x.uts.ts64);
1700  }
1701 
1702  inline void swapStruct(x86_float_state_t &x) {
1703  swapStruct(x.fsh);
1704  if (x.fsh.flavor == x86_FLOAT_STATE64)
1705  swapStruct(x.ufs.fs64);
1706  }
1707 
1709  swapStruct(x.esh);
1710  if (x.esh.flavor == x86_EXCEPTION_STATE64)
1711  swapStruct(x.ues.es64);
1712  }
1713 
1715  sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1717  sizeof(x86_float_state64_t) / sizeof(uint32_t);
1719  sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1720 
1722  sizeof(x86_thread_state_t) / sizeof(uint32_t);
1724  sizeof(x86_float_state_t) / sizeof(uint32_t);
1726  sizeof(x86_exception_state_t) / sizeof(uint32_t);
1727 
1734  };
1735 
1737  for (int i = 0; i < 13; i++)
1738  sys::swapByteOrder(x.r[i]);
1743  }
1744 
1746  uint64_t x[29];
1747  uint64_t fp;
1748  uint64_t lr;
1749  uint64_t sp;
1750  uint64_t pc;
1753  };
1754 
1756  for (int i = 0; i < 29; i++)
1757  sys::swapByteOrder(x.x[i]);
1763  }
1764 
1768  };
1769 
1772  union {
1774  } uts;
1775  };
1776 
1777  inline void swapStruct(arm_state_hdr_t &x) {
1780  }
1781 
1790  };
1791 
1792  inline void swapStruct(arm_thread_state_t &x) {
1793  swapStruct(x.tsh);
1794  if (x.tsh.flavor == ARM_THREAD_STATE)
1795  swapStruct(x.uts.ts32);
1796  }
1797 
1799  sizeof(arm_thread_state32_t) / sizeof(uint32_t);
1800 
1802  sizeof(arm_thread_state64_t) / sizeof(uint32_t);
1803 
1845  };
1846 
1888  }
1889 
1893  };
1894 
1897  union {
1899  } uts;
1900  };
1901 
1902  inline void swapStruct(ppc_state_hdr_t &x) {
1905  }
1906 
1915  };
1916 
1917  inline void swapStruct(ppc_thread_state_t &x) {
1918  swapStruct(x.tsh);
1919  if (x.tsh.flavor == PPC_THREAD_STATE)
1920  swapStruct(x.uts.ts32);
1921  }
1922 
1924  sizeof(ppc_thread_state32_t) / sizeof(uint32_t);
1925 
1926  // Define a union of all load command structs
1927  #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1928 
1930  #include "llvm/Support/MachO.def"
1931  };
1932 
1933  } // end namespace MachO
1934 } // end namespace llvm
1935 
1936 #endif
void swapStruct(fat_header &mh)
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
const uint32_t x86_FLOAT_STATE_COUNT
S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
void swapByteOrder(T &Value)
const uint32_t x86_EXCEPTION_STATE64_COUNT
S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by dyld.
size_t i
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
S_ATTR_DEBUG - A debug section.
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
lazy value info
S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to lazy loaded dylibs.
const uint32_t ARM_THREAD_STATE_COUNT
S_4BYTE_LITERALS - Section with 4 byte literals.
static F t[256]
uint16_t length
S_8BYTE_LITERALS - Section with 8 byte literals.
S_ATTR_LOC_RELOC - Section has local relocation entries.
S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for termination.
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents...
union llvm::MachO::ppc_thread_state_t::@209 uts
S_ATTR_NO_DEAD_STRIP - No dead stripping.
S_REGULAR - Regular section.
S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
S_INTERPOSING - Section with only pairs of function pointers for interposing.
static void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal)
static uint8_t GET_COMM_ALIGN(uint16_t n_desc)
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
S_LITERAL_POINTERS - Section with pointers to literals.
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
S_ATTR_EXT_RELOC - Section has external relocation entries.
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
const uint32_t x86_THREAD_STATE64_COUNT
#define H(x, y, z)
Definition: MD5.cpp:53
uint32_t offset
S_THREAD_LOCAL_REGULAR - Thread local data section.
S_CSTRING_LITERALS - Section with literal C strings.
static uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc)
uint16_t kind
x86_exception_state64_t es64
static int CPU_SUBTYPE_INTEL(int Family, int Model)
union llvm::MachO::x86_float_state_t::@206 ufs
union llvm::MachO::arm_thread_state_t::@208 uts
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
S_DTRACE_DOF - Section contains DTrace Object Format.
static void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align)
const uint32_t x86_FLOAT_STATE64_COUNT
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
const uint32_t x86_THREAD_STATE_COUNT
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
S_16BYTE_LITERALS - Section with only 16 byte literals.
const uint32_t x86_EXCEPTION_STATE_COUNT
static int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST)
static int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST)
S_COALESCED - Section contains symbols that are to be coalesced.
const uint32_t ARM_THREAD_STATE64_COUNT
union llvm::MachO::x86_thread_state_t::@205 uts
union llvm::MachO::x86_exception_state_t::@207 ues
S_ZEROFILL - Zero fill on demand section.
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
SectionType
These are the section type and attributes fields.
uint32_t current_version
uint32_t compatibility_version
const uint32_t PPC_THREAD_STATE_COUNT