MachO.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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. #ifndef LLVM_SUPPORT_MACHO_H
  14. #define LLVM_SUPPORT_MACHO_H
  15. #include "llvm/Support/Compiler.h"
  16. #include "llvm/Support/DataTypes.h"
  17. #include "llvm/Support/Host.h"
  18. namespace llvm {
  19. namespace MachO {
  20. // Enums from <mach-o/loader.h>
  21. enum : uint32_t {
  22. // Constants for the "magic" field in llvm::MachO::mach_header and
  23. // llvm::MachO::mach_header_64
  24. MH_MAGIC = 0xFEEDFACEu,
  25. MH_CIGAM = 0xCEFAEDFEu,
  26. MH_MAGIC_64 = 0xFEEDFACFu,
  27. MH_CIGAM_64 = 0xCFFAEDFEu,
  28. FAT_MAGIC = 0xCAFEBABEu,
  29. FAT_CIGAM = 0xBEBAFECAu
  30. };
  31. enum HeaderFileType {
  32. // Constants for the "filetype" field in llvm::MachO::mach_header and
  33. // llvm::MachO::mach_header_64
  34. MH_OBJECT = 0x1u,
  35. MH_EXECUTE = 0x2u,
  36. MH_FVMLIB = 0x3u,
  37. MH_CORE = 0x4u,
  38. MH_PRELOAD = 0x5u,
  39. MH_DYLIB = 0x6u,
  40. MH_DYLINKER = 0x7u,
  41. MH_BUNDLE = 0x8u,
  42. MH_DYLIB_STUB = 0x9u,
  43. MH_DSYM = 0xAu,
  44. MH_KEXT_BUNDLE = 0xBu
  45. };
  46. enum {
  47. // Constant bits for the "flags" field in llvm::MachO::mach_header and
  48. // llvm::MachO::mach_header_64
  49. MH_NOUNDEFS = 0x00000001u,
  50. MH_INCRLINK = 0x00000002u,
  51. MH_DYLDLINK = 0x00000004u,
  52. MH_BINDATLOAD = 0x00000008u,
  53. MH_PREBOUND = 0x00000010u,
  54. MH_SPLIT_SEGS = 0x00000020u,
  55. MH_LAZY_INIT = 0x00000040u,
  56. MH_TWOLEVEL = 0x00000080u,
  57. MH_FORCE_FLAT = 0x00000100u,
  58. MH_NOMULTIDEFS = 0x00000200u,
  59. MH_NOFIXPREBINDING = 0x00000400u,
  60. MH_PREBINDABLE = 0x00000800u,
  61. MH_ALLMODSBOUND = 0x00001000u,
  62. MH_SUBSECTIONS_VIA_SYMBOLS = 0x00002000u,
  63. MH_CANONICAL = 0x00004000u,
  64. MH_WEAK_DEFINES = 0x00008000u,
  65. MH_BINDS_TO_WEAK = 0x00010000u,
  66. MH_ALLOW_STACK_EXECUTION = 0x00020000u,
  67. MH_ROOT_SAFE = 0x00040000u,
  68. MH_SETUID_SAFE = 0x00080000u,
  69. MH_NO_REEXPORTED_DYLIBS = 0x00100000u,
  70. MH_PIE = 0x00200000u,
  71. MH_DEAD_STRIPPABLE_DYLIB = 0x00400000u,
  72. MH_HAS_TLV_DESCRIPTORS = 0x00800000u,
  73. MH_NO_HEAP_EXECUTION = 0x01000000u,
  74. MH_APP_EXTENSION_SAFE = 0x02000000u
  75. };
  76. enum : uint32_t {
  77. // Flags for the "cmd" field in llvm::MachO::load_command
  78. LC_REQ_DYLD = 0x80000000u
  79. };
  80. enum LoadCommandType : uint32_t {
  81. // Constants for the "cmd" field in llvm::MachO::load_command
  82. LC_SEGMENT = 0x00000001u,
  83. LC_SYMTAB = 0x00000002u,
  84. LC_SYMSEG = 0x00000003u,
  85. LC_THREAD = 0x00000004u,
  86. LC_UNIXTHREAD = 0x00000005u,
  87. LC_LOADFVMLIB = 0x00000006u,
  88. LC_IDFVMLIB = 0x00000007u,
  89. LC_IDENT = 0x00000008u,
  90. LC_FVMFILE = 0x00000009u,
  91. LC_PREPAGE = 0x0000000Au,
  92. LC_DYSYMTAB = 0x0000000Bu,
  93. LC_LOAD_DYLIB = 0x0000000Cu,
  94. LC_ID_DYLIB = 0x0000000Du,
  95. LC_LOAD_DYLINKER = 0x0000000Eu,
  96. LC_ID_DYLINKER = 0x0000000Fu,
  97. LC_PREBOUND_DYLIB = 0x00000010u,
  98. LC_ROUTINES = 0x00000011u,
  99. LC_SUB_FRAMEWORK = 0x00000012u,
  100. LC_SUB_UMBRELLA = 0x00000013u,
  101. LC_SUB_CLIENT = 0x00000014u,
  102. LC_SUB_LIBRARY = 0x00000015u,
  103. LC_TWOLEVEL_HINTS = 0x00000016u,
  104. LC_PREBIND_CKSUM = 0x00000017u,
  105. LC_LOAD_WEAK_DYLIB = 0x80000018u,
  106. LC_SEGMENT_64 = 0x00000019u,
  107. LC_ROUTINES_64 = 0x0000001Au,
  108. LC_UUID = 0x0000001Bu,
  109. LC_RPATH = 0x8000001Cu,
  110. LC_CODE_SIGNATURE = 0x0000001Du,
  111. LC_SEGMENT_SPLIT_INFO = 0x0000001Eu,
  112. LC_REEXPORT_DYLIB = 0x8000001Fu,
  113. LC_LAZY_LOAD_DYLIB = 0x00000020u,
  114. LC_ENCRYPTION_INFO = 0x00000021u,
  115. LC_DYLD_INFO = 0x00000022u,
  116. LC_DYLD_INFO_ONLY = 0x80000022u,
  117. LC_LOAD_UPWARD_DYLIB = 0x80000023u,
  118. LC_VERSION_MIN_MACOSX = 0x00000024u,
  119. LC_VERSION_MIN_IPHONEOS = 0x00000025u,
  120. LC_FUNCTION_STARTS = 0x00000026u,
  121. LC_DYLD_ENVIRONMENT = 0x00000027u,
  122. LC_MAIN = 0x80000028u,
  123. LC_DATA_IN_CODE = 0x00000029u,
  124. LC_SOURCE_VERSION = 0x0000002Au,
  125. LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu,
  126. LC_ENCRYPTION_INFO_64 = 0x0000002Cu,
  127. LC_LINKER_OPTION = 0x0000002Du,
  128. LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
  129. };
  130. enum : uint32_t {
  131. // Constant bits for the "flags" field in llvm::MachO::segment_command
  132. SG_HIGHVM = 0x1u,
  133. SG_FVMLIB = 0x2u,
  134. SG_NORELOC = 0x4u,
  135. SG_PROTECTED_VERSION_1 = 0x8u,
  136. // Constant masks for the "flags" field in llvm::MachO::section and
  137. // llvm::MachO::section_64
  138. SECTION_TYPE = 0x000000ffu, // SECTION_TYPE
  139. SECTION_ATTRIBUTES = 0xffffff00u, // SECTION_ATTRIBUTES
  140. SECTION_ATTRIBUTES_USR = 0xff000000u, // SECTION_ATTRIBUTES_USR
  141. SECTION_ATTRIBUTES_SYS = 0x00ffff00u // SECTION_ATTRIBUTES_SYS
  142. };
  143. /// These are the section type and attributes fields. A MachO section can
  144. /// have only one Type, but can have any of the attributes specified.
  145. enum SectionType : uint32_t {
  146. // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
  147. // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
  148. /// S_REGULAR - Regular section.
  149. S_REGULAR = 0x00u,
  150. /// S_ZEROFILL - Zero fill on demand section.
  151. S_ZEROFILL = 0x01u,
  152. /// S_CSTRING_LITERALS - Section with literal C strings.
  153. S_CSTRING_LITERALS = 0x02u,
  154. /// S_4BYTE_LITERALS - Section with 4 byte literals.
  155. S_4BYTE_LITERALS = 0x03u,
  156. /// S_8BYTE_LITERALS - Section with 8 byte literals.
  157. S_8BYTE_LITERALS = 0x04u,
  158. /// S_LITERAL_POINTERS - Section with pointers to literals.
  159. S_LITERAL_POINTERS = 0x05u,
  160. /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
  161. S_NON_LAZY_SYMBOL_POINTERS = 0x06u,
  162. /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
  163. S_LAZY_SYMBOL_POINTERS = 0x07u,
  164. /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
  165. /// the Reserved2 field.
  166. S_SYMBOL_STUBS = 0x08u,
  167. /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
  168. /// initialization.
  169. S_MOD_INIT_FUNC_POINTERS = 0x09u,
  170. /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
  171. /// termination.
  172. S_MOD_TERM_FUNC_POINTERS = 0x0au,
  173. /// S_COALESCED - Section contains symbols that are to be coalesced.
  174. S_COALESCED = 0x0bu,
  175. /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
  176. /// gigabytes).
  177. S_GB_ZEROFILL = 0x0cu,
  178. /// S_INTERPOSING - Section with only pairs of function pointers for
  179. /// interposing.
  180. S_INTERPOSING = 0x0du,
  181. /// S_16BYTE_LITERALS - Section with only 16 byte literals.
  182. S_16BYTE_LITERALS = 0x0eu,
  183. /// S_DTRACE_DOF - Section contains DTrace Object Format.
  184. S_DTRACE_DOF = 0x0fu,
  185. /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
  186. /// lazy loaded dylibs.
  187. S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10u,
  188. /// S_THREAD_LOCAL_REGULAR - Thread local data section.
  189. S_THREAD_LOCAL_REGULAR = 0x11u,
  190. /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
  191. S_THREAD_LOCAL_ZEROFILL = 0x12u,
  192. /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
  193. /// structure data.
  194. S_THREAD_LOCAL_VARIABLES = 0x13u,
  195. /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
  196. /// local structures.
  197. S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14u,
  198. /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
  199. /// variable initialization pointers to functions.
  200. S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u,
  201. LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
  202. };
  203. enum : uint32_t {
  204. // Constant masks for the "flags[31:24]" field in llvm::MachO::section and
  205. // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR)
  206. /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
  207. /// instructions.
  208. S_ATTR_PURE_INSTRUCTIONS = 0x80000000u,
  209. /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
  210. /// in a ranlib table of contents.
  211. S_ATTR_NO_TOC = 0x40000000u,
  212. /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
  213. /// in files with the MY_DYLDLINK flag.
  214. S_ATTR_STRIP_STATIC_SYMS = 0x20000000u,
  215. /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
  216. S_ATTR_NO_DEAD_STRIP = 0x10000000u,
  217. /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
  218. S_ATTR_LIVE_SUPPORT = 0x08000000u,
  219. /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
  220. /// dyld.
  221. S_ATTR_SELF_MODIFYING_CODE = 0x04000000u,
  222. /// S_ATTR_DEBUG - A debug section.
  223. S_ATTR_DEBUG = 0x02000000u,
  224. // Constant masks for the "flags[23:8]" field in llvm::MachO::section and
  225. // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS)
  226. /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
  227. S_ATTR_SOME_INSTRUCTIONS = 0x00000400u,
  228. /// S_ATTR_EXT_RELOC - Section has external relocation entries.
  229. S_ATTR_EXT_RELOC = 0x00000200u,
  230. /// S_ATTR_LOC_RELOC - Section has local relocation entries.
  231. S_ATTR_LOC_RELOC = 0x00000100u,
  232. // Constant masks for the value of an indirect symbol in an indirect
  233. // symbol table
  234. INDIRECT_SYMBOL_LOCAL = 0x80000000u,
  235. INDIRECT_SYMBOL_ABS = 0x40000000u
  236. };
  237. enum DataRegionType {
  238. // Constants for the "kind" field in a data_in_code_entry structure
  239. DICE_KIND_DATA = 1u,
  240. DICE_KIND_JUMP_TABLE8 = 2u,
  241. DICE_KIND_JUMP_TABLE16 = 3u,
  242. DICE_KIND_JUMP_TABLE32 = 4u,
  243. DICE_KIND_ABS_JUMP_TABLE32 = 5u
  244. };
  245. enum RebaseType {
  246. REBASE_TYPE_POINTER = 1u,
  247. REBASE_TYPE_TEXT_ABSOLUTE32 = 2u,
  248. REBASE_TYPE_TEXT_PCREL32 = 3u
  249. };
  250. enum {
  251. REBASE_OPCODE_MASK = 0xF0u,
  252. REBASE_IMMEDIATE_MASK = 0x0Fu
  253. };
  254. enum RebaseOpcode {
  255. REBASE_OPCODE_DONE = 0x00u,
  256. REBASE_OPCODE_SET_TYPE_IMM = 0x10u,
  257. REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x20u,
  258. REBASE_OPCODE_ADD_ADDR_ULEB = 0x30u,
  259. REBASE_OPCODE_ADD_ADDR_IMM_SCALED = 0x40u,
  260. REBASE_OPCODE_DO_REBASE_IMM_TIMES = 0x50u,
  261. REBASE_OPCODE_DO_REBASE_ULEB_TIMES = 0x60u,
  262. REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB = 0x70u,
  263. REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
  264. };
  265. enum BindType {
  266. BIND_TYPE_POINTER = 1u,
  267. BIND_TYPE_TEXT_ABSOLUTE32 = 2u,
  268. BIND_TYPE_TEXT_PCREL32 = 3u
  269. };
  270. enum BindSpecialDylib {
  271. BIND_SPECIAL_DYLIB_SELF = 0,
  272. BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1,
  273. BIND_SPECIAL_DYLIB_FLAT_LOOKUP = -2
  274. };
  275. enum {
  276. BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1u,
  277. BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u,
  278. BIND_OPCODE_MASK = 0xF0u,
  279. BIND_IMMEDIATE_MASK = 0x0Fu
  280. };
  281. enum BindOpcode {
  282. BIND_OPCODE_DONE = 0x00u,
  283. BIND_OPCODE_SET_DYLIB_ORDINAL_IMM = 0x10u,
  284. BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB = 0x20u,
  285. BIND_OPCODE_SET_DYLIB_SPECIAL_IMM = 0x30u,
  286. BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u,
  287. BIND_OPCODE_SET_TYPE_IMM = 0x50u,
  288. BIND_OPCODE_SET_ADDEND_SLEB = 0x60u,
  289. BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x70u,
  290. BIND_OPCODE_ADD_ADDR_ULEB = 0x80u,
  291. BIND_OPCODE_DO_BIND = 0x90u,
  292. BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB = 0xA0u,
  293. BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u,
  294. BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u
  295. };
  296. enum {
  297. EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03u,
  298. EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04u,
  299. EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08u,
  300. EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10u
  301. };
  302. enum ExportSymbolKind {
  303. EXPORT_SYMBOL_FLAGS_KIND_REGULAR = 0x00u,
  304. EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL = 0x01u,
  305. EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE = 0x02u
  306. };
  307. enum {
  308. // Constant masks for the "n_type" field in llvm::MachO::nlist and
  309. // llvm::MachO::nlist_64
  310. N_STAB = 0xe0,
  311. N_PEXT = 0x10,
  312. N_TYPE = 0x0e,
  313. N_EXT = 0x01
  314. };
  315. enum NListType {
  316. // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
  317. // llvm::MachO::nlist_64
  318. N_UNDF = 0x0u,
  319. N_ABS = 0x2u,
  320. N_SECT = 0xeu,
  321. N_PBUD = 0xcu,
  322. N_INDR = 0xau
  323. };
  324. enum SectionOrdinal {
  325. // Constants for the "n_sect" field in llvm::MachO::nlist and
  326. // llvm::MachO::nlist_64
  327. NO_SECT = 0u,
  328. MAX_SECT = 0xffu
  329. };
  330. enum {
  331. // Constant masks for the "n_desc" field in llvm::MachO::nlist and
  332. // llvm::MachO::nlist_64
  333. // The low 3 bits are the for the REFERENCE_TYPE.
  334. REFERENCE_TYPE = 0x7,
  335. REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0,
  336. REFERENCE_FLAG_UNDEFINED_LAZY = 1,
  337. REFERENCE_FLAG_DEFINED = 2,
  338. REFERENCE_FLAG_PRIVATE_DEFINED = 3,
  339. REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY = 4,
  340. REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY = 5,
  341. // Flag bits (some overlap with the library ordinal bits).
  342. N_ARM_THUMB_DEF = 0x0008u,
  343. REFERENCED_DYNAMICALLY = 0x0010u,
  344. N_NO_DEAD_STRIP = 0x0020u,
  345. N_WEAK_REF = 0x0040u,
  346. N_WEAK_DEF = 0x0080u,
  347. N_SYMBOL_RESOLVER = 0x0100u,
  348. N_ALT_ENTRY = 0x0200u,
  349. // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL()
  350. // as these are in the top 8 bits.
  351. SELF_LIBRARY_ORDINAL = 0x0,
  352. MAX_LIBRARY_ORDINAL = 0xfd,
  353. DYNAMIC_LOOKUP_ORDINAL = 0xfe,
  354. EXECUTABLE_ORDINAL = 0xff
  355. };
  356. enum StabType {
  357. // Constant values for the "n_type" field in llvm::MachO::nlist and
  358. // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
  359. N_GSYM = 0x20u,
  360. N_FNAME = 0x22u,
  361. N_FUN = 0x24u,
  362. N_STSYM = 0x26u,
  363. N_LCSYM = 0x28u,
  364. N_BNSYM = 0x2Eu,
  365. N_PC = 0x30u,
  366. N_AST = 0x32u,
  367. N_OPT = 0x3Cu,
  368. N_RSYM = 0x40u,
  369. N_SLINE = 0x44u,
  370. N_ENSYM = 0x4Eu,
  371. N_SSYM = 0x60u,
  372. N_SO = 0x64u,
  373. N_OSO = 0x66u,
  374. N_LSYM = 0x80u,
  375. N_BINCL = 0x82u,
  376. N_SOL = 0x84u,
  377. N_PARAMS = 0x86u,
  378. N_VERSION = 0x88u,
  379. N_OLEVEL = 0x8Au,
  380. N_PSYM = 0xA0u,
  381. N_EINCL = 0xA2u,
  382. N_ENTRY = 0xA4u,
  383. N_LBRAC = 0xC0u,
  384. N_EXCL = 0xC2u,
  385. N_RBRAC = 0xE0u,
  386. N_BCOMM = 0xE2u,
  387. N_ECOMM = 0xE4u,
  388. N_ECOML = 0xE8u,
  389. N_LENG = 0xFEu
  390. };
  391. enum : uint32_t {
  392. // Constant values for the r_symbolnum field in an
  393. // llvm::MachO::relocation_info structure when r_extern is 0.
  394. R_ABS = 0,
  395. // Constant bits for the r_address field in an
  396. // llvm::MachO::relocation_info structure.
  397. R_SCATTERED = 0x80000000
  398. };
  399. enum RelocationInfoType {
  400. // Constant values for the r_type field in an
  401. // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
  402. // structure.
  403. GENERIC_RELOC_VANILLA = 0,
  404. GENERIC_RELOC_PAIR = 1,
  405. GENERIC_RELOC_SECTDIFF = 2,
  406. GENERIC_RELOC_PB_LA_PTR = 3,
  407. GENERIC_RELOC_LOCAL_SECTDIFF = 4,
  408. GENERIC_RELOC_TLV = 5,
  409. // Constant values for the r_type field in a PowerPC architecture
  410. // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
  411. // structure.
  412. PPC_RELOC_VANILLA = GENERIC_RELOC_VANILLA,
  413. PPC_RELOC_PAIR = GENERIC_RELOC_PAIR,
  414. PPC_RELOC_BR14 = 2,
  415. PPC_RELOC_BR24 = 3,
  416. PPC_RELOC_HI16 = 4,
  417. PPC_RELOC_LO16 = 5,
  418. PPC_RELOC_HA16 = 6,
  419. PPC_RELOC_LO14 = 7,
  420. PPC_RELOC_SECTDIFF = 8,
  421. PPC_RELOC_PB_LA_PTR = 9,
  422. PPC_RELOC_HI16_SECTDIFF = 10,
  423. PPC_RELOC_LO16_SECTDIFF = 11,
  424. PPC_RELOC_HA16_SECTDIFF = 12,
  425. PPC_RELOC_JBSR = 13,
  426. PPC_RELOC_LO14_SECTDIFF = 14,
  427. PPC_RELOC_LOCAL_SECTDIFF = 15,
  428. // Constant values for the r_type field in an ARM architecture
  429. // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
  430. // structure.
  431. ARM_RELOC_VANILLA = GENERIC_RELOC_VANILLA,
  432. ARM_RELOC_PAIR = GENERIC_RELOC_PAIR,
  433. ARM_RELOC_SECTDIFF = GENERIC_RELOC_SECTDIFF,
  434. ARM_RELOC_LOCAL_SECTDIFF = 3,
  435. ARM_RELOC_PB_LA_PTR = 4,
  436. ARM_RELOC_BR24 = 5,
  437. ARM_THUMB_RELOC_BR22 = 6,
  438. ARM_THUMB_32BIT_BRANCH = 7, // obsolete
  439. ARM_RELOC_HALF = 8,
  440. ARM_RELOC_HALF_SECTDIFF = 9,
  441. // Constant values for the r_type field in an ARM64 architecture
  442. // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
  443. // structure.
  444. // For pointers.
  445. ARM64_RELOC_UNSIGNED = 0,
  446. // Must be followed by an ARM64_RELOC_UNSIGNED
  447. ARM64_RELOC_SUBTRACTOR = 1,
  448. // A B/BL instruction with 26-bit displacement.
  449. ARM64_RELOC_BRANCH26 = 2,
  450. // PC-rel distance to page of target.
  451. ARM64_RELOC_PAGE21 = 3,
  452. // Offset within page, scaled by r_length.
  453. ARM64_RELOC_PAGEOFF12 = 4,
  454. // PC-rel distance to page of GOT slot.
  455. ARM64_RELOC_GOT_LOAD_PAGE21 = 5,
  456. // Offset within page of GOT slot, scaled by r_length.
  457. ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6,
  458. // For pointers to GOT slots.
  459. ARM64_RELOC_POINTER_TO_GOT = 7,
  460. // PC-rel distance to page of TLVP slot.
  461. ARM64_RELOC_TLVP_LOAD_PAGE21 = 8,
  462. // Offset within page of TLVP slot, scaled by r_length.
  463. ARM64_RELOC_TLVP_LOAD_PAGEOFF12 = 9,
  464. // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
  465. ARM64_RELOC_ADDEND = 10,
  466. // Constant values for the r_type field in an x86_64 architecture
  467. // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
  468. // structure
  469. X86_64_RELOC_UNSIGNED = 0,
  470. X86_64_RELOC_SIGNED = 1,
  471. X86_64_RELOC_BRANCH = 2,
  472. X86_64_RELOC_GOT_LOAD = 3,
  473. X86_64_RELOC_GOT = 4,
  474. X86_64_RELOC_SUBTRACTOR = 5,
  475. X86_64_RELOC_SIGNED_1 = 6,
  476. X86_64_RELOC_SIGNED_2 = 7,
  477. X86_64_RELOC_SIGNED_4 = 8,
  478. X86_64_RELOC_TLV = 9
  479. };
  480. // Values for segment_command.initprot.
  481. // From <mach/vm_prot.h>
  482. enum {
  483. VM_PROT_READ = 0x1,
  484. VM_PROT_WRITE = 0x2,
  485. VM_PROT_EXECUTE = 0x4
  486. };
  487. // Structs from <mach-o/loader.h>
  488. struct mach_header {
  489. uint32_t magic;
  490. uint32_t cputype;
  491. uint32_t cpusubtype;
  492. uint32_t filetype;
  493. uint32_t ncmds;
  494. uint32_t sizeofcmds;
  495. uint32_t flags;
  496. };
  497. struct mach_header_64 {
  498. uint32_t magic;
  499. uint32_t cputype;
  500. uint32_t cpusubtype;
  501. uint32_t filetype;
  502. uint32_t ncmds;
  503. uint32_t sizeofcmds;
  504. uint32_t flags;
  505. uint32_t reserved;
  506. };
  507. struct load_command {
  508. uint32_t cmd;
  509. uint32_t cmdsize;
  510. };
  511. struct segment_command {
  512. uint32_t cmd;
  513. uint32_t cmdsize;
  514. char segname[16];
  515. uint32_t vmaddr;
  516. uint32_t vmsize;
  517. uint32_t fileoff;
  518. uint32_t filesize;
  519. uint32_t maxprot;
  520. uint32_t initprot;
  521. uint32_t nsects;
  522. uint32_t flags;
  523. };
  524. struct segment_command_64 {
  525. uint32_t cmd;
  526. uint32_t cmdsize;
  527. char segname[16];
  528. uint64_t vmaddr;
  529. uint64_t vmsize;
  530. uint64_t fileoff;
  531. uint64_t filesize;
  532. uint32_t maxprot;
  533. uint32_t initprot;
  534. uint32_t nsects;
  535. uint32_t flags;
  536. };
  537. struct section {
  538. char sectname[16];
  539. char segname[16];
  540. uint32_t addr;
  541. uint32_t size;
  542. uint32_t offset;
  543. uint32_t align;
  544. uint32_t reloff;
  545. uint32_t nreloc;
  546. uint32_t flags;
  547. uint32_t reserved1;
  548. uint32_t reserved2;
  549. };
  550. struct section_64 {
  551. char sectname[16];
  552. char segname[16];
  553. uint64_t addr;
  554. uint64_t size;
  555. uint32_t offset;
  556. uint32_t align;
  557. uint32_t reloff;
  558. uint32_t nreloc;
  559. uint32_t flags;
  560. uint32_t reserved1;
  561. uint32_t reserved2;
  562. uint32_t reserved3;
  563. };
  564. struct fvmlib {
  565. uint32_t name;
  566. uint32_t minor_version;
  567. uint32_t header_addr;
  568. };
  569. struct fvmlib_command {
  570. uint32_t cmd;
  571. uint32_t cmdsize;
  572. struct fvmlib fvmlib;
  573. };
  574. struct dylib {
  575. uint32_t name;
  576. uint32_t timestamp;
  577. uint32_t current_version;
  578. uint32_t compatibility_version;
  579. };
  580. struct dylib_command {
  581. uint32_t cmd;
  582. uint32_t cmdsize;
  583. struct dylib dylib;
  584. };
  585. struct sub_framework_command {
  586. uint32_t cmd;
  587. uint32_t cmdsize;
  588. uint32_t umbrella;
  589. };
  590. struct sub_client_command {
  591. uint32_t cmd;
  592. uint32_t cmdsize;
  593. uint32_t client;
  594. };
  595. struct sub_umbrella_command {
  596. uint32_t cmd;
  597. uint32_t cmdsize;
  598. uint32_t sub_umbrella;
  599. };
  600. struct sub_library_command {
  601. uint32_t cmd;
  602. uint32_t cmdsize;
  603. uint32_t sub_library;
  604. };
  605. struct prebound_dylib_command {
  606. uint32_t cmd;
  607. uint32_t cmdsize;
  608. uint32_t name;
  609. uint32_t nmodules;
  610. uint32_t linked_modules;
  611. };
  612. struct dylinker_command {
  613. uint32_t cmd;
  614. uint32_t cmdsize;
  615. uint32_t name;
  616. };
  617. struct thread_command {
  618. uint32_t cmd;
  619. uint32_t cmdsize;
  620. };
  621. struct routines_command {
  622. uint32_t cmd;
  623. uint32_t cmdsize;
  624. uint32_t init_address;
  625. uint32_t init_module;
  626. uint32_t reserved1;
  627. uint32_t reserved2;
  628. uint32_t reserved3;
  629. uint32_t reserved4;
  630. uint32_t reserved5;
  631. uint32_t reserved6;
  632. };
  633. struct routines_command_64 {
  634. uint32_t cmd;
  635. uint32_t cmdsize;
  636. uint64_t init_address;
  637. uint64_t init_module;
  638. uint64_t reserved1;
  639. uint64_t reserved2;
  640. uint64_t reserved3;
  641. uint64_t reserved4;
  642. uint64_t reserved5;
  643. uint64_t reserved6;
  644. };
  645. struct symtab_command {
  646. uint32_t cmd;
  647. uint32_t cmdsize;
  648. uint32_t symoff;
  649. uint32_t nsyms;
  650. uint32_t stroff;
  651. uint32_t strsize;
  652. };
  653. struct dysymtab_command {
  654. uint32_t cmd;
  655. uint32_t cmdsize;
  656. uint32_t ilocalsym;
  657. uint32_t nlocalsym;
  658. uint32_t iextdefsym;
  659. uint32_t nextdefsym;
  660. uint32_t iundefsym;
  661. uint32_t nundefsym;
  662. uint32_t tocoff;
  663. uint32_t ntoc;
  664. uint32_t modtaboff;
  665. uint32_t nmodtab;
  666. uint32_t extrefsymoff;
  667. uint32_t nextrefsyms;
  668. uint32_t indirectsymoff;
  669. uint32_t nindirectsyms;
  670. uint32_t extreloff;
  671. uint32_t nextrel;
  672. uint32_t locreloff;
  673. uint32_t nlocrel;
  674. };
  675. struct dylib_table_of_contents {
  676. uint32_t symbol_index;
  677. uint32_t module_index;
  678. };
  679. struct dylib_module {
  680. uint32_t module_name;
  681. uint32_t iextdefsym;
  682. uint32_t nextdefsym;
  683. uint32_t irefsym;
  684. uint32_t nrefsym;
  685. uint32_t ilocalsym;
  686. uint32_t nlocalsym;
  687. uint32_t iextrel;
  688. uint32_t nextrel;
  689. uint32_t iinit_iterm;
  690. uint32_t ninit_nterm;
  691. uint32_t objc_module_info_addr;
  692. uint32_t objc_module_info_size;
  693. };
  694. struct dylib_module_64 {
  695. uint32_t module_name;
  696. uint32_t iextdefsym;
  697. uint32_t nextdefsym;
  698. uint32_t irefsym;
  699. uint32_t nrefsym;
  700. uint32_t ilocalsym;
  701. uint32_t nlocalsym;
  702. uint32_t iextrel;
  703. uint32_t nextrel;
  704. uint32_t iinit_iterm;
  705. uint32_t ninit_nterm;
  706. uint32_t objc_module_info_size;
  707. uint64_t objc_module_info_addr;
  708. };
  709. struct dylib_reference {
  710. uint32_t isym:24,
  711. flags:8;
  712. };
  713. struct twolevel_hints_command {
  714. uint32_t cmd;
  715. uint32_t cmdsize;
  716. uint32_t offset;
  717. uint32_t nhints;
  718. };
  719. struct twolevel_hint {
  720. uint32_t isub_image:8,
  721. itoc:24;
  722. };
  723. struct prebind_cksum_command {
  724. uint32_t cmd;
  725. uint32_t cmdsize;
  726. uint32_t cksum;
  727. };
  728. struct uuid_command {
  729. uint32_t cmd;
  730. uint32_t cmdsize;
  731. uint8_t uuid[16];
  732. };
  733. struct rpath_command {
  734. uint32_t cmd;
  735. uint32_t cmdsize;
  736. uint32_t path;
  737. };
  738. struct linkedit_data_command {
  739. uint32_t cmd;
  740. uint32_t cmdsize;
  741. uint32_t dataoff;
  742. uint32_t datasize;
  743. };
  744. struct data_in_code_entry {
  745. uint32_t offset;
  746. uint16_t length;
  747. uint16_t kind;
  748. };
  749. struct source_version_command {
  750. uint32_t cmd;
  751. uint32_t cmdsize;
  752. uint64_t version;
  753. };
  754. struct encryption_info_command {
  755. uint32_t cmd;
  756. uint32_t cmdsize;
  757. uint32_t cryptoff;
  758. uint32_t cryptsize;
  759. uint32_t cryptid;
  760. };
  761. struct encryption_info_command_64 {
  762. uint32_t cmd;
  763. uint32_t cmdsize;
  764. uint32_t cryptoff;
  765. uint32_t cryptsize;
  766. uint32_t cryptid;
  767. uint32_t pad;
  768. };
  769. struct version_min_command {
  770. uint32_t cmd; // LC_VERSION_MIN_MACOSX or
  771. // LC_VERSION_MIN_IPHONEOS
  772. uint32_t cmdsize; // sizeof(struct version_min_command)
  773. uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
  774. uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
  775. };
  776. struct dyld_info_command {
  777. uint32_t cmd;
  778. uint32_t cmdsize;
  779. uint32_t rebase_off;
  780. uint32_t rebase_size;
  781. uint32_t bind_off;
  782. uint32_t bind_size;
  783. uint32_t weak_bind_off;
  784. uint32_t weak_bind_size;
  785. uint32_t lazy_bind_off;
  786. uint32_t lazy_bind_size;
  787. uint32_t export_off;
  788. uint32_t export_size;
  789. };
  790. struct linker_option_command {
  791. uint32_t cmd;
  792. uint32_t cmdsize;
  793. uint32_t count;
  794. };
  795. struct symseg_command {
  796. uint32_t cmd;
  797. uint32_t cmdsize;
  798. uint32_t offset;
  799. uint32_t size;
  800. };
  801. struct ident_command {
  802. uint32_t cmd;
  803. uint32_t cmdsize;
  804. };
  805. struct fvmfile_command {
  806. uint32_t cmd;
  807. uint32_t cmdsize;
  808. uint32_t name;
  809. uint32_t header_addr;
  810. };
  811. struct tlv_descriptor_32 {
  812. uint32_t thunk;
  813. uint32_t key;
  814. uint32_t offset;
  815. };
  816. struct tlv_descriptor_64 {
  817. uint64_t thunk;
  818. uint64_t key;
  819. uint64_t offset;
  820. };
  821. struct tlv_descriptor {
  822. uintptr_t thunk;
  823. uintptr_t key;
  824. uintptr_t offset;
  825. };
  826. struct entry_point_command {
  827. uint32_t cmd;
  828. uint32_t cmdsize;
  829. uint64_t entryoff;
  830. uint64_t stacksize;
  831. };
  832. // Structs from <mach-o/fat.h>
  833. struct fat_header {
  834. uint32_t magic;
  835. uint32_t nfat_arch;
  836. };
  837. struct fat_arch {
  838. uint32_t cputype;
  839. uint32_t cpusubtype;
  840. uint32_t offset;
  841. uint32_t size;
  842. uint32_t align;
  843. };
  844. // Structs from <mach-o/reloc.h>
  845. struct relocation_info {
  846. int32_t r_address;
  847. uint32_t r_symbolnum:24,
  848. r_pcrel:1,
  849. r_length:2,
  850. r_extern:1,
  851. r_type:4;
  852. };
  853. struct scattered_relocation_info {
  854. #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
  855. uint32_t r_scattered:1,
  856. r_pcrel:1,
  857. r_length:2,
  858. r_type:4,
  859. r_address:24;
  860. #else
  861. uint32_t r_address:24,
  862. r_type:4,
  863. r_length:2,
  864. r_pcrel:1,
  865. r_scattered:1;
  866. #endif
  867. int32_t r_value;
  868. };
  869. // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
  870. struct any_relocation_info {
  871. uint32_t r_word0, r_word1;
  872. };
  873. // Structs from <mach-o/nlist.h>
  874. struct nlist_base {
  875. uint32_t n_strx;
  876. uint8_t n_type;
  877. uint8_t n_sect;
  878. uint16_t n_desc;
  879. };
  880. struct nlist {
  881. uint32_t n_strx;
  882. uint8_t n_type;
  883. uint8_t n_sect;
  884. int16_t n_desc;
  885. uint32_t n_value;
  886. };
  887. struct nlist_64 {
  888. uint32_t n_strx;
  889. uint8_t n_type;
  890. uint8_t n_sect;
  891. uint16_t n_desc;
  892. uint64_t n_value;
  893. };
  894. // Byte order swapping functions for MachO structs
  895. inline void swapStruct(mach_header &mh) {
  896. sys::swapByteOrder(mh.magic);
  897. sys::swapByteOrder(mh.cputype);
  898. sys::swapByteOrder(mh.cpusubtype);
  899. sys::swapByteOrder(mh.filetype);
  900. sys::swapByteOrder(mh.ncmds);
  901. sys::swapByteOrder(mh.sizeofcmds);
  902. sys::swapByteOrder(mh.flags);
  903. }
  904. inline void swapStruct(mach_header_64 &H) {
  905. sys::swapByteOrder(H.magic);
  906. sys::swapByteOrder(H.cputype);
  907. sys::swapByteOrder(H.cpusubtype);
  908. sys::swapByteOrder(H.filetype);
  909. sys::swapByteOrder(H.ncmds);
  910. sys::swapByteOrder(H.sizeofcmds);
  911. sys::swapByteOrder(H.flags);
  912. sys::swapByteOrder(H.reserved);
  913. }
  914. inline void swapStruct(load_command &lc) {
  915. sys::swapByteOrder(lc.cmd);
  916. sys::swapByteOrder(lc.cmdsize);
  917. }
  918. inline void swapStruct(symtab_command &lc) {
  919. sys::swapByteOrder(lc.cmd);
  920. sys::swapByteOrder(lc.cmdsize);
  921. sys::swapByteOrder(lc.symoff);
  922. sys::swapByteOrder(lc.nsyms);
  923. sys::swapByteOrder(lc.stroff);
  924. sys::swapByteOrder(lc.strsize);
  925. }
  926. inline void swapStruct(segment_command_64 &seg) {
  927. sys::swapByteOrder(seg.cmd);
  928. sys::swapByteOrder(seg.cmdsize);
  929. sys::swapByteOrder(seg.vmaddr);
  930. sys::swapByteOrder(seg.vmsize);
  931. sys::swapByteOrder(seg.fileoff);
  932. sys::swapByteOrder(seg.filesize);
  933. sys::swapByteOrder(seg.maxprot);
  934. sys::swapByteOrder(seg.initprot);
  935. sys::swapByteOrder(seg.nsects);
  936. sys::swapByteOrder(seg.flags);
  937. }
  938. inline void swapStruct(segment_command &seg) {
  939. sys::swapByteOrder(seg.cmd);
  940. sys::swapByteOrder(seg.cmdsize);
  941. sys::swapByteOrder(seg.vmaddr);
  942. sys::swapByteOrder(seg.vmsize);
  943. sys::swapByteOrder(seg.fileoff);
  944. sys::swapByteOrder(seg.filesize);
  945. sys::swapByteOrder(seg.maxprot);
  946. sys::swapByteOrder(seg.initprot);
  947. sys::swapByteOrder(seg.nsects);
  948. sys::swapByteOrder(seg.flags);
  949. }
  950. inline void swapStruct(section_64 &sect) {
  951. sys::swapByteOrder(sect.addr);
  952. sys::swapByteOrder(sect.size);
  953. sys::swapByteOrder(sect.offset);
  954. sys::swapByteOrder(sect.align);
  955. sys::swapByteOrder(sect.reloff);
  956. sys::swapByteOrder(sect.nreloc);
  957. sys::swapByteOrder(sect.flags);
  958. sys::swapByteOrder(sect.reserved1);
  959. sys::swapByteOrder(sect.reserved2);
  960. }
  961. inline void swapStruct(section &sect) {
  962. sys::swapByteOrder(sect.addr);
  963. sys::swapByteOrder(sect.size);
  964. sys::swapByteOrder(sect.offset);
  965. sys::swapByteOrder(sect.align);
  966. sys::swapByteOrder(sect.reloff);
  967. sys::swapByteOrder(sect.nreloc);
  968. sys::swapByteOrder(sect.flags);
  969. sys::swapByteOrder(sect.reserved1);
  970. sys::swapByteOrder(sect.reserved2);
  971. }
  972. inline void swapStruct(dyld_info_command &info) {
  973. sys::swapByteOrder(info.cmd);
  974. sys::swapByteOrder(info.cmdsize);
  975. sys::swapByteOrder(info.rebase_off);
  976. sys::swapByteOrder(info.rebase_size);
  977. sys::swapByteOrder(info.bind_off);
  978. sys::swapByteOrder(info.bind_size);
  979. sys::swapByteOrder(info.weak_bind_off);
  980. sys::swapByteOrder(info.weak_bind_size);
  981. sys::swapByteOrder(info.lazy_bind_off);
  982. sys::swapByteOrder(info.lazy_bind_size);
  983. sys::swapByteOrder(info.export_off);
  984. sys::swapByteOrder(info.export_size);
  985. }
  986. inline void swapStruct(dylib_command &d) {
  987. sys::swapByteOrder(d.cmd);
  988. sys::swapByteOrder(d.cmdsize);
  989. sys::swapByteOrder(d.dylib.name);
  990. sys::swapByteOrder(d.dylib.timestamp);
  991. sys::swapByteOrder(d.dylib.current_version);
  992. sys::swapByteOrder(d.dylib.compatibility_version);
  993. }
  994. inline void swapStruct(sub_framework_command &s) {
  995. sys::swapByteOrder(s.cmd);
  996. sys::swapByteOrder(s.cmdsize);
  997. sys::swapByteOrder(s.umbrella);
  998. }
  999. inline void swapStruct(sub_umbrella_command &s) {
  1000. sys::swapByteOrder(s.cmd);
  1001. sys::swapByteOrder(s.cmdsize);
  1002. sys::swapByteOrder(s.sub_umbrella);
  1003. }
  1004. inline void swapStruct(sub_library_command &s) {
  1005. sys::swapByteOrder(s.cmd);
  1006. sys::swapByteOrder(s.cmdsize);
  1007. sys::swapByteOrder(s.sub_library);
  1008. }
  1009. inline void swapStruct(sub_client_command &s) {
  1010. sys::swapByteOrder(s.cmd);
  1011. sys::swapByteOrder(s.cmdsize);
  1012. sys::swapByteOrder(s.client);
  1013. }
  1014. inline void swapStruct(routines_command &r) {
  1015. sys::swapByteOrder(r.cmd);
  1016. sys::swapByteOrder(r.cmdsize);
  1017. sys::swapByteOrder(r.init_address);
  1018. sys::swapByteOrder(r.init_module);
  1019. sys::swapByteOrder(r.reserved1);
  1020. sys::swapByteOrder(r.reserved2);
  1021. sys::swapByteOrder(r.reserved3);
  1022. sys::swapByteOrder(r.reserved4);
  1023. sys::swapByteOrder(r.reserved5);
  1024. sys::swapByteOrder(r.reserved6);
  1025. }
  1026. inline void swapStruct(routines_command_64 &r) {
  1027. sys::swapByteOrder(r.cmd);
  1028. sys::swapByteOrder(r.cmdsize);
  1029. sys::swapByteOrder(r.init_address);
  1030. sys::swapByteOrder(r.init_module);
  1031. sys::swapByteOrder(r.reserved1);
  1032. sys::swapByteOrder(r.reserved2);
  1033. sys::swapByteOrder(r.reserved3);
  1034. sys::swapByteOrder(r.reserved4);
  1035. sys::swapByteOrder(r.reserved5);
  1036. sys::swapByteOrder(r.reserved6);
  1037. }
  1038. inline void swapStruct(thread_command &t) {
  1039. sys::swapByteOrder(t.cmd);
  1040. sys::swapByteOrder(t.cmdsize);
  1041. }
  1042. inline void swapStruct(dylinker_command &d) {
  1043. sys::swapByteOrder(d.cmd);
  1044. sys::swapByteOrder(d.cmdsize);
  1045. sys::swapByteOrder(d.name);
  1046. }
  1047. inline void swapStruct(uuid_command &u) {
  1048. sys::swapByteOrder(u.cmd);
  1049. sys::swapByteOrder(u.cmdsize);
  1050. }
  1051. inline void swapStruct(rpath_command &r) {
  1052. sys::swapByteOrder(r.cmd);
  1053. sys::swapByteOrder(r.cmdsize);
  1054. sys::swapByteOrder(r.path);
  1055. }
  1056. inline void swapStruct(source_version_command &s) {
  1057. sys::swapByteOrder(s.cmd);
  1058. sys::swapByteOrder(s.cmdsize);
  1059. sys::swapByteOrder(s.version);
  1060. }
  1061. inline void swapStruct(entry_point_command &e) {
  1062. sys::swapByteOrder(e.cmd);
  1063. sys::swapByteOrder(e.cmdsize);
  1064. sys::swapByteOrder(e.entryoff);
  1065. sys::swapByteOrder(e.stacksize);
  1066. }
  1067. inline void swapStruct(encryption_info_command &e) {
  1068. sys::swapByteOrder(e.cmd);
  1069. sys::swapByteOrder(e.cmdsize);
  1070. sys::swapByteOrder(e.cryptoff);
  1071. sys::swapByteOrder(e.cryptsize);
  1072. sys::swapByteOrder(e.cryptid);
  1073. }
  1074. inline void swapStruct(encryption_info_command_64 &e) {
  1075. sys::swapByteOrder(e.cmd);
  1076. sys::swapByteOrder(e.cmdsize);
  1077. sys::swapByteOrder(e.cryptoff);
  1078. sys::swapByteOrder(e.cryptsize);
  1079. sys::swapByteOrder(e.cryptid);
  1080. sys::swapByteOrder(e.pad);
  1081. }
  1082. inline void swapStruct(dysymtab_command &dst) {
  1083. sys::swapByteOrder(dst.cmd);
  1084. sys::swapByteOrder(dst.cmdsize);
  1085. sys::swapByteOrder(dst.ilocalsym);
  1086. sys::swapByteOrder(dst.nlocalsym);
  1087. sys::swapByteOrder(dst.iextdefsym);
  1088. sys::swapByteOrder(dst.nextdefsym);
  1089. sys::swapByteOrder(dst.iundefsym);
  1090. sys::swapByteOrder(dst.nundefsym);
  1091. sys::swapByteOrder(dst.tocoff);
  1092. sys::swapByteOrder(dst.ntoc);
  1093. sys::swapByteOrder(dst.modtaboff);
  1094. sys::swapByteOrder(dst.nmodtab);
  1095. sys::swapByteOrder(dst.extrefsymoff);
  1096. sys::swapByteOrder(dst.nextrefsyms);
  1097. sys::swapByteOrder(dst.indirectsymoff);
  1098. sys::swapByteOrder(dst.nindirectsyms);
  1099. sys::swapByteOrder(dst.extreloff);
  1100. sys::swapByteOrder(dst.nextrel);
  1101. sys::swapByteOrder(dst.locreloff);
  1102. sys::swapByteOrder(dst.nlocrel);
  1103. }
  1104. inline void swapStruct(any_relocation_info &reloc) {
  1105. sys::swapByteOrder(reloc.r_word0);
  1106. sys::swapByteOrder(reloc.r_word1);
  1107. }
  1108. inline void swapStruct(nlist_base &S) {
  1109. sys::swapByteOrder(S.n_strx);
  1110. sys::swapByteOrder(S.n_desc);
  1111. }
  1112. inline void swapStruct(nlist &sym) {
  1113. sys::swapByteOrder(sym.n_strx);
  1114. sys::swapByteOrder(sym.n_desc);
  1115. sys::swapByteOrder(sym.n_value);
  1116. }
  1117. inline void swapStruct(nlist_64 &sym) {
  1118. sys::swapByteOrder(sym.n_strx);
  1119. sys::swapByteOrder(sym.n_desc);
  1120. sys::swapByteOrder(sym.n_value);
  1121. }
  1122. inline void swapStruct(linkedit_data_command &C) {
  1123. sys::swapByteOrder(C.cmd);
  1124. sys::swapByteOrder(C.cmdsize);
  1125. sys::swapByteOrder(C.dataoff);
  1126. sys::swapByteOrder(C.datasize);
  1127. }
  1128. inline void swapStruct(linker_option_command &C) {
  1129. sys::swapByteOrder(C.cmd);
  1130. sys::swapByteOrder(C.cmdsize);
  1131. sys::swapByteOrder(C.count);
  1132. }
  1133. inline void swapStruct(version_min_command&C) {
  1134. sys::swapByteOrder(C.cmd);
  1135. sys::swapByteOrder(C.cmdsize);
  1136. sys::swapByteOrder(C.version);
  1137. sys::swapByteOrder(C.sdk);
  1138. }
  1139. inline void swapStruct(data_in_code_entry &C) {
  1140. sys::swapByteOrder(C.offset);
  1141. sys::swapByteOrder(C.length);
  1142. sys::swapByteOrder(C.kind);
  1143. }
  1144. inline void swapStruct(uint32_t &C) {
  1145. sys::swapByteOrder(C);
  1146. }
  1147. // Get/Set functions from <mach-o/nlist.h>
  1148. static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
  1149. return (((n_desc) >> 8u) & 0xffu);
  1150. }
  1151. static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
  1152. n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8));
  1153. }
  1154. static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) {
  1155. return (n_desc >> 8u) & 0x0fu;
  1156. }
  1157. static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) {
  1158. n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
  1159. }
  1160. // Enums from <mach/machine.h>
  1161. enum : uint32_t {
  1162. // Capability bits used in the definition of cpu_type.
  1163. CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
  1164. CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI
  1165. };
  1166. // Constants for the cputype field.
  1167. enum CPUType {
  1168. CPU_TYPE_ANY = -1,
  1169. CPU_TYPE_X86 = 7,
  1170. CPU_TYPE_I386 = CPU_TYPE_X86,
  1171. CPU_TYPE_X86_64 = CPU_TYPE_X86 | CPU_ARCH_ABI64,
  1172. /* CPU_TYPE_MIPS = 8, */
  1173. CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
  1174. CPU_TYPE_ARM = 12,
  1175. CPU_TYPE_ARM64 = CPU_TYPE_ARM | CPU_ARCH_ABI64,
  1176. CPU_TYPE_SPARC = 14,
  1177. CPU_TYPE_POWERPC = 18,
  1178. CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
  1179. };
  1180. enum : uint32_t {
  1181. // Capability bits used in the definition of cpusubtype.
  1182. CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
  1183. CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
  1184. // Special CPU subtype constants.
  1185. CPU_SUBTYPE_MULTIPLE = ~0u
  1186. };
  1187. // Constants for the cpusubtype field.
  1188. enum CPUSubTypeX86 {
  1189. CPU_SUBTYPE_I386_ALL = 3,
  1190. CPU_SUBTYPE_386 = 3,
  1191. CPU_SUBTYPE_486 = 4,
  1192. CPU_SUBTYPE_486SX = 0x84,
  1193. CPU_SUBTYPE_586 = 5,
  1194. CPU_SUBTYPE_PENT = CPU_SUBTYPE_586,
  1195. CPU_SUBTYPE_PENTPRO = 0x16,
  1196. CPU_SUBTYPE_PENTII_M3 = 0x36,
  1197. CPU_SUBTYPE_PENTII_M5 = 0x56,
  1198. CPU_SUBTYPE_CELERON = 0x67,
  1199. CPU_SUBTYPE_CELERON_MOBILE = 0x77,
  1200. CPU_SUBTYPE_PENTIUM_3 = 0x08,
  1201. CPU_SUBTYPE_PENTIUM_3_M = 0x18,
  1202. CPU_SUBTYPE_PENTIUM_3_XEON = 0x28,
  1203. CPU_SUBTYPE_PENTIUM_M = 0x09,
  1204. CPU_SUBTYPE_PENTIUM_4 = 0x0a,
  1205. CPU_SUBTYPE_PENTIUM_4_M = 0x1a,
  1206. CPU_SUBTYPE_ITANIUM = 0x0b,
  1207. CPU_SUBTYPE_ITANIUM_2 = 0x1b,
  1208. CPU_SUBTYPE_XEON = 0x0c,
  1209. CPU_SUBTYPE_XEON_MP = 0x1c,
  1210. CPU_SUBTYPE_X86_ALL = 3,
  1211. CPU_SUBTYPE_X86_64_ALL = 3,
  1212. CPU_SUBTYPE_X86_ARCH1 = 4,
  1213. CPU_SUBTYPE_X86_64_H = 8
  1214. };
  1215. static inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
  1216. return Family | (Model << 4);
  1217. }
  1218. static inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST) {
  1219. return ((int)ST) & 0x0f;
  1220. }
  1221. static inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) {
  1222. return ((int)ST) >> 4;
  1223. }
  1224. enum {
  1225. CPU_SUBTYPE_INTEL_FAMILY_MAX = 15,
  1226. CPU_SUBTYPE_INTEL_MODEL_ALL = 0
  1227. };
  1228. enum CPUSubTypeARM {
  1229. CPU_SUBTYPE_ARM_ALL = 0,
  1230. CPU_SUBTYPE_ARM_V4T = 5,
  1231. CPU_SUBTYPE_ARM_V6 = 6,
  1232. CPU_SUBTYPE_ARM_V5 = 7,
  1233. CPU_SUBTYPE_ARM_V5TEJ = 7,
  1234. CPU_SUBTYPE_ARM_XSCALE = 8,
  1235. CPU_SUBTYPE_ARM_V7 = 9,
  1236. // unused ARM_V7F = 10,
  1237. CPU_SUBTYPE_ARM_V7S = 11,
  1238. CPU_SUBTYPE_ARM_V7K = 12,
  1239. CPU_SUBTYPE_ARM_V6M = 14,
  1240. CPU_SUBTYPE_ARM_V7M = 15,
  1241. CPU_SUBTYPE_ARM_V7EM = 16
  1242. };
  1243. enum CPUSubTypeARM64 {
  1244. CPU_SUBTYPE_ARM64_ALL = 0
  1245. };
  1246. enum CPUSubTypeSPARC {
  1247. CPU_SUBTYPE_SPARC_ALL = 0
  1248. };
  1249. enum CPUSubTypePowerPC {
  1250. CPU_SUBTYPE_POWERPC_ALL = 0,
  1251. CPU_SUBTYPE_POWERPC_601 = 1,
  1252. CPU_SUBTYPE_POWERPC_602 = 2,
  1253. CPU_SUBTYPE_POWERPC_603 = 3,
  1254. CPU_SUBTYPE_POWERPC_603e = 4,
  1255. CPU_SUBTYPE_POWERPC_603ev = 5,
  1256. CPU_SUBTYPE_POWERPC_604 = 6,
  1257. CPU_SUBTYPE_POWERPC_604e = 7,
  1258. CPU_SUBTYPE_POWERPC_620 = 8,
  1259. CPU_SUBTYPE_POWERPC_750 = 9,
  1260. CPU_SUBTYPE_POWERPC_7400 = 10,
  1261. CPU_SUBTYPE_POWERPC_7450 = 11,
  1262. CPU_SUBTYPE_POWERPC_970 = 100,
  1263. CPU_SUBTYPE_MC980000_ALL = CPU_SUBTYPE_POWERPC_ALL,
  1264. CPU_SUBTYPE_MC98601 = CPU_SUBTYPE_POWERPC_601
  1265. };
  1266. struct x86_thread_state64_t {
  1267. uint64_t rax;
  1268. uint64_t rbx;
  1269. uint64_t rcx;
  1270. uint64_t rdx;
  1271. uint64_t rdi;
  1272. uint64_t rsi;
  1273. uint64_t rbp;
  1274. uint64_t rsp;
  1275. uint64_t r8;
  1276. uint64_t r9;
  1277. uint64_t r10;
  1278. uint64_t r11;
  1279. uint64_t r12;
  1280. uint64_t r13;
  1281. uint64_t r14;
  1282. uint64_t r15;
  1283. uint64_t rip;
  1284. uint64_t rflags;
  1285. uint64_t cs;
  1286. uint64_t fs;
  1287. uint64_t gs;
  1288. };
  1289. enum x86_fp_control_precis {
  1290. x86_FP_PREC_24B = 0,
  1291. x86_FP_PREC_53B = 2,
  1292. x86_FP_PREC_64B = 3
  1293. };
  1294. enum x86_fp_control_rc {
  1295. x86_FP_RND_NEAR = 0,
  1296. x86_FP_RND_DOWN = 1,
  1297. x86_FP_RND_UP = 2,
  1298. x86_FP_CHOP = 3
  1299. };
  1300. struct fp_control_t {
  1301. unsigned short
  1302. invalid :1,
  1303. denorm :1,
  1304. zdiv :1,
  1305. ovrfl :1,
  1306. undfl :1,
  1307. precis :1,
  1308. :2,
  1309. pc :2,
  1310. rc :2,
  1311. :1,
  1312. :3;
  1313. };
  1314. struct fp_status_t {
  1315. unsigned short
  1316. invalid :1,
  1317. denorm :1,
  1318. zdiv :1,
  1319. ovrfl :1,
  1320. undfl :1,
  1321. precis :1,
  1322. stkflt :1,
  1323. errsumm :1,
  1324. c0 :1,
  1325. c1 :1,
  1326. c2 :1,
  1327. tos :3,
  1328. c3 :1,
  1329. busy :1;
  1330. };
  1331. struct mmst_reg_t {
  1332. char mmst_reg[10];
  1333. char mmst_rsrv[6];
  1334. };
  1335. struct xmm_reg_t {
  1336. char xmm_reg[16];
  1337. };
  1338. struct x86_float_state64_t {
  1339. int32_t fpu_reserved[2];
  1340. fp_control_t fpu_fcw;
  1341. fp_status_t fpu_fsw;
  1342. uint8_t fpu_ftw;
  1343. uint8_t fpu_rsrv1;
  1344. uint16_t fpu_fop;
  1345. uint32_t fpu_ip;
  1346. uint16_t fpu_cs;
  1347. uint16_t fpu_rsrv2;
  1348. uint32_t fpu_dp;
  1349. uint16_t fpu_ds;
  1350. uint16_t fpu_rsrv3;
  1351. uint32_t fpu_mxcsr;
  1352. uint32_t fpu_mxcsrmask;
  1353. mmst_reg_t fpu_stmm0;
  1354. mmst_reg_t fpu_stmm1;
  1355. mmst_reg_t fpu_stmm2;
  1356. mmst_reg_t fpu_stmm3;
  1357. mmst_reg_t fpu_stmm4;
  1358. mmst_reg_t fpu_stmm5;
  1359. mmst_reg_t fpu_stmm6;
  1360. mmst_reg_t fpu_stmm7;
  1361. xmm_reg_t fpu_xmm0;
  1362. xmm_reg_t fpu_xmm1;
  1363. xmm_reg_t fpu_xmm2;
  1364. xmm_reg_t fpu_xmm3;
  1365. xmm_reg_t fpu_xmm4;
  1366. xmm_reg_t fpu_xmm5;
  1367. xmm_reg_t fpu_xmm6;
  1368. xmm_reg_t fpu_xmm7;
  1369. xmm_reg_t fpu_xmm8;
  1370. xmm_reg_t fpu_xmm9;
  1371. xmm_reg_t fpu_xmm10;
  1372. xmm_reg_t fpu_xmm11;
  1373. xmm_reg_t fpu_xmm12;
  1374. xmm_reg_t fpu_xmm13;
  1375. xmm_reg_t fpu_xmm14;
  1376. xmm_reg_t fpu_xmm15;
  1377. char fpu_rsrv4[6*16];
  1378. uint32_t fpu_reserved1;
  1379. };
  1380. struct x86_exception_state64_t {
  1381. uint16_t trapno;
  1382. uint16_t cpu;
  1383. uint32_t err;
  1384. uint64_t faultvaddr;
  1385. };
  1386. inline void swapStruct(x86_thread_state64_t &x) {
  1387. sys::swapByteOrder(x.rax);
  1388. sys::swapByteOrder(x.rbx);
  1389. sys::swapByteOrder(x.rcx);
  1390. sys::swapByteOrder(x.rdx);
  1391. sys::swapByteOrder(x.rdi);
  1392. sys::swapByteOrder(x.rsi);
  1393. sys::swapByteOrder(x.rbp);
  1394. sys::swapByteOrder(x.rsp);
  1395. sys::swapByteOrder(x.r8);
  1396. sys::swapByteOrder(x.r9);
  1397. sys::swapByteOrder(x.r10);
  1398. sys::swapByteOrder(x.r11);
  1399. sys::swapByteOrder(x.r12);
  1400. sys::swapByteOrder(x.r13);
  1401. sys::swapByteOrder(x.r14);
  1402. sys::swapByteOrder(x.r15);
  1403. sys::swapByteOrder(x.rip);
  1404. sys::swapByteOrder(x.rflags);
  1405. sys::swapByteOrder(x.cs);
  1406. sys::swapByteOrder(x.fs);
  1407. sys::swapByteOrder(x.gs);
  1408. }
  1409. inline void swapStruct(x86_float_state64_t &x) {
  1410. sys::swapByteOrder(x.fpu_reserved[0]);
  1411. sys::swapByteOrder(x.fpu_reserved[1]);
  1412. // TODO swap: fp_control_t fpu_fcw;
  1413. // TODO swap: fp_status_t fpu_fsw;
  1414. sys::swapByteOrder(x.fpu_fop);
  1415. sys::swapByteOrder(x.fpu_ip);
  1416. sys::swapByteOrder(x.fpu_cs);
  1417. sys::swapByteOrder(x.fpu_rsrv2);
  1418. sys::swapByteOrder(x.fpu_dp);
  1419. sys::swapByteOrder(x.fpu_ds);
  1420. sys::swapByteOrder(x.fpu_rsrv3);
  1421. sys::swapByteOrder(x.fpu_mxcsr);
  1422. sys::swapByteOrder(x.fpu_mxcsrmask);
  1423. sys::swapByteOrder(x.fpu_reserved1);
  1424. }
  1425. inline void swapStruct(x86_exception_state64_t &x) {
  1426. sys::swapByteOrder(x.trapno);
  1427. sys::swapByteOrder(x.cpu);
  1428. sys::swapByteOrder(x.err);
  1429. sys::swapByteOrder(x.faultvaddr);
  1430. }
  1431. struct x86_state_hdr_t {
  1432. uint32_t flavor;
  1433. uint32_t count;
  1434. };
  1435. struct x86_thread_state_t {
  1436. x86_state_hdr_t tsh;
  1437. union {
  1438. x86_thread_state64_t ts64;
  1439. } uts;
  1440. };
  1441. struct x86_float_state_t {
  1442. x86_state_hdr_t fsh;
  1443. union {
  1444. x86_float_state64_t fs64;
  1445. } ufs;
  1446. };
  1447. struct x86_exception_state_t {
  1448. x86_state_hdr_t esh;
  1449. union {
  1450. x86_exception_state64_t es64;
  1451. } ues;
  1452. };
  1453. inline void swapStruct(x86_state_hdr_t &x) {
  1454. sys::swapByteOrder(x.flavor);
  1455. sys::swapByteOrder(x.count);
  1456. }
  1457. enum X86ThreadFlavors {
  1458. x86_THREAD_STATE32 = 1,
  1459. x86_FLOAT_STATE32 = 2,
  1460. x86_EXCEPTION_STATE32 = 3,
  1461. x86_THREAD_STATE64 = 4,
  1462. x86_FLOAT_STATE64 = 5,
  1463. x86_EXCEPTION_STATE64 = 6,
  1464. x86_THREAD_STATE = 7,
  1465. x86_FLOAT_STATE = 8,
  1466. x86_EXCEPTION_STATE = 9,
  1467. x86_DEBUG_STATE32 = 10,
  1468. x86_DEBUG_STATE64 = 11,
  1469. x86_DEBUG_STATE = 12
  1470. };
  1471. inline void swapStruct(x86_thread_state_t &x) {
  1472. swapStruct(x.tsh);
  1473. if (x.tsh.flavor == x86_THREAD_STATE64)
  1474. swapStruct(x.uts.ts64);
  1475. }
  1476. inline void swapStruct(x86_float_state_t &x) {
  1477. swapStruct(x.fsh);
  1478. if (x.fsh.flavor == x86_FLOAT_STATE64)
  1479. swapStruct(x.ufs.fs64);
  1480. }
  1481. inline void swapStruct(x86_exception_state_t &x) {
  1482. swapStruct(x.esh);
  1483. if (x.esh.flavor == x86_EXCEPTION_STATE64)
  1484. swapStruct(x.ues.es64);
  1485. }
  1486. const uint32_t x86_THREAD_STATE64_COUNT =
  1487. sizeof(x86_thread_state64_t) / sizeof(uint32_t);
  1488. const uint32_t x86_FLOAT_STATE64_COUNT =
  1489. sizeof(x86_float_state64_t) / sizeof(uint32_t);
  1490. const uint32_t x86_EXCEPTION_STATE64_COUNT =
  1491. sizeof(x86_exception_state64_t) / sizeof(uint32_t);
  1492. const uint32_t x86_THREAD_STATE_COUNT =
  1493. sizeof(x86_thread_state_t) / sizeof(uint32_t);
  1494. const uint32_t x86_FLOAT_STATE_COUNT =
  1495. sizeof(x86_float_state_t) / sizeof(uint32_t);
  1496. const uint32_t x86_EXCEPTION_STATE_COUNT =
  1497. sizeof(x86_exception_state_t) / sizeof(uint32_t);
  1498. } // end namespace MachO
  1499. } // end namespace llvm
  1500. #endif