diff options
Diffstat (limited to 'include/llvm/Support/MachO.h')
-rw-r--r-- | include/llvm/Support/MachO.h | 150 |
1 files changed, 99 insertions, 51 deletions
diff --git a/include/llvm/Support/MachO.h b/include/llvm/Support/MachO.h index 54b8745de1c1..9a03722d250f 100644 --- a/include/llvm/Support/MachO.h +++ b/include/llvm/Support/MachO.h @@ -29,7 +29,9 @@ namespace llvm { MH_MAGIC_64 = 0xFEEDFACFu, MH_CIGAM_64 = 0xCFFAEDFEu, FAT_MAGIC = 0xCAFEBABEu, - FAT_CIGAM = 0xBEBAFECAu + FAT_CIGAM = 0xBEBAFECAu, + FAT_MAGIC_64 = 0xCAFEBABFu, + FAT_CIGAM_64 = 0xBFBAFECAu }; enum HeaderFileType { @@ -84,59 +86,15 @@ namespace llvm { LC_REQ_DYLD = 0x80000000u }; +#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ + LCName = LCValue, + enum LoadCommandType : uint32_t { - // Constants for the "cmd" field in llvm::MachO::load_command - LC_SEGMENT = 0x00000001u, - LC_SYMTAB = 0x00000002u, - LC_SYMSEG = 0x00000003u, - LC_THREAD = 0x00000004u, - LC_UNIXTHREAD = 0x00000005u, - LC_LOADFVMLIB = 0x00000006u, - LC_IDFVMLIB = 0x00000007u, - LC_IDENT = 0x00000008u, - LC_FVMFILE = 0x00000009u, - LC_PREPAGE = 0x0000000Au, - LC_DYSYMTAB = 0x0000000Bu, - LC_LOAD_DYLIB = 0x0000000Cu, - LC_ID_DYLIB = 0x0000000Du, - LC_LOAD_DYLINKER = 0x0000000Eu, - LC_ID_DYLINKER = 0x0000000Fu, - LC_PREBOUND_DYLIB = 0x00000010u, - LC_ROUTINES = 0x00000011u, - LC_SUB_FRAMEWORK = 0x00000012u, - LC_SUB_UMBRELLA = 0x00000013u, - LC_SUB_CLIENT = 0x00000014u, - LC_SUB_LIBRARY = 0x00000015u, - LC_TWOLEVEL_HINTS = 0x00000016u, - LC_PREBIND_CKSUM = 0x00000017u, - LC_LOAD_WEAK_DYLIB = 0x80000018u, - LC_SEGMENT_64 = 0x00000019u, - LC_ROUTINES_64 = 0x0000001Au, - LC_UUID = 0x0000001Bu, - LC_RPATH = 0x8000001Cu, - LC_CODE_SIGNATURE = 0x0000001Du, - LC_SEGMENT_SPLIT_INFO = 0x0000001Eu, - LC_REEXPORT_DYLIB = 0x8000001Fu, - LC_LAZY_LOAD_DYLIB = 0x00000020u, - LC_ENCRYPTION_INFO = 0x00000021u, - LC_DYLD_INFO = 0x00000022u, - LC_DYLD_INFO_ONLY = 0x80000022u, - LC_LOAD_UPWARD_DYLIB = 0x80000023u, - LC_VERSION_MIN_MACOSX = 0x00000024u, - LC_VERSION_MIN_IPHONEOS = 0x00000025u, - LC_FUNCTION_STARTS = 0x00000026u, - LC_DYLD_ENVIRONMENT = 0x00000027u, - LC_MAIN = 0x80000028u, - LC_DATA_IN_CODE = 0x00000029u, - LC_SOURCE_VERSION = 0x0000002Au, - LC_DYLIB_CODE_SIGN_DRS = 0x0000002Bu, - LC_ENCRYPTION_INFO_64 = 0x0000002Cu, - LC_LINKER_OPTION = 0x0000002Du, - LC_LINKER_OPTIMIZATION_HINT = 0x0000002Eu, - LC_VERSION_MIN_TVOS = 0x0000002Fu, - LC_VERSION_MIN_WATCHOS = 0x00000030u, + #include "llvm/Support/MachO.def" }; +#undef HANDLE_LOAD_COMMAND + enum : uint32_t { // Constant bits for the "flags" field in llvm::MachO::segment_command SG_HIGHVM = 0x1u, @@ -935,6 +893,15 @@ namespace llvm { uint32_t align; }; + struct fat_arch_64 { + uint32_t cputype; + uint32_t cpusubtype; + uint64_t offset; + uint64_t size; + uint32_t align; + uint32_t reserved; + }; + // Structs from <mach-o/reloc.h> struct relocation_info { int32_t r_address; @@ -993,6 +960,28 @@ namespace llvm { // Byte order swapping functions for MachO structs + inline void swapStruct(fat_header &mh) { + sys::swapByteOrder(mh.magic); + sys::swapByteOrder(mh.nfat_arch); + } + + inline void swapStruct(fat_arch &mh) { + sys::swapByteOrder(mh.cputype); + sys::swapByteOrder(mh.cpusubtype); + sys::swapByteOrder(mh.offset); + sys::swapByteOrder(mh.size); + sys::swapByteOrder(mh.align); + } + + inline void swapStruct(fat_arch_64 &mh) { + sys::swapByteOrder(mh.cputype); + sys::swapByteOrder(mh.cpusubtype); + sys::swapByteOrder(mh.offset); + sys::swapByteOrder(mh.size); + sys::swapByteOrder(mh.align); + sys::swapByteOrder(mh.reserved); + } + inline void swapStruct(mach_header &mh) { sys::swapByteOrder(mh.magic); sys::swapByteOrder(mh.cputype); @@ -1279,6 +1268,58 @@ namespace llvm { sys::swapByteOrder(C); } + inline void swapStruct(prebind_cksum_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + sys::swapByteOrder(C.cksum); + } + + inline void swapStruct(twolevel_hints_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + sys::swapByteOrder(C.offset); + sys::swapByteOrder(C.nhints); + } + + inline void swapStruct(prebound_dylib_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + sys::swapByteOrder(C.name); + sys::swapByteOrder(C.nmodules); + sys::swapByteOrder(C.linked_modules); + } + + inline void swapStruct(fvmfile_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + sys::swapByteOrder(C.name); + sys::swapByteOrder(C.header_addr); + } + + inline void swapStruct(symseg_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + sys::swapByteOrder(C.offset); + sys::swapByteOrder(C.size); + } + + inline void swapStruct(ident_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + } + + inline void swapStruct(fvmlib &C) { + sys::swapByteOrder(C.name); + sys::swapByteOrder(C.minor_version); + sys::swapByteOrder(C.header_addr); + } + + inline void swapStruct(fvmlib_command &C) { + sys::swapByteOrder(C.cmd); + sys::swapByteOrder(C.cmdsize); + swapStruct(C.fvmlib); + } + // Get/Set functions from <mach-o/nlist.h> static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) { @@ -1669,6 +1710,13 @@ namespace llvm { const uint32_t x86_EXCEPTION_STATE_COUNT = sizeof(x86_exception_state_t) / sizeof(uint32_t); + // Define a union of all load command structs + #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data; + + union macho_load_command { + #include "llvm/Support/MachO.def" + }; + } // end namespace MachO } // end namespace llvm |