LLVM API Documentation

Support/MachO.h
Go to the documentation of this file.
00001 //===-- llvm/Support/MachO.h - The MachO file format ------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines manifest constants for the MachO object file format.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_SUPPORT_MACHO_H
00015 #define LLVM_SUPPORT_MACHO_H
00016 
00017 #include "llvm/Support/Compiler.h"
00018 #include "llvm/Support/DataTypes.h"
00019 #include "llvm/Support/Host.h"
00020 
00021 namespace llvm {
00022   namespace MachO {
00023     // Enums from <mach-o/loader.h>
00024     enum : uint32_t {
00025       // Constants for the "magic" field in llvm::MachO::mach_header and
00026       // llvm::MachO::mach_header_64
00027       MH_MAGIC    = 0xFEEDFACEu,
00028       MH_CIGAM    = 0xCEFAEDFEu,
00029       MH_MAGIC_64 = 0xFEEDFACFu,
00030       MH_CIGAM_64 = 0xCFFAEDFEu,
00031       FAT_MAGIC   = 0xCAFEBABEu,
00032       FAT_CIGAM   = 0xBEBAFECAu
00033     };
00034 
00035     enum HeaderFileType {
00036       // Constants for the "filetype" field in llvm::MachO::mach_header and
00037       // llvm::MachO::mach_header_64
00038       MH_OBJECT      = 0x1u,
00039       MH_EXECUTE     = 0x2u,
00040       MH_FVMLIB      = 0x3u,
00041       MH_CORE        = 0x4u,
00042       MH_PRELOAD     = 0x5u,
00043       MH_DYLIB       = 0x6u,
00044       MH_DYLINKER    = 0x7u,
00045       MH_BUNDLE      = 0x8u,
00046       MH_DYLIB_STUB  = 0x9u,
00047       MH_DSYM        = 0xAu,
00048       MH_KEXT_BUNDLE = 0xBu
00049     };
00050 
00051     enum {
00052       // Constant bits for the "flags" field in llvm::MachO::mach_header and
00053       // llvm::MachO::mach_header_64
00054       MH_NOUNDEFS                = 0x00000001u,
00055       MH_INCRLINK                = 0x00000002u,
00056       MH_DYLDLINK                = 0x00000004u,
00057       MH_BINDATLOAD              = 0x00000008u,
00058       MH_PREBOUND                = 0x00000010u,
00059       MH_SPLIT_SEGS              = 0x00000020u,
00060       MH_LAZY_INIT               = 0x00000040u,
00061       MH_TWOLEVEL                = 0x00000080u,
00062       MH_FORCE_FLAT              = 0x00000100u,
00063       MH_NOMULTIDEFS             = 0x00000200u,
00064       MH_NOFIXPREBINDING         = 0x00000400u,
00065       MH_PREBINDABLE             = 0x00000800u,
00066       MH_ALLMODSBOUND            = 0x00001000u,
00067       MH_SUBSECTIONS_VIA_SYMBOLS = 0x00002000u,
00068       MH_CANONICAL               = 0x00004000u,
00069       MH_WEAK_DEFINES            = 0x00008000u,
00070       MH_BINDS_TO_WEAK           = 0x00010000u,
00071       MH_ALLOW_STACK_EXECUTION   = 0x00020000u,
00072       MH_ROOT_SAFE               = 0x00040000u,
00073       MH_SETUID_SAFE             = 0x00080000u,
00074       MH_NO_REEXPORTED_DYLIBS    = 0x00100000u,
00075       MH_PIE                     = 0x00200000u,
00076       MH_DEAD_STRIPPABLE_DYLIB   = 0x00400000u,
00077       MH_HAS_TLV_DESCRIPTORS     = 0x00800000u,
00078       MH_NO_HEAP_EXECUTION       = 0x01000000u,
00079       MH_APP_EXTENSION_SAFE      = 0x02000000u
00080     };
00081 
00082     enum : uint32_t {
00083       // Flags for the "cmd" field in llvm::MachO::load_command
00084       LC_REQ_DYLD    = 0x80000000u
00085     };
00086 
00087     enum LoadCommandType : uint32_t {
00088       // Constants for the "cmd" field in llvm::MachO::load_command
00089       LC_SEGMENT              = 0x00000001u,
00090       LC_SYMTAB               = 0x00000002u,
00091       LC_SYMSEG               = 0x00000003u,
00092       LC_THREAD               = 0x00000004u,
00093       LC_UNIXTHREAD           = 0x00000005u,
00094       LC_LOADFVMLIB           = 0x00000006u,
00095       LC_IDFVMLIB             = 0x00000007u,
00096       LC_IDENT                = 0x00000008u,
00097       LC_FVMFILE              = 0x00000009u,
00098       LC_PREPAGE              = 0x0000000Au,
00099       LC_DYSYMTAB             = 0x0000000Bu,
00100       LC_LOAD_DYLIB           = 0x0000000Cu,
00101       LC_ID_DYLIB             = 0x0000000Du,
00102       LC_LOAD_DYLINKER        = 0x0000000Eu,
00103       LC_ID_DYLINKER          = 0x0000000Fu,
00104       LC_PREBOUND_DYLIB       = 0x00000010u,
00105       LC_ROUTINES             = 0x00000011u,
00106       LC_SUB_FRAMEWORK        = 0x00000012u,
00107       LC_SUB_UMBRELLA         = 0x00000013u,
00108       LC_SUB_CLIENT           = 0x00000014u,
00109       LC_SUB_LIBRARY          = 0x00000015u,
00110       LC_TWOLEVEL_HINTS       = 0x00000016u,
00111       LC_PREBIND_CKSUM        = 0x00000017u,
00112       LC_LOAD_WEAK_DYLIB      = 0x80000018u,
00113       LC_SEGMENT_64           = 0x00000019u,
00114       LC_ROUTINES_64          = 0x0000001Au,
00115       LC_UUID                 = 0x0000001Bu,
00116       LC_RPATH                = 0x8000001Cu,
00117       LC_CODE_SIGNATURE       = 0x0000001Du,
00118       LC_SEGMENT_SPLIT_INFO   = 0x0000001Eu,
00119       LC_REEXPORT_DYLIB       = 0x8000001Fu,
00120       LC_LAZY_LOAD_DYLIB      = 0x00000020u,
00121       LC_ENCRYPTION_INFO      = 0x00000021u,
00122       LC_DYLD_INFO            = 0x00000022u,
00123       LC_DYLD_INFO_ONLY       = 0x80000022u,
00124       LC_LOAD_UPWARD_DYLIB    = 0x80000023u,
00125       LC_VERSION_MIN_MACOSX   = 0x00000024u,
00126       LC_VERSION_MIN_IPHONEOS = 0x00000025u,
00127       LC_FUNCTION_STARTS      = 0x00000026u,
00128       LC_DYLD_ENVIRONMENT     = 0x00000027u,
00129       LC_MAIN                 = 0x80000028u,
00130       LC_DATA_IN_CODE         = 0x00000029u,
00131       LC_SOURCE_VERSION       = 0x0000002Au,
00132       LC_DYLIB_CODE_SIGN_DRS  = 0x0000002Bu,
00133       //                        0x0000002Cu,
00134       LC_LINKER_OPTIONS       = 0x0000002Du,
00135       LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu
00136     };
00137 
00138     enum : uint32_t {
00139       // Constant bits for the "flags" field in llvm::MachO::segment_command
00140       SG_HIGHVM              = 0x1u,
00141       SG_FVMLIB              = 0x2u,
00142       SG_NORELOC             = 0x4u,
00143       SG_PROTECTED_VERSION_1 = 0x8u,
00144 
00145 
00146       // Constant masks for the "flags" field in llvm::MachO::section and
00147       // llvm::MachO::section_64
00148       SECTION_TYPE           = 0x000000ffu, // SECTION_TYPE
00149       SECTION_ATTRIBUTES     = 0xffffff00u, // SECTION_ATTRIBUTES
00150       SECTION_ATTRIBUTES_USR = 0xff000000u, // SECTION_ATTRIBUTES_USR
00151       SECTION_ATTRIBUTES_SYS = 0x00ffff00u  // SECTION_ATTRIBUTES_SYS
00152     };
00153 
00154     /// These are the section type and attributes fields.  A MachO section can
00155     /// have only one Type, but can have any of the attributes specified.
00156     enum SectionType : uint32_t {
00157       // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
00158       // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
00159 
00160       /// S_REGULAR - Regular section.
00161       S_REGULAR                             = 0x00u,
00162       /// S_ZEROFILL - Zero fill on demand section.
00163       S_ZEROFILL                            = 0x01u,
00164       /// S_CSTRING_LITERALS - Section with literal C strings.
00165       S_CSTRING_LITERALS                    = 0x02u,
00166       /// S_4BYTE_LITERALS - Section with 4 byte literals.
00167       S_4BYTE_LITERALS                      = 0x03u,
00168       /// S_8BYTE_LITERALS - Section with 8 byte literals.
00169       S_8BYTE_LITERALS                      = 0x04u,
00170       /// S_LITERAL_POINTERS - Section with pointers to literals.
00171       S_LITERAL_POINTERS                    = 0x05u,
00172       /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
00173       S_NON_LAZY_SYMBOL_POINTERS            = 0x06u,
00174       /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
00175       S_LAZY_SYMBOL_POINTERS                = 0x07u,
00176       /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
00177       /// the Reserved2 field.
00178       S_SYMBOL_STUBS                        = 0x08u,
00179       /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
00180       /// initialization.
00181       S_MOD_INIT_FUNC_POINTERS              = 0x09u,
00182       /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
00183       /// termination.
00184       S_MOD_TERM_FUNC_POINTERS              = 0x0au,
00185       /// S_COALESCED - Section contains symbols that are to be coalesced.
00186       S_COALESCED                           = 0x0bu,
00187       /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
00188       /// gigabytes).
00189       S_GB_ZEROFILL                         = 0x0cu,
00190       /// S_INTERPOSING - Section with only pairs of function pointers for
00191       /// interposing.
00192       S_INTERPOSING                         = 0x0du,
00193       /// S_16BYTE_LITERALS - Section with only 16 byte literals.
00194       S_16BYTE_LITERALS                     = 0x0eu,
00195       /// S_DTRACE_DOF - Section contains DTrace Object Format.
00196       S_DTRACE_DOF                          = 0x0fu,
00197       /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
00198       /// lazy loaded dylibs.
00199       S_LAZY_DYLIB_SYMBOL_POINTERS          = 0x10u,
00200       /// S_THREAD_LOCAL_REGULAR - Thread local data section.
00201       S_THREAD_LOCAL_REGULAR                = 0x11u,
00202       /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
00203       S_THREAD_LOCAL_ZEROFILL               = 0x12u,
00204       /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
00205       /// structure data.
00206       S_THREAD_LOCAL_VARIABLES              = 0x13u,
00207       /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
00208       /// local structures.
00209       S_THREAD_LOCAL_VARIABLE_POINTERS      = 0x14u,
00210       /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
00211       /// variable initialization pointers to functions.
00212       S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u,
00213 
00214       LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
00215     };
00216 
00217     enum : uint32_t {
00218       // Constant masks for the "flags[31:24]" field in llvm::MachO::section and
00219       // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR)
00220 
00221       /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
00222       /// instructions.
00223       S_ATTR_PURE_INSTRUCTIONS   = 0x80000000u,
00224       /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
00225       /// in a ranlib table of contents.
00226       S_ATTR_NO_TOC              = 0x40000000u,
00227       /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
00228       /// in files with the MY_DYLDLINK flag.
00229       S_ATTR_STRIP_STATIC_SYMS   = 0x20000000u,
00230       /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
00231       S_ATTR_NO_DEAD_STRIP       = 0x10000000u,
00232       /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
00233       S_ATTR_LIVE_SUPPORT        = 0x08000000u,
00234       /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
00235       /// dyld.
00236       S_ATTR_SELF_MODIFYING_CODE = 0x04000000u,
00237       /// S_ATTR_DEBUG - A debug section.
00238       S_ATTR_DEBUG               = 0x02000000u,
00239 
00240       // Constant masks for the "flags[23:8]" field in llvm::MachO::section and
00241       // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS)
00242 
00243       /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
00244       S_ATTR_SOME_INSTRUCTIONS   = 0x00000400u,
00245       /// S_ATTR_EXT_RELOC - Section has external relocation entries.
00246       S_ATTR_EXT_RELOC           = 0x00000200u,
00247       /// S_ATTR_LOC_RELOC - Section has local relocation entries.
00248       S_ATTR_LOC_RELOC           = 0x00000100u,
00249 
00250       // Constant masks for the value of an indirect symbol in an indirect
00251       // symbol table
00252       INDIRECT_SYMBOL_LOCAL = 0x80000000u,
00253       INDIRECT_SYMBOL_ABS   = 0x40000000u
00254     };
00255 
00256     enum DataRegionType {
00257       // Constants for the "kind" field in a data_in_code_entry structure
00258       DICE_KIND_DATA             = 1u,
00259       DICE_KIND_JUMP_TABLE8      = 2u,
00260       DICE_KIND_JUMP_TABLE16     = 3u,
00261       DICE_KIND_JUMP_TABLE32     = 4u,
00262       DICE_KIND_ABS_JUMP_TABLE32 = 5u
00263     };
00264 
00265     enum RebaseType {
00266       REBASE_TYPE_POINTER         = 1u,
00267       REBASE_TYPE_TEXT_ABSOLUTE32 = 2u,
00268       REBASE_TYPE_TEXT_PCREL32    = 3u
00269     };
00270 
00271     enum {
00272       REBASE_OPCODE_MASK    = 0xF0u,
00273       REBASE_IMMEDIATE_MASK = 0x0Fu
00274     };
00275 
00276     enum RebaseOpcode {
00277       REBASE_OPCODE_DONE                               = 0x00u,
00278       REBASE_OPCODE_SET_TYPE_IMM                       = 0x10u,
00279       REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB        = 0x20u,
00280       REBASE_OPCODE_ADD_ADDR_ULEB                      = 0x30u,
00281       REBASE_OPCODE_ADD_ADDR_IMM_SCALED                = 0x40u,
00282       REBASE_OPCODE_DO_REBASE_IMM_TIMES                = 0x50u,
00283       REBASE_OPCODE_DO_REBASE_ULEB_TIMES               = 0x60u,
00284       REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB            = 0x70u,
00285       REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
00286     };
00287 
00288     enum BindType {
00289       BIND_TYPE_POINTER         = 1u,
00290       BIND_TYPE_TEXT_ABSOLUTE32 = 2u,
00291       BIND_TYPE_TEXT_PCREL32    = 3u
00292     };
00293 
00294     enum BindSpecialDylib {
00295       BIND_SPECIAL_DYLIB_SELF            =  0,
00296       BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1,
00297       BIND_SPECIAL_DYLIB_FLAT_LOOKUP     = -2
00298     };
00299 
00300     enum {
00301       BIND_SYMBOL_FLAGS_WEAK_IMPORT         = 0x1u,
00302       BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u,
00303 
00304       BIND_OPCODE_MASK                      = 0xF0u,
00305       BIND_IMMEDIATE_MASK                   = 0x0Fu
00306     };
00307 
00308     enum BindOpcode {
00309       BIND_OPCODE_DONE                             = 0x00u,
00310       BIND_OPCODE_SET_DYLIB_ORDINAL_IMM            = 0x10u,
00311       BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB           = 0x20u,
00312       BIND_OPCODE_SET_DYLIB_SPECIAL_IMM            = 0x30u,
00313       BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM    = 0x40u,
00314       BIND_OPCODE_SET_TYPE_IMM                     = 0x50u,
00315       BIND_OPCODE_SET_ADDEND_SLEB                  = 0x60u,
00316       BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB      = 0x70u,
00317       BIND_OPCODE_ADD_ADDR_ULEB                    = 0x80u,
00318       BIND_OPCODE_DO_BIND                          = 0x90u,
00319       BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB            = 0xA0u,
00320       BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED      = 0xB0u,
00321       BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u
00322     };
00323 
00324     enum {
00325       EXPORT_SYMBOL_FLAGS_KIND_MASK           = 0x03u,
00326       EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION     = 0x04u,
00327       EXPORT_SYMBOL_FLAGS_REEXPORT            = 0x08u,
00328       EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER   = 0x10u
00329     };
00330 
00331     enum ExportSymbolKind {
00332       EXPORT_SYMBOL_FLAGS_KIND_REGULAR        = 0x00u,
00333       EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL   = 0x01u,
00334       EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE       = 0x02u
00335     };
00336 
00337 
00338     enum {
00339       // Constant masks for the "n_type" field in llvm::MachO::nlist and
00340       // llvm::MachO::nlist_64
00341       N_STAB = 0xe0,
00342       N_PEXT = 0x10,
00343       N_TYPE = 0x0e,
00344       N_EXT  = 0x01
00345     };
00346 
00347     enum NListType {
00348       // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
00349       // llvm::MachO::nlist_64
00350       N_UNDF = 0x0u,
00351       N_ABS  = 0x2u,
00352       N_SECT = 0xeu,
00353       N_PBUD = 0xcu,
00354       N_INDR = 0xau
00355     };
00356 
00357     enum SectionOrdinal {
00358       // Constants for the "n_sect" field in llvm::MachO::nlist and
00359       // llvm::MachO::nlist_64
00360       NO_SECT  = 0u,
00361       MAX_SECT = 0xffu
00362     };
00363 
00364     enum {
00365       // Constant masks for the "n_desc" field in llvm::MachO::nlist and
00366       // llvm::MachO::nlist_64
00367       // The low 3 bits are the for the REFERENCE_TYPE.
00368       REFERENCE_TYPE                            = 0x7,
00369       REFERENCE_FLAG_UNDEFINED_NON_LAZY         = 0,
00370       REFERENCE_FLAG_UNDEFINED_LAZY             = 1,
00371       REFERENCE_FLAG_DEFINED                    = 2,
00372       REFERENCE_FLAG_PRIVATE_DEFINED            = 3,
00373       REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY = 4,
00374       REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY     = 5,
00375       // Flag bits (some overlap with the library ordinal bits).
00376       N_ARM_THUMB_DEF   = 0x0008u,
00377       REFERENCED_DYNAMICALLY = 0x0010u,
00378       N_NO_DEAD_STRIP   = 0x0020u,
00379       N_WEAK_REF        = 0x0040u,
00380       N_WEAK_DEF        = 0x0080u,
00381       N_SYMBOL_RESOLVER = 0x0100u,
00382       N_ALT_ENTRY       = 0x0200u,
00383       // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL()
00384       // as these are in the top 8 bits.
00385       SELF_LIBRARY_ORDINAL   = 0x0,
00386       MAX_LIBRARY_ORDINAL    = 0xfd,
00387       DYNAMIC_LOOKUP_ORDINAL = 0xfe,
00388       EXECUTABLE_ORDINAL     = 0xff 
00389     };
00390 
00391     enum StabType {
00392       // Constant values for the "n_type" field in llvm::MachO::nlist and
00393       // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
00394       N_GSYM    = 0x20u,
00395       N_FNAME   = 0x22u,
00396       N_FUN     = 0x24u,
00397       N_STSYM   = 0x26u,
00398       N_LCSYM   = 0x28u,
00399       N_BNSYM   = 0x2Eu,
00400       N_PC      = 0x30u,
00401       N_AST     = 0x32u,
00402       N_OPT     = 0x3Cu,
00403       N_RSYM    = 0x40u,
00404       N_SLINE   = 0x44u,
00405       N_ENSYM   = 0x4Eu,
00406       N_SSYM    = 0x60u,
00407       N_SO      = 0x64u,
00408       N_OSO     = 0x66u,
00409       N_LSYM    = 0x80u,
00410       N_BINCL   = 0x82u,
00411       N_SOL     = 0x84u,
00412       N_PARAMS  = 0x86u,
00413       N_VERSION = 0x88u,
00414       N_OLEVEL  = 0x8Au,
00415       N_PSYM    = 0xA0u,
00416       N_EINCL   = 0xA2u,
00417       N_ENTRY   = 0xA4u,
00418       N_LBRAC   = 0xC0u,
00419       N_EXCL    = 0xC2u,
00420       N_RBRAC   = 0xE0u,
00421       N_BCOMM   = 0xE2u,
00422       N_ECOMM   = 0xE4u,
00423       N_ECOML   = 0xE8u,
00424       N_LENG    = 0xFEu
00425     };
00426 
00427     enum : uint32_t {
00428       // Constant values for the r_symbolnum field in an
00429       // llvm::MachO::relocation_info structure when r_extern is 0.
00430       R_ABS = 0,
00431 
00432       // Constant bits for the r_address field in an
00433       // llvm::MachO::relocation_info structure.
00434       R_SCATTERED = 0x80000000
00435     };
00436 
00437     enum RelocationInfoType {
00438       // Constant values for the r_type field in an
00439       // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
00440       // structure.
00441       GENERIC_RELOC_VANILLA        = 0,
00442       GENERIC_RELOC_PAIR           = 1,
00443       GENERIC_RELOC_SECTDIFF       = 2,
00444       GENERIC_RELOC_PB_LA_PTR      = 3,
00445       GENERIC_RELOC_LOCAL_SECTDIFF = 4,
00446       GENERIC_RELOC_TLV            = 5,
00447 
00448       // Constant values for the r_type field in a PowerPC architecture
00449       // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
00450       // structure.
00451       PPC_RELOC_VANILLA            = GENERIC_RELOC_VANILLA,
00452       PPC_RELOC_PAIR               = GENERIC_RELOC_PAIR,
00453       PPC_RELOC_BR14               = 2,
00454       PPC_RELOC_BR24               = 3,
00455       PPC_RELOC_HI16               = 4,
00456       PPC_RELOC_LO16               = 5,
00457       PPC_RELOC_HA16               = 6,
00458       PPC_RELOC_LO14               = 7,
00459       PPC_RELOC_SECTDIFF           = 8,
00460       PPC_RELOC_PB_LA_PTR          = 9,
00461       PPC_RELOC_HI16_SECTDIFF      = 10,
00462       PPC_RELOC_LO16_SECTDIFF      = 11,
00463       PPC_RELOC_HA16_SECTDIFF      = 12,
00464       PPC_RELOC_JBSR               = 13,
00465       PPC_RELOC_LO14_SECTDIFF      = 14,
00466       PPC_RELOC_LOCAL_SECTDIFF     = 15,
00467 
00468       // Constant values for the r_type field in an ARM architecture
00469       // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
00470       // structure.
00471       ARM_RELOC_VANILLA            = GENERIC_RELOC_VANILLA,
00472       ARM_RELOC_PAIR               = GENERIC_RELOC_PAIR,
00473       ARM_RELOC_SECTDIFF           = GENERIC_RELOC_SECTDIFF,
00474       ARM_RELOC_LOCAL_SECTDIFF     = 3,
00475       ARM_RELOC_PB_LA_PTR          = 4,
00476       ARM_RELOC_BR24               = 5,
00477       ARM_THUMB_RELOC_BR22         = 6,
00478       ARM_THUMB_32BIT_BRANCH       = 7, // obsolete
00479       ARM_RELOC_HALF               = 8,
00480       ARM_RELOC_HALF_SECTDIFF      = 9,
00481 
00482       // Constant values for the r_type field in an ARM64 architecture
00483       // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
00484       // structure.
00485 
00486       // For pointers.
00487       ARM64_RELOC_UNSIGNED            = 0,
00488       // Must be followed by an ARM64_RELOC_UNSIGNED
00489       ARM64_RELOC_SUBTRACTOR          = 1,
00490       // A B/BL instruction with 26-bit displacement.
00491       ARM64_RELOC_BRANCH26            = 2,
00492       // PC-rel distance to page of target.
00493       ARM64_RELOC_PAGE21              = 3,
00494       // Offset within page, scaled by r_length.
00495       ARM64_RELOC_PAGEOFF12           = 4,
00496       // PC-rel distance to page of GOT slot.
00497       ARM64_RELOC_GOT_LOAD_PAGE21     = 5,
00498       // Offset within page of GOT slot, scaled by r_length.
00499       ARM64_RELOC_GOT_LOAD_PAGEOFF12  = 6,
00500       // For pointers to GOT slots.
00501       ARM64_RELOC_POINTER_TO_GOT      = 7,
00502       // PC-rel distance to page of TLVP slot.
00503       ARM64_RELOC_TLVP_LOAD_PAGE21    = 8,
00504       // Offset within page of TLVP slot, scaled by r_length.
00505       ARM64_RELOC_TLVP_LOAD_PAGEOFF12 = 9,
00506       // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
00507       ARM64_RELOC_ADDEND              = 10,
00508 
00509 
00510       // Constant values for the r_type field in an x86_64 architecture
00511       // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
00512       // structure
00513       X86_64_RELOC_UNSIGNED        = 0,
00514       X86_64_RELOC_SIGNED          = 1,
00515       X86_64_RELOC_BRANCH          = 2,
00516       X86_64_RELOC_GOT_LOAD        = 3,
00517       X86_64_RELOC_GOT             = 4,
00518       X86_64_RELOC_SUBTRACTOR      = 5,
00519       X86_64_RELOC_SIGNED_1        = 6,
00520       X86_64_RELOC_SIGNED_2        = 7,
00521       X86_64_RELOC_SIGNED_4        = 8,
00522       X86_64_RELOC_TLV             = 9
00523     };
00524 
00525     // Values for segment_command.initprot.
00526     // From <mach/vm_prot.h>
00527     enum {
00528       VM_PROT_READ    = 0x1,
00529       VM_PROT_WRITE   = 0x2,
00530       VM_PROT_EXECUTE = 0x4
00531     };
00532 
00533 
00534     // Structs from <mach-o/loader.h>
00535 
00536     struct mach_header {
00537       uint32_t magic;
00538       uint32_t cputype;
00539       uint32_t cpusubtype;
00540       uint32_t filetype;
00541       uint32_t ncmds;
00542       uint32_t sizeofcmds;
00543       uint32_t flags;
00544     };
00545 
00546     struct mach_header_64 {
00547       uint32_t magic;
00548       uint32_t cputype;
00549       uint32_t cpusubtype;
00550       uint32_t filetype;
00551       uint32_t ncmds;
00552       uint32_t sizeofcmds;
00553       uint32_t flags;
00554       uint32_t reserved;
00555     };
00556 
00557     struct load_command {
00558       uint32_t cmd;
00559       uint32_t cmdsize;
00560     };
00561 
00562     struct segment_command {
00563       uint32_t cmd;
00564       uint32_t cmdsize;
00565       char segname[16];
00566       uint32_t vmaddr;
00567       uint32_t vmsize;
00568       uint32_t fileoff;
00569       uint32_t filesize;
00570       uint32_t maxprot;
00571       uint32_t initprot;
00572       uint32_t nsects;
00573       uint32_t flags;
00574     };
00575 
00576     struct segment_command_64 {
00577       uint32_t cmd;
00578       uint32_t cmdsize;
00579       char segname[16];
00580       uint64_t vmaddr;
00581       uint64_t vmsize;
00582       uint64_t fileoff;
00583       uint64_t filesize;
00584       uint32_t maxprot;
00585       uint32_t initprot;
00586       uint32_t nsects;
00587       uint32_t flags;
00588     };
00589 
00590     struct section {
00591       char sectname[16];
00592       char segname[16];
00593       uint32_t addr;
00594       uint32_t size;
00595       uint32_t offset;
00596       uint32_t align;
00597       uint32_t reloff;
00598       uint32_t nreloc;
00599       uint32_t flags;
00600       uint32_t reserved1;
00601       uint32_t reserved2;
00602     };
00603 
00604     struct section_64 {
00605       char sectname[16];
00606       char segname[16];
00607       uint64_t addr;
00608       uint64_t size;
00609       uint32_t offset;
00610       uint32_t align;
00611       uint32_t reloff;
00612       uint32_t nreloc;
00613       uint32_t flags;
00614       uint32_t reserved1;
00615       uint32_t reserved2;
00616       uint32_t reserved3;
00617     };
00618 
00619     struct fvmlib {
00620       uint32_t name;
00621       uint32_t minor_version;
00622       uint32_t header_addr;
00623     };
00624 
00625     struct fvmlib_command {
00626       uint32_t  cmd;
00627       uint32_t cmdsize;
00628       struct fvmlib fvmlib;
00629     };
00630 
00631     struct dylib {
00632       uint32_t name;
00633       uint32_t timestamp;
00634       uint32_t current_version;
00635       uint32_t compatibility_version;
00636     };
00637 
00638     struct dylib_command {
00639       uint32_t cmd;
00640       uint32_t cmdsize;
00641       struct dylib dylib;
00642     };
00643 
00644     struct sub_framework_command {
00645       uint32_t cmd;
00646       uint32_t cmdsize;
00647       uint32_t umbrella;
00648     };
00649 
00650     struct sub_client_command {
00651       uint32_t cmd;
00652       uint32_t cmdsize;
00653       uint32_t client;
00654     };
00655 
00656     struct sub_umbrella_command {
00657       uint32_t cmd;
00658       uint32_t cmdsize;
00659       uint32_t sub_umbrella;
00660     };
00661 
00662     struct sub_library_command {
00663       uint32_t cmd;
00664       uint32_t cmdsize;
00665       uint32_t sub_library;
00666     };
00667 
00668     struct prebound_dylib_command {
00669       uint32_t cmd;
00670       uint32_t cmdsize;
00671       uint32_t name;
00672       uint32_t nmodules;
00673       uint32_t linked_modules;
00674     };
00675 
00676     struct dylinker_command {
00677       uint32_t cmd;
00678       uint32_t cmdsize;
00679       uint32_t name;
00680     };
00681 
00682     struct thread_command {
00683       uint32_t cmd;
00684       uint32_t cmdsize;
00685     };
00686 
00687     struct routines_command {
00688       uint32_t cmd;
00689       uint32_t cmdsize;
00690       uint32_t init_address;
00691       uint32_t init_module;
00692       uint32_t reserved1;
00693       uint32_t reserved2;
00694       uint32_t reserved3;
00695       uint32_t reserved4;
00696       uint32_t reserved5;
00697       uint32_t reserved6;
00698     };
00699 
00700     struct routines_command_64 {
00701       uint32_t cmd;
00702       uint32_t cmdsize;
00703       uint64_t init_address;
00704       uint64_t init_module;
00705       uint64_t reserved1;
00706       uint64_t reserved2;
00707       uint64_t reserved3;
00708       uint64_t reserved4;
00709       uint64_t reserved5;
00710       uint64_t reserved6;
00711     };
00712 
00713     struct symtab_command {
00714       uint32_t cmd;
00715       uint32_t cmdsize;
00716       uint32_t symoff;
00717       uint32_t nsyms;
00718       uint32_t stroff;
00719       uint32_t strsize;
00720     };
00721 
00722     struct dysymtab_command {
00723       uint32_t cmd;
00724       uint32_t cmdsize;
00725       uint32_t ilocalsym;
00726       uint32_t nlocalsym;
00727       uint32_t iextdefsym;
00728       uint32_t nextdefsym;
00729       uint32_t iundefsym;
00730       uint32_t nundefsym;
00731       uint32_t tocoff;
00732       uint32_t ntoc;
00733       uint32_t modtaboff;
00734       uint32_t nmodtab;
00735       uint32_t extrefsymoff;
00736       uint32_t nextrefsyms;
00737       uint32_t indirectsymoff;
00738       uint32_t nindirectsyms;
00739       uint32_t extreloff;
00740       uint32_t nextrel;
00741       uint32_t locreloff;
00742       uint32_t nlocrel;
00743     };
00744 
00745     struct dylib_table_of_contents {
00746       uint32_t symbol_index;
00747       uint32_t module_index;
00748     };
00749 
00750     struct dylib_module {
00751       uint32_t module_name;
00752       uint32_t iextdefsym;
00753       uint32_t nextdefsym;
00754       uint32_t irefsym;
00755       uint32_t nrefsym;
00756       uint32_t ilocalsym;
00757       uint32_t nlocalsym;
00758       uint32_t iextrel;
00759       uint32_t nextrel;
00760       uint32_t iinit_iterm;
00761       uint32_t ninit_nterm;
00762       uint32_t objc_module_info_addr;
00763       uint32_t objc_module_info_size;
00764     };
00765 
00766     struct dylib_module_64 {
00767       uint32_t module_name;
00768       uint32_t iextdefsym;
00769       uint32_t nextdefsym;
00770       uint32_t irefsym;
00771       uint32_t nrefsym;
00772       uint32_t ilocalsym;
00773       uint32_t nlocalsym;
00774       uint32_t iextrel;
00775       uint32_t nextrel;
00776       uint32_t iinit_iterm;
00777       uint32_t ninit_nterm;
00778       uint32_t objc_module_info_size;
00779       uint64_t objc_module_info_addr;
00780     };
00781 
00782     struct dylib_reference {
00783       uint32_t isym:24,
00784                flags:8;
00785     };
00786 
00787 
00788     struct twolevel_hints_command {
00789       uint32_t cmd;
00790       uint32_t cmdsize;
00791       uint32_t offset;
00792       uint32_t nhints;
00793     };
00794 
00795     struct twolevel_hint {
00796       uint32_t isub_image:8,
00797                itoc:24;
00798     };
00799 
00800     struct prebind_cksum_command {
00801       uint32_t cmd;
00802       uint32_t cmdsize;
00803       uint32_t cksum;
00804     };
00805 
00806     struct uuid_command {
00807       uint32_t cmd;
00808       uint32_t cmdsize;
00809       uint8_t uuid[16];
00810     };
00811 
00812     struct rpath_command {
00813       uint32_t cmd;
00814       uint32_t cmdsize;
00815       uint32_t path;
00816     };
00817 
00818     struct linkedit_data_command {
00819       uint32_t cmd;
00820       uint32_t cmdsize;
00821       uint32_t dataoff;
00822       uint32_t datasize;
00823     };
00824 
00825     struct data_in_code_entry {
00826       uint32_t offset;
00827       uint16_t length;
00828       uint16_t kind;
00829     };
00830 
00831     struct source_version_command {
00832       uint32_t cmd;
00833       uint32_t cmdsize;
00834       uint64_t version;
00835     };
00836 
00837     struct encryption_info_command {
00838       uint32_t cmd;
00839       uint32_t cmdsize;
00840       uint32_t cryptoff;
00841       uint32_t cryptsize;
00842       uint32_t cryptid;
00843     };
00844 
00845     struct version_min_command {
00846       uint32_t cmd;       // LC_VERSION_MIN_MACOSX or
00847                           // LC_VERSION_MIN_IPHONEOS
00848       uint32_t cmdsize;   // sizeof(struct version_min_command)
00849       uint32_t version;   // X.Y.Z is encoded in nibbles xxxx.yy.zz
00850       uint32_t sdk;       // X.Y.Z is encoded in nibbles xxxx.yy.zz
00851     };
00852 
00853     struct dyld_info_command {
00854       uint32_t cmd;
00855       uint32_t cmdsize;
00856       uint32_t rebase_off;
00857       uint32_t rebase_size;
00858       uint32_t bind_off;
00859       uint32_t bind_size;
00860       uint32_t weak_bind_off;
00861       uint32_t weak_bind_size;
00862       uint32_t lazy_bind_off;
00863       uint32_t lazy_bind_size;
00864       uint32_t export_off;
00865       uint32_t export_size;
00866     };
00867 
00868     struct linker_options_command {
00869       uint32_t cmd;
00870       uint32_t cmdsize;
00871       uint32_t count;
00872     };
00873 
00874     struct symseg_command {
00875       uint32_t cmd;
00876       uint32_t cmdsize;
00877       uint32_t offset;
00878       uint32_t size;
00879     };
00880 
00881     struct ident_command {
00882       uint32_t cmd;
00883       uint32_t cmdsize;
00884     };
00885 
00886     struct fvmfile_command {
00887       uint32_t cmd;
00888       uint32_t cmdsize;
00889       uint32_t name;
00890       uint32_t header_addr;
00891     };
00892 
00893     struct tlv_descriptor_32 {
00894       uint32_t thunk;
00895       uint32_t key;
00896       uint32_t offset;
00897     };
00898 
00899     struct tlv_descriptor_64 {
00900       uint64_t thunk;
00901       uint64_t key;
00902       uint64_t offset;
00903     };
00904 
00905     struct tlv_descriptor {
00906       uintptr_t thunk;
00907       uintptr_t key;
00908       uintptr_t offset;
00909     };
00910 
00911     struct entry_point_command {
00912       uint32_t cmd;
00913       uint32_t cmdsize;
00914       uint64_t entryoff;
00915       uint64_t stacksize;
00916     };
00917 
00918 
00919     // Structs from <mach-o/fat.h>
00920     struct fat_header {
00921       uint32_t magic;
00922       uint32_t nfat_arch;
00923     };
00924 
00925     struct fat_arch {
00926       uint32_t cputype;
00927       uint32_t cpusubtype;
00928       uint32_t offset;
00929       uint32_t size;
00930       uint32_t align;
00931     };
00932 
00933     // Structs from <mach-o/reloc.h>
00934     struct relocation_info {
00935       int32_t r_address;
00936       uint32_t r_symbolnum:24,
00937                r_pcrel:1,
00938                r_length:2,
00939                r_extern:1,
00940                r_type:4;
00941     };
00942 
00943     struct scattered_relocation_info {
00944 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
00945       uint32_t r_scattered:1,
00946                r_pcrel:1,
00947                r_length:2,
00948                r_type:4,
00949                r_address:24;
00950 #else
00951       uint32_t r_address:24,
00952                r_type:4,
00953                r_length:2,
00954                r_pcrel:1,
00955                r_scattered:1;
00956 #endif
00957       int32_t r_value;
00958     };
00959 
00960     // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
00961     struct any_relocation_info {
00962       uint32_t r_word0, r_word1;
00963     };
00964 
00965     // Structs from <mach-o/nlist.h>
00966     struct nlist_base {
00967       uint32_t n_strx;
00968       uint8_t n_type;
00969       uint8_t n_sect;
00970       uint16_t n_desc;
00971     };
00972 
00973     struct nlist {
00974       uint32_t n_strx;
00975       uint8_t n_type;
00976       uint8_t n_sect;
00977       int16_t n_desc;
00978       uint32_t n_value;
00979     };
00980 
00981     struct nlist_64 {
00982       uint32_t n_strx;
00983       uint8_t n_type;
00984       uint8_t n_sect;
00985       uint16_t n_desc;
00986       uint64_t n_value;
00987     };
00988 
00989 
00990     // Byte order swapping functions for MachO structs
00991 
00992     inline void swapStruct(mach_header &mh) {
00993       sys::swapByteOrder(mh.magic);
00994       sys::swapByteOrder(mh.cputype);
00995       sys::swapByteOrder(mh.cpusubtype);
00996       sys::swapByteOrder(mh.filetype);
00997       sys::swapByteOrder(mh.ncmds);
00998       sys::swapByteOrder(mh.sizeofcmds);
00999       sys::swapByteOrder(mh.flags);
01000     }
01001 
01002     inline void swapStruct(mach_header_64 &H) {
01003       sys::swapByteOrder(H.magic);
01004       sys::swapByteOrder(H.cputype);
01005       sys::swapByteOrder(H.cpusubtype);
01006       sys::swapByteOrder(H.filetype);
01007       sys::swapByteOrder(H.ncmds);
01008       sys::swapByteOrder(H.sizeofcmds);
01009       sys::swapByteOrder(H.flags);
01010       sys::swapByteOrder(H.reserved);
01011     }
01012 
01013     inline void swapStruct(load_command &lc) {
01014       sys::swapByteOrder(lc.cmd);
01015       sys::swapByteOrder(lc.cmdsize);
01016     }
01017 
01018     inline void swapStruct(symtab_command &lc) {
01019       sys::swapByteOrder(lc.cmd);
01020       sys::swapByteOrder(lc.cmdsize);
01021       sys::swapByteOrder(lc.symoff);
01022       sys::swapByteOrder(lc.nsyms);
01023       sys::swapByteOrder(lc.stroff);
01024       sys::swapByteOrder(lc.strsize);
01025     }
01026 
01027     inline void swapStruct(segment_command_64 &seg) {
01028       sys::swapByteOrder(seg.cmd);
01029       sys::swapByteOrder(seg.cmdsize);
01030       sys::swapByteOrder(seg.vmaddr);
01031       sys::swapByteOrder(seg.vmsize);
01032       sys::swapByteOrder(seg.fileoff);
01033       sys::swapByteOrder(seg.filesize);
01034       sys::swapByteOrder(seg.maxprot);
01035       sys::swapByteOrder(seg.initprot);
01036       sys::swapByteOrder(seg.nsects);
01037       sys::swapByteOrder(seg.flags);
01038     }
01039 
01040     inline void swapStruct(segment_command &seg) {
01041       sys::swapByteOrder(seg.cmd);
01042       sys::swapByteOrder(seg.cmdsize);
01043       sys::swapByteOrder(seg.vmaddr);
01044       sys::swapByteOrder(seg.vmsize);
01045       sys::swapByteOrder(seg.fileoff);
01046       sys::swapByteOrder(seg.filesize);
01047       sys::swapByteOrder(seg.maxprot);
01048       sys::swapByteOrder(seg.initprot);
01049       sys::swapByteOrder(seg.nsects);
01050       sys::swapByteOrder(seg.flags);
01051     }
01052 
01053     inline void swapStruct(section_64 &sect) {
01054       sys::swapByteOrder(sect.addr);
01055       sys::swapByteOrder(sect.size);
01056       sys::swapByteOrder(sect.offset);
01057       sys::swapByteOrder(sect.align);
01058       sys::swapByteOrder(sect.reloff);
01059       sys::swapByteOrder(sect.nreloc);
01060       sys::swapByteOrder(sect.flags);
01061       sys::swapByteOrder(sect.reserved1);
01062       sys::swapByteOrder(sect.reserved2);
01063     }
01064 
01065     inline void swapStruct(section &sect) {
01066       sys::swapByteOrder(sect.addr);
01067       sys::swapByteOrder(sect.size);
01068       sys::swapByteOrder(sect.offset);
01069       sys::swapByteOrder(sect.align);
01070       sys::swapByteOrder(sect.reloff);
01071       sys::swapByteOrder(sect.nreloc);
01072       sys::swapByteOrder(sect.flags);
01073       sys::swapByteOrder(sect.reserved1);
01074       sys::swapByteOrder(sect.reserved2);
01075     }
01076 
01077     inline void swapStruct(dyld_info_command &info) {
01078       sys::swapByteOrder(info.cmd);
01079       sys::swapByteOrder(info.cmdsize);
01080       sys::swapByteOrder(info.rebase_off);
01081       sys::swapByteOrder(info.rebase_size);
01082       sys::swapByteOrder(info.bind_off);
01083       sys::swapByteOrder(info.bind_size);
01084       sys::swapByteOrder(info.weak_bind_off);
01085       sys::swapByteOrder(info.weak_bind_size);
01086       sys::swapByteOrder(info.lazy_bind_off);
01087       sys::swapByteOrder(info.lazy_bind_size);
01088       sys::swapByteOrder(info.export_off);
01089       sys::swapByteOrder(info.export_size);
01090     }
01091 
01092     inline void swapStruct(dylib_command &d) {
01093       sys::swapByteOrder(d.cmd);
01094       sys::swapByteOrder(d.cmdsize);
01095       sys::swapByteOrder(d.dylib.name);
01096       sys::swapByteOrder(d.dylib.timestamp);
01097       sys::swapByteOrder(d.dylib.current_version);
01098       sys::swapByteOrder(d.dylib.compatibility_version);
01099     }
01100 
01101     inline void swapStruct(dylinker_command &d) {
01102       sys::swapByteOrder(d.cmd);
01103       sys::swapByteOrder(d.cmdsize);
01104       sys::swapByteOrder(d.name);
01105     }
01106 
01107     inline void swapStruct(uuid_command &u) {
01108       sys::swapByteOrder(u.cmd);
01109       sys::swapByteOrder(u.cmdsize);
01110     }
01111 
01112     inline void swapStruct(source_version_command &s) {
01113       sys::swapByteOrder(s.cmd);
01114       sys::swapByteOrder(s.cmdsize);
01115       sys::swapByteOrder(s.version);
01116     }
01117 
01118     inline void swapStruct(entry_point_command &e) {
01119       sys::swapByteOrder(e.cmd);
01120       sys::swapByteOrder(e.cmdsize);
01121       sys::swapByteOrder(e.entryoff);
01122       sys::swapByteOrder(e.stacksize);
01123     }
01124 
01125     inline void swapStruct(dysymtab_command &dst) {
01126       sys::swapByteOrder(dst.cmd);
01127       sys::swapByteOrder(dst.cmdsize);
01128       sys::swapByteOrder(dst.ilocalsym);
01129       sys::swapByteOrder(dst.nlocalsym);
01130       sys::swapByteOrder(dst.iextdefsym);
01131       sys::swapByteOrder(dst.nextdefsym);
01132       sys::swapByteOrder(dst.iundefsym);
01133       sys::swapByteOrder(dst.nundefsym);
01134       sys::swapByteOrder(dst.tocoff);
01135       sys::swapByteOrder(dst.ntoc);
01136       sys::swapByteOrder(dst.modtaboff);
01137       sys::swapByteOrder(dst.nmodtab);
01138       sys::swapByteOrder(dst.extrefsymoff);
01139       sys::swapByteOrder(dst.nextrefsyms);
01140       sys::swapByteOrder(dst.indirectsymoff);
01141       sys::swapByteOrder(dst.nindirectsyms);
01142       sys::swapByteOrder(dst.extreloff);
01143       sys::swapByteOrder(dst.nextrel);
01144       sys::swapByteOrder(dst.locreloff);
01145       sys::swapByteOrder(dst.nlocrel);
01146     }
01147 
01148     inline void swapStruct(any_relocation_info &reloc) {
01149       sys::swapByteOrder(reloc.r_word0);
01150       sys::swapByteOrder(reloc.r_word1);
01151     }
01152 
01153     inline void swapStruct(nlist_base &S) {
01154       sys::swapByteOrder(S.n_strx);
01155       sys::swapByteOrder(S.n_desc);
01156     }
01157 
01158     inline void swapStruct(nlist &sym) {
01159       sys::swapByteOrder(sym.n_strx);
01160       sys::swapByteOrder(sym.n_desc);
01161       sys::swapByteOrder(sym.n_value);
01162     }
01163 
01164     inline void swapStruct(nlist_64 &sym) {
01165       sys::swapByteOrder(sym.n_strx);
01166       sys::swapByteOrder(sym.n_desc);
01167       sys::swapByteOrder(sym.n_value);
01168     }
01169 
01170     inline void swapStruct(linkedit_data_command &C) {
01171       sys::swapByteOrder(C.cmd);
01172       sys::swapByteOrder(C.cmdsize);
01173       sys::swapByteOrder(C.dataoff);
01174       sys::swapByteOrder(C.datasize);
01175     }
01176 
01177     inline void swapStruct(linker_options_command &C) {
01178       sys::swapByteOrder(C.cmd);
01179       sys::swapByteOrder(C.cmdsize);
01180       sys::swapByteOrder(C.count);
01181     }
01182 
01183     inline void swapStruct(version_min_command&C) {
01184       sys::swapByteOrder(C.cmd);
01185       sys::swapByteOrder(C.cmdsize);
01186       sys::swapByteOrder(C.version);
01187       sys::swapByteOrder(C.sdk);
01188     }
01189 
01190     inline void swapStruct(data_in_code_entry &C) {
01191       sys::swapByteOrder(C.offset);
01192       sys::swapByteOrder(C.length);
01193       sys::swapByteOrder(C.kind);
01194     }
01195 
01196     inline void swapStruct(uint32_t &C) {
01197       sys::swapByteOrder(C);
01198     }
01199 
01200     // Get/Set functions from <mach-o/nlist.h>
01201 
01202     static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
01203       return (((n_desc) >> 8u) & 0xffu);
01204     }
01205 
01206     static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
01207       n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8));
01208     }
01209 
01210     static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) {
01211       return (n_desc >> 8u) & 0x0fu;
01212     }
01213 
01214     static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) {
01215       n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
01216     }
01217 
01218     // Enums from <mach/machine.h>
01219     enum : uint32_t {
01220       // Capability bits used in the definition of cpu_type.
01221       CPU_ARCH_MASK  = 0xff000000,   // Mask for architecture bits
01222       CPU_ARCH_ABI64 = 0x01000000    // 64 bit ABI
01223     };
01224 
01225     // Constants for the cputype field.
01226     enum CPUType {
01227       CPU_TYPE_ANY       = -1,
01228       CPU_TYPE_X86       = 7,
01229       CPU_TYPE_I386      = CPU_TYPE_X86,
01230       CPU_TYPE_X86_64    = CPU_TYPE_X86 | CPU_ARCH_ABI64,
01231    /* CPU_TYPE_MIPS      = 8, */
01232       CPU_TYPE_MC98000   = 10, // Old Motorola PowerPC
01233       CPU_TYPE_ARM       = 12,
01234       CPU_TYPE_ARM64     = CPU_TYPE_ARM | CPU_ARCH_ABI64,
01235       CPU_TYPE_SPARC     = 14,
01236       CPU_TYPE_POWERPC   = 18,
01237       CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
01238     };
01239 
01240     enum : uint32_t {
01241       // Capability bits used in the definition of cpusubtype.
01242       CPU_SUBTYPE_MASK  = 0xff000000,   // Mask for architecture bits
01243       CPU_SUBTYPE_LIB64 = 0x80000000,   // 64 bit libraries
01244 
01245       // Special CPU subtype constants.
01246       CPU_SUBTYPE_MULTIPLE = ~0u
01247     };
01248 
01249     // Constants for the cpusubtype field.
01250     enum CPUSubTypeX86 {
01251       CPU_SUBTYPE_I386_ALL       = 3,
01252       CPU_SUBTYPE_386            = 3,
01253       CPU_SUBTYPE_486            = 4,
01254       CPU_SUBTYPE_486SX          = 0x84,
01255       CPU_SUBTYPE_586            = 5,
01256       CPU_SUBTYPE_PENT           = CPU_SUBTYPE_586,
01257       CPU_SUBTYPE_PENTPRO        = 0x16,
01258       CPU_SUBTYPE_PENTII_M3      = 0x36,
01259       CPU_SUBTYPE_PENTII_M5      = 0x56,
01260       CPU_SUBTYPE_CELERON        = 0x67,
01261       CPU_SUBTYPE_CELERON_MOBILE = 0x77,
01262       CPU_SUBTYPE_PENTIUM_3      = 0x08,
01263       CPU_SUBTYPE_PENTIUM_3_M    = 0x18,
01264       CPU_SUBTYPE_PENTIUM_3_XEON = 0x28,
01265       CPU_SUBTYPE_PENTIUM_M      = 0x09,
01266       CPU_SUBTYPE_PENTIUM_4      = 0x0a,
01267       CPU_SUBTYPE_PENTIUM_4_M    = 0x1a,
01268       CPU_SUBTYPE_ITANIUM        = 0x0b,
01269       CPU_SUBTYPE_ITANIUM_2      = 0x1b,
01270       CPU_SUBTYPE_XEON           = 0x0c,
01271       CPU_SUBTYPE_XEON_MP        = 0x1c,
01272 
01273       CPU_SUBTYPE_X86_ALL     = 3,
01274       CPU_SUBTYPE_X86_64_ALL  = 3,
01275       CPU_SUBTYPE_X86_ARCH1   = 4,
01276       CPU_SUBTYPE_X86_64_H    = 8
01277     };
01278     static inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
01279       return Family | (Model << 4);
01280     }
01281     static inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST) {
01282       return ((int)ST) & 0x0f;
01283     }
01284     static inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) {
01285       return ((int)ST) >> 4;
01286     }
01287     enum {
01288       CPU_SUBTYPE_INTEL_FAMILY_MAX = 15,
01289       CPU_SUBTYPE_INTEL_MODEL_ALL  = 0
01290     };
01291 
01292     enum CPUSubTypeARM {
01293       CPU_SUBTYPE_ARM_ALL     = 0,
01294       CPU_SUBTYPE_ARM_V4T     = 5,
01295       CPU_SUBTYPE_ARM_V6      = 6,
01296       CPU_SUBTYPE_ARM_V5      = 7,
01297       CPU_SUBTYPE_ARM_V5TEJ   = 7,
01298       CPU_SUBTYPE_ARM_XSCALE  = 8,
01299       CPU_SUBTYPE_ARM_V7      = 9,
01300       //  unused  ARM_V7F     = 10,
01301       CPU_SUBTYPE_ARM_V7S     = 11,
01302       CPU_SUBTYPE_ARM_V7K     = 12,
01303       CPU_SUBTYPE_ARM_V6M     = 14,
01304       CPU_SUBTYPE_ARM_V7M     = 15,
01305       CPU_SUBTYPE_ARM_V7EM    = 16
01306     };
01307 
01308     enum CPUSubTypeARM64 {
01309       CPU_SUBTYPE_ARM64_ALL   = 0
01310     };
01311 
01312     enum CPUSubTypeSPARC {
01313       CPU_SUBTYPE_SPARC_ALL   = 0
01314     };
01315 
01316     enum CPUSubTypePowerPC {
01317       CPU_SUBTYPE_POWERPC_ALL   = 0,
01318       CPU_SUBTYPE_POWERPC_601   = 1,
01319       CPU_SUBTYPE_POWERPC_602   = 2,
01320       CPU_SUBTYPE_POWERPC_603   = 3,
01321       CPU_SUBTYPE_POWERPC_603e  = 4,
01322       CPU_SUBTYPE_POWERPC_603ev = 5,
01323       CPU_SUBTYPE_POWERPC_604   = 6,
01324       CPU_SUBTYPE_POWERPC_604e  = 7,
01325       CPU_SUBTYPE_POWERPC_620   = 8,
01326       CPU_SUBTYPE_POWERPC_750   = 9,
01327       CPU_SUBTYPE_POWERPC_7400  = 10,
01328       CPU_SUBTYPE_POWERPC_7450  = 11,
01329       CPU_SUBTYPE_POWERPC_970   = 100,
01330 
01331       CPU_SUBTYPE_MC980000_ALL  = CPU_SUBTYPE_POWERPC_ALL,
01332       CPU_SUBTYPE_MC98601       = CPU_SUBTYPE_POWERPC_601
01333     };
01334   } // end namespace MachO
01335 } // end namespace llvm
01336 
01337 #endif