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