1 /* 2 * Copyright (c) 1999-2010 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 #ifndef _MACHO_LOADER_H_ 24 #define _MACHO_LOADER_H_ 25 26 /* 27 * This file describes the format of mach object files. 28 */ 29 #include <stdint.h> 30 31 /* 32 * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types 33 * and contains the constants for the possible values of these types. 34 */ 35 #include <mach/machine.h> 36 37 /* 38 * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the 39 * constants that are or'ed together for the possible values of this type. 40 */ 41 #include <mach/vm_prot.h> 42 43 /* 44 * <machine/thread_status.h> is expected to define the flavors of the thread 45 * states and the structures of those flavors for each machine. 46 */ 47 #include <mach/machine/thread_status.h> 48 #include <architecture/byte_order.h> 49 50 /* 51 * The 32-bit mach header appears at the very beginning of the object file for 52 * 32-bit architectures. 53 */ 54 struct mach_header { 55 uint32_t magic; /* mach magic number identifier */ 56 cpu_type_t cputype; /* cpu specifier */ 57 cpu_subtype_t cpusubtype; /* machine specifier */ 58 uint32_t filetype; /* type of file */ 59 uint32_t ncmds; /* number of load commands */ 60 uint32_t sizeofcmds; /* the size of all the load commands */ 61 uint32_t flags; /* flags */ 62 }; 63 64 /* Constant for the magic field of the mach_header (32-bit architectures) */ 65 #define MH_MAGIC 0xfeedface /* the mach magic number */ 66 #define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */ 67 68 /* 69 * The 64-bit mach header appears at the very beginning of object files for 70 * 64-bit architectures. 71 */ 72 struct mach_header_64 { 73 uint32_t magic; /* mach magic number identifier */ 74 cpu_type_t cputype; /* cpu specifier */ 75 cpu_subtype_t cpusubtype; /* machine specifier */ 76 uint32_t filetype; /* type of file */ 77 uint32_t ncmds; /* number of load commands */ 78 uint32_t sizeofcmds; /* the size of all the load commands */ 79 uint32_t flags; /* flags */ 80 uint32_t reserved; /* reserved */ 81 }; 82 83 /* Constant for the magic field of the mach_header_64 (64-bit architectures) */ 84 #define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */ 85 #define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */ 86 87 /* 88 * The layout of the file depends on the filetype. For all but the MH_OBJECT 89 * file type the segments are padded out and aligned on a segment alignment 90 * boundary for efficient demand pageing. The MH_EXECUTE, MH_FVMLIB, MH_DYLIB, 91 * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part 92 * of their first segment. 93 * 94 * The file type MH_OBJECT is a compact format intended as output of the 95 * assembler and input (and possibly output) of the link editor (the .o 96 * format). All sections are in one unnamed segment with no segment padding. 97 * This format is used as an executable format when the file is so small the 98 * segment padding greatly increases its size. 99 * 100 * The file type MH_PRELOAD is an executable format intended for things that 101 * are not executed under the kernel (proms, stand alones, kernels, etc). The 102 * format can be executed under the kernel but may demand paged it and not 103 * preload it before execution. 104 * 105 * A core file is in MH_CORE format and can be any in an arbritray legal 106 * Mach-O file. 107 * 108 * Constants for the filetype field of the mach_header 109 */ 110 #define MH_OBJECT 0x1 /* relocatable object file */ 111 #define MH_EXECUTE 0x2 /* demand paged executable file */ 112 #define MH_FVMLIB 0x3 /* fixed VM shared library file */ 113 #define MH_CORE 0x4 /* core file */ 114 #define MH_PRELOAD 0x5 /* preloaded executable file */ 115 #define MH_DYLIB 0x6 /* dynamically bound shared library */ 116 #define MH_DYLINKER 0x7 /* dynamic link editor */ 117 #define MH_BUNDLE 0x8 /* dynamically bound bundle file */ 118 #define MH_DYLIB_STUB 0x9 /* shared library stub for static 119 linking only, no section contents */ 120 #define MH_DSYM 0xa /* companion file with only debug 121 sections */ 122 #define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */ 123 #define MH_FILESET 0xc /* a file composed of other Mach-Os to 124 be run in the same userspace sharing 125 a single linkedit. */ 126 127 /* Constants for the flags field of the mach_header */ 128 #define MH_NOUNDEFS 0x1 /* the object file has no undefined 129 references */ 130 #define MH_INCRLINK 0x2 /* the object file is the output of an 131 incremental link against a base file 132 and can't be link edited again */ 133 #define MH_DYLDLINK 0x4 /* the object file is input for the 134 dynamic linker and can't be staticly 135 link edited again */ 136 #define MH_BINDATLOAD 0x8 /* the object file's undefined 137 references are bound by the dynamic 138 linker when loaded. */ 139 #define MH_PREBOUND 0x10 /* the file has its dynamic undefined 140 references prebound. */ 141 #define MH_SPLIT_SEGS 0x20 /* the file has its read-only and 142 read-write segments split */ 143 #define MH_LAZY_INIT 0x40 /* the shared library init routine is 144 to be run lazily via catching memory 145 faults to its writeable segments 146 (obsolete) */ 147 #define MH_TWOLEVEL 0x80 /* the image is using two-level name 148 space bindings */ 149 #define MH_FORCE_FLAT 0x100 /* the executable is forcing all images 150 to use flat name space bindings */ 151 #define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees no multiple 152 defintions of symbols in its 153 sub-images so the two-level namespace 154 hints can always be used. */ 155 #define MH_NOFIXPREBINDING 0x400 /* do not have dyld notify the 156 prebinding agent about this 157 executable */ 158 #define MH_PREBINDABLE 0x800 /* the binary is not prebound but can 159 have its prebinding redone. only used 160 when MH_PREBOUND is not set. */ 161 #define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to 162 all two-level namespace modules of 163 its dependent libraries. only used 164 when MH_PREBINDABLE and MH_TWOLEVEL 165 are both set. */ 166 #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into 167 sub-sections via symbols for dead 168 code stripping */ 169 #define MH_CANONICAL 0x4000 /* the binary has been canonicalized 170 via the unprebind operation */ 171 #define MH_WEAK_DEFINES 0x8000 /* the final linked image contains 172 external weak symbols */ 173 #define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses 174 weak symbols */ 175 176 #define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks 177 in the task will be given stack 178 execution privilege. Only used in 179 MH_EXECUTE filetypes. */ 180 #define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary 181 declares it is safe for use in 182 processes with uid zero */ 183 184 #define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary 185 declares it is safe for use in 186 processes when issetugid() is true */ 187 188 #define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, 189 the static linker does not need to 190 examine dependent dylibs to see 191 if any are re-exported */ 192 #define MH_PIE 0x200000 /* When this bit is set, the OS will 193 load the main executable at a 194 random address. Only used in 195 MH_EXECUTE filetypes. */ 196 #define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When 197 linking against a dylib that 198 has this bit set, the static linker 199 will automatically not create a 200 LC_LOAD_DYLIB load command to the 201 dylib if no symbols are being 202 referenced from the dylib. */ 203 #define MH_HAS_TLV_DESCRIPTORS 0x800000 /* Contains a section of type 204 S_THREAD_LOCAL_VARIABLES */ 205 206 #define MH_NO_HEAP_EXECUTION 0x1000000 /* When this bit is set, the OS will 207 run the main executable with 208 a non-executable heap even on 209 platforms (e.g. i386) that don't 210 require it. Only used in MH_EXECUTE 211 filetypes. */ 212 213 #define MH_APP_EXTENSION_SAFE 0x02000000 /* The code was linked for use in an 214 application extension. */ 215 216 #define MH_NLIST_OUTOFSYNC_WITH_DYLDINFO 0x04000000 /* The external symbols 217 listed in the nlist symbol table do 218 not include all the symbols listed in 219 the dyld info. */ 220 221 #define MH_SIM_SUPPORT 0x08000000 /* Allow LC_MIN_VERSION_MACOS and 222 LC_BUILD_VERSION load commands with 223 the platforms macOS, macCatalyst, 224 iOSSimulator, tvOSSimulator and 225 watchOSSimulator. */ 226 227 #define MH_DYLIB_IN_CACHE 0x80000000 /* Only for use on dylibs. When this bit 228 is set, the dylib is part of the dyld 229 shared cache, rather than loose in 230 the filesystem. */ 231 232 /* 233 * The load commands directly follow the mach_header. The total size of all 234 * of the commands is given by the sizeofcmds field in the mach_header. All 235 * load commands must have as their first two fields cmd and cmdsize. The cmd 236 * field is filled in with a constant for that command type. Each command type 237 * has a structure specifically for it. The cmdsize field is the size in bytes 238 * of the particular load command structure plus anything that follows it that 239 * is a part of the load command (i.e. section structures, strings, etc.). To 240 * advance to the next load command the cmdsize can be added to the offset or 241 * pointer of the current load command. The cmdsize for 32-bit architectures 242 * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple 243 * of 8 bytes (these are forever the maximum alignment of any load commands). 244 * The padded bytes must be zero. All tables in the object file must also 245 * follow these rules so the file can be memory mapped. Otherwise the pointers 246 * to these tables will not work well or at all on some machines. With all 247 * padding zeroed like objects will compare byte for byte. 248 */ 249 struct load_command { 250 uint32_t cmd; /* type of load command */ 251 uint32_t cmdsize; /* total size of command in bytes */ 252 }; 253 254 /* 255 * After MacOS X 10.1 when a new load command is added that is required to be 256 * understood by the dynamic linker for the image to execute properly the 257 * LC_REQ_DYLD bit will be or'ed into the load command constant. If the dynamic 258 * linker sees such a load command it it does not understand will issue a 259 * "unknown load command required for execution" error and refuse to use the 260 * image. Other load commands without this bit that are not understood will 261 * simply be ignored. 262 */ 263 #define LC_REQ_DYLD 0x80000000 264 265 /* Constants for the cmd field of all load commands, the type */ 266 #define LC_SEGMENT 0x1 /* segment of this file to be mapped */ 267 #define LC_SYMTAB 0x2 /* link-edit stab symbol table info */ 268 #define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */ 269 #define LC_THREAD 0x4 /* thread */ 270 #define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */ 271 #define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */ 272 #define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */ 273 #define LC_IDENT 0x8 /* object identification info (obsolete) */ 274 #define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */ 275 #define LC_PREPAGE 0xa /* prepage command (internal use) */ 276 #define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */ 277 #define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */ 278 #define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */ 279 #define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */ 280 #define LC_ID_DYLINKER 0xf /* dynamic linker identification */ 281 #define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */ 282 /* linked shared library */ 283 #define LC_ROUTINES 0x11 /* image routines */ 284 #define LC_SUB_FRAMEWORK 0x12 /* sub framework */ 285 #define LC_SUB_UMBRELLA 0x13 /* sub umbrella */ 286 #define LC_SUB_CLIENT 0x14 /* sub client */ 287 #define LC_SUB_LIBRARY 0x15 /* sub library */ 288 #define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */ 289 #define LC_PREBIND_CKSUM 0x17 /* prebind checksum */ 290 291 /* 292 * load a dynamically linked shared library that is allowed to be missing 293 * (all symbols are weak imported). 294 */ 295 #define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) 296 297 #define LC_SEGMENT_64 0x19 /* 64-bit segment of this file to be 298 mapped */ 299 #define LC_ROUTINES_64 0x1a /* 64-bit image routines */ 300 #define LC_UUID 0x1b /* the uuid */ 301 #define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */ 302 #define LC_CODE_SIGNATURE 0x1d /* local of code signature */ 303 #define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */ 304 #define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */ 305 #define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */ 306 #define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */ 307 #define LC_DYLD_INFO 0x22 /* compressed dyld information */ 308 #define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */ 309 #define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */ 310 #define LC_VERSION_MIN_MACOSX 0x24 /* build for MacOSX min OS version */ 311 #define LC_VERSION_MIN_IPHONEOS 0x25 /* build for iPhoneOS min OS version */ 312 #define LC_FUNCTION_STARTS 0x26 /* compressed table of function start addresses */ 313 #define LC_DYLD_ENVIRONMENT 0x27 /* string for dyld to treat 314 like environment variable */ 315 #define LC_MAIN (0x28|LC_REQ_DYLD) /* replacement for LC_UNIXTHREAD */ 316 #define LC_DATA_IN_CODE 0x29 /* table of non-instructions in __text */ 317 #define LC_SOURCE_VERSION 0x2A /* source version used to build binary */ 318 #define LC_DYLIB_CODE_SIGN_DRS 0x2B /* Code signing DRs copied from linked dylibs */ 319 #define LC_ENCRYPTION_INFO_64 0x2C /* 64-bit encrypted segment information */ 320 #define LC_LINKER_OPTION 0x2D /* linker options in MH_OBJECT files */ 321 #define LC_LINKER_OPTIMIZATION_HINT 0x2E /* optimization hints in MH_OBJECT files */ 322 #define LC_VERSION_MIN_TVOS 0x2F /* build for AppleTV min OS version */ 323 #define LC_VERSION_MIN_WATCHOS 0x30 /* build for Watch min OS version */ 324 #define LC_NOTE 0x31 /* arbitrary data included within a Mach-O file */ 325 #define LC_BUILD_VERSION 0x32 /* build for platform min OS version */ 326 #define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD) /* used with linkedit_data_command, payload is trie */ 327 #define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD) /* used with linkedit_data_command */ 328 #define LC_FILESET_ENTRY (0x35 | LC_REQ_DYLD) /* used with fileset_entry_command */ 329 330 /* 331 * A variable length string in a load command is represented by an lc_str 332 * union. The strings are stored just after the load command structure and 333 * the offset is from the start of the load command structure. The size 334 * of the string is reflected in the cmdsize field of the load command. 335 * Once again any padded bytes to bring the cmdsize field to a multiple 336 * of 4 bytes must be zero. 337 */ 338 union lc_str { 339 uint32_t offset; /* offset to the string */ 340 #ifndef __LP64__ 341 char *ptr; /* pointer to the string */ 342 #endif 343 }; 344 345 /* 346 * The segment load command indicates that a part of this file is to be 347 * mapped into the task's address space. The size of this segment in memory, 348 * vmsize, maybe equal to or larger than the amount to map from this file, 349 * filesize. The file is mapped starting at fileoff to the beginning of 350 * the segment in memory, vmaddr. The rest of the memory of the segment, 351 * if any, is allocated zero fill on demand. The segment's maximum virtual 352 * memory protection and initial virtual memory protection are specified 353 * by the maxprot and initprot fields. If the segment has sections then the 354 * section structures directly follow the segment command and their size is 355 * reflected in cmdsize. 356 */ 357 struct segment_command { /* for 32-bit architectures */ 358 uint32_t cmd; /* LC_SEGMENT */ 359 uint32_t cmdsize; /* includes sizeof section structs */ 360 char segname[16]; /* segment name */ 361 uint32_t vmaddr; /* memory address of this segment */ 362 uint32_t vmsize; /* memory size of this segment */ 363 uint32_t fileoff; /* file offset of this segment */ 364 uint32_t filesize; /* amount to map from the file */ 365 vm_prot_t maxprot; /* maximum VM protection */ 366 vm_prot_t initprot; /* initial VM protection */ 367 uint32_t nsects; /* number of sections in segment */ 368 uint32_t flags; /* flags */ 369 }; 370 371 /* 372 * The 64-bit segment load command indicates that a part of this file is to be 373 * mapped into a 64-bit task's address space. If the 64-bit segment has 374 * sections then section_64 structures directly follow the 64-bit segment 375 * command and their size is reflected in cmdsize. 376 */ 377 struct segment_command_64 { /* for 64-bit architectures */ 378 uint32_t cmd; /* LC_SEGMENT_64 */ 379 uint32_t cmdsize; /* includes sizeof section_64 structs */ 380 char segname[16]; /* segment name */ 381 uint64_t vmaddr; /* memory address of this segment */ 382 uint64_t vmsize; /* memory size of this segment */ 383 uint64_t fileoff; /* file offset of this segment */ 384 uint64_t filesize; /* amount to map from the file */ 385 vm_prot_t maxprot; /* maximum VM protection */ 386 vm_prot_t initprot; /* initial VM protection */ 387 uint32_t nsects; /* number of sections in segment */ 388 uint32_t flags; /* flags */ 389 }; 390 391 /* Constants for the flags field of the segment_command */ 392 #define SG_HIGHVM 0x1 /* the file contents for this segment is for 393 the high part of the VM space, the low part 394 is zero filled (for stacks in core files) */ 395 #define SG_FVMLIB 0x2 /* this segment is the VM that is allocated by 396 a fixed VM library, for overlap checking in 397 the link editor */ 398 #define SG_NORELOC 0x4 /* this segment has nothing that was relocated 399 in it and nothing relocated to it, that is 400 it maybe safely replaced without relocation*/ 401 #define SG_PROTECTED_VERSION_1 0x8 /* This segment is protected. If the 402 segment starts at file offset 0, the 403 first page of the segment is not 404 protected. All other pages of the 405 segment are protected. */ 406 #define SG_READ_ONLY 0x10 /* This segment is made read-only after fixups */ 407 408 409 410 /* 411 * A segment is made up of zero or more sections. Non-MH_OBJECT files have 412 * all of their segments with the proper sections in each, and padded to the 413 * specified segment alignment when produced by the link editor. The first 414 * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header 415 * and load commands of the object file before its first section. The zero 416 * fill sections are always last in their segment (in all formats). This 417 * allows the zeroed segment padding to be mapped into memory where zero fill 418 * sections might be. The gigabyte zero fill sections, those with the section 419 * type S_GB_ZEROFILL, can only be in a segment with sections of this type. 420 * These segments are then placed after all other segments. 421 * 422 * The MH_OBJECT format has all of its sections in one segment for 423 * compactness. There is no padding to a specified segment boundary and the 424 * mach_header and load commands are not part of the segment. 425 * 426 * Sections with the same section name, sectname, going into the same segment, 427 * segname, are combined by the link editor. The resulting section is aligned 428 * to the maximum alignment of the combined sections and is the new section's 429 * alignment. The combined sections are aligned to their original alignment in 430 * the combined section. Any padded bytes to get the specified alignment are 431 * zeroed. 432 * 433 * The format of the relocation entries referenced by the reloff and nreloc 434 * fields of the section structure for mach object files is described in the 435 * header file <reloc.h>. 436 */ 437 struct section { /* for 32-bit architectures */ 438 char sectname[16]; /* name of this section */ 439 char segname[16]; /* segment this section goes in */ 440 uint32_t addr; /* memory address of this section */ 441 uint32_t size; /* size in bytes of this section */ 442 uint32_t offset; /* file offset of this section */ 443 uint32_t align; /* section alignment (power of 2) */ 444 uint32_t reloff; /* file offset of relocation entries */ 445 uint32_t nreloc; /* number of relocation entries */ 446 uint32_t flags; /* flags (section type and attributes)*/ 447 uint32_t reserved1; /* reserved (for offset or index) */ 448 uint32_t reserved2; /* reserved (for count or sizeof) */ 449 }; 450 451 struct section_64 { /* for 64-bit architectures */ 452 char sectname[16]; /* name of this section */ 453 char segname[16]; /* segment this section goes in */ 454 uint64_t addr; /* memory address of this section */ 455 uint64_t size; /* size in bytes of this section */ 456 uint32_t offset; /* file offset of this section */ 457 uint32_t align; /* section alignment (power of 2) */ 458 uint32_t reloff; /* file offset of relocation entries */ 459 uint32_t nreloc; /* number of relocation entries */ 460 uint32_t flags; /* flags (section type and attributes)*/ 461 uint32_t reserved1; /* reserved (for offset or index) */ 462 uint32_t reserved2; /* reserved (for count or sizeof) */ 463 uint32_t reserved3; /* reserved */ 464 }; 465 466 /* 467 * The flags field of a section structure is separated into two parts a section 468 * type and section attributes. The section types are mutually exclusive (it 469 * can only have one type) but the section attributes are not (it may have more 470 * than one attribute). 471 */ 472 #define SECTION_TYPE 0x000000ff /* 256 section types */ 473 #define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */ 474 475 /* Constants for the type of a section */ 476 #define S_REGULAR 0x0 /* regular section */ 477 #define S_ZEROFILL 0x1 /* zero fill on demand section */ 478 #define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/ 479 #define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */ 480 #define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */ 481 #define S_LITERAL_POINTERS 0x5 /* section with only pointers to */ 482 /* literals */ 483 /* 484 * For the two types of symbol pointers sections and the symbol stubs section 485 * they have indirect symbol table entries. For each of the entries in the 486 * section the indirect symbol table entries, in corresponding order in the 487 * indirect symbol table, start at the index stored in the reserved1 field 488 * of the section structure. Since the indirect symbol table entries 489 * correspond to the entries in the section the number of indirect symbol table 490 * entries is inferred from the size of the section divided by the size of the 491 * entries in the section. For symbol pointers sections the size of the entries 492 * in the section is 4 bytes and for symbol stubs sections the byte size of the 493 * stubs is stored in the reserved2 field of the section structure. 494 */ 495 #define S_NON_LAZY_SYMBOL_POINTERS 0x6 /* section with only non-lazy 496 symbol pointers */ 497 #define S_LAZY_SYMBOL_POINTERS 0x7 /* section with only lazy symbol 498 pointers */ 499 #define S_SYMBOL_STUBS 0x8 /* section with only symbol 500 stubs, byte size of stub in 501 the reserved2 field */ 502 #define S_MOD_INIT_FUNC_POINTERS 0x9 /* section with only function 503 pointers for initialization*/ 504 #define S_MOD_TERM_FUNC_POINTERS 0xa /* section with only function 505 pointers for termination */ 506 #define S_COALESCED 0xb /* section contains symbols that 507 are to be coalesced */ 508 #define S_GB_ZEROFILL 0xc /* zero fill on demand section 509 (that can be larger than 4 510 gigabytes) */ 511 #define S_INTERPOSING 0xd /* section with only pairs of 512 function pointers for 513 interposing */ 514 #define S_16BYTE_LITERALS 0xe /* section with only 16 byte 515 literals */ 516 #define S_DTRACE_DOF 0xf /* section contains 517 DTrace Object Format */ 518 #define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy 519 symbol pointers to lazy 520 loaded dylibs */ 521 /* 522 * Section types to support thread local variables 523 */ 524 #define S_THREAD_LOCAL_REGULAR 0x11 /* template of initial 525 values for TLVs */ 526 #define S_THREAD_LOCAL_ZEROFILL 0x12 /* template of initial 527 values for TLVs */ 528 #define S_THREAD_LOCAL_VARIABLES 0x13 /* TLV descriptors */ 529 #define S_THREAD_LOCAL_VARIABLE_POINTERS 0x14 /* pointers to TLV 530 descriptors */ 531 #define S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 0x15 /* functions to call 532 to initialize TLV 533 values */ 534 #define S_INIT_FUNC_OFFSETS 0x16 /* 32-bit offsets to 535 initializers */ 536 537 /* 538 * Constants for the section attributes part of the flags field of a section 539 * structure. 540 */ 541 #define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */ 542 #define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section contains only true 543 machine instructions */ 544 #define S_ATTR_NO_TOC 0x40000000 /* section contains coalesced 545 symbols that are not to be 546 in a ranlib table of 547 contents */ 548 #define S_ATTR_STRIP_STATIC_SYMS 0x20000000 /* ok to strip static symbols 549 in this section in files 550 with the MH_DYLDLINK flag */ 551 #define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */ 552 #define S_ATTR_LIVE_SUPPORT 0x08000000 /* blocks are live if they 553 reference live blocks */ 554 #define S_ATTR_SELF_MODIFYING_CODE 0x04000000 /* Used with i386 code stubs 555 written on by dyld */ 556 /* 557 * If a segment contains any sections marked with S_ATTR_DEBUG then all 558 * sections in that segment must have this attribute. No section other than 559 * a section marked with this attribute may reference the contents of this 560 * section. A section with this attribute may contain no symbols and must have 561 * a section type S_REGULAR. The static linker will not copy section contents 562 * from sections with this attribute into its output file. These sections 563 * generally contain DWARF debugging info. 564 */ 565 #define S_ATTR_DEBUG 0x02000000 /* a debug section */ 566 #define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */ 567 #define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some 568 machine instructions */ 569 #define S_ATTR_EXT_RELOC 0x00000200 /* section has external 570 relocation entries */ 571 #define S_ATTR_LOC_RELOC 0x00000100 /* section has local 572 relocation entries */ 573 574 575 /* 576 * The names of segments and sections in them are mostly meaningless to the 577 * link-editor. But there are few things to support traditional UNIX 578 * executables that require the link-editor and assembler to use some names 579 * agreed upon by convention. 580 * 581 * The initial protection of the "__TEXT" segment has write protection turned 582 * off (not writeable). 583 * 584 * The link-editor will allocate common symbols at the end of the "__common" 585 * section in the "__DATA" segment. It will create the section and segment 586 * if needed. 587 */ 588 589 /* The currently known segment names and the section names in those segments */ 590 591 #define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */ 592 /* protections and catches NULL */ 593 /* references for MH_EXECUTE files */ 594 595 596 #define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */ 597 #define SECT_TEXT "__text" /* the real text part of the text */ 598 /* section no headers, and no padding */ 599 #define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */ 600 /* section */ 601 #define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */ 602 /* fvmlib initialization */ 603 /* section */ 604 605 #define SEG_DATA "__DATA" /* the tradition UNIX data segment */ 606 #define SECT_DATA "__data" /* the real initialized data section */ 607 /* no padding, no bss overlap */ 608 #define SECT_BSS "__bss" /* the real uninitialized data section*/ 609 /* no padding */ 610 #define SECT_COMMON "__common" /* the section common symbols are */ 611 /* allocated in by the link editor */ 612 613 #define SEG_OBJC "__OBJC" /* objective-C runtime segment */ 614 #define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */ 615 #define SECT_OBJC_MODULES "__module_info" /* module information */ 616 #define SECT_OBJC_STRINGS "__selector_strs" /* string table */ 617 #define SECT_OBJC_REFS "__selector_refs" /* string table */ 618 619 #define SEG_ICON "__ICON" /* the icon segment */ 620 #define SECT_ICON_HEADER "__header" /* the icon headers */ 621 #define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */ 622 623 #define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */ 624 /* created and maintained by the link */ 625 /* editor. Created with -seglinkedit */ 626 /* option to ld(1) for MH_EXECUTE and */ 627 /* FVMLIB file types only */ 628 629 #define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */ 630 631 #define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */ 632 /* modifing code stubs that has read, */ 633 /* write and execute permissions */ 634 635 /* 636 * Fixed virtual memory shared libraries are identified by two things. The 637 * target pathname (the name of the library as found for execution), and the 638 * minor version number. The address of where the headers are loaded is in 639 * header_addr. (THIS IS OBSOLETE and no longer supported). 640 */ 641 struct fvmlib { 642 union lc_str name; /* library's target pathname */ 643 uint32_t minor_version; /* library's minor version number */ 644 uint32_t header_addr; /* library's header address */ 645 }; 646 647 /* 648 * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header) 649 * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library. 650 * An object that uses a fixed virtual shared library also contains a 651 * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses. 652 * (THIS IS OBSOLETE and no longer supported). 653 */ 654 struct fvmlib_command { 655 uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */ 656 uint32_t cmdsize; /* includes pathname string */ 657 struct fvmlib fvmlib; /* the library identification */ 658 }; 659 660 /* 661 * Dynamicly linked shared libraries are identified by two things. The 662 * pathname (the name of the library as found for execution), and the 663 * compatibility version number. The pathname must match and the compatibility 664 * number in the user of the library must be greater than or equal to the 665 * library being used. The time stamp is used to record the time a library was 666 * built and copied into user so it can be use to determined if the library used 667 * at runtime is exactly the same as used to built the program. 668 */ 669 struct dylib { 670 union lc_str name; /* library's path name */ 671 uint32_t timestamp; /* library's build time stamp */ 672 uint32_t current_version; /* library's current version number */ 673 uint32_t compatibility_version; /* library's compatibility vers number*/ 674 }; 675 676 /* 677 * A dynamically linked shared library (filetype == MH_DYLIB in the mach header) 678 * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library. 679 * An object that uses a dynamically linked shared library also contains a 680 * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or 681 * LC_REEXPORT_DYLIB) for each library it uses. 682 */ 683 struct dylib_command { 684 uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB, 685 LC_REEXPORT_DYLIB */ 686 uint32_t cmdsize; /* includes pathname string */ 687 struct dylib dylib; /* the library identification */ 688 }; 689 690 /* 691 * A dynamically linked shared library may be a subframework of an umbrella 692 * framework. If so it will be linked with "-umbrella umbrella_name" where 693 * Where "umbrella_name" is the name of the umbrella framework. A subframework 694 * can only be linked against by its umbrella framework or other subframeworks 695 * that are part of the same umbrella framework. Otherwise the static link 696 * editor produces an error and states to link against the umbrella framework. 697 * The name of the umbrella framework for subframeworks is recorded in the 698 * following structure. 699 */ 700 struct sub_framework_command { 701 uint32_t cmd; /* LC_SUB_FRAMEWORK */ 702 uint32_t cmdsize; /* includes umbrella string */ 703 union lc_str umbrella; /* the umbrella framework name */ 704 }; 705 706 /* 707 * For dynamically linked shared libraries that are subframework of an umbrella 708 * framework they can allow clients other than the umbrella framework or other 709 * subframeworks in the same umbrella framework. To do this the subframework 710 * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load 711 * command is created for each -allowable_client flag. The client_name is 712 * usually a framework name. It can also be a name used for bundles clients 713 * where the bundle is built with "-client_name client_name". 714 */ 715 struct sub_client_command { 716 uint32_t cmd; /* LC_SUB_CLIENT */ 717 uint32_t cmdsize; /* includes client string */ 718 union lc_str client; /* the client name */ 719 }; 720 721 /* 722 * A dynamically linked shared library may be a sub_umbrella of an umbrella 723 * framework. If so it will be linked with "-sub_umbrella umbrella_name" where 724 * Where "umbrella_name" is the name of the sub_umbrella framework. When 725 * staticly linking when -twolevel_namespace is in effect a twolevel namespace 726 * umbrella framework will only cause its subframeworks and those frameworks 727 * listed as sub_umbrella frameworks to be implicited linked in. Any other 728 * dependent dynamic libraries will not be linked it when -twolevel_namespace 729 * is in effect. The primary library recorded by the static linker when 730 * resolving a symbol in these libraries will be the umbrella framework. 731 * Zero or more sub_umbrella frameworks may be use by an umbrella framework. 732 * The name of a sub_umbrella framework is recorded in the following structure. 733 */ 734 struct sub_umbrella_command { 735 uint32_t cmd; /* LC_SUB_UMBRELLA */ 736 uint32_t cmdsize; /* includes sub_umbrella string */ 737 union lc_str sub_umbrella; /* the sub_umbrella framework name */ 738 }; 739 740 /* 741 * A dynamically linked shared library may be a sub_library of another shared 742 * library. If so it will be linked with "-sub_library library_name" where 743 * Where "library_name" is the name of the sub_library shared library. When 744 * staticly linking when -twolevel_namespace is in effect a twolevel namespace 745 * shared library will only cause its subframeworks and those frameworks 746 * listed as sub_umbrella frameworks and libraries listed as sub_libraries to 747 * be implicited linked in. Any other dependent dynamic libraries will not be 748 * linked it when -twolevel_namespace is in effect. The primary library 749 * recorded by the static linker when resolving a symbol in these libraries 750 * will be the umbrella framework (or dynamic library). Zero or more sub_library 751 * shared libraries may be use by an umbrella framework or (or dynamic library). 752 * The name of a sub_library framework is recorded in the following structure. 753 * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc". 754 */ 755 struct sub_library_command { 756 uint32_t cmd; /* LC_SUB_LIBRARY */ 757 uint32_t cmdsize; /* includes sub_library string */ 758 union lc_str sub_library; /* the sub_library name */ 759 }; 760 761 /* 762 * A program (filetype == MH_EXECUTE) that is 763 * prebound to its dynamic libraries has one of these for each library that 764 * the static linker used in prebinding. It contains a bit vector for the 765 * modules in the library. The bits indicate which modules are bound (1) and 766 * which are not (0) from the library. The bit for module 0 is the low bit 767 * of the first byte. So the bit for the Nth module is: 768 * (linked_modules[N/8] >> N%8) & 1 769 */ 770 struct prebound_dylib_command { 771 uint32_t cmd; /* LC_PREBOUND_DYLIB */ 772 uint32_t cmdsize; /* includes strings */ 773 union lc_str name; /* library's path name */ 774 uint32_t nmodules; /* number of modules in library */ 775 union lc_str linked_modules; /* bit vector of linked modules */ 776 }; 777 778 /* 779 * A program that uses a dynamic linker contains a dylinker_command to identify 780 * the name of the dynamic linker (LC_LOAD_DYLINKER). And a dynamic linker 781 * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER). 782 * A file can have at most one of these. 783 * This struct is also used for the LC_DYLD_ENVIRONMENT load command and 784 * contains string for dyld to treat like environment variable. 785 */ 786 struct dylinker_command { 787 uint32_t cmd; /* LC_ID_DYLINKER, LC_LOAD_DYLINKER or 788 LC_DYLD_ENVIRONMENT */ 789 uint32_t cmdsize; /* includes pathname string */ 790 union lc_str name; /* dynamic linker's path name */ 791 }; 792 793 /* 794 * Thread commands contain machine-specific data structures suitable for 795 * use in the thread state primitives. The machine specific data structures 796 * follow the struct thread_command as follows. 797 * Each flavor of machine specific data structure is preceded by an uint32_t 798 * constant for the flavor of that data structure, an uint32_t that is the 799 * count of uint32_t's of the size of the state data structure and then 800 * the state data structure follows. This triple may be repeated for many 801 * flavors. The constants for the flavors, counts and state data structure 802 * definitions are expected to be in the header file <machine/thread_status.h>. 803 * These machine specific data structures sizes must be multiples of 804 * 4 bytes. The cmdsize reflects the total size of the thread_command 805 * and all of the sizes of the constants for the flavors, counts and state 806 * data structures. 807 * 808 * For executable objects that are unix processes there will be one 809 * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor. 810 * This is the same as a LC_THREAD, except that a stack is automatically 811 * created (based on the shell's limit for the stack size). Command arguments 812 * and environment variables are copied onto that stack. 813 */ 814 struct thread_command { 815 uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */ 816 uint32_t cmdsize; /* total size of this command */ 817 /* uint32_t flavor flavor of thread state */ 818 /* uint32_t count count of uint32_t's in thread state */ 819 /* struct XXX_thread_state state thread state for this flavor */ 820 /* ... */ 821 }; 822 823 /* 824 * The routines command contains the address of the dynamic shared library 825 * initialization routine and an index into the module table for the module 826 * that defines the routine. Before any modules are used from the library the 827 * dynamic linker fully binds the module that defines the initialization routine 828 * and then calls it. This gets called before any module initialization 829 * routines (used for C++ static constructors) in the library. 830 */ 831 struct routines_command { /* for 32-bit architectures */ 832 uint32_t cmd; /* LC_ROUTINES */ 833 uint32_t cmdsize; /* total size of this command */ 834 uint32_t init_address; /* address of initialization routine */ 835 uint32_t init_module; /* index into the module table that */ 836 /* the init routine is defined in */ 837 uint32_t reserved1; 838 uint32_t reserved2; 839 uint32_t reserved3; 840 uint32_t reserved4; 841 uint32_t reserved5; 842 uint32_t reserved6; 843 }; 844 845 /* 846 * The 64-bit routines command. Same use as above. 847 */ 848 struct routines_command_64 { /* for 64-bit architectures */ 849 uint32_t cmd; /* LC_ROUTINES_64 */ 850 uint32_t cmdsize; /* total size of this command */ 851 uint64_t init_address; /* address of initialization routine */ 852 uint64_t init_module; /* index into the module table that */ 853 /* the init routine is defined in */ 854 uint64_t reserved1; 855 uint64_t reserved2; 856 uint64_t reserved3; 857 uint64_t reserved4; 858 uint64_t reserved5; 859 uint64_t reserved6; 860 }; 861 862 /* 863 * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD 864 * "stab" style symbol table information as described in the header files 865 * <nlist.h> and <stab.h>. 866 */ 867 struct symtab_command { 868 uint32_t cmd; /* LC_SYMTAB */ 869 uint32_t cmdsize; /* sizeof(struct symtab_command) */ 870 uint32_t symoff; /* symbol table offset */ 871 uint32_t nsyms; /* number of symbol table entries */ 872 uint32_t stroff; /* string table offset */ 873 uint32_t strsize; /* string table size in bytes */ 874 }; 875 876 /* 877 * This is the second set of the symbolic information which is used to support 878 * the data structures for the dynamically link editor. 879 * 880 * The original set of symbolic information in the symtab_command which contains 881 * the symbol and string tables must also be present when this load command is 882 * present. When this load command is present the symbol table is organized 883 * into three groups of symbols: 884 * local symbols (static and debugging symbols) - grouped by module 885 * defined external symbols - grouped by module (sorted by name if not lib) 886 * undefined external symbols (sorted by name if MH_BINDATLOAD is not set, 887 * and in order the were seen by the static 888 * linker if MH_BINDATLOAD is set) 889 * In this load command there are offsets and counts to each of the three groups 890 * of symbols. 891 * 892 * This load command contains a the offsets and sizes of the following new 893 * symbolic information tables: 894 * table of contents 895 * module table 896 * reference symbol table 897 * indirect symbol table 898 * The first three tables above (the table of contents, module table and 899 * reference symbol table) are only present if the file is a dynamically linked 900 * shared library. For executable and object modules, which are files 901 * containing only one module, the information that would be in these three 902 * tables is determined as follows: 903 * table of contents - the defined external symbols are sorted by name 904 * module table - the file contains only one module so everything in the 905 * file is part of the module. 906 * reference symbol table - is the defined and undefined external symbols 907 * 908 * For dynamically linked shared library files this load command also contains 909 * offsets and sizes to the pool of relocation entries for all sections 910 * separated into two groups: 911 * external relocation entries 912 * local relocation entries 913 * For executable and object modules the relocation entries continue to hang 914 * off the section structures. 915 */ 916 struct dysymtab_command { 917 uint32_t cmd; /* LC_DYSYMTAB */ 918 uint32_t cmdsize; /* sizeof(struct dysymtab_command) */ 919 920 /* 921 * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command 922 * are grouped into the following three groups: 923 * local symbols (further grouped by the module they are from) 924 * defined external symbols (further grouped by the module they are from) 925 * undefined symbols 926 * 927 * The local symbols are used only for debugging. The dynamic binding 928 * process may have to use them to indicate to the debugger the local 929 * symbols for a module that is being bound. 930 * 931 * The last two groups are used by the dynamic binding process to do the 932 * binding (indirectly through the module table and the reference symbol 933 * table when this is a dynamically linked shared library file). 934 */ 935 uint32_t ilocalsym; /* index to local symbols */ 936 uint32_t nlocalsym; /* number of local symbols */ 937 938 uint32_t iextdefsym;/* index to externally defined symbols */ 939 uint32_t nextdefsym;/* number of externally defined symbols */ 940 941 uint32_t iundefsym; /* index to undefined symbols */ 942 uint32_t nundefsym; /* number of undefined symbols */ 943 944 /* 945 * For the for the dynamic binding process to find which module a symbol 946 * is defined in the table of contents is used (analogous to the ranlib 947 * structure in an archive) which maps defined external symbols to modules 948 * they are defined in. This exists only in a dynamically linked shared 949 * library file. For executable and object modules the defined external 950 * symbols are sorted by name and is use as the table of contents. 951 */ 952 uint32_t tocoff; /* file offset to table of contents */ 953 uint32_t ntoc; /* number of entries in table of contents */ 954 955 /* 956 * To support dynamic binding of "modules" (whole object files) the symbol 957 * table must reflect the modules that the file was created from. This is 958 * done by having a module table that has indexes and counts into the merged 959 * tables for each module. The module structure that these two entries 960 * refer to is described below. This exists only in a dynamically linked 961 * shared library file. For executable and object modules the file only 962 * contains one module so everything in the file belongs to the module. 963 */ 964 uint32_t modtaboff; /* file offset to module table */ 965 uint32_t nmodtab; /* number of module table entries */ 966 967 /* 968 * To support dynamic module binding the module structure for each module 969 * indicates the external references (defined and undefined) each module 970 * makes. For each module there is an offset and a count into the 971 * reference symbol table for the symbols that the module references. 972 * This exists only in a dynamically linked shared library file. For 973 * executable and object modules the defined external symbols and the 974 * undefined external symbols indicates the external references. 975 */ 976 uint32_t extrefsymoff; /* offset to referenced symbol table */ 977 uint32_t nextrefsyms; /* number of referenced symbol table entries */ 978 979 /* 980 * The sections that contain "symbol pointers" and "routine stubs" have 981 * indexes and (implied counts based on the size of the section and fixed 982 * size of the entry) into the "indirect symbol" table for each pointer 983 * and stub. For every section of these two types the index into the 984 * indirect symbol table is stored in the section header in the field 985 * reserved1. An indirect symbol table entry is simply a 32bit index into 986 * the symbol table to the symbol that the pointer or stub is referring to. 987 * The indirect symbol table is ordered to match the entries in the section. 988 */ 989 uint32_t indirectsymoff; /* file offset to the indirect symbol table */ 990 uint32_t nindirectsyms; /* number of indirect symbol table entries */ 991 992 /* 993 * To support relocating an individual module in a library file quickly the 994 * external relocation entries for each module in the library need to be 995 * accessed efficiently. Since the relocation entries can't be accessed 996 * through the section headers for a library file they are separated into 997 * groups of local and external entries further grouped by module. In this 998 * case the presents of this load command who's extreloff, nextrel, 999 * locreloff and nlocrel fields are non-zero indicates that the relocation 1000 * entries of non-merged sections are not referenced through the section 1001 * structures (and the reloff and nreloc fields in the section headers are 1002 * set to zero). 1003 * 1004 * Since the relocation entries are not accessed through the section headers 1005 * this requires the r_address field to be something other than a section 1006 * offset to identify the item to be relocated. In this case r_address is 1007 * set to the offset from the vmaddr of the first LC_SEGMENT command. 1008 * For MH_SPLIT_SEGS images r_address is set to the the offset from the 1009 * vmaddr of the first read-write LC_SEGMENT command. 1010 * 1011 * The relocation entries are grouped by module and the module table 1012 * entries have indexes and counts into them for the group of external 1013 * relocation entries for that the module. 1014 * 1015 * For sections that are merged across modules there must not be any 1016 * remaining external relocation entries for them (for merged sections 1017 * remaining relocation entries must be local). 1018 */ 1019 uint32_t extreloff; /* offset to external relocation entries */ 1020 uint32_t nextrel; /* number of external relocation entries */ 1021 1022 /* 1023 * All the local relocation entries are grouped together (they are not 1024 * grouped by their module since they are only used if the object is moved 1025 * from it staticly link edited address). 1026 */ 1027 uint32_t locreloff; /* offset to local relocation entries */ 1028 uint32_t nlocrel; /* number of local relocation entries */ 1029 1030 }; 1031 1032 /* 1033 * An indirect symbol table entry is simply a 32bit index into the symbol table 1034 * to the symbol that the pointer or stub is refering to. Unless it is for a 1035 * non-lazy symbol pointer section for a defined symbol which strip(1) as 1036 * removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the 1037 * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that. 1038 */ 1039 #define INDIRECT_SYMBOL_LOCAL 0x80000000 1040 #define INDIRECT_SYMBOL_ABS 0x40000000 1041 1042 1043 /* a table of contents entry */ 1044 struct dylib_table_of_contents { 1045 uint32_t symbol_index; /* the defined external symbol 1046 (index into the symbol table) */ 1047 uint32_t module_index; /* index into the module table this symbol 1048 is defined in */ 1049 }; 1050 1051 /* a module table entry */ 1052 struct dylib_module { 1053 uint32_t module_name; /* the module name (index into string table) */ 1054 1055 uint32_t iextdefsym; /* index into externally defined symbols */ 1056 uint32_t nextdefsym; /* number of externally defined symbols */ 1057 uint32_t irefsym; /* index into reference symbol table */ 1058 uint32_t nrefsym; /* number of reference symbol table entries */ 1059 uint32_t ilocalsym; /* index into symbols for local symbols */ 1060 uint32_t nlocalsym; /* number of local symbols */ 1061 1062 uint32_t iextrel; /* index into external relocation entries */ 1063 uint32_t nextrel; /* number of external relocation entries */ 1064 1065 uint32_t iinit_iterm; /* low 16 bits are the index into the init 1066 section, high 16 bits are the index into 1067 the term section */ 1068 uint32_t ninit_nterm; /* low 16 bits are the number of init section 1069 entries, high 16 bits are the number of 1070 term section entries */ 1071 1072 uint32_t /* for this module address of the start of */ 1073 objc_module_info_addr; /* the (__OBJC,__module_info) section */ 1074 uint32_t /* for this module size of */ 1075 objc_module_info_size; /* the (__OBJC,__module_info) section */ 1076 }; 1077 1078 /* a 64-bit module table entry */ 1079 struct dylib_module_64 { 1080 uint32_t module_name; /* the module name (index into string table) */ 1081 1082 uint32_t iextdefsym; /* index into externally defined symbols */ 1083 uint32_t nextdefsym; /* number of externally defined symbols */ 1084 uint32_t irefsym; /* index into reference symbol table */ 1085 uint32_t nrefsym; /* number of reference symbol table entries */ 1086 uint32_t ilocalsym; /* index into symbols for local symbols */ 1087 uint32_t nlocalsym; /* number of local symbols */ 1088 1089 uint32_t iextrel; /* index into external relocation entries */ 1090 uint32_t nextrel; /* number of external relocation entries */ 1091 1092 uint32_t iinit_iterm; /* low 16 bits are the index into the init 1093 section, high 16 bits are the index into 1094 the term section */ 1095 uint32_t ninit_nterm; /* low 16 bits are the number of init section 1096 entries, high 16 bits are the number of 1097 term section entries */ 1098 1099 uint32_t /* for this module size of */ 1100 objc_module_info_size; /* the (__OBJC,__module_info) section */ 1101 uint64_t /* for this module address of the start of */ 1102 objc_module_info_addr; /* the (__OBJC,__module_info) section */ 1103 }; 1104 1105 /* 1106 * The entries in the reference symbol table are used when loading the module 1107 * (both by the static and dynamic link editors) and if the module is unloaded 1108 * or replaced. Therefore all external symbols (defined and undefined) are 1109 * listed in the module's reference table. The flags describe the type of 1110 * reference that is being made. The constants for the flags are defined in 1111 * <mach-o/nlist.h> as they are also used for symbol table entries. 1112 */ 1113 struct dylib_reference { 1114 uint32_t isym:24, /* index into the symbol table */ 1115 flags:8; /* flags to indicate the type of reference */ 1116 }; 1117 1118 /* 1119 * The twolevel_hints_command contains the offset and number of hints in the 1120 * two-level namespace lookup hints table. 1121 */ 1122 struct twolevel_hints_command { 1123 uint32_t cmd; /* LC_TWOLEVEL_HINTS */ 1124 uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */ 1125 uint32_t offset; /* offset to the hint table */ 1126 uint32_t nhints; /* number of hints in the hint table */ 1127 }; 1128 1129 /* 1130 * The entries in the two-level namespace lookup hints table are twolevel_hint 1131 * structs. These provide hints to the dynamic link editor where to start 1132 * looking for an undefined symbol in a two-level namespace image. The 1133 * isub_image field is an index into the sub-images (sub-frameworks and 1134 * sub-umbrellas list) that made up the two-level image that the undefined 1135 * symbol was found in when it was built by the static link editor. If 1136 * isub-image is 0 the the symbol is expected to be defined in library and not 1137 * in the sub-images. If isub-image is non-zero it is an index into the array 1138 * of sub-images for the umbrella with the first index in the sub-images being 1139 * 1. The array of sub-images is the ordered list of sub-images of the umbrella 1140 * that would be searched for a symbol that has the umbrella recorded as its 1141 * primary library. The table of contents index is an index into the 1142 * library's table of contents. This is used as the starting point of the 1143 * binary search or a directed linear search. 1144 */ 1145 struct twolevel_hint { 1146 uint32_t 1147 isub_image:8, /* index into the sub images */ 1148 itoc:24; /* index into the table of contents */ 1149 }; 1150 1151 /* 1152 * The prebind_cksum_command contains the value of the original check sum for 1153 * prebound files or zero. When a prebound file is first created or modified 1154 * for other than updating its prebinding information the value of the check sum 1155 * is set to zero. When the file has it prebinding re-done and if the value of 1156 * the check sum is zero the original check sum is calculated and stored in 1157 * cksum field of this load command in the output file. If when the prebinding 1158 * is re-done and the cksum field is non-zero it is left unchanged from the 1159 * input file. 1160 */ 1161 struct prebind_cksum_command { 1162 uint32_t cmd; /* LC_PREBIND_CKSUM */ 1163 uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */ 1164 uint32_t cksum; /* the check sum or zero */ 1165 }; 1166 1167 /* 1168 * The uuid load command contains a single 128-bit unique random number that 1169 * identifies an object produced by the static link editor. 1170 */ 1171 struct uuid_command { 1172 uint32_t cmd; /* LC_UUID */ 1173 uint32_t cmdsize; /* sizeof(struct uuid_command) */ 1174 uint8_t uuid[16]; /* the 128-bit uuid */ 1175 }; 1176 1177 /* 1178 * The rpath_command contains a path which at runtime should be added to 1179 * the current run path used to find @rpath prefixed dylibs. 1180 */ 1181 struct rpath_command { 1182 uint32_t cmd; /* LC_RPATH */ 1183 uint32_t cmdsize; /* includes string */ 1184 union lc_str path; /* path to add to run path */ 1185 }; 1186 1187 /* 1188 * The linkedit_data_command contains the offsets and sizes of a blob 1189 * of data in the __LINKEDIT segment. 1190 */ 1191 struct linkedit_data_command { 1192 uint32_t cmd; /* LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, 1193 LC_FUNCTION_STARTS, LC_DATA_IN_CODE, 1194 LC_DYLIB_CODE_SIGN_DRS, 1195 LC_LINKER_OPTIMIZATION_HINT, 1196 LC_DYLD_EXPORTS_TRIE, or 1197 LC_DYLD_CHAINED_FIXUPS. */ 1198 uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */ 1199 uint32_t dataoff; /* file offset of data in __LINKEDIT segment */ 1200 uint32_t datasize; /* file size of data in __LINKEDIT segment */ 1201 }; 1202 1203 /* 1204 * The encryption_info_command contains the file offset and size of an 1205 * of an encrypted segment. 1206 */ 1207 struct encryption_info_command { 1208 uint32_t cmd; /* LC_ENCRYPTION_INFO */ 1209 uint32_t cmdsize; /* sizeof(struct encryption_info_command) */ 1210 uint32_t cryptoff; /* file offset of encrypted range */ 1211 uint32_t cryptsize; /* file size of encrypted range */ 1212 uint32_t cryptid; /* which enryption system, 1213 0 means not-encrypted yet */ 1214 }; 1215 1216 /* 1217 * The encryption_info_command_64 contains the file offset and size of an 1218 * of an encrypted segment (for use in x86_64 targets). 1219 */ 1220 struct encryption_info_command_64 { 1221 uint32_t cmd; /* LC_ENCRYPTION_INFO_64 */ 1222 uint32_t cmdsize; /* sizeof(struct encryption_info_command_64) */ 1223 uint32_t cryptoff; /* file offset of encrypted range */ 1224 uint32_t cryptsize; /* file size of encrypted range */ 1225 uint32_t cryptid; /* which enryption system, 1226 0 means not-encrypted yet */ 1227 uint32_t pad; /* padding to make this struct's size a multiple 1228 of 8 bytes */ 1229 }; 1230 1231 /* 1232 * The version_min_command contains the min OS version on which this 1233 * binary was built to run. 1234 */ 1235 struct version_min_command { 1236 uint32_t cmd; /* LC_VERSION_MIN_MACOSX or 1237 LC_VERSION_MIN_IPHONEOS or 1238 LC_VERSION_MIN_WATCHOS or 1239 LC_VERSION_MIN_TVOS */ 1240 uint32_t cmdsize; /* sizeof(struct min_version_command) */ 1241 uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1242 uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1243 }; 1244 1245 /* 1246 * The build_version_command contains the min OS version on which this 1247 * binary was built to run for its platform. The list of known platforms and 1248 * tool values following it. 1249 */ 1250 struct build_version_command { 1251 uint32_t cmd; /* LC_BUILD_VERSION */ 1252 uint32_t cmdsize; /* sizeof(struct build_version_command) plus */ 1253 /* ntools * sizeof(struct build_tool_version) */ 1254 uint32_t platform; /* platform */ 1255 uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1256 uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */ 1257 uint32_t ntools; /* number of tool entries following this */ 1258 }; 1259 1260 struct build_tool_version { 1261 uint32_t tool; /* enum for the tool */ 1262 uint32_t version; /* version number of the tool */ 1263 }; 1264 1265 /* Known values for the platform field above. */ 1266 #define PLATFORM_MACOS 1 1267 #define PLATFORM_IOS 2 1268 #define PLATFORM_TVOS 3 1269 #define PLATFORM_WATCHOS 4 1270 #define PLATFORM_BRIDGEOS 5 1271 #define PLATFORM_MACCATALYST 6 1272 #define PLATFORM_IOSSIMULATOR 7 1273 #define PLATFORM_TVOSSIMULATOR 8 1274 #define PLATFORM_WATCHOSSIMULATOR 9 1275 #define PLATFORM_DRIVERKIT 10 1276 1277 #ifndef __APPLE_BLEACH_SDK__ 1278 #endif /* __APPLE_BLEACH_SDK__ */ 1279 1280 /* Known values for the tool field above. */ 1281 #define TOOL_CLANG 1 1282 #define TOOL_SWIFT 2 1283 #define TOOL_LD 3 1284 1285 /* 1286 * The dyld_info_command contains the file offsets and sizes of 1287 * the new compressed form of the information dyld needs to 1288 * load the image. This information is used by dyld on Mac OS X 1289 * 10.6 and later. All information pointed to by this command 1290 * is encoded using byte streams, so no endian swapping is needed 1291 * to interpret it. 1292 */ 1293 struct dyld_info_command { 1294 uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */ 1295 uint32_t cmdsize; /* sizeof(struct dyld_info_command) */ 1296 1297 /* 1298 * Dyld rebases an image whenever dyld loads it at an address different 1299 * from its preferred address. The rebase information is a stream 1300 * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_. 1301 * Conceptually the rebase information is a table of tuples: 1302 * <seg-index, seg-offset, type> 1303 * The opcodes are a compressed way to encode the table by only 1304 * encoding when a column changes. In addition simple patterns 1305 * like "every n'th offset for m times" can be encoded in a few 1306 * bytes. 1307 */ 1308 uint32_t rebase_off; /* file offset to rebase info */ 1309 uint32_t rebase_size; /* size of rebase info */ 1310 1311 /* 1312 * Dyld binds an image during the loading process, if the image 1313 * requires any pointers to be initialized to symbols in other images. 1314 * The bind information is a stream of byte sized 1315 * opcodes whose symbolic names start with BIND_OPCODE_. 1316 * Conceptually the bind information is a table of tuples: 1317 * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend> 1318 * The opcodes are a compressed way to encode the table by only 1319 * encoding when a column changes. In addition simple patterns 1320 * like for runs of pointers initialzed to the same value can be 1321 * encoded in a few bytes. 1322 */ 1323 uint32_t bind_off; /* file offset to binding info */ 1324 uint32_t bind_size; /* size of binding info */ 1325 1326 /* 1327 * Some C++ programs require dyld to unique symbols so that all 1328 * images in the process use the same copy of some code/data. 1329 * This step is done after binding. The content of the weak_bind 1330 * info is an opcode stream like the bind_info. But it is sorted 1331 * alphabetically by symbol name. This enable dyld to walk 1332 * all images with weak binding information in order and look 1333 * for collisions. If there are no collisions, dyld does 1334 * no updating. That means that some fixups are also encoded 1335 * in the bind_info. For instance, all calls to "operator new" 1336 * are first bound to libstdc++.dylib using the information 1337 * in bind_info. Then if some image overrides operator new 1338 * that is detected when the weak_bind information is processed 1339 * and the call to operator new is then rebound. 1340 */ 1341 uint32_t weak_bind_off; /* file offset to weak binding info */ 1342 uint32_t weak_bind_size; /* size of weak binding info */ 1343 1344 /* 1345 * Some uses of external symbols do not need to be bound immediately. 1346 * Instead they can be lazily bound on first use. The lazy_bind 1347 * are contains a stream of BIND opcodes to bind all lazy symbols. 1348 * Normal use is that dyld ignores the lazy_bind section when 1349 * loading an image. Instead the static linker arranged for the 1350 * lazy pointer to initially point to a helper function which 1351 * pushes the offset into the lazy_bind area for the symbol 1352 * needing to be bound, then jumps to dyld which simply adds 1353 * the offset to lazy_bind_off to get the information on what 1354 * to bind. 1355 */ 1356 uint32_t lazy_bind_off; /* file offset to lazy binding info */ 1357 uint32_t lazy_bind_size; /* size of lazy binding infs */ 1358 1359 /* 1360 * The symbols exported by a dylib are encoded in a trie. This 1361 * is a compact representation that factors out common prefixes. 1362 * It also reduces LINKEDIT pages in RAM because it encodes all 1363 * information (name, address, flags) in one small, contiguous range. 1364 * The export area is a stream of nodes. The first node sequentially 1365 * is the start node for the trie. 1366 * 1367 * Nodes for a symbol start with a uleb128 that is the length of 1368 * the exported symbol information for the string so far. 1369 * If there is no exported symbol, the node starts with a zero byte. 1370 * If there is exported info, it follows the length. 1371 * 1372 * First is a uleb128 containing flags. Normally, it is followed by 1373 * a uleb128 encoded offset which is location of the content named 1374 * by the symbol from the mach_header for the image. If the flags 1375 * is EXPORT_SYMBOL_FLAGS_REEXPORT, then following the flags is 1376 * a uleb128 encoded library ordinal, then a zero terminated 1377 * UTF8 string. If the string is zero length, then the symbol 1378 * is re-export from the specified dylib with the same name. 1379 * If the flags is EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER, then following 1380 * the flags is two uleb128s: the stub offset and the resolver offset. 1381 * The stub is used by non-lazy pointers. The resolver is used 1382 * by lazy pointers and must be called to get the actual address to use. 1383 * 1384 * After the optional exported symbol information is a byte of 1385 * how many edges (0-255) that this node has leaving it, 1386 * followed by each edge. 1387 * Each edge is a zero terminated UTF8 of the addition chars 1388 * in the symbol, followed by a uleb128 offset for the node that 1389 * edge points to. 1390 * 1391 */ 1392 uint32_t export_off; /* file offset to lazy binding info */ 1393 uint32_t export_size; /* size of lazy binding infs */ 1394 }; 1395 1396 /* 1397 * The following are used to encode rebasing information 1398 */ 1399 #define REBASE_TYPE_POINTER 1 1400 #define REBASE_TYPE_TEXT_ABSOLUTE32 2 1401 #define REBASE_TYPE_TEXT_PCREL32 3 1402 1403 #define REBASE_OPCODE_MASK 0xF0 1404 #define REBASE_IMMEDIATE_MASK 0x0F 1405 #define REBASE_OPCODE_DONE 0x00 1406 #define REBASE_OPCODE_SET_TYPE_IMM 0x10 1407 #define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20 1408 #define REBASE_OPCODE_ADD_ADDR_ULEB 0x30 1409 #define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40 1410 #define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50 1411 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60 1412 #define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70 1413 #define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80 1414 1415 1416 /* 1417 * The following are used to encode binding information 1418 */ 1419 #define BIND_TYPE_POINTER 1 1420 #define BIND_TYPE_TEXT_ABSOLUTE32 2 1421 #define BIND_TYPE_TEXT_PCREL32 3 1422 1423 #define BIND_SPECIAL_DYLIB_SELF 0 1424 #define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1 1425 #define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2 1426 #define BIND_SPECIAL_DYLIB_WEAK_LOOKUP -3 1427 1428 #define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1 1429 #define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8 1430 1431 #define BIND_OPCODE_MASK 0xF0 1432 #define BIND_IMMEDIATE_MASK 0x0F 1433 #define BIND_OPCODE_DONE 0x00 1434 #define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10 1435 #define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20 1436 #define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30 1437 #define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40 1438 #define BIND_OPCODE_SET_TYPE_IMM 0x50 1439 #define BIND_OPCODE_SET_ADDEND_SLEB 0x60 1440 #define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70 1441 #define BIND_OPCODE_ADD_ADDR_ULEB 0x80 1442 #define BIND_OPCODE_DO_BIND 0x90 1443 #define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0 1444 #define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0 1445 #define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0 1446 #define BIND_OPCODE_THREADED 0xD0 1447 #define BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB 0x00 1448 #define BIND_SUBOPCODE_THREADED_APPLY 0x01 1449 1450 1451 /* 1452 * The following are used on the flags byte of a terminal node 1453 * in the export information. 1454 */ 1455 #define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03 1456 #define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00 1457 #define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01 1458 #define EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE 0x02 1459 #define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04 1460 #define EXPORT_SYMBOL_FLAGS_REEXPORT 0x08 1461 #define EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER 0x10 1462 #define EXPORT_SYMBOL_FLAGS_STATIC_RESOLVER 0x20 1463 1464 1465 /* 1466 * The linker_option_command contains linker options embedded in object files. 1467 */ 1468 struct linker_option_command { 1469 uint32_t cmd; /* LC_LINKER_OPTION only used in MH_OBJECT filetypes */ 1470 uint32_t cmdsize; 1471 uint32_t count; /* number of strings */ 1472 /* concatenation of zero terminated UTF8 strings. 1473 Zero filled at end to align */ 1474 }; 1475 1476 /* 1477 * The symseg_command contains the offset and size of the GNU style 1478 * symbol table information as described in the header file <symseg.h>. 1479 * The symbol roots of the symbol segments must also be aligned properly 1480 * in the file. So the requirement of keeping the offsets aligned to a 1481 * multiple of a 4 bytes translates to the length field of the symbol 1482 * roots also being a multiple of a long. Also the padding must again be 1483 * zeroed. (THIS IS OBSOLETE and no longer supported). 1484 */ 1485 struct symseg_command { 1486 uint32_t cmd; /* LC_SYMSEG */ 1487 uint32_t cmdsize; /* sizeof(struct symseg_command) */ 1488 uint32_t offset; /* symbol segment offset */ 1489 uint32_t size; /* symbol segment size in bytes */ 1490 }; 1491 1492 /* 1493 * The ident_command contains a free format string table following the 1494 * ident_command structure. The strings are null terminated and the size of 1495 * the command is padded out with zero bytes to a multiple of 4 bytes/ 1496 * (THIS IS OBSOLETE and no longer supported). 1497 */ 1498 struct ident_command { 1499 uint32_t cmd; /* LC_IDENT */ 1500 uint32_t cmdsize; /* strings that follow this command */ 1501 }; 1502 1503 /* 1504 * The fvmfile_command contains a reference to a file to be loaded at the 1505 * specified virtual address. (Presently, this command is reserved for 1506 * internal use. The kernel ignores this command when loading a program into 1507 * memory). 1508 */ 1509 struct fvmfile_command { 1510 uint32_t cmd; /* LC_FVMFILE */ 1511 uint32_t cmdsize; /* includes pathname string */ 1512 union lc_str name; /* files pathname */ 1513 uint32_t header_addr; /* files virtual address */ 1514 }; 1515 1516 1517 /* 1518 * The entry_point_command is a replacement for thread_command. 1519 * It is used for main executables to specify the location (file offset) 1520 * of main(). If -stack_size was used at link time, the stacksize 1521 * field will contain the stack size need for the main thread. 1522 */ 1523 struct entry_point_command { 1524 uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */ 1525 uint32_t cmdsize; /* 24 */ 1526 uint64_t entryoff; /* file (__TEXT) offset of main() */ 1527 uint64_t stacksize;/* if not zero, initial stack size */ 1528 }; 1529 1530 1531 /* 1532 * The source_version_command is an optional load command containing 1533 * the version of the sources used to build the binary. 1534 */ 1535 struct source_version_command { 1536 uint32_t cmd; /* LC_SOURCE_VERSION */ 1537 uint32_t cmdsize; /* 16 */ 1538 uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */ 1539 }; 1540 1541 1542 /* 1543 * The LC_DATA_IN_CODE load commands uses a linkedit_data_command 1544 * to point to an array of data_in_code_entry entries. Each entry 1545 * describes a range of data in a code section. 1546 */ 1547 struct data_in_code_entry { 1548 uint32_t offset; /* from mach_header to start of data range*/ 1549 uint16_t length; /* number of bytes in data range */ 1550 uint16_t kind; /* a DICE_KIND_* value */ 1551 }; 1552 #define DICE_KIND_DATA 0x0001 1553 #define DICE_KIND_JUMP_TABLE8 0x0002 1554 #define DICE_KIND_JUMP_TABLE16 0x0003 1555 #define DICE_KIND_JUMP_TABLE32 0x0004 1556 #define DICE_KIND_ABS_JUMP_TABLE32 0x0005 1557 1558 1559 1560 /* 1561 * Sections of type S_THREAD_LOCAL_VARIABLES contain an array 1562 * of tlv_descriptor structures. 1563 */ 1564 struct tlv_descriptor 1565 { 1566 void* (*thunk)(struct tlv_descriptor*); 1567 unsigned long key; 1568 unsigned long offset; 1569 }; 1570 1571 /* 1572 * LC_NOTE commands describe a region of arbitrary data included in a Mach-O 1573 * file. Its initial use is to record extra data in MH_CORE files. 1574 */ 1575 struct note_command { 1576 uint32_t cmd; /* LC_NOTE */ 1577 uint32_t cmdsize; /* sizeof(struct note_command) */ 1578 char data_owner[16]; /* owner name for this LC_NOTE */ 1579 uint64_t offset; /* file offset of this data */ 1580 uint64_t size; /* length of data region */ 1581 }; 1582 1583 /* 1584 * LC_FILESET_ENTRY commands describe constituent Mach-O files that are part 1585 * of a fileset. In one implementation, entries are dylibs with individual 1586 * mach headers and repositionable text and data segments. Each entry is 1587 * further described by its own mach header. 1588 */ 1589 struct fileset_entry_command { 1590 uint32_t cmd; /* LC_FILESET_ENTRY */ 1591 uint32_t cmdsize; /* includes entry_id string */ 1592 uint64_t vmaddr; /* memory address of the entry */ 1593 uint64_t fileoff; /* file offset of the entry */ 1594 union lc_str entry_id; /* contained entry id */ 1595 uint32_t reserved; /* reserved */ 1596 }; 1597 1598 /* 1599 * These deprecated values may still be used within Apple but are mechanically 1600 * removed from public API. The mechanical process may produce unusual results. 1601 */ 1602 #if (!defined(PLATFORM_IOSMAC)) 1603 #define PLATFORM_IOSMAC PLATFORM_MACCATALYST 1604 #endif 1605 1606 #endif /* _MACHO_LOADER_H_ */