| 1 | /* $Id $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * Mach-0 structures, types and defines.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #ifndef ___k_kLdrFmts_mach_o_h___
|
|---|
| 7 | #define ___k_kLdrFmts_mach_o_h___
|
|---|
| 8 |
|
|---|
| 9 | #include <k/kDefs.h>
|
|---|
| 10 | #include <k/kTypes.h>
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | /** @defgroup grp_mach_o The Mach-O Structures, Types, and Defines.
|
|---|
| 14 | * @{
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | #ifndef IMAGE_FAT_SIGNATURE
|
|---|
| 19 | /** The FAT signature (universal binaries). */
|
|---|
| 20 | # define IMAGE_FAT_SIGNATURE KU32_C(0xcafebabe)
|
|---|
| 21 | #endif
|
|---|
| 22 | #ifndef IMAGE_FAT_SIGNATURE_OE
|
|---|
| 23 | /** The FAT signature (universal binaries), other endian. */
|
|---|
| 24 | # define IMAGE_FAT_SIGNATURE_OE KU32_C(0xbebafeca)
|
|---|
| 25 | #endif
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * The fat header found at the start of universal binaries.
|
|---|
| 29 | * It is followed by \a nfat_arch numbers of \a fat_arch structures.
|
|---|
| 30 | */
|
|---|
| 31 | typedef struct fat_header
|
|---|
| 32 | {
|
|---|
| 33 | KU32 magic;
|
|---|
| 34 | KU32 nfat_arch;
|
|---|
| 35 | } fat_header_t;
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Description of fat file item.
|
|---|
| 39 | */
|
|---|
| 40 | typedef struct fat_arch
|
|---|
| 41 | {
|
|---|
| 42 | KI32 cputype;
|
|---|
| 43 | KI32 cpusubtype;
|
|---|
| 44 | KU32 offset;
|
|---|
| 45 | KU32 size;
|
|---|
| 46 | KU32 align; /**< Power of 2. */
|
|---|
| 47 | } fat_arch_t;
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | #ifndef IMAGE_MACHO32_SIGNATURE
|
|---|
| 52 | /** The 32-bit Mach-O signature. */
|
|---|
| 53 | # define IMAGE_MACHO32_SIGNATURE KU32_C(0xfeedface)
|
|---|
| 54 | #endif
|
|---|
| 55 | #ifndef IMAGE_MACHO32_SIGNATURE_OE
|
|---|
| 56 | /** The 32-bit Mach-O signature, other endian. */
|
|---|
| 57 | # define IMAGE_MACHO32_SIGNATURE_OE KU32_C(0xcefaedfe)
|
|---|
| 58 | #endif
|
|---|
| 59 | #define MH_MAGIC IMAGE_MACHO32_SIGNATURE
|
|---|
| 60 | #define MH_CIGAM IMAGE_MACHO32_SIGNATURE_OE
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * 32-bit Mach-O header.
|
|---|
| 64 | * This is followed by \a ncmds number of load commands.
|
|---|
| 65 | * @see mach_header_64
|
|---|
| 66 | */
|
|---|
| 67 | typedef struct mach_header_32
|
|---|
| 68 | {
|
|---|
| 69 | KU32 magic;
|
|---|
| 70 | KI32 cputype;
|
|---|
| 71 | KI32 cpusubtype;
|
|---|
| 72 | KU32 filetype;
|
|---|
| 73 | KU32 ncmds;
|
|---|
| 74 | KU32 sizeofcmds;
|
|---|
| 75 | KU32 flags;
|
|---|
| 76 | } mach_header_32_t;
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | #ifndef IMAGE_MACHO64_SIGNATURE
|
|---|
| 81 | /** The 64-bit Mach-O signature. */
|
|---|
| 82 | # define IMAGE_MACHO64_SIGNATURE KU32_C(0xfeedfacf)
|
|---|
| 83 | #endif
|
|---|
| 84 | #ifndef IMAGE_MACHO64_SIGNATURE_OE
|
|---|
| 85 | /** The 64-bit Mach-O signature, other endian. */
|
|---|
| 86 | # define IMAGE_MACHO64_SIGNATURE_OE KU32_C(0xfefaedfe)
|
|---|
| 87 | #endif
|
|---|
| 88 | #define MH_MAGIC_64 IMAGE_MACHO64_SIGNATURE
|
|---|
| 89 | #define MH_CIGAM_64 IMAGE_MACHO64_SIGNATURE_OE
|
|---|
| 90 |
|
|---|
| 91 | /**
|
|---|
| 92 | * 64-bit Mach-O header.
|
|---|
| 93 | * This is followed by \a ncmds number of load commands.
|
|---|
| 94 | * @see mach_header
|
|---|
| 95 | */
|
|---|
| 96 | typedef struct mach_header_64
|
|---|
| 97 | {
|
|---|
| 98 | KU32 magic;
|
|---|
| 99 | KI32 cputype;
|
|---|
| 100 | KI32 cpusubtype;
|
|---|
| 101 | KU32 filetype;
|
|---|
| 102 | KU32 ncmds;
|
|---|
| 103 | KU32 sizeofcmds;
|
|---|
| 104 | KU32 flags;
|
|---|
| 105 | KU32 reserved; /**< (for proper struct and command alignment I guess) */
|
|---|
| 106 | } mach_header_64_t;
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | /** @name File types (mach_header_64::filetype, mach_header_32::filetype)
|
|---|
| 110 | * @{
|
|---|
| 111 | */
|
|---|
| 112 | #define MH_OBJECT KU32_C(1) /**< Object (relocatable). */
|
|---|
| 113 | #define MH_EXECUTE KU32_C(2) /**< Executable (demand paged). */
|
|---|
| 114 | #define MH_FVMLIB KU32_C(3) /**< Fixed VM shared library. */
|
|---|
| 115 | #define MH_CORE KU32_C(4) /**< Core file. */
|
|---|
| 116 | #define MH_PRELOAD KU32_C(5) /**< Preloaded executable. */
|
|---|
| 117 | #define MH_DYLIB KU32_C(6) /**< Dynamically bound shared library. */
|
|---|
| 118 | #define MH_DYLINKER KU32_C(7) /**< Dynamic linker. */
|
|---|
| 119 | #define MH_BUNDLE KU32_C(8) /**< Dymamically bound bundle. */
|
|---|
| 120 | #define MH_DYLIB_STUB KU32_C(9) /**< Shared library stub for static linking. */
|
|---|
| 121 | #define MH_DSYM KU32_C(10)/**< Debug symbols. */
|
|---|
| 122 |
|
|---|
| 123 | /** @} */
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | /** @name Mach-O Header flags (mach_header_64::flags, mach_header_32::flags)
|
|---|
| 127 | * @{
|
|---|
| 128 | */
|
|---|
| 129 | #define MH_NOUNDEFS KU32_C(0x00000001) /**< No undefined symbols. */
|
|---|
| 130 | #define MH_INCRLINK KU32_C(0x00000002) /**< Partial increment link output. */
|
|---|
| 131 | #define MH_DYLDLINK KU32_C(0x00000004) /**< Food for the dynamic linker, not for ld. */
|
|---|
| 132 | #define MH_BINDATLOAD KU32_C(0x00000008) /**< Bind all undefined symbols at load time. */
|
|---|
| 133 | #define MH_PREBOUND KU32_C(0x00000010) /**< Contains prebound undefined symbols. */
|
|---|
| 134 | #define MH_SPLIT_SEGS KU32_C(0x00000020) /**< Read-only and read-write segments are split. */
|
|---|
| 135 | #define MH_LAZY_INIT KU32_C(0x00000040) /**< Obsolete flag for doing lazy init when data is written. */
|
|---|
| 136 | #define MH_TWOLEVEL KU32_C(0x00000080) /**< Uses two-level name space bindings. */
|
|---|
| 137 | #define MH_FORCE_FLAT KU32_C(0x00000100) /**< Task: The executable forces all images to use flat name space bindings. */
|
|---|
| 138 | #define MH_NOMULTIDEFS KU32_C(0x00000200) /**< No multiple symbol definitions, safe to use two-level namespace hints. */
|
|---|
| 139 | #define MH_NOFIXPREBINDING KU32_C(0x00000400) /**< The dynamic linker should not notify the prebinding agent about this executable. */
|
|---|
| 140 | #define MH_PREBINDABLE KU32_C(0x00000800) /**< Not prebound, but it can be. Invalid if MH_PREBOUND is set. */
|
|---|
| 141 | #define MH_ALLMODSBOUND KU32_C(0x00001000) /**< Binds to all two-level namespace modules of preqs. Requires MH_PREBINDABLE and MH_TWOLEVEL to be set. */
|
|---|
| 142 | #define MH_SUBSECTIONS_VIA_SYMBOLS KU32_C(0x00002000) /**< Safe to divide sections into sub-sections via symbols for dead code stripping. */
|
|---|
| 143 | #define MH_CANONICAL KU32_C(0x00004000) /**< Canonicalized via unprebind. */
|
|---|
| 144 | #define MH_WEAK_DEFINES KU32_C(0x00008000) /**< The (finally) linked image has weak symbols. */
|
|---|
| 145 | #define MH_BINDS_TO_WEAK KU32_C(0x00010000) /**< The (finally) linked image uses weak symbols. */
|
|---|
| 146 | #define MH_ALLOW_STACK_EXECUTION KU32_C(0x00020000) /**< Task: allow stack execution. (MH_EXECUTE only) */
|
|---|
| 147 | #define MH_VALID_FLAGS KU32_C(0x0003ffff) /**< Mask containing the defined flags. */
|
|---|
| 148 | /** @} */
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | /** @name CPU types / bits (mach_header_64::cputype, mach_header_32::cputype, fat_arch::cputype)
|
|---|
| 152 | * @{
|
|---|
| 153 | */
|
|---|
| 154 | #define CPU_ARCH_MASK KI32_C(0xff000000)
|
|---|
| 155 | #define CPU_ARCH_ABI64 KI32_C(0x01000000)
|
|---|
| 156 | #define CPU_TYPE_ANY KI32_C(-1)
|
|---|
| 157 | #define CPU_TYPE_VAX KI32_C(1)
|
|---|
| 158 | #define CPU_TYPE_MC680x0 KI32_C(6)
|
|---|
| 159 | #define CPU_TYPE_X86 KI32_C(7)
|
|---|
| 160 | #define CPU_TYPE_I386 CPU_TYPE_X86
|
|---|
| 161 | #define CPU_TYPE_X86_64 (CPU_TYPE_X86 | CPU_ARCH_ABI64)
|
|---|
| 162 | #define CPU_TYPE_MC98000 KI32_C(10)
|
|---|
| 163 | #define CPU_TYPE_HPPA KI32_C(11)
|
|---|
| 164 | #define CPU_TYPE_MC88000 KI32_C(13)
|
|---|
| 165 | #define CPU_TYPE_SPARC KI32_C(14)
|
|---|
| 166 | #define CPU_TYPE_I860 KI32_C(15)
|
|---|
| 167 | #define CPU_TYPE_POWERPC KI32_C(18)
|
|---|
| 168 | #define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64)
|
|---|
| 169 | /** @} */
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /** @name CPU subtypes (mach_header_64::cpusubtype, mach_header_32::cpusubtype, fat_arch::cpusubtype)
|
|---|
| 173 | * @{ */
|
|---|
| 174 | #define CPU_SUBTYPE_MULTIPLE KI32_C(-1)
|
|---|
| 175 | #define CPU_SUBTYPE_LITTLE_ENDIAN KI32_C(0) /**< figure this one out. */
|
|---|
| 176 | #define CPU_SUBTYPE_BIG_ENDIAN KI32_C(1) /**< ditto */
|
|---|
| 177 |
|
|---|
| 178 | /* VAX */
|
|---|
| 179 | #define CPU_SUBTYPE_VAX_ALL KI32_C(0)
|
|---|
| 180 | #define CPU_SUBTYPE_VAX780 KI32_C(1)
|
|---|
| 181 | #define CPU_SUBTYPE_VAX785 KI32_C(2)
|
|---|
| 182 | #define CPU_SUBTYPE_VAX750 KI32_C(3)
|
|---|
| 183 | #define CPU_SUBTYPE_VAX730 KI32_C(4)
|
|---|
| 184 | #define CPU_SUBTYPE_UVAXI KI32_C(5)
|
|---|
| 185 | #define CPU_SUBTYPE_UVAXII KI32_C(6)
|
|---|
| 186 | #define CPU_SUBTYPE_VAX8200 KI32_C(7)
|
|---|
| 187 | #define CPU_SUBTYPE_VAX8500 KI32_C(8)
|
|---|
| 188 | #define CPU_SUBTYPE_VAX8600 KI32_C(9)
|
|---|
| 189 | #define CPU_SUBTYPE_VAX8650 KI32_C(10)
|
|---|
| 190 | #define CPU_SUBTYPE_VAX8800 KI32_C(11)
|
|---|
| 191 | #define CPU_SUBTYPE_UVAXIII KI32_C(12)
|
|---|
| 192 |
|
|---|
| 193 | /* MC680xx */
|
|---|
| 194 | #define CPU_SUBTYPE_MC680x0_ALL KI32_C(1)
|
|---|
| 195 | #define CPU_SUBTYPE_MC68030 KI32_C(1)
|
|---|
| 196 | #define CPU_SUBTYPE_MC68040 KI32_C(2)
|
|---|
| 197 | #define CPU_SUBTYPE_MC68030_ONLY KI32_C(3)
|
|---|
| 198 |
|
|---|
| 199 | /* I386 */
|
|---|
| 200 | #define CPU_SUBTYPE_INTEL(fam, model) ( (KI32)(((model) << 4) | (fam)) )
|
|---|
| 201 | #define CPU_SUBTYPE_INTEL_FAMILY(subtype) ( (subtype) & 0xf )
|
|---|
| 202 | #define CPU_SUBTYPE_INTEL_MODEL(subtype) ( (subtype) >> 4 )
|
|---|
| 203 | #define CPU_SUBTYPE_INTEL_FAMILY_MAX 0xf
|
|---|
| 204 | #define CPU_SUBTYPE_INTEL_MODEL_ALL 0
|
|---|
| 205 |
|
|---|
| 206 | #define CPU_SUBTYPE_I386_ALL CPU_SUBTYPE_INTEL(3, 0)
|
|---|
| 207 | #define CPU_SUBTYPE_386 CPU_SUBTYPE_INTEL(3, 0)
|
|---|
| 208 | #define CPU_SUBTYPE_486 CPU_SUBTYPE_INTEL(4, 0)
|
|---|
| 209 | #define CPU_SUBTYPE_486SX CPU_SUBTYPE_INTEL(4, 8)
|
|---|
| 210 | #define CPU_SUBTYPE_586 CPU_SUBTYPE_INTEL(5, 0)
|
|---|
| 211 | #define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
|
|---|
| 212 | #define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
|
|---|
| 213 | #define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
|
|---|
| 214 | #define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
|
|---|
| 215 | #define CPU_SUBTYPE_CELERON CPU_SUBTYPE_INTEL(7, 6)
|
|---|
| 216 | #define CPU_SUBTYPE_CELERON_MOBILE CPU_SUBTYPE_INTEL(7, 7)
|
|---|
| 217 | #define CPU_SUBTYPE_PENTIUM_3 CPU_SUBTYPE_INTEL(8, 0)
|
|---|
| 218 | #define CPU_SUBTYPE_PENTIUM_3_M CPU_SUBTYPE_INTEL(8, 1)
|
|---|
| 219 | #define CPU_SUBTYPE_PENTIUM_3_XEON CPU_SUBTYPE_INTEL(8, 2)
|
|---|
| 220 | #define CPU_SUBTYPE_PENTIUM_M CPU_SUBTYPE_INTEL(9, 0)
|
|---|
| 221 | #define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
|
|---|
| 222 | #define CPU_SUBTYPE_PENTIUM_4_M CPU_SUBTYPE_INTEL(10, 1)
|
|---|
| 223 | #define CPU_SUBTYPE_ITANIUM CPU_SUBTYPE_INTEL(11, 0)
|
|---|
| 224 | #define CPU_SUBTYPE_ITANIUM_2 CPU_SUBTYPE_INTEL(11, 1)
|
|---|
| 225 | #define CPU_SUBTYPE_XEON CPU_SUBTYPE_INTEL(12, 0)
|
|---|
| 226 | #define CPU_SUBTYPE_XEON_MP CPU_SUBTYPE_INTEL(12, 1)
|
|---|
| 227 |
|
|---|
| 228 | /* X86 */
|
|---|
| 229 | #define CPU_SUBTYPE_X86_ALL KI32_C(3) /* CPU_SUBTYPE_I386_ALL */
|
|---|
| 230 | #define CPU_SUBTYPE_X86_64_ALL KI32_C(3) /* CPU_SUBTYPE_I386_ALL */
|
|---|
| 231 | #define CPU_SUBTYPE_X86_ARCH1 KI32_C(4) /* CPU_SUBTYPE_I486_ALL */
|
|---|
| 232 |
|
|---|
| 233 | /* MIPS */
|
|---|
| 234 | #define CPU_SUBTYPE_MIPS_ALL KI32_C(0)
|
|---|
| 235 | #define CPU_SUBTYPE_MIPS_R2300 KI32_C(1)
|
|---|
| 236 | #define CPU_SUBTYPE_MIPS_R2600 KI32_C(2)
|
|---|
| 237 | #define CPU_SUBTYPE_MIPS_R2800 KI32_C(3)
|
|---|
| 238 | #define CPU_SUBTYPE_MIPS_R2000a KI32_C(4)
|
|---|
| 239 | #define CPU_SUBTYPE_MIPS_R2000 KI32_C(5)
|
|---|
| 240 | #define CPU_SUBTYPE_MIPS_R3000a KI32_C(6)
|
|---|
| 241 | #define CPU_SUBTYPE_MIPS_R3000 KI32_C(7)
|
|---|
| 242 |
|
|---|
| 243 | /* MC98000 (PowerPC) */
|
|---|
| 244 | #define CPU_SUBTYPE_MC98000_ALL KI32_C(0)
|
|---|
| 245 | #define CPU_SUBTYPE_MC98601 KI32_C(1)
|
|---|
| 246 |
|
|---|
| 247 | /* HP-PA */
|
|---|
| 248 | #define CPU_SUBTYPE_HPPA_ALL KI32_C(0)
|
|---|
| 249 | #define CPU_SUBTYPE_HPPA_7100 KI32_C(0)
|
|---|
| 250 | #define CPU_SUBTYPE_HPPA_7100LC KI32_C(1)
|
|---|
| 251 |
|
|---|
| 252 | /* MC88000 */
|
|---|
| 253 | #define CPU_SUBTYPE_MC88000_ALL KI32_C(0)
|
|---|
| 254 | #define CPU_SUBTYPE_MC88100 KI32_C(1)
|
|---|
| 255 | #define CPU_SUBTYPE_MC88110 KI32_C(2)
|
|---|
| 256 |
|
|---|
| 257 | /* SPARC */
|
|---|
| 258 | #define CPU_SUBTYPE_SPARC_ALL KI32_C(0)
|
|---|
| 259 |
|
|---|
| 260 | /* I860 */
|
|---|
| 261 | #define CPU_SUBTYPE_I860_ALL KI32_C(0)
|
|---|
| 262 | #define CPU_SUBTYPE_I860_860 KI32_C(1)
|
|---|
| 263 |
|
|---|
| 264 | /* PowerPC */
|
|---|
| 265 | #define CPU_SUBTYPE_POWERPC_ALL KI32_C(0)
|
|---|
| 266 | #define CPU_SUBTYPE_POWERPC_601 KI32_C(1)
|
|---|
| 267 | #define CPU_SUBTYPE_POWERPC_602 KI32_C(2)
|
|---|
| 268 | #define CPU_SUBTYPE_POWERPC_603 KI32_C(3)
|
|---|
| 269 | #define CPU_SUBTYPE_POWERPC_603e KI32_C(4)
|
|---|
| 270 | #define CPU_SUBTYPE_POWERPC_603ev KI32_C(5)
|
|---|
| 271 | #define CPU_SUBTYPE_POWERPC_604 KI32_C(6)
|
|---|
| 272 | #define CPU_SUBTYPE_POWERPC_604e KI32_C(7)
|
|---|
| 273 | #define CPU_SUBTYPE_POWERPC_620 KI32_C(8)
|
|---|
| 274 | #define CPU_SUBTYPE_POWERPC_750 KI32_C(9)
|
|---|
| 275 | #define CPU_SUBTYPE_POWERPC_7400 KI32_C(10)
|
|---|
| 276 | #define CPU_SUBTYPE_POWERPC_7450 KI32_C(11)
|
|---|
| 277 | #define CPU_SUBTYPE_POWERPC_Max KI32_C(10)
|
|---|
| 278 | #define CPU_SUBTYPE_POWERPC_SCVger KI32_C(11)
|
|---|
| 279 | #define CPU_SUBTYPE_POWERPC_970 KI32_C(100)
|
|---|
| 280 |
|
|---|
| 281 | /** @} */
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 | /** @defgroup grp_macho_o_lc Load Commands
|
|---|
| 286 | * @{ */
|
|---|
| 287 |
|
|---|
| 288 | /**
|
|---|
| 289 | * The load command common core structure.
|
|---|
| 290 | *
|
|---|
| 291 | * After the Mach-O header follows an array of variable sized
|
|---|
| 292 | * load command which all has this header in common.
|
|---|
| 293 | */
|
|---|
| 294 | typedef struct load_command
|
|---|
| 295 | {
|
|---|
| 296 | KU32 cmd; /**< The load command id. */
|
|---|
| 297 | KU32 cmdsize; /**< The size of the command (including this header). */
|
|---|
| 298 | } load_command_t;
|
|---|
| 299 |
|
|---|
| 300 | /** @name Load Command IDs (load_command::cmd)
|
|---|
| 301 | * @{
|
|---|
| 302 | */
|
|---|
| 303 | /** Flag that when set requires the dynamic linker to fail if it doesn't
|
|---|
| 304 | * grok the command. The dynamic linker will otherwise ignore commands it
|
|---|
| 305 | * doesn't understand. Introduced with Mac OS X 10.1. */
|
|---|
| 306 | #define LC_REQ_DYLD KU32_C(0x80000000)
|
|---|
| 307 |
|
|---|
| 308 | #define LC_SEGMENT_32 KU32_C(0x01) /**< Segment to be mapped (32-bit). See segment_command_32. */
|
|---|
| 309 | #define LC_SYMTAB KU32_C(0x02) /**< 'stab' symbol table. See symtab_command. */
|
|---|
| 310 | #define LC_SYMSEG KU32_C(0x03) /**< Obsoleted gdb symbol table. */
|
|---|
| 311 | #define LC_THREAD KU32_C(0x04) /**< Thread. See thread_command. */
|
|---|
| 312 | #define LC_UNIXTHREAD KU32_C(0x05) /**< Unix thread (includes stack and stuff). See thread_command. */
|
|---|
| 313 | #define LC_LOADFVMLIB KU32_C(0x06) /**< Load a specified fixed VM shared library (obsolete?). See fvmlib_command. */
|
|---|
| 314 | #define LC_IDFVMLIB KU32_C(0x07) /**< Fixed VM shared library id (obsolete?). See fvmlib_command. */
|
|---|
| 315 | #define LC_IDENT KU32_C(0x08) /**< Identification info (obsolete). See ident_command. */
|
|---|
| 316 | #define LC_FVMFILE KU32_C(0x09) /**< Fixed VM file inclusion (internal). See fvmfile_command. */
|
|---|
| 317 | #define LC_PREPAGE KU32_C(0x0a) /**< Prepage command (internal). See ?? */
|
|---|
| 318 | #define LC_DYSYMTAB KU32_C(0x0b) /**< Symbol table for dynamic linking. See dysymtab_command. */
|
|---|
| 319 | #define LC_LOAD_DYLIB KU32_C(0x0c) /**< Load a dynamically linked shared library. See dylib_command. */
|
|---|
| 320 | #define LC_ID_DYLIB KU32_C(0x0d) /**< Dynamically linked share library ident. See dylib_command. */
|
|---|
| 321 | #define LC_LOAD_DYLINKER KU32_C(0x0e) /**< Load a dynamical link editor. See dylinker_command. */
|
|---|
| 322 | #define LC_ID_DYLINKER KU32_C(0x0f) /**< Dynamic link editor ident. See dylinker_command. */
|
|---|
| 323 | #define LC_PREBOUND_DYLIB KU32_C(0x10) /**< Prebound modules for dynamically linking of a shared lib. See prebound_dylib_command. */
|
|---|
| 324 | #define LC_ROUTINES KU32_C(0x11) /**< Image routines. See routines_command_32. */
|
|---|
| 325 | #define LC_SUB_FRAMEWORK KU32_C(0x12) /**< Sub framework. See sub_framework_command. */
|
|---|
| 326 | #define LC_SUB_UMBRELLA KU32_C(0x13) /**< Sub umbrella. See sub_umbrella_command. */
|
|---|
| 327 | #define LC_SUB_CLIENT KU32_C(0x14) /**< Sub client. See sub_client_command. */
|
|---|
| 328 | #define LC_SUB_LIBRARY KU32_C(0x15) /**< Sub library. See sub_library_command. */
|
|---|
| 329 | #define LC_TWOLEVEL_HINTS KU32_C(0x16) /**< Two-level namespace lookup hints. See twolevel_hints_command. */
|
|---|
| 330 | #define LC_PREBIND_CKSUM KU32_C(0x17) /**< Prebind checksum. See prebind_cksum_command. */
|
|---|
| 331 | #define LC_LOAD_WEAK_DYLIB (KU32_C(0x18) | LC_REQ_DYLD) /**< Dylib that can be missing, all symbols weak. See dylib_command. */
|
|---|
| 332 | #define LC_SEGMENT_64 KU32_C(0x19) /**< segment to be mapped (64-bit). See segment_command_32. */
|
|---|
| 333 | #define LC_ROUTINES_64 KU32_C(0x1a) /**< Image routines (64-bit). See routines_command_32. */
|
|---|
| 334 | #define LC_UUID KU32_C(0x1b) /**< The UUID of the object module. See uuid_command. */
|
|---|
| 335 | /** @} */
|
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 | /**
|
|---|
| 339 | * Load Command String.
|
|---|
| 340 | */
|
|---|
| 341 | typedef struct lc_str
|
|---|
| 342 | {
|
|---|
| 343 | /** Offset of the string relative to the load_command structure.
|
|---|
| 344 | * The string is zero-terminated. the size of the load command
|
|---|
| 345 | * is zero padded up to a multiple of 4 bytes. */
|
|---|
| 346 | KU32 offset;
|
|---|
| 347 | } lc_str_t;
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 | /**
|
|---|
| 351 | * Segment load command (32-bit).
|
|---|
| 352 | */
|
|---|
| 353 | typedef struct segment_command_32
|
|---|
| 354 | {
|
|---|
| 355 | KU32 cmd; /**< LC_SEGMENT */
|
|---|
| 356 | KU32 cmdsize; /**< sizeof(self) + sections. */
|
|---|
| 357 | char segname[16]; /**< The segment name. */
|
|---|
| 358 | KU32 vmaddr; /**< Memory address of this segment. */
|
|---|
| 359 | KU32 vmsize; /**< Size of this segment. */
|
|---|
| 360 | KU32 fileoff; /**< The file location of the segment. */
|
|---|
| 361 | KU32 filesize; /**< The file size of the segment. */
|
|---|
| 362 | KU32 maxprot; /**< Maximum VM protection. */
|
|---|
| 363 | KU32 initprot; /**< Initial VM protection. */
|
|---|
| 364 | KU32 nsects; /**< Number of section desciptors following this structure. */
|
|---|
| 365 | KU32 flags; /**< Flags (SG_*). */
|
|---|
| 366 | } segment_command_32_t;
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 | /**
|
|---|
| 370 | * Segment load command (64-bit).
|
|---|
| 371 | * Same as segment_command_32 except 4 members has been blown up to 64-bit.
|
|---|
| 372 | */
|
|---|
| 373 | typedef struct segment_command_64
|
|---|
| 374 | {
|
|---|
| 375 | KU32 cmd; /**< LC_SEGMENT */
|
|---|
| 376 | KU32 cmdsize; /**< sizeof(self) + sections. */
|
|---|
| 377 | char segname[16]; /**< The segment name. */
|
|---|
| 378 | KU64 vmaddr; /**< Memory address of this segment. */
|
|---|
| 379 | KU64 vmsize; /**< Size of this segment. */
|
|---|
| 380 | KU64 fileoff; /**< The file location of the segment. */
|
|---|
| 381 | KU64 filesize; /**< The file size of the segment. */
|
|---|
| 382 | KU32 maxprot; /**< Maximum VM protection. */
|
|---|
| 383 | KU32 initprot; /**< Initial VM protection. */
|
|---|
| 384 | KU32 nsects; /**< Number of section desciptors following this structure. */
|
|---|
| 385 | KU32 flags; /**< Flags (SG_*). */
|
|---|
| 386 | } segment_command_64_t;
|
|---|
| 387 |
|
|---|
| 388 | /** @name Segment flags (segment_command_64::flags, segment_command_32::flags)
|
|---|
| 389 | * @{ */
|
|---|
| 390 | /** Map the file bits in the top end of the memory area for the segment
|
|---|
| 391 | * instead of the low end. Intended for stacks in core dumps.
|
|---|
| 392 | * The part of the segment memory not covered by file bits will be zeroed. */
|
|---|
| 393 | #define SG_HIGHVM KU32_C(0x00000001)
|
|---|
| 394 | /** This segment is the virtual memory allocated by a fixed VM library.
|
|---|
| 395 | * (Used for overlap checking in the linker.) */
|
|---|
| 396 | #define SG_FVMLIB KU32_C(0x00000002)
|
|---|
| 397 | /** No relocations for or symbols that's relocated to in this segment.
|
|---|
| 398 | * The segment can therefore safely be replaced. */
|
|---|
| 399 | #define SG_NORELOC KU32_C(0x00000004)
|
|---|
| 400 | /** The segment is protected.
|
|---|
| 401 | * The first page isn't protected if it starts at file offset 0
|
|---|
| 402 | * (so that the mach header and this load command can be easily mapped). */
|
|---|
| 403 | #define SG_PROTECTED_VERSION_1 KU32_C(0x00000008)
|
|---|
| 404 | /** @} */
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 | /**
|
|---|
| 408 | * 32-bit section (part of a segment load command).
|
|---|
| 409 | */
|
|---|
| 410 | typedef struct section_32
|
|---|
| 411 | {
|
|---|
| 412 | char sectname[16]; /**< The section name. */
|
|---|
| 413 | char segname[16]; /**< The name of the segment this section goes into. */
|
|---|
| 414 | KU32 addr; /**< The memory address of this section. */
|
|---|
| 415 | KU32 size; /**< The size of this section. */
|
|---|
| 416 | KU32 offset; /**< The file offset of this section. */
|
|---|
| 417 | KU32 align; /**< The section alignment (**2). */
|
|---|
| 418 | KU32 reloff; /**< The file offset of the relocations. */
|
|---|
| 419 | KU32 nreloc; /**< The number of relocations. */
|
|---|
| 420 | KU32 flags; /**< The section flags; section type and attribs */
|
|---|
| 421 | KU32 reserved1; /**< Reserved / offset / index. */
|
|---|
| 422 | KU32 reserved2; /**< Reserved / count / sizeof. */
|
|---|
| 423 | } section_32_t;
|
|---|
| 424 |
|
|---|
| 425 | /**
|
|---|
| 426 | * 64-bit section (part of a segment load command).
|
|---|
| 427 | */
|
|---|
| 428 | typedef struct section_64
|
|---|
| 429 | {
|
|---|
| 430 | char sectname[16]; /**< The section name. */
|
|---|
| 431 | char segname[16]; /**< The name of the segment this section goes into. */
|
|---|
| 432 | KU64 addr; /**< The memory address of this section. */
|
|---|
| 433 | KU64 size; /**< The size of this section. */
|
|---|
| 434 | KU32 offset; /**< The file offset of this section. */
|
|---|
| 435 | KU32 align; /**< The section alignment (**2). */
|
|---|
| 436 | KU32 reloff; /**< The file offset of the relocations. */
|
|---|
| 437 | KU32 nreloc; /**< The number of relocations. */
|
|---|
| 438 | KU32 flags; /**< The section flags; section type and attribs */
|
|---|
| 439 | KU32 reserved1; /**< Reserved / offset / index. */
|
|---|
| 440 | KU32 reserved2; /**< Reserved / count / sizeof. */
|
|---|
| 441 | KU32 reserved3; /**< (Just) Reserved. */
|
|---|
| 442 | } section_64_t;
|
|---|
| 443 |
|
|---|
| 444 | /** @name Section flags (section_64::flags, section_32::flags)
|
|---|
| 445 | * @{
|
|---|
| 446 | */
|
|---|
| 447 | /** Section type mask. */
|
|---|
| 448 | #define SECTION_TYPE KU32_C(0x000000ff)
|
|---|
| 449 | /** Regular section. */
|
|---|
| 450 | #define S_REGULAR 0x0
|
|---|
| 451 | /** Zero filled section. */
|
|---|
| 452 | #define S_ZEROFILL 0x1
|
|---|
| 453 | /** C literals. */
|
|---|
| 454 | #define S_CSTRING_LITERALS 0x2
|
|---|
| 455 | /** 4 byte literals. */
|
|---|
| 456 | #define S_4BYTE_LITERALS 0x3
|
|---|
| 457 | /** 8 byte literals. */
|
|---|
| 458 | #define S_8BYTE_LITERALS 0x4
|
|---|
| 459 | /** Pointer to literals. */
|
|---|
| 460 | #define S_LITERAL_POINTERS 0x5
|
|---|
| 461 | /** Section containing non-lazy symbol pointers.
|
|---|
| 462 | * Reserved1 == start index in the indirect symbol table. */
|
|---|
| 463 | #define S_NON_LAZY_SYMBOL_POINTERS 0x6
|
|---|
| 464 | /** Section containing lazy symbol pointers.
|
|---|
| 465 | * Reserved1 == start index in the indirect symbol table. */
|
|---|
| 466 | #define S_LAZY_SYMBOL_POINTERS 0x7
|
|---|
| 467 | /** Section containing symbol stubs.
|
|---|
| 468 | * Reserved2 == stub size. */
|
|---|
| 469 | #define S_SYMBOL_STUBS 0x8
|
|---|
| 470 | /** Section containing function pointers for module initialization. . */
|
|---|
| 471 | #define S_MOD_INIT_FUNC_POINTERS 0x9
|
|---|
| 472 | /** Section containing function pointers for module termination. . */
|
|---|
| 473 | #define S_MOD_TERM_FUNC_POINTERS 0xa
|
|---|
| 474 | /** Section containing symbols that are to be coalesced. */
|
|---|
| 475 | #define S_COALESCED 0xb
|
|---|
| 476 | /** Zero filled section that be larger than 4GB. */
|
|---|
| 477 | #define S_GB_ZEROFILL 0xc
|
|---|
| 478 | /** Section containing pairs of function pointers for interposing. */
|
|---|
| 479 | #define S_INTERPOSING 0xd
|
|---|
| 480 | /** 16 byte literals. */
|
|---|
| 481 | #define S_16BYTE_LITERALS 0xe
|
|---|
| 482 |
|
|---|
| 483 | /** Section attribute mask. */
|
|---|
| 484 | #define SECTION_ATTRIBUTES KU32_C(0xffffff00)
|
|---|
| 485 |
|
|---|
| 486 | /** User settable attribute mask. */
|
|---|
| 487 | #define SECTION_ATTRIBUTES_USR KU32_C(0xff000000)
|
|---|
| 488 | /** Pure instruction (code). */
|
|---|
| 489 | #define S_ATTR_PURE_INSTRUCTIONS KU32_C(0x80000000)
|
|---|
| 490 | /** ranlib, ignore my symbols... */
|
|---|
| 491 | #define S_ATTR_NO_TOC KU32_C(0x40000000)
|
|---|
| 492 | /** May strip static symbols when linking int a MH_DYLDLINK file. */
|
|---|
| 493 | #define S_ATTR_STRIP_STATIC_SYMS KU32_C(0x20000000)
|
|---|
| 494 | /** No dead stripping. */
|
|---|
| 495 | #define S_ATTR_NO_DEAD_STRIP KU32_C(0x10000000)
|
|---|
| 496 | /** Live support. */
|
|---|
| 497 | #define S_ATTR_LIVE_SUPPORT KU32_C(0x08000000)
|
|---|
| 498 | /** Contains self modifying code (generally i386 code stub for dyld). */
|
|---|
| 499 | #define S_ATTR_SELF_MODIFYING_CODE KU32_C(0x04000000)
|
|---|
| 500 | /** Debug info (DWARF usually). */
|
|---|
| 501 | #define S_ATTR_DEBUG KU32_C(0x02000000)
|
|---|
| 502 |
|
|---|
| 503 | /** System settable attribute mask. */
|
|---|
| 504 | #define SECTION_ATTRIBUTES_SYS KU32_C(0x00ffff00)
|
|---|
| 505 | /** Contains some instructions (code). */
|
|---|
| 506 | #define S_ATTR_SOME_INSTRUCTIONS KU32_C(0x00000400)
|
|---|
| 507 | /** Has external relocations. */
|
|---|
| 508 | #define S_ATTR_EXT_RELOC KU32_C(0x00000200)
|
|---|
| 509 | /** Has internal (local) relocations. */
|
|---|
| 510 | #define S_ATTR_LOC_RELOC KU32_C(0x00000100)
|
|---|
| 511 | /** @} */
|
|---|
| 512 |
|
|---|
| 513 | /** @name Known Segment and Section Names.
|
|---|
| 514 | * Some of these implies special linker behaviour.
|
|---|
| 515 | * @{
|
|---|
| 516 | */
|
|---|
| 517 | /** Page zero - not-present page for catching invalid access. (MH_EXECUTE typically) */
|
|---|
| 518 | #define SEG_PAGEZERO "__PAGEZERO"
|
|---|
| 519 | /** Traditional UNIX text segment.
|
|---|
| 520 | * Defaults to R-X. */
|
|---|
| 521 | #define SEG_TEXT "__TEXT"
|
|---|
| 522 | /** The text part of SEG_TEXT. */
|
|---|
| 523 | #define SECT_TEXT "__text"
|
|---|
| 524 | /** The fvmlib initialization. */
|
|---|
| 525 | #define SECT_FVMLIB_INIT0 "__fvmlib_init0"
|
|---|
| 526 | /** The section following the fvmlib initialization. */
|
|---|
| 527 | #define SECT_FVMLIB_INIT1 "__fvmlib_init1"
|
|---|
| 528 | /** The traditional UNIX data segment. (DGROUP to DOS and OS/2 people.) */
|
|---|
| 529 | #define SEG_DATA "__DATA"
|
|---|
| 530 | /** The initialized data section. */
|
|---|
| 531 | #define SECT_DATA "__data"
|
|---|
| 532 | /** The uninitialized data section. */
|
|---|
| 533 | #define SECT_BSS "__bss"
|
|---|
| 534 | /** The common symbol section. */
|
|---|
| 535 | #define SECT_COMMON "__common"
|
|---|
| 536 | /** Objective-C runtime segment. */
|
|---|
| 537 | #define SEG_OBJC "__OBJC"
|
|---|
| 538 | /** Objective-C symbol table section. */
|
|---|
| 539 | #define SECT_OBJC_SYMBOLS "__symbol_table"
|
|---|
| 540 | /** Objective-C module information section. */
|
|---|
| 541 | #define SECT_OBJC_MODULES "__module_info"
|
|---|
| 542 | /** Objective-C string table section. */
|
|---|
| 543 | #define SECT_OBJC_STRINGS "__selector_strs"
|
|---|
| 544 | /** Objective-C string table section. */
|
|---|
| 545 | #define SECT_OBJC_REFS "__selector_refs"
|
|---|
| 546 | /** Icon segment. */
|
|---|
| 547 | #define SEG_ICON "__ICON"
|
|---|
| 548 | /** The icon headers. */
|
|---|
| 549 | #define SECT_ICON_HEADER "__header"
|
|---|
| 550 | /** The icons in the TIFF format. */
|
|---|
| 551 | #define SECT_ICON_TIFF "__tiff"
|
|---|
| 552 | /** ld -seglinkedit segment containing all the structs create and maintained
|
|---|
| 553 | * by the linker. MH_EXECUTE and MH_FVMLIB only. */
|
|---|
| 554 | #define SEG_LINKEDIT "__LINKEDIT"
|
|---|
| 555 | /** The unix stack segment. */
|
|---|
| 556 | #define SEG_UNIXSTACK "__UNIXSTACK"
|
|---|
| 557 | /** The segment for the self modifying code for dynamic linking.
|
|---|
| 558 | * Implies RWX permissions. */
|
|---|
| 559 | #define SEG_IMPORT "__IMPORT"
|
|---|
| 560 | /** @} */
|
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 | /** @todo fvmlib */
|
|---|
| 564 | /** @todo fvmlib_command (LC_IDFVMLIB or LC_LOADFVMLIB) */
|
|---|
| 565 | /** @todo dylib */
|
|---|
| 566 | /** @todo dylib_command (LC_ID_DYLIB, LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB) */
|
|---|
| 567 | /** @todo sub_framework_command (LC_SUB_FRAMEWORK) */
|
|---|
| 568 | /** @todo sub_client_command (LC_SUB_CLIENT) */
|
|---|
| 569 | /** @todo sub_umbrella_command (LC_SUB_UMBRELLA) */
|
|---|
| 570 | /** @todo sub_library_command (LC_SUB_LIBRARY) */
|
|---|
| 571 | /** @todo prebound_dylib_command (LC_PREBOUND_DYLIB) */
|
|---|
| 572 | /** @todo dylinker_command (LC_ID_DYLINKER or LC_LOAD_DYLINKER) */
|
|---|
| 573 |
|
|---|
| 574 |
|
|---|
| 575 | /**
|
|---|
| 576 | * Thread command.
|
|---|
| 577 | *
|
|---|
| 578 | * State description of a thread that is to be created. The description
|
|---|
| 579 | * is made up of a number of state structures preceded by a 32-bit flavor
|
|---|
| 580 | * and 32-bit count field stating the kind of stat structure and it's size
|
|---|
| 581 | * in KU32 items respecitvly.
|
|---|
| 582 | *
|
|---|
| 583 | * LC_UNIXTHREAD differs from LC_THREAD in that it implies stack creation
|
|---|
| 584 | * and that it's started with the typical main(int, char **, char **) frame
|
|---|
| 585 | * on the stack.
|
|---|
| 586 | */
|
|---|
| 587 | typedef struct thread_command
|
|---|
| 588 | {
|
|---|
| 589 | KU32 cmd; /**< LC_UNIXTHREAD or LC_THREAD. */
|
|---|
| 590 | KU32 cmdsize; /**< The size of the command (including this header). */
|
|---|
| 591 | } thread_command_t;
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 | /** @todo routines_command (LC_ROUTINES) */
|
|---|
| 595 | /** @todo routines_command_64 (LC_ROUTINES_64) */
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 | /**
|
|---|
| 599 | * Symbol table command.
|
|---|
| 600 | * Contains a.out style symbol table with some tricks.
|
|---|
| 601 | */
|
|---|
| 602 | typedef struct symtab_command
|
|---|
| 603 | {
|
|---|
| 604 | KU32 cmd; /**< LC_SYMTAB */
|
|---|
| 605 | KU32 cmdsize; /** sizeof(symtab_command_t) */
|
|---|
| 606 | KU32 symoff; /** The file offset of the symbol table. */
|
|---|
| 607 | KU32 nsyms; /** The number of symbols in the symbol table. */
|
|---|
| 608 | KU32 stroff; /** The file offset of the string table. */
|
|---|
| 609 | KU32 strsize; /** The size of the string table. */
|
|---|
| 610 | } symtab_command_t;
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 | /** @todo dysymtab_command (LC_DYSYMTAB) */
|
|---|
| 614 | /** @todo dylib_table_of_contents */
|
|---|
| 615 | /** @todo dylib_module_32 */
|
|---|
| 616 | /** @todo dylib_module_64 */
|
|---|
| 617 | /** @todo dylib_reference */
|
|---|
| 618 | /** @todo twolevel_hints_command (LC_TWOLEVEL_HINTS) */
|
|---|
| 619 | /** @todo twolevel_hint */
|
|---|
| 620 | /** @todo prebind_cksum_command (LC_PREBIND_CKSUM) */
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 | /**
|
|---|
| 624 | * UUID generated by ld.
|
|---|
| 625 | */
|
|---|
| 626 | typedef struct uuid_command
|
|---|
| 627 | {
|
|---|
| 628 | KU32 cmd; /**< LC_UUID */
|
|---|
| 629 | KU32 cmdsize; /**< sizeof(uuid_command_t) */
|
|---|
| 630 | KU8 uuid[16]; /** The UUID bytes. */
|
|---|
| 631 | } uuid_command_t;
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 | /** @todo symseg_command (LC_SYMSEG) */
|
|---|
| 635 | /** @todo ident_command (LC_IDENT) */
|
|---|
| 636 | /** @todo fvmfile_command (LC_FVMFILE) */
|
|---|
| 637 |
|
|---|
| 638 | /** @} */
|
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 | /** @defgroup grp_macho_o_syms Symbol Table
|
|---|
| 643 | * @{ */
|
|---|
| 644 |
|
|---|
| 645 | /**
|
|---|
| 646 | * The 32-bit Mach-O version of the nlist structure.
|
|---|
| 647 | *
|
|---|
| 648 | * This differs from the a.out nlist struct in that the unused n_other field
|
|---|
| 649 | * was renamed to n_sect and used for keeping the relevant section number.
|
|---|
| 650 | * @remark This structure is not name mach_nlist_32 in the Apple headers, but nlist.
|
|---|
| 651 | */
|
|---|
| 652 | typedef struct macho_nlist_32
|
|---|
| 653 | {
|
|---|
| 654 | union
|
|---|
| 655 | {
|
|---|
| 656 | KI32 n_strx; /**< Offset (index) into the string table. 0 means "". */
|
|---|
| 657 | } n_un;
|
|---|
| 658 | KU8 n_type; /**< Symbol type. */
|
|---|
| 659 | KU8 n_sect; /**< Section number of NO_SECT. */
|
|---|
| 660 | KI16 n_desc; /**< Type specific, debug info details mostly.*/
|
|---|
| 661 | KU32 n_value; /**< The symbol value or stab offset. */
|
|---|
| 662 | } macho_nlist_32_t;
|
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 | /**
|
|---|
| 666 | * The 64-bit Mach-O version of the nlist structure.
|
|---|
| 667 | * @see macho_nlist_32
|
|---|
| 668 | */
|
|---|
| 669 | typedef struct macho_nlist_64
|
|---|
| 670 | {
|
|---|
| 671 | union
|
|---|
| 672 | {
|
|---|
| 673 | KU32 n_strx; /**< Offset (index) into the string table. 0 means "". */
|
|---|
| 674 | } n_un;
|
|---|
| 675 | KU8 n_type; /**< Symbol type. */
|
|---|
| 676 | KU8 n_sect; /**< Section number of NO_SECT. */
|
|---|
| 677 | KI16 n_desc; /**< Type specific, debug info details mostly.*/
|
|---|
| 678 | KU64 n_value; /**< The symbol value or stab offset. */
|
|---|
| 679 | } macho_nlist_64_t;
|
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 | /** @name Symbol Type Constants (macho_nlist_32_t::n_type, macho_nlist_64_t::n_type)
|
|---|
| 683 | *
|
|---|
| 684 | * In the Mach-O world n_type is somewhat similar to a.out, meaning N_EXT, N_UNDF, N_ABS
|
|---|
| 685 | * and the debug symbols are essentially the same, but the remaining stuff is different.
|
|---|
| 686 | * The main reason for this is that the encoding of section has been moved to n_sect
|
|---|
| 687 | * to permit up to 255 sections instead of the fixed 3 a.out sections (not counting
|
|---|
| 688 | * the abs symbols and set vectors).
|
|---|
| 689 | *
|
|---|
| 690 | * To avoid confusion with a.out the Mach-O constants has been fitted with a MACHO_
|
|---|
| 691 | * prefix here.
|
|---|
| 692 | *
|
|---|
| 693 | * Common symbols (aka communal symbols and comdefs) are represented by
|
|---|
| 694 | * n_type = MACHO_N_EXT | MACHO_N_UNDF, n_sect = NO_SECT and n_value giving
|
|---|
| 695 | * the size.
|
|---|
| 696 | *
|
|---|
| 697 | *
|
|---|
| 698 | * Symbol table entries can be inserted directly in the assembly code using
|
|---|
| 699 | * this notation:
|
|---|
| 700 | * @code
|
|---|
| 701 | * .stabs "n_name", n_type, n_sect, n_desc, n_value
|
|---|
| 702 | * @endcode
|
|---|
| 703 | *
|
|---|
| 704 | * (1) The line number is optional, GCC doesn't set it.
|
|---|
| 705 | * (2) The type is optional, GCC doesn't set it.
|
|---|
| 706 | * (3) The binutil header is "skeptical" about the line. I'm skeptical about the whole thing... :-)
|
|---|
| 707 | * (M) Mach-O specific?
|
|---|
| 708 | * (S) Sun specific?
|
|---|
| 709 | * @{
|
|---|
| 710 | */
|
|---|
| 711 |
|
|---|
| 712 | /* Base masks. */
|
|---|
| 713 | #define MACHO_N_EXT KU8_C(0x01) /**< External symbol (when set) (N_EXT). */
|
|---|
| 714 | #define MACHO_N_TYPE KU8_C(0x0e) /**< Symbol type (N_TYPE without the 8th bit). */
|
|---|
| 715 | #define MACHO_N_PEXT KU8_C(0x10) /**< Private extern symbol (when set). (M) */
|
|---|
| 716 | #define MACHO_N_STAB KU8_C(0xe0) /**< Debug symbol mask (N_STAB). */
|
|---|
| 717 |
|
|---|
| 718 | /* MACHO_N_TYPE values. */
|
|---|
| 719 | #define MACHO_N_UNDF KU8_C(0x00) /**< MACHO_N_TYPE: Undefined symbol (N_UNDF). n_sect = NO_SECT. */
|
|---|
| 720 | #define MACHO_N_ABS KU8_C(0x02) /**< MACHO_N_TYPE: Absolute symbol (N_UNDF). n_sect = NO_SECT. */
|
|---|
| 721 | #define MACHO_N_INDR KU8_C(0x0a) /**< MACHO_N_TYPE: Indirect symbol, n_value is the index of the symbol. (M) */
|
|---|
| 722 | #define MACHO_N_PBUD KU8_C(0x0c) /**< MACHO_N_TYPE: Prebound undefined symbo (defined in a dylib). (M) */
|
|---|
| 723 | #define MACHO_N_SECT KU8_C(0x0e) /**< MACHO_N_TYPE: Defined in the section given by n_sects. (M) */
|
|---|
| 724 |
|
|---|
| 725 | /* Debug symbols. */
|
|---|
| 726 | #define MACHO_N_GSYM KU8_C(0x20) /**< Global variable. "name",, NO_SECT, type, 0 (2) */
|
|---|
| 727 | #define MACHO_N_FNAME KU8_C(0x22) /**< Function name (F77). "name",, NO_SECT, 0, 0 */
|
|---|
| 728 | #define MACHO_N_FUN KU8_C(0x24) /**< Function / text var. "name",, section, line, address (1) */
|
|---|
| 729 | #define MACHO_N_STSYM KU8_C(0x26) /**< Static data symbol. "name",, section, type, address (2) */
|
|---|
| 730 | #define MACHO_N_LCSYM KU8_C(0x28) /**< static bss symbol. "name",, section, type, address (2) */
|
|---|
| 731 | /* omits N_MAIN and N_ROSYM. */
|
|---|
| 732 | #define MACHO_N_BNSYM KU8_C(0x2e) /**< Begin nsect symbol. 0,, section, 0, address (M) */
|
|---|
| 733 | #define MACHO_N_PC KU8_C(0x30) /**< Global pascal symbol. "name",, NO_SECT, subtype?, line (3) */
|
|---|
| 734 | /* omits N_NSYMS, N_NOMAP and N_OBJ. */
|
|---|
| 735 | #define MACHO_N_OPT KU8_C(0x3c) /**< Options for the debugger related to the language of the
|
|---|
| 736 | source file. "options?",,,, */
|
|---|
| 737 | #define MACHO_N_RSYM KU8_C(0x40) /**< Register variable. "name",, NO_SECT, type, register */
|
|---|
| 738 | /* omits N_M2C */
|
|---|
| 739 | #define MACHO_N_SLINE KU8_C(0x44) /**< Source line. 0,, section, line, address */
|
|---|
| 740 | /* omits N_DSLINE, N_BSLINE / N_BROWS, N_DEFD and N_FLINE. */
|
|---|
| 741 | #define MACHO_N_ENSYM KU8_C(0x4e) /**< End nsect symbol. 0,, section, 0, address (M) */
|
|---|
| 742 | /* omits N_EHDECL / N_MOD2 and N_CATCH. */
|
|---|
| 743 | #define MACHO_N_SSYM KU8_C(0x60) /**< Struct/union element. "name",, NO_SECT, type, offset */
|
|---|
| 744 | /* omits N_ENDM */
|
|---|
| 745 | #define MACHO_N_SO KU8_C(0x64) /**< Source file name. "fname",, section, 0, address */
|
|---|
| 746 | #define MACHO_N_OSO KU8_C(0x66) /**< Object file name. "fname",, 0, 0, st_mtime (M?) */
|
|---|
| 747 | /* omits N_ALIAS */
|
|---|
| 748 | #define MACHO_N_LSYM KU8_C(0x80) /**< Stack variable. "name",, NO_SECT, type, frame_offset */
|
|---|
| 749 | #define MACHO_N_BINCL KU8_C(0x82) /**< Begin #include. "fname",, NO_SECT, 0, sum? */
|
|---|
| 750 | #define MACHO_N_SOL KU8_C(0x84) /**< #included file. "fname",, section, 0, start_address (S) */
|
|---|
| 751 | #define MACHO_N_PARAMS KU8_C(0x86) /**< Compiler params. "params",, NO_SECT, 0, 0 */
|
|---|
| 752 | #define MACHO_N_VERSION KU8_C(0x88) /**< Compiler version. "version",, NO_SECT, 0, 0 */
|
|---|
| 753 | #define MACHO_N_OLEVEL KU8_C(0x8A) /**< Compiler -O level. "level",, NO_SECT, 0, 0 */
|
|---|
| 754 | #define MACHO_N_PSYM KU8_C(0xa0) /**< Parameter variable. "name",, NO_SECT, type, frame_offset */
|
|---|
| 755 | #define MACHO_N_EINCL KU8_C(0xa2) /**< End #include. "fname",, NO_SECT, 0, 0 (S) */
|
|---|
| 756 | #define MACHO_N_ENTRY KU8_C(0xa4) /**< Alternate entry point. "name",, section, line, address */
|
|---|
| 757 | #define MACHO_N_LBRAC KU8_C(0xc0) /**< Left bracket. 0,, NO_SECT, nesting_level, address */
|
|---|
| 758 | #define MACHO_N_EXCL KU8_C(0xc2) /**< Deleted include file. "fname",, NO_SECT, 0, sum? (S) */
|
|---|
| 759 | /* omits N_SCOPE */
|
|---|
| 760 | #define MACHO_N_RBRAC KU8_C(0xe0) /**< Right bracket. 0,, NO_SECT, nesting_level, address */
|
|---|
| 761 | #define MACHO_N_BCOMM KU8_C(0xe2) /**< Begin common. "name",, NO_SECT?, 0, 0 */
|
|---|
| 762 | #define MACHO_N_ECOMM KU8_C(0xe4) /**< End common. "name",, section, 0, 0 */
|
|---|
| 763 | #define MACHO_N_ECOML KU8_C(0xe8) /**< End local common. 0,, section, 0, address */
|
|---|
| 764 | #define MACHO_N_LENG KU8_C(0xfe) /**< Length-value of the preceding entry.
|
|---|
| 765 | "name",, NO_SECT, 0, length */
|
|---|
| 766 |
|
|---|
| 767 | /** @} */
|
|---|
| 768 |
|
|---|
| 769 | /** @name Symbol Description Bits (macho_nlist_32_t::n_desc, macho_nlist_64_t::n_desc)
|
|---|
| 770 | *
|
|---|
| 771 | * Mach-O puts the n_desc field to a number of uses, like lazy binding , library
|
|---|
| 772 | * ordinal numbers for -twolevel_namespace, stripping and weak symbol handling.
|
|---|
| 773 | *
|
|---|
| 774 | * @remark The REFERENCE_FLAGS_* are really not flags in the normal sense (bit),
|
|---|
| 775 | * they are more like enum values.
|
|---|
| 776 | * @{
|
|---|
| 777 | */
|
|---|
| 778 |
|
|---|
| 779 | #define REFERENCE_TYPE KU16_C(0x000f) /**< The reference type mask. */
|
|---|
| 780 | #define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0 /**< Normal undefined symbol. */
|
|---|
| 781 | #define REFERENCE_FLAG_UNDEFINED_LAZY 1 /**< Lazy undefined symbol. */
|
|---|
| 782 | #define REFERENCE_FLAG_DEFINED 2 /**< Defined symbol (dynamic linking). */
|
|---|
| 783 | #define REFERENCE_FLAG_PRIVATE_DEFINED 3 /**< Defined private symbol (dynamic linking). */
|
|---|
| 784 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4 /**< Normal undefined private symbol. */
|
|---|
| 785 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5 /**< Lazy undefined private symbol. */
|
|---|
| 786 |
|
|---|
| 787 | #define REFERENCED_DYNAMICALLY KU16_C(0x0010) /**< Don't strip. */
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 | /** Get the dynamic library ordinal. */
|
|---|
| 791 | #define GET_LIBRARY_ORDINAL(n_desc) \
|
|---|
| 792 | (((n_desc) >> 8) & 0xff)
|
|---|
| 793 | /** Set the dynamic library ordinal. */
|
|---|
| 794 | #define SET_LIBRARY_ORDINAL(n_desc, ordinal) \
|
|---|
| 795 | (n_desc) = (((n_desc) & 0xff) | (((ordinal) & 0xff) << 8))
|
|---|
| 796 | #define SELF_LIBRARY_ORDINAL 0x00 /**< Special ordinal for refering to onself. */
|
|---|
| 797 | #define MAX_LIBRARY_ORDINAL 0xfd /**< Maximum ordinal number. */
|
|---|
| 798 | #define DYNAMIC_LOOKUP_ORDINAL 0xfe /**< Special ordinal number for dynamic lookup. (Mac OS X 10.3 and later) */
|
|---|
| 799 | #define EXECUTABLE_ORDINAL 0xff /**< Special ordinal number for the executable. */
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 | /** Only MH_OBJECT: Never dead strip me! */
|
|---|
| 803 | #define N_NO_DEAD_STRIP KU16_C(0x0020)
|
|---|
| 804 | /** Not MH_OBJECT: Discarded symbol. */
|
|---|
| 805 | #define N_DESC_DISCARDED KU16_C(0x0020)
|
|---|
| 806 | /** Weak external symbol. Symbol can be missing, in which case it's will have the value 0. */
|
|---|
| 807 | #define N_WEAK_REF KU16_C(0x0040)
|
|---|
| 808 | /** Weak symbol definition. The symbol can be overridden by another weak
|
|---|
| 809 | * symbol already present or by a non-weak (strong) symbol definition.
|
|---|
| 810 | * Currently only supported for coalesed symbols.
|
|---|
| 811 | * @remark This bit means something differently for undefined symbols, see N_REF_TO_WEAK.
|
|---|
| 812 | */
|
|---|
| 813 | #define N_WEAK_DEF KU16_C(0x0080)
|
|---|
| 814 | /** Reference to a weak symbol, resolve using flat namespace searching.
|
|---|
| 815 | * @remark This bit means something differently for defined symbols, see N_WEAK_DEF. */
|
|---|
| 816 | #define N_REF_TO_WEAK KU16_C(0x0080)
|
|---|
| 817 |
|
|---|
| 818 | /** @} */
|
|---|
| 819 |
|
|---|
| 820 | /** @} */
|
|---|
| 821 |
|
|---|
| 822 |
|
|---|
| 823 | /** @defgroup grp_macho_o_relocs Relocations
|
|---|
| 824 | * @{ */
|
|---|
| 825 |
|
|---|
| 826 | /**
|
|---|
| 827 | * Relocation entry.
|
|---|
| 828 | *
|
|---|
| 829 | * Differs from a.out in the meaning of r_symbolnum when r_extern=0 and
|
|---|
| 830 | * that r_pad is made into r_type.
|
|---|
| 831 | *
|
|---|
| 832 | * @remark This structure and type has been prefixed with macho_ to avoid
|
|---|
| 833 | * confusion with the original a.out type.
|
|---|
| 834 | */
|
|---|
| 835 | typedef struct macho_relocation_info
|
|---|
| 836 | {
|
|---|
| 837 | KI32 r_address; /**< Section relative address of the fixup.
|
|---|
| 838 | The top bit (signed) indicates that this is a scattered
|
|---|
| 839 | relocation if set, see scattered_relocation_info_t. */
|
|---|
| 840 | KU32 r_symbolnum : 24, /**< r_extern=1: Symbol table index, relocate with the address of this symbol.
|
|---|
| 841 | r_extern=0: Section ordinal, relocate with the address of this section. */
|
|---|
| 842 | r_pcrel : 1, /**< PC (program counter) relative fixup; subtract the fixup address. */
|
|---|
| 843 | r_length : 2, /**< Fixup length: 0=KU8, 1=KU16, 2=KU32, 3=KU64. */
|
|---|
| 844 | r_extern : 1, /**< External or internal fixup, decides the r_symbolnum interpretation.. */
|
|---|
| 845 | r_type : 4; /**< Relocation type; 0 is standard, non-zero are machine specific. */
|
|---|
| 846 | } macho_relocation_info_t;
|
|---|
| 847 |
|
|---|
| 848 | /** Special section ordinal value for absolute relocations. */
|
|---|
| 849 | #define R_ABS 0
|
|---|
| 850 |
|
|---|
| 851 | /** Flag in r_address indicating that the relocation is of the
|
|---|
| 852 | * scattered_relocation_info_t kind and not macho_relocation_info_t. */
|
|---|
| 853 | #define R_SCATTERED KU32_C(0x80000000)
|
|---|
| 854 |
|
|---|
| 855 | /**
|
|---|
| 856 | * Scattered relocation.
|
|---|
| 857 | *
|
|---|
| 858 | * This is a hack mainly for RISC machines which restricts section size
|
|---|
| 859 | * to 16MB among other things.
|
|---|
| 860 | *
|
|---|
| 861 | * The reason for the big/little endian differences here is of course because
|
|---|
| 862 | * of the R_SCATTERED mask and the way bitfields are implemented by the
|
|---|
| 863 | * C/C++ compilers.
|
|---|
| 864 | */
|
|---|
| 865 | typedef struct scattered_relocation_info
|
|---|
| 866 | {
|
|---|
| 867 | #if K_ENDIAN == K_ENDIAN_LITTLE
|
|---|
| 868 | KU32 r_address : 24, /**< Section relative address of the fixup. (macho_relocation_info_t::r_address) */
|
|---|
| 869 | r_type : 4, /**< Relocation type; 0 is standard, non-zero are machine specific. (macho_relocation_info_t::r_type) */
|
|---|
| 870 | r_length : 2, /**< Fixup length: 0=KU8, 1=KU16, 2=KU32, 3=KU64. (macho_relocation_info_t::r_length) */
|
|---|
| 871 | r_pcrel : 1, /**< PC (program counter) relative fixup; subtract the fixup address. (macho_relocation_info_t::r_pcrel) */
|
|---|
| 872 | r_scattered : 1; /**< Set if scattered relocation, clear if normal relocation. */
|
|---|
| 873 | #elif K_ENDIAN == K_ENDIAN_BIG
|
|---|
| 874 | KU32 r_scattered : 1, /**< Set if scattered relocation, clear if normal relocation. */
|
|---|
| 875 | r_pcrel : 1, /**< PC (program counter) relative fixup; subtract the fixup address. (macho_relocation_info_t::r_pcrel) */
|
|---|
| 876 | r_length : 2, /**< Fixup length: 0=KU8, 1=KU16, 2=KU32, 3=KU64. (macho_relocation_info_t::r_length) */
|
|---|
| 877 | r_type : 4, /**< Relocation type; 0 is standard, non-zero are machine specific. (macho_relocation_info_t::r_type) */
|
|---|
| 878 | r_address : 24; /**< Section relative address of the fixup. (macho_relocation_info_t::r_address) */
|
|---|
| 879 | #else
|
|---|
| 880 | # error "Neither K_ENDIAN isn't LITTLE or BIG!"
|
|---|
| 881 | #endif
|
|---|
| 882 | KI32 r_value; /**< The value the fixup is refering to (without offset added). */
|
|---|
| 883 | } scattered_relocation_info_t;
|
|---|
| 884 |
|
|---|
| 885 | /**
|
|---|
| 886 | * Relocation type values for a generic implementation (for r_type).
|
|---|
| 887 | */
|
|---|
| 888 | typedef enum reloc_type_generic
|
|---|
| 889 | {
|
|---|
| 890 | GENERIC_RELOC_VANILLA = 0, /**< Standard relocation. */
|
|---|
| 891 | GENERIC_RELOC_PAIR, /**< Follows GENERIC_RELOC_SECTDIFF. */
|
|---|
| 892 | GENERIC_RELOC_SECTDIFF, /**< ??? */
|
|---|
| 893 | GENERIC_RELOC_PB_LA_PTR, /**< Prebound lazy pointer whatever that. */
|
|---|
| 894 | GENERIC_RELOC_LOCAL_SECTDIFF /**< ??? */
|
|---|
| 895 | } reloc_type_generic_t;
|
|---|
| 896 |
|
|---|
| 897 | /** @} */
|
|---|
| 898 |
|
|---|
| 899 |
|
|---|
| 900 | /** @} */
|
|---|
| 901 | #endif
|
|---|
| 902 |
|
|---|