Annotation of XNU/EXTERNAL_HEADERS/mach-o/loader.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: #ifndef _MACHO_LOADER_H_
                     23: #define _MACHO_LOADER_H_
                     24: 
                     25: /*
                     26:  * This file describes the format of mach object files.
                     27:  */
                     28: 
                     29: /*
                     30:  * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
                     31:  * and contains the constants for the possible values of these types.
                     32:  */
                     33: #import <mach/machine.h>
                     34: 
                     35: /*
                     36:  * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the 
                     37:  * constants that are or'ed together for the possible values of this type.
                     38:  */
                     39: #import <mach/vm_prot.h>
                     40: 
                     41: /*
                     42:  * <machine/thread_status.h> is expected to define the flavors of the thread
                     43:  * states and the structures of those flavors for each machine.
                     44:  */
                     45: #import <mach/machine/thread_status.h>
                     46: #import <architecture/byte_order.h>
                     47: 
                     48: /*
                     49:  * The mach header appears at the very beginning of the object file.
                     50:  */
                     51: struct mach_header {
                     52:        unsigned long   magic;          /* mach magic number identifier */
                     53:        cpu_type_t      cputype;        /* cpu specifier */
                     54:        cpu_subtype_t   cpusubtype;     /* machine specifier */
                     55:        unsigned long   filetype;       /* type of file */
                     56:        unsigned long   ncmds;          /* number of load commands */
                     57:        unsigned long   sizeofcmds;     /* the size of all the load commands */
                     58:        unsigned long   flags;          /* flags */
                     59: };
                     60: 
                     61: /* Constant for the magic field of the mach_header */
                     62: #define        MH_MAGIC        0xfeedface      /* the mach magic number */
                     63: #define MH_CIGAM       NXSwapInt(MH_MAGIC)
                     64: 
                     65: /*
                     66:  * The layout of the file depends on the filetype.  For all but the MH_OBJECT
                     67:  * file type the segments are padded out and aligned on a segment alignment
                     68:  * boundary for efficient demand pageing.  The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
                     69:  * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
                     70:  * of their first segment.
                     71:  * 
                     72:  * The file type MH_OBJECT is a compact format intended as output of the
                     73:  * assembler and input (and possibly output) of the link editor (the .o
                     74:  * format).  All sections are in one unnamed segment with no segment padding. 
                     75:  * This format is used as an executable format when the file is so small the
                     76:  * segment padding greatly increases it's size.
                     77:  *
                     78:  * The file type MH_PRELOAD is an executable format intended for things that
                     79:  * not executed under the kernel (proms, stand alones, kernels, etc).  The
                     80:  * format can be executed under the kernel but may demand paged it and not
                     81:  * preload it before execution.
                     82:  *
                     83:  * A core file is in MH_CORE format and can be any in an arbritray legal
                     84:  * Mach-O file.
                     85:  *
                     86:  * Constants for the filetype field of the mach_header
                     87:  */
                     88: #define        MH_OBJECT       0x1             /* relocatable object file */
                     89: #define        MH_EXECUTE      0x2             /* demand paged executable file */
                     90: #define        MH_FVMLIB       0x3             /* fixed VM shared library file */
                     91: #define        MH_CORE         0x4             /* core file */
                     92: #define        MH_PRELOAD      0x5             /* preloaded executable file */
                     93: #define        MH_DYLIB        0x6             /* dynamicly bound shared library file*/
                     94: #define        MH_DYLINKER     0x7             /* dynamic link editor */
                     95: #define        MH_BUNDLE       0x8             /* dynamicly bound bundle file */
                     96: 
                     97: /* Constants for the flags field of the mach_header */
                     98: #define        MH_NOUNDEFS     0x1             /* the object file has no undefined
                     99:                                           references, can be executed */
                    100: #define        MH_INCRLINK     0x2             /* the object file is the output of an
                    101:                                           incremental link against a base file
                    102:                                           and can't be link edited again */
                    103: #define MH_DYLDLINK    0x4             /* the object file is input for the
                    104:                                           dynamic linker and can't be staticly
                    105:                                           link edited again */
                    106: #define MH_BINDATLOAD  0x8             /* the object file's undefined
                    107:                                           references are bound by the dynamic
                    108:                                           linker when loaded. */
                    109: #define MH_PREBOUND    0x10            /* the file has it's dynamic undefined
                    110:                                           references prebound. */
                    111: 
                    112: /*
                    113:  * The load commands directly follow the mach_header.  The total size of all
                    114:  * of the commands is given by the sizeofcmds field in the mach_header.  All
                    115:  * load commands must have as their first two fields cmd and cmdsize.  The cmd
                    116:  * field is filled in with a constant for that command type.  Each command type
                    117:  * has a structure specifically for it.  The cmdsize field is the size in bytes
                    118:  * of the particular load command structure plus anything that follows it that
                    119:  * is a part of the load command (i.e. section structures, strings, etc.).  To
                    120:  * advance to the next load command the cmdsize can be added to the offset or
                    121:  * pointer of the current load command.  The cmdsize MUST be a multiple of
                    122:  * sizeof(long) (this is forever the maximum alignment of any load commands).
                    123:  * The padded bytes must be zero.  All tables in the object file must also
                    124:  * follow these rules so the file can be memory mapped.  Otherwise the pointers
                    125:  * to these tables will not work well or at all on some machines.  With all
                    126:  * padding zeroed like objects will compare byte for byte.
                    127:  */
                    128: struct load_command {
                    129:        unsigned long cmd;              /* type of load command */
                    130:        unsigned long cmdsize;          /* total size of command in bytes */
                    131: };
                    132: 
                    133: /* Constants for the cmd field of all load commands, the type */
                    134: #define        LC_SEGMENT      0x1     /* segment of this file to be mapped */
                    135: #define        LC_SYMTAB       0x2     /* link-edit stab symbol table info */
                    136: #define        LC_SYMSEG       0x3     /* link-edit gdb symbol table info (obsolete) */
                    137: #define        LC_THREAD       0x4     /* thread */
                    138: #define        LC_UNIXTHREAD   0x5     /* unix thread (includes a stack) */
                    139: #define        LC_LOADFVMLIB   0x6     /* load a specified fixed VM shared library */
                    140: #define        LC_IDFVMLIB     0x7     /* fixed VM shared library identification */
                    141: #define        LC_IDENT        0x8     /* object identification info (obsolete) */
                    142: #define LC_FVMFILE     0x9     /* fixed VM file inclusion (internal use) */
                    143: #define LC_PREPAGE      0xa     /* prepage command (internal use) */
                    144: #define        LC_DYSYMTAB     0xb     /* dynamic link-edit symbol table info */
                    145: #define        LC_LOAD_DYLIB   0xc     /* load a dynamicly linked shared library */
                    146: #define        LC_ID_DYLIB     0xd     /* dynamicly linked shared lib identification */
                    147: #define LC_LOAD_DYLINKER 0xe   /* load a dynamic linker */
                    148: #define LC_ID_DYLINKER 0xf     /* dynamic linker identification */
                    149: #define        LC_PREBOUND_DYLIB 0x10  /* modules prebound for a dynamicly */
                    150:                                /*  linked shared library */
                    151: 
                    152: /*
                    153:  * A variable length string in a load command is represented by an lc_str
                    154:  * union.  The strings are stored just after the load command structure and
                    155:  * the offset is from the start of the load command structure.  The size
                    156:  * of the string is reflected in the cmdsize field of the load command.
                    157:  * Once again any padded bytes to bring the cmdsize field to a multiple
                    158:  * of sizeof(long) must be zero.
                    159:  */
                    160: union lc_str {
                    161:        unsigned long   offset; /* offset to the string */
                    162:        char            *ptr;   /* pointer to the string */
                    163: };
                    164: 
                    165: /*
                    166:  * The segment load command indicates that a part of this file is to be
                    167:  * mapped into the task's address space.  The size of this segment in memory,
                    168:  * vmsize, maybe equal to or larger than the amount to map from this file,
                    169:  * filesize.  The file is mapped starting at fileoff to the beginning of
                    170:  * the segment in memory, vmaddr.  The rest of the memory of the segment,
                    171:  * if any, is allocated zero fill on demand.  The segment's maximum virtual
                    172:  * memory protection and initial virtual memory protection are specified
                    173:  * by the maxprot and initprot fields.  If the segment has sections then the
                    174:  * section structures directly follow the segment command and their size is
                    175:  * reflected in cmdsize.
                    176:  */
                    177: struct segment_command {
                    178:        unsigned long   cmd;            /* LC_SEGMENT */
                    179:        unsigned long   cmdsize;        /* includes sizeof section structs */
                    180:        char            segname[16];    /* segment name */
                    181:        unsigned long   vmaddr;         /* memory address of this segment */
                    182:        unsigned long   vmsize;         /* memory size of this segment */
                    183:        unsigned long   fileoff;        /* file offset of this segment */
                    184:        unsigned long   filesize;       /* amount to map from the file */
                    185:        vm_prot_t       maxprot;        /* maximum VM protection */
                    186:        vm_prot_t       initprot;       /* initial VM protection */
                    187:        unsigned long   nsects;         /* number of sections in segment */
                    188:        unsigned long   flags;          /* flags */
                    189: };
                    190: 
                    191: /* Constants for the flags field of the segment_command */
                    192: #define        SG_HIGHVM       0x1     /* the file contents for this segment is for
                    193:                                   the high part of the VM space, the low part
                    194:                                   is zero filled (for stacks in core files) */
                    195: #define        SG_FVMLIB       0x2     /* this segment is the VM that is allocated by
                    196:                                   a fixed VM library, for overlap checking in
                    197:                                   the link editor */
                    198: #define        SG_NORELOC      0x4     /* this segment has nothing that was relocated
                    199:                                   in it and nothing relocated to it, that is
                    200:                                   it maybe safely replaced without relocation*/
                    201: 
                    202: /*
                    203:  * A segment is made up of zero or more sections.  Non-MH_OBJECT files have
                    204:  * all of their segments with the proper sections in each, and padded to the
                    205:  * specified segment alignment when produced by the link editor.  The first
                    206:  * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
                    207:  * and load commands of the object file before it's first section.  The zero
                    208:  * fill sections are always last in their segment (in all formats).  This
                    209:  * allows the zeroed segment padding to be mapped into memory where zero fill
                    210:  * sections might be.
                    211:  *
                    212:  * The MH_OBJECT format has all of it's sections in one segment for
                    213:  * compactness.  There is no padding to a specified segment boundary and the
                    214:  * mach_header and load commands are not part of the segment.
                    215:  *
                    216:  * Sections with the same section name, sectname, going into the same segment,
                    217:  * segname, are combined by the link editor.  The resulting section is aligned
                    218:  * to the maximum alignment of the combined sections and is the new section's
                    219:  * alignment.  The combined sections are aligned to their original alignment in
                    220:  * the combined section.  Any padded bytes to get the specified alignment are
                    221:  * zeroed.
                    222:  *
                    223:  * The format of the relocation entries referenced by the reloff and nreloc
                    224:  * fields of the section structure for mach object files is described in the
                    225:  * header file <reloc.h>.
                    226:  */
                    227: struct section {
                    228:        char            sectname[16];   /* name of this section */
                    229:        char            segname[16];    /* segment this section goes in */
                    230:        unsigned long   addr;           /* memory address of this section */
                    231:        unsigned long   size;           /* size in bytes of this section */
                    232:        unsigned long   offset;         /* file offset of this section */
                    233:        unsigned long   align;          /* section alignment (power of 2) */
                    234:        unsigned long   reloff;         /* file offset of relocation entries */
                    235:        unsigned long   nreloc;         /* number of relocation entries */
                    236:        unsigned long   flags;          /* flags (section type and attributes)*/
                    237:        unsigned long   reserved1;      /* reserved */
                    238:        unsigned long   reserved2;      /* reserved */
                    239: };
                    240: 
                    241: /*
                    242:  * The flags field of a section structure is separated into two parts a section
                    243:  * type and section attributes.  The section types are mutually exclusive (it
                    244:  * can only have one type) but the section attributes are not (it may have more
                    245:  * than one attribute).
                    246:  */
                    247: #define SECTION_TYPE            0x000000ff     /* 256 section types */
                    248: #define SECTION_ATTRIBUTES      0xffffff00     /*  24 section attributes */
                    249: 
                    250: /* Constants for the type of a section */
                    251: #define        S_REGULAR               0x0     /* regular section */
                    252: #define        S_ZEROFILL              0x1     /* zero fill on demand section */
                    253: #define        S_CSTRING_LITERALS      0x2     /* section with only literal C strings*/
                    254: #define        S_4BYTE_LITERALS        0x3     /* section with only 4 byte literals */
                    255: #define        S_8BYTE_LITERALS        0x4     /* section with only 8 byte literals */
                    256: #define        S_LITERAL_POINTERS      0x5     /* section with only pointers to */
                    257:                                        /*  literals */
                    258: /*
                    259:  * For the two types of symbol pointers sections and the symbol stubs section
                    260:  * they have indirect symbol table entries.  For each of the entries in the
                    261:  * section the indirect symbol table entries, in corresponding order in the
                    262:  * indirect symbol table, start at the index stored in the reserved1 field
                    263:  * of the section structure.  Since the indirect symbol table entries
                    264:  * correspond to the entries in the section the number of indirect symbol table
                    265:  * entries is inferred from the size of the section divided by the size of the
                    266:  * entries in the section.  For symbol pointers sections the size of the entries
                    267:  * in the section is 4 bytes and for symbol stubs sections the byte size of the
                    268:  * stubs is stored in the reserved2 field of the section structure.
                    269:  */
                    270: #define        S_NON_LAZY_SYMBOL_POINTERS      0x6     /* section with only non-lazy
                    271:                                                   symbol pointers */
                    272: #define        S_LAZY_SYMBOL_POINTERS          0x7     /* section with only lazy symbol
                    273:                                                   pointers */
                    274: #define        S_SYMBOL_STUBS                  0x8     /* section with only symbol
                    275:                                                   stubs, byte size of stub in
                    276:                                                   the reserved2 field */
                    277: #define        S_MOD_INIT_FUNC_POINTERS        0x9     /* section with only function
                    278:                                                   pointers for initialization*/
                    279: /*
                    280:  * Constants for the section attributes part of the flags field of a section
                    281:  * structure.
                    282:  */
                    283: #define SECTION_ATTRIBUTES_USR  0xff000000     /* User setable attributes */
                    284: #define S_ATTR_PURE_INSTRUCTIONS 0x80000000    /* section contains only true
                    285:                                                   machine instructions */
                    286: #define SECTION_ATTRIBUTES_SYS  0x00ffff00     /* system setable attributes */
                    287: #define S_ATTR_SOME_INSTRUCTIONS 0x00000400    /* section contains some
                    288:                                                   machine instructions */
                    289: #define S_ATTR_EXT_RELOC        0x00000200     /* section has external
                    290:                                                   relocation entries */
                    291: #define S_ATTR_LOC_RELOC        0x00000100     /* section has local
                    292:                                                   relocation entries */
                    293: 
                    294: 
                    295: /*
                    296:  * The names of segments and sections in them are mostly meaningless to the
                    297:  * link-editor.  But there are few things to support traditional UNIX
                    298:  * executables that require the link-editor and assembler to use some names
                    299:  * agreed upon by convention.
                    300:  *
                    301:  * The initial protection of the "__TEXT" segment has write protection turned
                    302:  * off (not writeable).
                    303:  *
                    304:  * The link-editor will allocate common symbols at the end of the "__common"
                    305:  * section in the "__DATA" segment.  It will create the section and segment
                    306:  * if needed.
                    307:  */
                    308: 
                    309: /* The currently known segment names and the section names in those segments */
                    310: 
                    311: #define        SEG_PAGEZERO    "__PAGEZERO"    /* the pagezero segment which has no */
                    312:                                        /* protections and catches NULL */
                    313:                                        /* references for MH_EXECUTE files */
                    314: 
                    315: 
                    316: #define        SEG_TEXT        "__TEXT"        /* the tradition UNIX text segment */
                    317: #define        SECT_TEXT       "__text"        /* the real text part of the text */
                    318:                                        /* section no headers, and no padding */
                    319: #define SECT_FVMLIB_INIT0 "__fvmlib_init0"     /* the fvmlib initialization */
                    320:                                                /*  section */
                    321: #define SECT_FVMLIB_INIT1 "__fvmlib_init1"     /* the section following the */
                    322:                                                /*  fvmlib initialization */
                    323:                                                /*  section */
                    324: 
                    325: #define        SEG_DATA        "__DATA"        /* the tradition UNIX data segment */
                    326: #define        SECT_DATA       "__data"        /* the real initialized data section */
                    327:                                        /* no padding, no bss overlap */
                    328: #define        SECT_BSS        "__bss"         /* the real uninitialized data section*/
                    329:                                        /* no padding */
                    330: #define SECT_COMMON    "__common"      /* the section common symbols are */
                    331:                                        /* allocated in by the link editor */
                    332: 
                    333: #define        SEG_OBJC        "__OBJC"        /* objective-C runtime segment */
                    334: #define SECT_OBJC_SYMBOLS "__symbol_table"     /* symbol table */
                    335: #define SECT_OBJC_MODULES "__module_info"      /* module information */
                    336: #define SECT_OBJC_STRINGS "__selector_strs"    /* string table */
                    337: #define SECT_OBJC_REFS "__selector_refs"       /* string table */
                    338: 
                    339: #define        SEG_ICON         "__ICON"       /* the NeXT icon segment */
                    340: #define        SECT_ICON_HEADER "__header"     /* the icon headers */
                    341: #define        SECT_ICON_TIFF   "__tiff"       /* the icons in tiff format */
                    342: 
                    343: #define        SEG_LINKEDIT    "__LINKEDIT"    /* the segment containing all structs */
                    344:                                        /* created and maintained by the link */
                    345:                                        /* editor.  Created with -seglinkedit */
                    346:                                        /* option to ld(1) for MH_EXECUTE and */
                    347:                                        /* FVMLIB file types only */
                    348: 
                    349: #define SEG_UNIXSTACK  "__UNIXSTACK"   /* the unix stack segment */
                    350: 
                    351: /*
                    352:  * Fixed virtual memory shared libraries are identified by two things.  The
                    353:  * target pathname (the name of the library as found for execution), and the
                    354:  * minor version number.  The address of where the headers are loaded is in
                    355:  * header_addr.
                    356:  */
                    357: struct fvmlib {
                    358:        union lc_str    name;           /* library's target pathname */
                    359:        unsigned long   minor_version;  /* library's minor version number */
                    360:        unsigned long   header_addr;    /* library's header address */
                    361: };
                    362: 
                    363: /*
                    364:  * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
                    365:  * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
                    366:  * An object that uses a fixed virtual shared library also contains a
                    367:  * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
                    368:  */
                    369: struct fvmlib_command {
                    370:        unsigned long   cmd;            /* LC_IDFVMLIB or LC_LOADFVMLIB */
                    371:        unsigned long   cmdsize;        /* includes pathname string */
                    372:        struct fvmlib   fvmlib;         /* the library identification */
                    373: };
                    374: 
                    375: /*
                    376:  * Dynamicly linked shared libraries are identified by two things.  The
                    377:  * pathname (the name of the library as found for execution), and the
                    378:  * compatibility version number.  The pathname must match and the compatibility
                    379:  * number in the user of the library must be greater than or equal to the
                    380:  * library being used.  The time stamp is used to record the time a library was
                    381:  * built and copied into user so it can be use to determined if the library used
                    382:  * at runtime is exactly the same as used to built the program.
                    383:  */
                    384: struct dylib {
                    385:     union lc_str  name;                        /* library's path name */
                    386:     unsigned long timestamp;           /* library's build time stamp */
                    387:     unsigned long current_version;     /* library's current version number */
                    388:     unsigned long compatibility_version;/* library's compatibility vers number*/
                    389: };
                    390: 
                    391: /*
                    392:  * A dynamicly linked shared library (filetype == MH_DYLIB in the mach header)
                    393:  * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library.
                    394:  * An object that uses a dynamicly linked shared library also contains a
                    395:  * dylib_command (cmd == LC_LOAD_DYLIB) for each library it uses.
                    396:  */
                    397: struct dylib_command {
                    398:        unsigned long   cmd;            /* LC_ID_DYLIB or LC_LOAD_DYLIB */
                    399:        unsigned long   cmdsize;        /* includes pathname string */
                    400:        struct dylib    dylib;          /* the library identification */
                    401: };
                    402: 
                    403: /*
                    404:  * A program (filetype == MH_EXECUTE) or bundle (filetype == MH_BUNDLE) that is
                    405:  * prebound to it's dynamic libraries has one of these for each library that
                    406:  * the static linker used in prebinding.  It contains a bit vector for the
                    407:  * modules in the library.  The bits indicate which modules are bound (1) and
                    408:  * which are not (0) from the library.  The bit for module 0 is the low bit
                    409:  * of the first byte.  So the bit for the Nth module is:
                    410:  * (linked_modules[N/8] >> N%8) & 1
                    411:  */
                    412: struct prebound_dylib_command {
                    413:        unsigned long   cmd;            /* LC_PREBOUND_DYLIB */
                    414:        unsigned long   cmdsize;        /* includes strings */
                    415:        union lc_str    name;           /* library's path name */
                    416:        unsigned long   nmodules;       /* number of modules in library */
                    417:        union lc_str    linked_modules; /* bit vector of linked modules */
                    418: };
                    419: 
                    420: /*
                    421:  * A program that uses a dynamic linker contains a dylinker_command to identify
                    422:  * the name of the dynamic linker (LC_LOAD_DYLINKER).  And a dynamic linker
                    423:  * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER).
                    424:  * A file can have at most one of these.
                    425:  */
                    426: struct dylinker_command {
                    427:        unsigned long   cmd;            /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */
                    428:        unsigned long   cmdsize;        /* includes pathname string */
                    429:        union lc_str    name;           /* dynamic linker's path name */
                    430: };
                    431: 
                    432: /*
                    433:  * Thread commands contain machine-specific data structures suitable for
                    434:  * use in the thread state primitives.  The machine specific data structures
                    435:  * follow the struct thread_command as follows.
                    436:  * Each flavor of machine specific data structure is preceded by an unsigned
                    437:  * long constant for the flavor of that data structure, an unsigned long
                    438:  * that is the count of longs of the size of the state data structure and then
                    439:  * the state data structure follows.  This triple may be repeated for many
                    440:  * flavors.  The constants for the flavors, counts and state data structure
                    441:  * definitions are expected to be in the header file <machine/thread_status.h>.
                    442:  * These machine specific data structures sizes must be multiples of
                    443:  * sizeof(long).  The cmdsize reflects the total size of the thread_command
                    444:  * and all of the sizes of the constants for the flavors, counts and state
                    445:  * data structures.
                    446:  *
                    447:  * For executable objects that are unix processes there will be one
                    448:  * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
                    449:  * This is the same as a LC_THREAD, except that a stack is automatically
                    450:  * created (based on the shell's limit for the stack size).  Command arguments
                    451:  * and environment variables are copied onto that stack.
                    452:  */
                    453: struct thread_command {
                    454:        unsigned long   cmd;            /* LC_THREAD or  LC_UNIXTHREAD */
                    455:        unsigned long   cmdsize;        /* total size of this command */
                    456:        /* unsigned long flavor            flavor of thread state */
                    457:        /* unsigned long count             count of longs in thread state */
                    458:        /* struct XXX_thread_state state   thread state for this flavor */
                    459:        /* ... */
                    460: };
                    461: 
                    462: /*
                    463:  * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
                    464:  * "stab" style symbol table information as described in the header files
                    465:  * <nlist.h> and <stab.h>.
                    466:  */
                    467: struct symtab_command {
                    468:        unsigned long   cmd;            /* LC_SYMTAB */
                    469:        unsigned long   cmdsize;        /* sizeof(struct symtab_command) */
                    470:        unsigned long   symoff;         /* symbol table offset */
                    471:        unsigned long   nsyms;          /* number of symbol table entries */
                    472:        unsigned long   stroff;         /* string table offset */
                    473:        unsigned long   strsize;        /* string table size in bytes */
                    474: };
                    475: 
                    476: /*
                    477:  * This is the second set of the symbolic information which is used to support
                    478:  * the data structures for the dynamicly link editor.
                    479:  *
                    480:  * The original set of symbolic information in the symtab_command which contains
                    481:  * the symbol and string tables must also be present when this load command is
                    482:  * present.  When this load command is present the symbol table is organized
                    483:  * into three groups of symbols:
                    484:  *     local symbols (static and debugging symbols) - grouped by module
                    485:  *     defined external symbols - grouped by module (sorted by name if not lib)
                    486:  *     undefined external symbols (sorted by name)
                    487:  * In this load command there are offsets and counts to each of the three groups
                    488:  * of symbols.
                    489:  *
                    490:  * This load command contains a the offsets and sizes of the following new
                    491:  * symbolic information tables:
                    492:  *     table of contents
                    493:  *     module table
                    494:  *     reference symbol table
                    495:  *     indirect symbol table
                    496:  * The first three tables above (the table of contents, module table and
                    497:  * reference symbol table) are only present if the file is a dynamicly linked
                    498:  * shared library.  For executable and object modules, which are files
                    499:  * containing only one module, the information that would be in these three
                    500:  * tables is determined as follows:
                    501:  *     table of contents - the defined external symbols are sorted by name
                    502:  *     module table - the file contains only one module so everything in the
                    503:  *                    file is part of the module.
                    504:  *     reference symbol table - is the defined and undefined external symbols
                    505:  *
                    506:  * For dynamicly linked shared library files this load command also contains
                    507:  * offsets and sizes to the pool of relocation entries for all sections
                    508:  * separated into two groups:
                    509:  *     external relocation entries
                    510:  *     local relocation entries
                    511:  * For executable and object modules the relocation entries continue to hang
                    512:  * off the section structures.
                    513:  */
                    514: struct dysymtab_command {
                    515:     unsigned long cmd;         /* LC_DYSYMTAB */
                    516:     unsigned long cmdsize;     /* sizeof(struct dysymtab_command) */
                    517: 
                    518:     /*
                    519:      * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
                    520:      * are grouped into the following three groups:
                    521:      *    local symbols (further grouped by the module they are from)
                    522:      *    defined external symbols (further grouped by the module they are from)
                    523:      *    undefined symbols
                    524:      *
                    525:      * The local symbols are used only for debugging.  The dynamic binding
                    526:      * process may have to use them to indicate to the debugger the local
                    527:      * symbols for a module that is being bound.
                    528:      *
                    529:      * The last two groups are used by the dynamic binding process to do the
                    530:      * binding (indirectly through the module table and the reference symbol
                    531:      * table when this is a dynamicly linked shared library file).
                    532:      */
                    533:     unsigned long ilocalsym;   /* index to local symbols */
                    534:     unsigned long nlocalsym;   /* number of local symbols */
                    535: 
                    536:     unsigned long iextdefsym;  /* index to externally defined symbols */
                    537:     unsigned long nextdefsym;  /* number of externally defined symbols */
                    538: 
                    539:     unsigned long iundefsym;   /* index to undefined symbols */
                    540:     unsigned long nundefsym;   /* number of undefined symbols */
                    541: 
                    542:     /*
                    543:      * For the for the dynamic binding process to find which module a symbol
                    544:      * is defined in the table of contents is used (analogous to the ranlib
                    545:      * structure in an archive) which maps defined external symbols to modules
                    546:      * they are defined in.  This exists only in a dynamicly linked shared
                    547:      * library file.  For executable and object modules the defined external
                    548:      * symbols are sorted by name and is use as the table of contents.
                    549:      */
                    550:     unsigned long tocoff;      /* file offset to table of contents */
                    551:     unsigned long ntoc;                /* number of entries in table of contents */
                    552: 
                    553:     /*
                    554:      * To support dynamic binding of "modules" (whole object files) the symbol
                    555:      * table must reflect the modules that the file was created from.  This is
                    556:      * done by having a module table that has indexes and counts into the merged
                    557:      * tables for each module.  The module structure that these two entries
                    558:      * refer to is described below.  This exists only in a dynamicly linked
                    559:      * shared library file.  For executable and object modules the file only
                    560:      * contains one module so everything in the file belongs to the module.
                    561:      */
                    562:     unsigned long modtaboff;   /* file offset to module table */
                    563:     unsigned long nmodtab;     /* number of module table entries */
                    564: 
                    565:     /*
                    566:      * To support dynamic module binding the module structure for each module
                    567:      * indicates the external references (defined and undefined) each module
                    568:      * makes.  For each module there is an offset and a count into the
                    569:      * reference symbol table for the symbols that the module references.
                    570:      * This exists only in a dynamicly linked shared library file.  For
                    571:      * executable and object modules the defined external symbols and the
                    572:      * undefined external symbols indicates the external references.
                    573:      */
                    574:     unsigned long extrefsymoff;  /* offset to referenced symbol table */
                    575:     unsigned long nextrefsyms;  /* number of referenced symbol table entries */
                    576: 
                    577:     /*
                    578:      * The sections that contain "symbol pointers" and "routine stubs" have
                    579:      * indexes and (implied counts based on the size of the section and fixed
                    580:      * size of the entry) into the "indirect symbol" table for each pointer
                    581:      * and stub.  For every section of these two types the index into the
                    582:      * indirect symbol table is stored in the section header in the field
                    583:      * reserved1.  An indirect symbol table entry is simply a 32bit index into
                    584:      * the symbol table to the symbol that the pointer or stub is referring to.
                    585:      * The indirect symbol table is ordered to match the entries in the section.
                    586:      */
                    587:     unsigned long indirectsymoff; /* file offset to the indirect symbol table */
                    588:     unsigned long nindirectsyms;  /* number of indirect symbol table entries */
                    589: 
                    590:     /*
                    591:      * To support relocating an individual module in a library file quickly the
                    592:      * external relocation entries for each module in the library need to be
                    593:      * accessed efficiently.  Since the relocation entries can't be accessed
                    594:      * through the section headers for a library file they are separated into
                    595:      * groups of local and external entries further grouped by module.  In this
                    596:      * case the presents of this load command who's extreloff, nextrel,
                    597:      * locreloff and nlocrel fields are non-zero indicates that the relocation
                    598:      * entries of non-merged sections are not referenced through the section
                    599:      * structures (and the reloff and nreloc fields in the section headers are
                    600:      * set to zero).
                    601:      *
                    602:      * Since the relocation entries are not accessed through the section headers
                    603:      * this requires the r_address field to be something other than a section
                    604:      * offset to identify the item to be relocated.  In this case r_address is
                    605:      * set to the offset from the vmaddr of the first LC_SEGMENT command.
                    606:      *
                    607:      * The relocation entries are grouped by module and the module table
                    608:      * entries have indexes and counts into them for the group of external
                    609:      * relocation entries for that the module.
                    610:      *
                    611:      * For sections that are merged across modules there must not be any
                    612:      * remaining external relocation entries for them (for merged sections
                    613:      * remaining relocation entries must be local).
                    614:      */
                    615:     unsigned long extreloff;   /* offset to external relocation entries */
                    616:     unsigned long nextrel;     /* number of external relocation entries */
                    617: 
                    618:     /*
                    619:      * All the local relocation entries are grouped together (they are not
                    620:      * grouped by their module since they are only used if the object is moved
                    621:      * from it staticly link edited address).
                    622:      */
                    623:     unsigned long locreloff;   /* offset to local relocation entries */
                    624:     unsigned long nlocrel;     /* number of local relocation entries */
                    625: 
                    626: };     
                    627: 
                    628: /*
                    629:  * An indirect symbol table entry is simply a 32bit index into the symbol table 
                    630:  * to the symbol that the pointer or stub is refering to.  Unless it is for a
                    631:  * non-lazy symbol pointer section for a defined symbol which strip(1) as 
                    632:  * removed.  In which case it has the value INDIRECT_SYMBOL_LOCAL.  If the
                    633:  * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
                    634:  */
                    635: #define INDIRECT_SYMBOL_LOCAL  0x80000000
                    636: #define INDIRECT_SYMBOL_ABS    0x40000000
                    637: 
                    638: 
                    639: /* a table of contents entry */
                    640: struct dylib_table_of_contents {
                    641:     unsigned long symbol_index;        /* the defined external symbol
                    642:                                   (index into the symbol table) */
                    643:     unsigned long module_index;        /* index into the module table this symbol
                    644:                                   is defined in */
                    645: };     
                    646: 
                    647: /* a module table entry */
                    648: struct dylib_module {
                    649:     unsigned long module_name; /* the module name (index into string table) */
                    650: 
                    651:     unsigned long iextdefsym;  /* index into externally defined symbols */
                    652:     unsigned long nextdefsym;  /* number of externally defined symbols */
                    653:     unsigned long irefsym;             /* index into reference symbol table */
                    654:     unsigned long nrefsym;     /* number of reference symbol table entries */
                    655:     unsigned long ilocalsym;   /* index into symbols for local symbols */
                    656:     unsigned long nlocalsym;   /* number of local symbols */
                    657: 
                    658:     unsigned long iextrel;     /* index into external relocation entries */
                    659:     unsigned long nextrel;     /* number of external relocation entries */
                    660: 
                    661:     unsigned long iinit;       /* index into the init section */
                    662:     unsigned long ninit;       /* number of init section entries */
                    663: 
                    664:     unsigned long              /* for this module address of the start of */
                    665:        objc_module_info_addr;  /*  the (__OBJC,__module_info) section */
                    666:     unsigned long              /* for this module size of */
                    667:        objc_module_info_size;  /*  the (__OBJC,__module_info) section */
                    668: };     
                    669: 
                    670: /* 
                    671:  * The entries in the reference symbol table are used when loading the module
                    672:  * (both by the static and dynamic link editors) and if the module is unloaded
                    673:  * or replaced.  Therefore all external symbols (defined and undefined) are
                    674:  * listed in the module's reference table.  The flags describe the type of
                    675:  * reference that is being made.  The constants for the flags are defined in
                    676:  * <mach-o/nlist.h> as they are also used for symbol table entries.
                    677:  */
                    678: struct dylib_reference {
                    679:     unsigned long isym:24,     /* index into the symbol table */
                    680:                  flags:8;      /* flags to indicate the type of reference */
                    681: };
                    682: 
                    683: /*
                    684:  * The symseg_command contains the offset and size of the GNU style
                    685:  * symbol table information as described in the header file <symseg.h>.
                    686:  * The symbol roots of the symbol segments must also be aligned properly
                    687:  * in the file.  So the requirement of keeping the offsets aligned to a
                    688:  * multiple of a sizeof(long) translates to the length field of the symbol
                    689:  * roots also being a multiple of a long.  Also the padding must again be
                    690:  * zeroed. (THIS IS OBSOLETE and no longer supported).
                    691:  */
                    692: struct symseg_command {
                    693:        unsigned long   cmd;            /* LC_SYMSEG */
                    694:        unsigned long   cmdsize;        /* sizeof(struct symseg_command) */
                    695:        unsigned long   offset;         /* symbol segment offset */
                    696:        unsigned long   size;           /* symbol segment size in bytes */
                    697: };
                    698: 
                    699: /*
                    700:  * The ident_command contains a free format string table following the
                    701:  * ident_command structure.  The strings are null terminated and the size of
                    702:  * the command is padded out with zero bytes to a multiple of sizeof(long).
                    703:  * (THIS IS OBSOLETE and no longer supported).
                    704:  */
                    705: struct ident_command {
                    706:        unsigned long cmd;              /* LC_IDENT */
                    707:        unsigned long cmdsize;          /* strings that follow this command */
                    708: };
                    709: 
                    710: /*
                    711:  * The fvmfile_command contains a reference to a file to be loaded at the
                    712:  * specified virtual address.  (Presently, this command is reserved for NeXT
                    713:  * internal use.  The kernel ignores this command when loading a program into
                    714:  * memory).
                    715:  */
                    716: struct fvmfile_command {
                    717:        unsigned long cmd;              /* LC_FVMFILE */
                    718:        unsigned long cmdsize;          /* includes pathname string */
                    719:        union lc_str    name;           /* files pathname */
                    720:        unsigned long   header_addr;    /* files virtual address */
                    721: };
                    722: 
                    723: #endif _MACHO_LOADER_H_

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.