The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/EXTERNAL_HEADERS/mach-o/loader.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
    3  *
    4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
    5  * 
    6  * This file contains Original Code and/or Modifications of Original Code
    7  * as defined in and that are subject to the Apple Public Source License
    8  * Version 2.0 (the 'License'). You may not use this file except in
    9  * compliance with the License. The rights granted to you under the License
   10  * may not be used to create, or enable the creation or redistribution of,
   11  * unlawful or unlicensed copies of an Apple operating system, or to
   12  * circumvent, violate, or enable the circumvention or violation of, any
   13  * terms of an Apple operating system software license agreement.
   14  * 
   15  * Please obtain a copy of the License at
   16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
   17  * 
   18  * The Original Code and all software distributed under the License are
   19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
   20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
   21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
   22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
   23  * Please see the License for the specific language governing rights and
   24  * limitations under the License.
   25  * 
   26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
   27  */
   28 #ifndef _MACHO_LOADER_H_
   29 #define _MACHO_LOADER_H_
   30 
   31 /*
   32  * This file describes the format of mach object files.
   33  */
   34 #include <stdint.h>
   35 
   36 /*
   37  * <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
   38  * and contains the constants for the possible values of these types.
   39  */
   40 #include <mach/machine.h>
   41 
   42 /*
   43  * <mach/vm_prot.h> is needed here for the vm_prot_t type and contains the 
   44  * constants that are or'ed together for the possible values of this type.
   45  */
   46 #include <mach/vm_prot.h>
   47 
   48 /*
   49  * <machine/thread_status.h> is expected to define the flavors of the thread
   50  * states and the structures of those flavors for each machine.
   51  */
   52 #include <mach/machine/thread_status.h>
   53 #ifndef KERNEL
   54 #include <architecture/byte_order.h>
   55 #endif /* KERNEL */
   56 
   57 /*
   58  * The 32-bit mach header appears at the very beginning of the object file for
   59  * 32-bit architectures.
   60  */
   61 struct mach_header {
   62         uint32_t        magic;          /* mach magic number identifier */
   63         cpu_type_t      cputype;        /* cpu specifier */
   64         cpu_subtype_t   cpusubtype;     /* machine specifier */
   65         uint32_t        filetype;       /* type of file */
   66         uint32_t        ncmds;          /* number of load commands */
   67         uint32_t        sizeofcmds;     /* the size of all the load commands */
   68         uint32_t        flags;          /* flags */
   69 };
   70 
   71 /* Constant for the magic field of the mach_header (32-bit architectures) */
   72 #define MH_MAGIC        0xfeedface      /* the mach magic number */
   73 #define MH_CIGAM        0xcefaedfe      /* NXSwapInt(MH_MAGIC) */
   74 
   75 /*
   76  * The 64-bit mach header appears at the very beginning of object files for
   77  * 64-bit architectures.
   78  */
   79 struct mach_header_64 {
   80         uint32_t        magic;          /* mach magic number identifier */
   81         cpu_type_t      cputype;        /* cpu specifier */
   82         cpu_subtype_t   cpusubtype;     /* machine specifier */
   83         uint32_t        filetype;       /* type of file */
   84         uint32_t        ncmds;          /* number of load commands */
   85         uint32_t        sizeofcmds;     /* the size of all the load commands */
   86         uint32_t        flags;          /* flags */
   87         uint32_t        reserved;       /* reserved */
   88 };
   89 
   90 /* Constant for the magic field of the mach_header_64 (64-bit architectures) */
   91 #define MH_MAGIC_64 0xfeedfacf /* the 64-bit mach magic number */
   92 #define MH_CIGAM_64 0xcffaedfe /* NXSwapInt(MH_MAGIC_64) */
   93 
   94 /*
   95  * The layout of the file depends on the filetype.  For all but the MH_OBJECT
   96  * file type the segments are padded out and aligned on a segment alignment
   97  * boundary for efficient demand pageing.  The MH_EXECUTE, MH_FVMLIB, MH_DYLIB,
   98  * MH_DYLINKER and MH_BUNDLE file types also have the headers included as part
   99  * of their first segment.
  100  * 
  101  * The file type MH_OBJECT is a compact format intended as output of the
  102  * assembler and input (and possibly output) of the link editor (the .o
  103  * format).  All sections are in one unnamed segment with no segment padding. 
  104  * This format is used as an executable format when the file is so small the
  105  * segment padding greatly increases its size.
  106  *
  107  * The file type MH_PRELOAD is an executable format intended for things that
  108  * are not executed under the kernel (proms, stand alones, kernels, etc).  The
  109  * format can be executed under the kernel but may demand paged it and not
  110  * preload it before execution.
  111  *
  112  * A core file is in MH_CORE format and can be any in an arbritray legal
  113  * Mach-O file.
  114  *
  115  * Constants for the filetype field of the mach_header
  116  */
  117 #define MH_OBJECT       0x1             /* relocatable object file */
  118 #define MH_EXECUTE      0x2             /* demand paged executable file */
  119 #define MH_FVMLIB       0x3             /* fixed VM shared library file */
  120 #define MH_CORE         0x4             /* core file */
  121 #define MH_PRELOAD      0x5             /* preloaded executable file */
  122 #define MH_DYLIB        0x6             /* dynamically bound shared library */
  123 #define MH_DYLINKER     0x7             /* dynamic link editor */
  124 #define MH_BUNDLE       0x8             /* dynamically bound bundle file */
  125 #define MH_DYLIB_STUB   0x9             /* shared library stub for static */
  126                                         /*  linking only, no section contents */
  127 #define MH_DSYM         0xa             /* companion file with only debug */
  128                                         /*  sections */
  129 
  130 /* Constants for the flags field of the mach_header */
  131 #define MH_NOUNDEFS     0x1             /* the object file has no undefined
  132                                            references */
  133 #define MH_INCRLINK     0x2             /* the object file is the output of an
  134                                            incremental link against a base file
  135                                            and can't be link edited again */
  136 #define MH_DYLDLINK     0x4             /* the object file is input for the
  137                                            dynamic linker and can't be staticly
  138                                            link edited again */
  139 #define MH_BINDATLOAD   0x8             /* the object file's undefined
  140                                            references are bound by the dynamic
  141                                            linker when loaded. */
  142 #define MH_PREBOUND     0x10            /* the file has its dynamic undefined
  143                                            references prebound. */
  144 #define MH_SPLIT_SEGS   0x20            /* the file has its read-only and
  145                                            read-write segments split */
  146 #define MH_LAZY_INIT    0x40            /* the shared library init routine is
  147                                            to be run lazily via catching memory
  148                                            faults to its writeable segments
  149                                            (obsolete) */
  150 #define MH_TWOLEVEL     0x80            /* the image is using two-level name
  151                                            space bindings */
  152 #define MH_FORCE_FLAT   0x100           /* the executable is forcing all images
  153                                            to use flat name space bindings */
  154 #define MH_NOMULTIDEFS  0x200           /* this umbrella guarantees no multiple
  155                                            defintions of symbols in its
  156                                            sub-images so the two-level namespace
  157                                            hints can always be used. */
  158 #define MH_NOFIXPREBINDING 0x400        /* do not have dyld notify the
  159                                            prebinding agent about this
  160                                            executable */
  161 #define MH_PREBINDABLE  0x800           /* the binary is not prebound but can
  162                                            have its prebinding redone. only used
  163                                            when MH_PREBOUND is not set. */
  164 #define MH_ALLMODSBOUND 0x1000          /* indicates that this binary binds to
  165                                            all two-level namespace modules of
  166                                            its dependent libraries. only used
  167                                            when MH_PREBINDABLE and MH_TWOLEVEL
  168                                            are both set. */ 
  169 #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into
  170                                             sub-sections via symbols for dead
  171                                             code stripping */
  172 #define MH_CANONICAL    0x4000          /* the binary has been canonicalized
  173                                            via the unprebind operation */
  174 #define MH_WEAK_DEFINES 0x8000          /* the final linked image contains
  175                                            external weak symbols */
  176 #define MH_BINDS_TO_WEAK 0x10000        /* the final linked image uses
  177                                            weak symbols */
  178 
  179 #define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks 
  180                                            in the task will be given stack
  181                                            execution privilege.  Only used in
  182                                            MH_EXECUTE filetypes. */
  183 #define MH_ROOT_SAFE 0x40000           /* When this bit is set, the binary 
  184                                           declares it is safe for use in
  185                                           processes with uid zero */
  186                                          
  187 #define MH_SETUID_SAFE 0x80000         /* When this bit is set, the binary 
  188                                           declares it is safe for use in
  189                                           processes when issetugid() is true */
  190 
  191 #define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib, 
  192                                           the static linker does not need to
  193                                           examine dependent dylibs to see
  194                                           if any are re-exported */
  195 
  196 /*
  197  * The load commands directly follow the mach_header.  The total size of all
  198  * of the commands is given by the sizeofcmds field in the mach_header.  All
  199  * load commands must have as their first two fields cmd and cmdsize.  The cmd
  200  * field is filled in with a constant for that command type.  Each command type
  201  * has a structure specifically for it.  The cmdsize field is the size in bytes
  202  * of the particular load command structure plus anything that follows it that
  203  * is a part of the load command (i.e. section structures, strings, etc.).  To
  204  * advance to the next load command the cmdsize can be added to the offset or
  205  * pointer of the current load command.  The cmdsize for 32-bit architectures
  206  * MUST be a multiple of 4 bytes and for 64-bit architectures MUST be a multiple
  207  * of 8 bytes (these are forever the maximum alignment of any load commands).
  208  * The padded bytes must be zero.  All tables in the object file must also
  209  * follow these rules so the file can be memory mapped.  Otherwise the pointers
  210  * to these tables will not work well or at all on some machines.  With all
  211  * padding zeroed like objects will compare byte for byte.
  212  */
  213 struct load_command {
  214         uint32_t cmd;           /* type of load command */
  215         uint32_t cmdsize;       /* total size of command in bytes */
  216 };
  217 
  218 /*
  219  * After MacOS X 10.1 when a new load command is added that is required to be
  220  * understood by the dynamic linker for the image to execute properly the
  221  * LC_REQ_DYLD bit will be or'ed into the load command constant.  If the dynamic
  222  * linker sees such a load command it it does not understand will issue a
  223  * "unknown load command required for execution" error and refuse to use the
  224  * image.  Other load commands without this bit that are not understood will
  225  * simply be ignored.
  226  */
  227 #define LC_REQ_DYLD 0x80000000
  228 
  229 /* Constants for the cmd field of all load commands, the type */
  230 #define LC_SEGMENT      0x1     /* segment of this file to be mapped */
  231 #define LC_SYMTAB       0x2     /* link-edit stab symbol table info */
  232 #define LC_SYMSEG       0x3     /* link-edit gdb symbol table info (obsolete) */
  233 #define LC_THREAD       0x4     /* thread */
  234 #define LC_UNIXTHREAD   0x5     /* unix thread (includes a stack) */
  235 #define LC_LOADFVMLIB   0x6     /* load a specified fixed VM shared library */
  236 #define LC_IDFVMLIB     0x7     /* fixed VM shared library identification */
  237 #define LC_IDENT        0x8     /* object identification info (obsolete) */
  238 #define LC_FVMFILE      0x9     /* fixed VM file inclusion (internal use) */
  239 #define LC_PREPAGE      0xa     /* prepage command (internal use) */
  240 #define LC_DYSYMTAB     0xb     /* dynamic link-edit symbol table info */
  241 #define LC_LOAD_DYLIB   0xc     /* load a dynamically linked shared library */
  242 #define LC_ID_DYLIB     0xd     /* dynamically linked shared lib ident */
  243 #define LC_LOAD_DYLINKER 0xe    /* load a dynamic linker */
  244 #define LC_ID_DYLINKER  0xf     /* dynamic linker identification */
  245 #define LC_PREBOUND_DYLIB 0x10  /* modules prebound for a dynamically */
  246                                 /*  linked shared library */
  247 #define LC_ROUTINES     0x11    /* image routines */
  248 #define LC_SUB_FRAMEWORK 0x12   /* sub framework */
  249 #define LC_SUB_UMBRELLA 0x13    /* sub umbrella */
  250 #define LC_SUB_CLIENT   0x14    /* sub client */
  251 #define LC_SUB_LIBRARY  0x15    /* sub library */
  252 #define LC_TWOLEVEL_HINTS 0x16  /* two-level namespace lookup hints */
  253 #define LC_PREBIND_CKSUM  0x17  /* prebind checksum */
  254 
  255 /*
  256  * load a dynamically linked shared library that is allowed to be missing
  257  * (all symbols are weak imported).
  258  */
  259 #define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
  260 
  261 #define LC_SEGMENT_64   0x19    /* 64-bit segment of this file to be
  262                                    mapped */
  263 #define LC_ROUTINES_64  0x1a    /* 64-bit image routines */
  264 #define LC_UUID         0x1b    /* the uuid */
  265 #define LC_RPATH       (0x1c | LC_REQ_DYLD)    /* runpath additions */
  266 #define LC_CODE_SIGNATURE 0x1d  /* local of code signature */
  267 #define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */
  268 #define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
  269 
  270 /*
  271  * A variable length string in a load command is represented by an lc_str
  272  * union.  The strings are stored just after the load command structure and
  273  * the offset is from the start of the load command structure.  The size
  274  * of the string is reflected in the cmdsize field of the load command.
  275  * Once again any padded bytes to bring the cmdsize field to a multiple
  276  * of 4 bytes must be zero.
  277  */
  278 union lc_str {
  279         uint32_t        offset; /* offset to the string */
  280 #ifndef __LP64__
  281         char            *ptr;   /* pointer to the string */
  282 #endif 
  283 };
  284 
  285 /*
  286  * The segment load command indicates that a part of this file is to be
  287  * mapped into the task's address space.  The size of this segment in memory,
  288  * vmsize, maybe equal to or larger than the amount to map from this file,
  289  * filesize.  The file is mapped starting at fileoff to the beginning of
  290  * the segment in memory, vmaddr.  The rest of the memory of the segment,
  291  * if any, is allocated zero fill on demand.  The segment's maximum virtual
  292  * memory protection and initial virtual memory protection are specified
  293  * by the maxprot and initprot fields.  If the segment has sections then the
  294  * section structures directly follow the segment command and their size is
  295  * reflected in cmdsize.
  296  */
  297 struct segment_command { /* for 32-bit architectures */
  298         uint32_t        cmd;            /* LC_SEGMENT */
  299         uint32_t        cmdsize;        /* includes sizeof section structs */
  300         char            segname[16];    /* segment name */
  301         uint32_t        vmaddr;         /* memory address of this segment */
  302         uint32_t        vmsize;         /* memory size of this segment */
  303         uint32_t        fileoff;        /* file offset of this segment */
  304         uint32_t        filesize;       /* amount to map from the file */
  305         vm_prot_t       maxprot;        /* maximum VM protection */
  306         vm_prot_t       initprot;       /* initial VM protection */
  307         uint32_t        nsects;         /* number of sections in segment */
  308         uint32_t        flags;          /* flags */
  309 };
  310 
  311 /*
  312  * The 64-bit segment load command indicates that a part of this file is to be
  313  * mapped into a 64-bit task's address space.  If the 64-bit segment has
  314  * sections then section_64 structures directly follow the 64-bit segment
  315  * command and their size is reflected in cmdsize.
  316  */
  317 struct segment_command_64 { /* for 64-bit architectures */
  318         uint32_t        cmd;            /* LC_SEGMENT_64 */
  319         uint32_t        cmdsize;        /* includes sizeof section_64 structs */
  320         char            segname[16];    /* segment name */
  321         uint64_t        vmaddr;         /* memory address of this segment */
  322         uint64_t        vmsize;         /* memory size of this segment */
  323         uint64_t        fileoff;        /* file offset of this segment */
  324         uint64_t        filesize;       /* amount to map from the file */
  325         vm_prot_t       maxprot;        /* maximum VM protection */
  326         vm_prot_t       initprot;       /* initial VM protection */
  327         uint32_t        nsects;         /* number of sections in segment */
  328         uint32_t        flags;          /* flags */
  329 };
  330 
  331 /* Constants for the flags field of the segment_command */
  332 #define SG_HIGHVM       0x1     /* the file contents for this segment is for
  333                                    the high part of the VM space, the low part
  334                                    is zero filled (for stacks in core files) */
  335 #define SG_FVMLIB       0x2     /* this segment is the VM that is allocated by
  336                                    a fixed VM library, for overlap checking in
  337                                    the link editor */
  338 #define SG_NORELOC      0x4     /* this segment has nothing that was relocated
  339                                    in it and nothing relocated to it, that is
  340                                    it maybe safely replaced without relocation*/
  341 #define SG_PROTECTED_VERSION_1  0x8 /* This segment is protected.  If the
  342                                        segment starts at file offset 0, the
  343                                        first page of the segment is not
  344                                        protected.  All other pages of the
  345                                        segment are protected. */
  346 
  347 /*
  348  * A segment is made up of zero or more sections.  Non-MH_OBJECT files have
  349  * all of their segments with the proper sections in each, and padded to the
  350  * specified segment alignment when produced by the link editor.  The first
  351  * segment of a MH_EXECUTE and MH_FVMLIB format file contains the mach_header
  352  * and load commands of the object file before its first section.  The zero
  353  * fill sections are always last in their segment (in all formats).  This
  354  * allows the zeroed segment padding to be mapped into memory where zero fill
  355  * sections might be. The gigabyte zero fill sections, those with the section
  356  * type S_GB_ZEROFILL, can only be in a segment with sections of this type.
  357  * These segments are then placed after all other segments.
  358  *
  359  * The MH_OBJECT format has all of its sections in one segment for
  360  * compactness.  There is no padding to a specified segment boundary and the
  361  * mach_header and load commands are not part of the segment.
  362  *
  363  * Sections with the same section name, sectname, going into the same segment,
  364  * segname, are combined by the link editor.  The resulting section is aligned
  365  * to the maximum alignment of the combined sections and is the new section's
  366  * alignment.  The combined sections are aligned to their original alignment in
  367  * the combined section.  Any padded bytes to get the specified alignment are
  368  * zeroed.
  369  *
  370  * The format of the relocation entries referenced by the reloff and nreloc
  371  * fields of the section structure for mach object files is described in the
  372  * header file <reloc.h>.
  373  */
  374 struct section { /* for 32-bit architectures */
  375         char            sectname[16];   /* name of this section */
  376         char            segname[16];    /* segment this section goes in */
  377         uint32_t        addr;           /* memory address of this section */
  378         uint32_t        size;           /* size in bytes of this section */
  379         uint32_t        offset;         /* file offset of this section */
  380         uint32_t        align;          /* section alignment (power of 2) */
  381         uint32_t        reloff;         /* file offset of relocation entries */
  382         uint32_t        nreloc;         /* number of relocation entries */
  383         uint32_t        flags;          /* flags (section type and attributes)*/
  384         uint32_t        reserved1;      /* reserved (for offset or index) */
  385         uint32_t        reserved2;      /* reserved (for count or sizeof) */
  386 };
  387 
  388 struct section_64 { /* for 64-bit architectures */
  389         char            sectname[16];   /* name of this section */
  390         char            segname[16];    /* segment this section goes in */
  391         uint64_t        addr;           /* memory address of this section */
  392         uint64_t        size;           /* size in bytes of this section */
  393         uint32_t        offset;         /* file offset of this section */
  394         uint32_t        align;          /* section alignment (power of 2) */
  395         uint32_t        reloff;         /* file offset of relocation entries */
  396         uint32_t        nreloc;         /* number of relocation entries */
  397         uint32_t        flags;          /* flags (section type and attributes)*/
  398         uint32_t        reserved1;      /* reserved (for offset or index) */
  399         uint32_t        reserved2;      /* reserved (for count or sizeof) */
  400         uint32_t        reserved3;      /* reserved */
  401 };
  402 
  403 /*
  404  * The flags field of a section structure is separated into two parts a section
  405  * type and section attributes.  The section types are mutually exclusive (it
  406  * can only have one type) but the section attributes are not (it may have more
  407  * than one attribute).
  408  */
  409 #define SECTION_TYPE             0x000000ff     /* 256 section types */
  410 #define SECTION_ATTRIBUTES       0xffffff00     /*  24 section attributes */
  411 
  412 /* Constants for the type of a section */
  413 #define S_REGULAR               0x0     /* regular section */
  414 #define S_ZEROFILL              0x1     /* zero fill on demand section */
  415 #define S_CSTRING_LITERALS      0x2     /* section with only literal C strings*/
  416 #define S_4BYTE_LITERALS        0x3     /* section with only 4 byte literals */
  417 #define S_8BYTE_LITERALS        0x4     /* section with only 8 byte literals */
  418 #define S_LITERAL_POINTERS      0x5     /* section with only pointers to */
  419                                         /*  literals */
  420 /*
  421  * For the two types of symbol pointers sections and the symbol stubs section
  422  * they have indirect symbol table entries.  For each of the entries in the
  423  * section the indirect symbol table entries, in corresponding order in the
  424  * indirect symbol table, start at the index stored in the reserved1 field
  425  * of the section structure.  Since the indirect symbol table entries
  426  * correspond to the entries in the section the number of indirect symbol table
  427  * entries is inferred from the size of the section divided by the size of the
  428  * entries in the section.  For symbol pointers sections the size of the entries
  429  * in the section is 4 bytes and for symbol stubs sections the byte size of the
  430  * stubs is stored in the reserved2 field of the section structure.
  431  */
  432 #define S_NON_LAZY_SYMBOL_POINTERS      0x6     /* section with only non-lazy
  433                                                    symbol pointers */
  434 #define S_LAZY_SYMBOL_POINTERS          0x7     /* section with only lazy symbol
  435                                                    pointers */
  436 #define S_SYMBOL_STUBS                  0x8     /* section with only symbol
  437                                                    stubs, byte size of stub in
  438                                                    the reserved2 field */
  439 #define S_MOD_INIT_FUNC_POINTERS        0x9     /* section with only function
  440                                                    pointers for initialization*/
  441 #define S_MOD_TERM_FUNC_POINTERS        0xa     /* section with only function
  442                                                    pointers for termination */
  443 #define S_COALESCED                     0xb     /* section contains symbols that
  444                                                    are to be coalesced */
  445 #define S_GB_ZEROFILL                   0xc     /* zero fill on demand section
  446                                                    (that can be larger than 4
  447                                                    gigabytes) */
  448 #define S_INTERPOSING                   0xd     /* section with only pairs of
  449                                                    function pointers for
  450                                                    interposing */
  451 #define S_16BYTE_LITERALS       0xe     /* section with only 16 byte literals */
  452 /*
  453  * Constants for the section attributes part of the flags field of a section
  454  * structure.
  455  */
  456 #define SECTION_ATTRIBUTES_USR   0xff000000     /* User setable attributes */
  457 #define S_ATTR_PURE_INSTRUCTIONS 0x80000000     /* section contains only true
  458                                                    machine instructions */
  459 #define S_ATTR_NO_TOC            0x40000000     /* section contains coalesced
  460                                                    symbols that are not to be
  461                                                    in a ranlib table of
  462                                                    contents */
  463 #define S_ATTR_STRIP_STATIC_SYMS 0x20000000     /* ok to strip static symbols
  464                                                    in this section in files
  465                                                    with the MH_DYLDLINK flag */
  466 #define S_ATTR_NO_DEAD_STRIP     0x10000000     /* no dead stripping */
  467 #define S_ATTR_LIVE_SUPPORT      0x08000000     /* blocks are live if they
  468                                                    reference live blocks */
  469 #define S_ATTR_SELF_MODIFYING_CODE 0x04000000   /* Used with i386 code stubs
  470                                                    written on by dyld */
  471 /*
  472  * If a segment contains any sections marked with S_ATTR_DEBUG then all
  473  * sections in that segment must have this attribute.  No section other than
  474  * a section marked with this attribute may reference the contents of this
  475  * section.  A section with this attribute may contain no symbols and must have
  476  * a section type S_REGULAR.  The static linker will not copy section contents
  477  * from sections with this attribute into its output file.  These sections
  478  * generally contain DWARF debugging info.
  479  */ 
  480 #define S_ATTR_DEBUG             0x02000000     /* a debug section */
  481 #define SECTION_ATTRIBUTES_SYS   0x00ffff00     /* system setable attributes */
  482 #define S_ATTR_SOME_INSTRUCTIONS 0x00000400     /* section contains some
  483                                                    machine instructions */
  484 #define S_ATTR_EXT_RELOC         0x00000200     /* section has external
  485                                                    relocation entries */
  486 #define S_ATTR_LOC_RELOC         0x00000100     /* section has local
  487                                                    relocation entries */
  488 
  489 
  490 /*
  491  * The names of segments and sections in them are mostly meaningless to the
  492  * link-editor.  But there are few things to support traditional UNIX
  493  * executables that require the link-editor and assembler to use some names
  494  * agreed upon by convention.
  495  *
  496  * The initial protection of the "__TEXT" segment has write protection turned
  497  * off (not writeable).
  498  *
  499  * The link-editor will allocate common symbols at the end of the "__common"
  500  * section in the "__DATA" segment.  It will create the section and segment
  501  * if needed.
  502  */
  503 
  504 /* The currently known segment names and the section names in those segments */
  505 
  506 #define SEG_PAGEZERO    "__PAGEZERO"    /* the pagezero segment which has no */
  507                                         /* protections and catches NULL */
  508                                         /* references for MH_EXECUTE files */
  509 
  510 
  511 #define SEG_TEXT        "__TEXT"        /* the tradition UNIX text segment */
  512 #define SECT_TEXT       "__text"        /* the real text part of the text */
  513                                         /* section no headers, and no padding */
  514 #define SECT_FVMLIB_INIT0 "__fvmlib_init0"      /* the fvmlib initialization */
  515                                                 /*  section */
  516 #define SECT_FVMLIB_INIT1 "__fvmlib_init1"      /* the section following the */
  517                                                 /*  fvmlib initialization */
  518                                                 /*  section */
  519 
  520 #define SEG_DATA        "__DATA"        /* the tradition UNIX data segment */
  521 #define SECT_DATA       "__data"        /* the real initialized data section */
  522                                         /* no padding, no bss overlap */
  523 #define SECT_BSS        "__bss"         /* the real uninitialized data section*/
  524                                         /* no padding */
  525 #define SECT_COMMON     "__common"      /* the section common symbols are */
  526                                         /* allocated in by the link editor */
  527 
  528 #define SEG_OBJC        "__OBJC"        /* objective-C runtime segment */
  529 #define SECT_OBJC_SYMBOLS "__symbol_table"      /* symbol table */
  530 #define SECT_OBJC_MODULES "__module_info"       /* module information */
  531 #define SECT_OBJC_STRINGS "__selector_strs"     /* string table */
  532 #define SECT_OBJC_REFS "__selector_refs"        /* string table */
  533 
  534 #define SEG_ICON         "__ICON"       /* the icon segment */
  535 #define SECT_ICON_HEADER "__header"     /* the icon headers */
  536 #define SECT_ICON_TIFF   "__tiff"       /* the icons in tiff format */
  537 
  538 #define SEG_LINKEDIT    "__LINKEDIT"    /* the segment containing all structs */
  539                                         /* created and maintained by the link */
  540                                         /* editor.  Created with -seglinkedit */
  541                                         /* option to ld(1) for MH_EXECUTE and */
  542                                         /* FVMLIB file types only */
  543 
  544 #define SEG_UNIXSTACK   "__UNIXSTACK"   /* the unix stack segment */
  545 
  546 #define SEG_IMPORT      "__IMPORT"      /* the segment for the self (dyld) */
  547                                         /* modifing code stubs that has read, */
  548                                         /* write and execute permissions */
  549 
  550 /*
  551  * Fixed virtual memory shared libraries are identified by two things.  The
  552  * target pathname (the name of the library as found for execution), and the
  553  * minor version number.  The address of where the headers are loaded is in
  554  * header_addr. (THIS IS OBSOLETE and no longer supported).
  555  */
  556 struct fvmlib {
  557         union lc_str    name;           /* library's target pathname */
  558         uint32_t        minor_version;  /* library's minor version number */
  559         uint32_t        header_addr;    /* library's header address */
  560 };
  561 
  562 /*
  563  * A fixed virtual shared library (filetype == MH_FVMLIB in the mach header)
  564  * contains a fvmlib_command (cmd == LC_IDFVMLIB) to identify the library.
  565  * An object that uses a fixed virtual shared library also contains a
  566  * fvmlib_command (cmd == LC_LOADFVMLIB) for each library it uses.
  567  * (THIS IS OBSOLETE and no longer supported).
  568  */
  569 struct fvmlib_command {
  570         uint32_t        cmd;            /* LC_IDFVMLIB or LC_LOADFVMLIB */
  571         uint32_t        cmdsize;        /* includes pathname string */
  572         struct fvmlib   fvmlib;         /* the library identification */
  573 };
  574 
  575 /*
  576  * Dynamicly linked shared libraries are identified by two things.  The
  577  * pathname (the name of the library as found for execution), and the
  578  * compatibility version number.  The pathname must match and the compatibility
  579  * number in the user of the library must be greater than or equal to the
  580  * library being used.  The time stamp is used to record the time a library was
  581  * built and copied into user so it can be use to determined if the library used
  582  * at runtime is exactly the same as used to built the program.
  583  */
  584 struct dylib {
  585     union lc_str  name;                 /* library's path name */
  586     uint32_t timestamp;                 /* library's build time stamp */
  587     uint32_t current_version;           /* library's current version number */
  588     uint32_t compatibility_version;     /* library's compatibility vers number*/
  589 };
  590 
  591 /*
  592  * A dynamically linked shared library (filetype == MH_DYLIB in the mach header)
  593  * contains a dylib_command (cmd == LC_ID_DYLIB) to identify the library.
  594  * An object that uses a dynamically linked shared library also contains a
  595  * dylib_command (cmd == LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or
  596  * LC_REEXPORT_DYLIB) for each library it uses.
  597  */
  598 struct dylib_command {
  599         uint32_t        cmd;            /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,
  600                                            LC_REEXPORT_DYLIB */
  601         uint32_t        cmdsize;        /* includes pathname string */
  602         struct dylib    dylib;          /* the library identification */
  603 };
  604 
  605 /*
  606  * A dynamically linked shared library may be a subframework of an umbrella
  607  * framework.  If so it will be linked with "-umbrella umbrella_name" where
  608  * Where "umbrella_name" is the name of the umbrella framework. A subframework
  609  * can only be linked against by its umbrella framework or other subframeworks
  610  * that are part of the same umbrella framework.  Otherwise the static link
  611  * editor produces an error and states to link against the umbrella framework.
  612  * The name of the umbrella framework for subframeworks is recorded in the
  613  * following structure.
  614  */
  615 struct sub_framework_command {
  616         uint32_t        cmd;            /* LC_SUB_FRAMEWORK */
  617         uint32_t        cmdsize;        /* includes umbrella string */
  618         union lc_str    umbrella;       /* the umbrella framework name */
  619 };
  620 
  621 /*
  622  * For dynamically linked shared libraries that are subframework of an umbrella
  623  * framework they can allow clients other than the umbrella framework or other
  624  * subframeworks in the same umbrella framework.  To do this the subframework
  625  * is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
  626  * command is created for each -allowable_client flag.  The client_name is
  627  * usually a framework name.  It can also be a name used for bundles clients
  628  * where the bundle is built with "-client_name client_name".
  629  */
  630 struct sub_client_command {
  631         uint32_t        cmd;            /* LC_SUB_CLIENT */
  632         uint32_t        cmdsize;        /* includes client string */
  633         union lc_str    client;         /* the client name */
  634 };
  635 
  636 /*
  637  * A dynamically linked shared library may be a sub_umbrella of an umbrella
  638  * framework.  If so it will be linked with "-sub_umbrella umbrella_name" where
  639  * Where "umbrella_name" is the name of the sub_umbrella framework.  When
  640  * staticly linking when -twolevel_namespace is in effect a twolevel namespace 
  641  * umbrella framework will only cause its subframeworks and those frameworks
  642  * listed as sub_umbrella frameworks to be implicited linked in.  Any other
  643  * dependent dynamic libraries will not be linked it when -twolevel_namespace
  644  * is in effect.  The primary library recorded by the static linker when
  645  * resolving a symbol in these libraries will be the umbrella framework.
  646  * Zero or more sub_umbrella frameworks may be use by an umbrella framework.
  647  * The name of a sub_umbrella framework is recorded in the following structure.
  648  */
  649 struct sub_umbrella_command {
  650         uint32_t        cmd;            /* LC_SUB_UMBRELLA */
  651         uint32_t        cmdsize;        /* includes sub_umbrella string */
  652         union lc_str    sub_umbrella;   /* the sub_umbrella framework name */
  653 };
  654 
  655 /*
  656  * A dynamically linked shared library may be a sub_library of another shared
  657  * library.  If so it will be linked with "-sub_library library_name" where
  658  * Where "library_name" is the name of the sub_library shared library.  When
  659  * staticly linking when -twolevel_namespace is in effect a twolevel namespace 
  660  * shared library will only cause its subframeworks and those frameworks
  661  * listed as sub_umbrella frameworks and libraries listed as sub_libraries to
  662  * be implicited linked in.  Any other dependent dynamic libraries will not be
  663  * linked it when -twolevel_namespace is in effect.  The primary library
  664  * recorded by the static linker when resolving a symbol in these libraries
  665  * will be the umbrella framework (or dynamic library). Zero or more sub_library
  666  * shared libraries may be use by an umbrella framework or (or dynamic library).
  667  * The name of a sub_library framework is recorded in the following structure.
  668  * For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
  669  */
  670 struct sub_library_command {
  671         uint32_t        cmd;            /* LC_SUB_LIBRARY */
  672         uint32_t        cmdsize;        /* includes sub_library string */
  673         union lc_str    sub_library;    /* the sub_library name */
  674 };
  675 
  676 /*
  677  * A program (filetype == MH_EXECUTE) that is
  678  * prebound to its dynamic libraries has one of these for each library that
  679  * the static linker used in prebinding.  It contains a bit vector for the
  680  * modules in the library.  The bits indicate which modules are bound (1) and
  681  * which are not (0) from the library.  The bit for module 0 is the low bit
  682  * of the first byte.  So the bit for the Nth module is:
  683  * (linked_modules[N/8] >> N%8) & 1
  684  */
  685 struct prebound_dylib_command {
  686         uint32_t        cmd;            /* LC_PREBOUND_DYLIB */
  687         uint32_t        cmdsize;        /* includes strings */
  688         union lc_str    name;           /* library's path name */
  689         uint32_t        nmodules;       /* number of modules in library */
  690         union lc_str    linked_modules; /* bit vector of linked modules */
  691 };
  692 
  693 /*
  694  * A program that uses a dynamic linker contains a dylinker_command to identify
  695  * the name of the dynamic linker (LC_LOAD_DYLINKER).  And a dynamic linker
  696  * contains a dylinker_command to identify the dynamic linker (LC_ID_DYLINKER).
  697  * A file can have at most one of these.
  698  */
  699 struct dylinker_command {
  700         uint32_t        cmd;            /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */
  701         uint32_t        cmdsize;        /* includes pathname string */
  702         union lc_str    name;           /* dynamic linker's path name */
  703 };
  704 
  705 /*
  706  * Thread commands contain machine-specific data structures suitable for
  707  * use in the thread state primitives.  The machine specific data structures
  708  * follow the struct thread_command as follows.
  709  * Each flavor of machine specific data structure is preceded by an unsigned
  710  * long constant for the flavor of that data structure, an uint32_t
  711  * that is the count of longs of the size of the state data structure and then
  712  * the state data structure follows.  This triple may be repeated for many
  713  * flavors.  The constants for the flavors, counts and state data structure
  714  * definitions are expected to be in the header file <machine/thread_status.h>.
  715  * These machine specific data structures sizes must be multiples of
  716  * 4 bytes  The cmdsize reflects the total size of the thread_command
  717  * and all of the sizes of the constants for the flavors, counts and state
  718  * data structures.
  719  *
  720  * For executable objects that are unix processes there will be one
  721  * thread_command (cmd == LC_UNIXTHREAD) created for it by the link-editor.
  722  * This is the same as a LC_THREAD, except that a stack is automatically
  723  * created (based on the shell's limit for the stack size).  Command arguments
  724  * and environment variables are copied onto that stack.
  725  */
  726 struct thread_command {
  727         uint32_t        cmd;            /* LC_THREAD or  LC_UNIXTHREAD */
  728         uint32_t        cmdsize;        /* total size of this command */
  729         /* uint32_t flavor                 flavor of thread state */
  730         /* uint32_t count                  count of longs in thread state */
  731         /* struct XXX_thread_state state   thread state for this flavor */
  732         /* ... */
  733 };
  734 
  735 /*
  736  * The routines command contains the address of the dynamic shared library 
  737  * initialization routine and an index into the module table for the module
  738  * that defines the routine.  Before any modules are used from the library the
  739  * dynamic linker fully binds the module that defines the initialization routine
  740  * and then calls it.  This gets called before any module initialization
  741  * routines (used for C++ static constructors) in the library.
  742  */
  743 struct routines_command { /* for 32-bit architectures */
  744         uint32_t        cmd;            /* LC_ROUTINES */
  745         uint32_t        cmdsize;        /* total size of this command */
  746         uint32_t        init_address;   /* address of initialization routine */
  747         uint32_t        init_module;    /* index into the module table that */
  748                                         /*  the init routine is defined in */
  749         uint32_t        reserved1;
  750         uint32_t        reserved2;
  751         uint32_t        reserved3;
  752         uint32_t        reserved4;
  753         uint32_t        reserved5;
  754         uint32_t        reserved6;
  755 };
  756 
  757 /*
  758  * The 64-bit routines command.  Same use as above.
  759  */
  760 struct routines_command_64 { /* for 64-bit architectures */
  761         uint32_t        cmd;            /* LC_ROUTINES_64 */
  762         uint32_t        cmdsize;        /* total size of this command */
  763         uint64_t        init_address;   /* address of initialization routine */
  764         uint64_t        init_module;    /* index into the module table that */
  765                                         /*  the init routine is defined in */
  766         uint64_t        reserved1;
  767         uint64_t        reserved2;
  768         uint64_t        reserved3;
  769         uint64_t        reserved4;
  770         uint64_t        reserved5;
  771         uint64_t        reserved6;
  772 };
  773 
  774 /*
  775  * The symtab_command contains the offsets and sizes of the link-edit 4.3BSD
  776  * "stab" style symbol table information as described in the header files
  777  * <nlist.h> and <stab.h>.
  778  */
  779 struct symtab_command {
  780         uint32_t        cmd;            /* LC_SYMTAB */
  781         uint32_t        cmdsize;        /* sizeof(struct symtab_command) */
  782         uint32_t        symoff;         /* symbol table offset */
  783         uint32_t        nsyms;          /* number of symbol table entries */
  784         uint32_t        stroff;         /* string table offset */
  785         uint32_t        strsize;        /* string table size in bytes */
  786 };
  787 
  788 /*
  789  * This is the second set of the symbolic information which is used to support
  790  * the data structures for the dynamically link editor.
  791  *
  792  * The original set of symbolic information in the symtab_command which contains
  793  * the symbol and string tables must also be present when this load command is
  794  * present.  When this load command is present the symbol table is organized
  795  * into three groups of symbols:
  796  *      local symbols (static and debugging symbols) - grouped by module
  797  *      defined external symbols - grouped by module (sorted by name if not lib)
  798  *      undefined external symbols (sorted by name if MH_BINDATLOAD is not set,
  799  *                                  and in order the were seen by the static
  800  *                                  linker if MH_BINDATLOAD is set)
  801  * In this load command there are offsets and counts to each of the three groups
  802  * of symbols.
  803  *
  804  * This load command contains a the offsets and sizes of the following new
  805  * symbolic information tables:
  806  *      table of contents
  807  *      module table
  808  *      reference symbol table
  809  *      indirect symbol table
  810  * The first three tables above (the table of contents, module table and
  811  * reference symbol table) are only present if the file is a dynamically linked
  812  * shared library.  For executable and object modules, which are files
  813  * containing only one module, the information that would be in these three
  814  * tables is determined as follows:
  815  *      table of contents - the defined external symbols are sorted by name
  816  *      module table - the file contains only one module so everything in the
  817  *                     file is part of the module.
  818  *      reference symbol table - is the defined and undefined external symbols
  819  *
  820  * For dynamically linked shared library files this load command also contains
  821  * offsets and sizes to the pool of relocation entries for all sections
  822  * separated into two groups:
  823  *      external relocation entries
  824  *      local relocation entries
  825  * For executable and object modules the relocation entries continue to hang
  826  * off the section structures.
  827  */
  828 struct dysymtab_command {
  829     uint32_t cmd;       /* LC_DYSYMTAB */
  830     uint32_t cmdsize;   /* sizeof(struct dysymtab_command) */
  831 
  832     /*
  833      * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
  834      * are grouped into the following three groups:
  835      *    local symbols (further grouped by the module they are from)
  836      *    defined external symbols (further grouped by the module they are from)
  837      *    undefined symbols
  838      *
  839      * The local symbols are used only for debugging.  The dynamic binding
  840      * process may have to use them to indicate to the debugger the local
  841      * symbols for a module that is being bound.
  842      *
  843      * The last two groups are used by the dynamic binding process to do the
  844      * binding (indirectly through the module table and the reference symbol
  845      * table when this is a dynamically linked shared library file).
  846      */
  847     uint32_t ilocalsym; /* index to local symbols */
  848     uint32_t nlocalsym; /* number of local symbols */
  849 
  850     uint32_t iextdefsym;/* index to externally defined symbols */
  851     uint32_t nextdefsym;/* number of externally defined symbols */
  852 
  853     uint32_t iundefsym; /* index to undefined symbols */
  854     uint32_t nundefsym; /* number of undefined symbols */
  855 
  856     /*
  857      * For the for the dynamic binding process to find which module a symbol
  858      * is defined in the table of contents is used (analogous to the ranlib
  859      * structure in an archive) which maps defined external symbols to modules
  860      * they are defined in.  This exists only in a dynamically linked shared
  861      * library file.  For executable and object modules the defined external
  862      * symbols are sorted by name and is use as the table of contents.
  863      */
  864     uint32_t tocoff;    /* file offset to table of contents */
  865     uint32_t ntoc;      /* number of entries in table of contents */
  866 
  867     /*
  868      * To support dynamic binding of "modules" (whole object files) the symbol
  869      * table must reflect the modules that the file was created from.  This is
  870      * done by having a module table that has indexes and counts into the merged
  871      * tables for each module.  The module structure that these two entries
  872      * refer to is described below.  This exists only in a dynamically linked
  873      * shared library file.  For executable and object modules the file only
  874      * contains one module so everything in the file belongs to the module.
  875      */
  876     uint32_t modtaboff; /* file offset to module table */
  877     uint32_t nmodtab;   /* number of module table entries */
  878 
  879     /*
  880      * To support dynamic module binding the module structure for each module
  881      * indicates the external references (defined and undefined) each module
  882      * makes.  For each module there is an offset and a count into the
  883      * reference symbol table for the symbols that the module references.
  884      * This exists only in a dynamically linked shared library file.  For
  885      * executable and object modules the defined external symbols and the
  886      * undefined external symbols indicates the external references.
  887      */
  888     uint32_t extrefsymoff;      /* offset to referenced symbol table */
  889     uint32_t nextrefsyms;       /* number of referenced symbol table entries */
  890 
  891     /*
  892      * The sections that contain "symbol pointers" and "routine stubs" have
  893      * indexes and (implied counts based on the size of the section and fixed
  894      * size of the entry) into the "indirect symbol" table for each pointer
  895      * and stub.  For every section of these two types the index into the
  896      * indirect symbol table is stored in the section header in the field
  897      * reserved1.  An indirect symbol table entry is simply a 32bit index into
  898      * the symbol table to the symbol that the pointer or stub is referring to.
  899      * The indirect symbol table is ordered to match the entries in the section.
  900      */
  901     uint32_t indirectsymoff; /* file offset to the indirect symbol table */
  902     uint32_t nindirectsyms;  /* number of indirect symbol table entries */
  903 
  904     /*
  905      * To support relocating an individual module in a library file quickly the
  906      * external relocation entries for each module in the library need to be
  907      * accessed efficiently.  Since the relocation entries can't be accessed
  908      * through the section headers for a library file they are separated into
  909      * groups of local and external entries further grouped by module.  In this
  910      * case the presents of this load command who's extreloff, nextrel,
  911      * locreloff and nlocrel fields are non-zero indicates that the relocation
  912      * entries of non-merged sections are not referenced through the section
  913      * structures (and the reloff and nreloc fields in the section headers are
  914      * set to zero).
  915      *
  916      * Since the relocation entries are not accessed through the section headers
  917      * this requires the r_address field to be something other than a section
  918      * offset to identify the item to be relocated.  In this case r_address is
  919      * set to the offset from the vmaddr of the first LC_SEGMENT command.
  920      * For MH_SPLIT_SEGS images r_address is set to the the offset from the
  921      * vmaddr of the first read-write LC_SEGMENT command.
  922      *
  923      * The relocation entries are grouped by module and the module table
  924      * entries have indexes and counts into them for the group of external
  925      * relocation entries for that the module.
  926      *
  927      * For sections that are merged across modules there must not be any
  928      * remaining external relocation entries for them (for merged sections
  929      * remaining relocation entries must be local).
  930      */
  931     uint32_t extreloff; /* offset to external relocation entries */
  932     uint32_t nextrel;   /* number of external relocation entries */
  933 
  934     /*
  935      * All the local relocation entries are grouped together (they are not
  936      * grouped by their module since they are only used if the object is moved
  937      * from it staticly link edited address).
  938      */
  939     uint32_t locreloff; /* offset to local relocation entries */
  940     uint32_t nlocrel;   /* number of local relocation entries */
  941 
  942 };      
  943 
  944 /*
  945  * An indirect symbol table entry is simply a 32bit index into the symbol table 
  946  * to the symbol that the pointer or stub is refering to.  Unless it is for a
  947  * non-lazy symbol pointer section for a defined symbol which strip(1) as 
  948  * removed.  In which case it has the value INDIRECT_SYMBOL_LOCAL.  If the
  949  * symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
  950  */
  951 #define INDIRECT_SYMBOL_LOCAL   0x80000000
  952 #define INDIRECT_SYMBOL_ABS     0x40000000
  953 
  954 
  955 /* a table of contents entry */
  956 struct dylib_table_of_contents {
  957     uint32_t symbol_index;      /* the defined external symbol
  958                                    (index into the symbol table) */
  959     uint32_t module_index;      /* index into the module table this symbol
  960                                    is defined in */
  961 };      
  962 
  963 /* a module table entry */
  964 struct dylib_module {
  965     uint32_t module_name;       /* the module name (index into string table) */
  966 
  967     uint32_t iextdefsym;        /* index into externally defined symbols */
  968     uint32_t nextdefsym;        /* number of externally defined symbols */
  969     uint32_t irefsym;           /* index into reference symbol table */
  970     uint32_t nrefsym;           /* number of reference symbol table entries */
  971     uint32_t ilocalsym;         /* index into symbols for local symbols */
  972     uint32_t nlocalsym;         /* number of local symbols */
  973 
  974     uint32_t iextrel;           /* index into external relocation entries */
  975     uint32_t nextrel;           /* number of external relocation entries */
  976 
  977     uint32_t iinit_iterm;       /* low 16 bits are the index into the init
  978                                    section, high 16 bits are the index into
  979                                    the term section */
  980     uint32_t ninit_nterm;       /* low 16 bits are the number of init section
  981                                    entries, high 16 bits are the number of
  982                                    term section entries */
  983 
  984     uint32_t                    /* for this module address of the start of */
  985         objc_module_info_addr;  /*  the (__OBJC,__module_info) section */
  986     uint32_t                    /* for this module size of */
  987         objc_module_info_size;  /*  the (__OBJC,__module_info) section */
  988 };      
  989 
  990 /* a 64-bit module table entry */
  991 struct dylib_module_64 {
  992     uint32_t module_name;       /* the module name (index into string table) */
  993 
  994     uint32_t iextdefsym;        /* index into externally defined symbols */
  995     uint32_t nextdefsym;        /* number of externally defined symbols */
  996     uint32_t irefsym;           /* index into reference symbol table */
  997     uint32_t nrefsym;           /* number of reference symbol table entries */
  998     uint32_t ilocalsym;         /* index into symbols for local symbols */
  999     uint32_t nlocalsym;         /* number of local symbols */
 1000 
 1001     uint32_t iextrel;           /* index into external relocation entries */
 1002     uint32_t nextrel;           /* number of external relocation entries */
 1003 
 1004     uint32_t iinit_iterm;       /* low 16 bits are the index into the init
 1005                                    section, high 16 bits are the index into
 1006                                    the term section */
 1007     uint32_t ninit_nterm;      /* low 16 bits are the number of init section
 1008                                   entries, high 16 bits are the number of
 1009                                   term section entries */
 1010 
 1011     uint32_t                    /* for this module size of */
 1012         objc_module_info_size;  /*  the (__OBJC,__module_info) section */
 1013     uint64_t                    /* for this module address of the start of */
 1014         objc_module_info_addr;  /*  the (__OBJC,__module_info) section */
 1015 };
 1016 
 1017 /* 
 1018  * The entries in the reference symbol table are used when loading the module
 1019  * (both by the static and dynamic link editors) and if the module is unloaded
 1020  * or replaced.  Therefore all external symbols (defined and undefined) are
 1021  * listed in the module's reference table.  The flags describe the type of
 1022  * reference that is being made.  The constants for the flags are defined in
 1023  * <mach-o/nlist.h> as they are also used for symbol table entries.
 1024  */
 1025 struct dylib_reference {
 1026     uint32_t isym:24,           /* index into the symbol table */
 1027                   flags:8;      /* flags to indicate the type of reference */
 1028 };
 1029 
 1030 /*
 1031  * The twolevel_hints_command contains the offset and number of hints in the
 1032  * two-level namespace lookup hints table.
 1033  */
 1034 struct twolevel_hints_command {
 1035     uint32_t cmd;       /* LC_TWOLEVEL_HINTS */
 1036     uint32_t cmdsize;   /* sizeof(struct twolevel_hints_command) */
 1037     uint32_t offset;    /* offset to the hint table */
 1038     uint32_t nhints;    /* number of hints in the hint table */
 1039 };
 1040 
 1041 /*
 1042  * The entries in the two-level namespace lookup hints table are twolevel_hint
 1043  * structs.  These provide hints to the dynamic link editor where to start
 1044  * looking for an undefined symbol in a two-level namespace image.  The
 1045  * isub_image field is an index into the sub-images (sub-frameworks and
 1046  * sub-umbrellas list) that made up the two-level image that the undefined
 1047  * symbol was found in when it was built by the static link editor.  If
 1048  * isub-image is 0 the the symbol is expected to be defined in library and not
 1049  * in the sub-images.  If isub-image is non-zero it is an index into the array
 1050  * of sub-images for the umbrella with the first index in the sub-images being
 1051  * 1. The array of sub-images is the ordered list of sub-images of the umbrella
 1052  * that would be searched for a symbol that has the umbrella recorded as its
 1053  * primary library.  The table of contents index is an index into the
 1054  * library's table of contents.  This is used as the starting point of the
 1055  * binary search or a directed linear search.
 1056  */
 1057 struct twolevel_hint {
 1058     uint32_t 
 1059         isub_image:8,   /* index into the sub images */
 1060         itoc:24;        /* index into the table of contents */
 1061 };
 1062 
 1063 /*
 1064  * The prebind_cksum_command contains the value of the original check sum for
 1065  * prebound files or zero.  When a prebound file is first created or modified
 1066  * for other than updating its prebinding information the value of the check sum
 1067  * is set to zero.  When the file has it prebinding re-done and if the value of
 1068  * the check sum is zero the original check sum is calculated and stored in
 1069  * cksum field of this load command in the output file.  If when the prebinding
 1070  * is re-done and the cksum field is non-zero it is left unchanged from the
 1071  * input file.
 1072  */
 1073 struct prebind_cksum_command {
 1074     uint32_t cmd;       /* LC_PREBIND_CKSUM */
 1075     uint32_t cmdsize;   /* sizeof(struct prebind_cksum_command) */
 1076     uint32_t cksum;     /* the check sum or zero */
 1077 };
 1078 
 1079 /*
 1080  * The uuid load command contains a single 128-bit unique random number that
 1081  * identifies an object produced by the static link editor.
 1082  */
 1083 struct uuid_command {
 1084     uint32_t    cmd;            /* LC_UUID */
 1085     uint32_t    cmdsize;        /* sizeof(struct uuid_command) */
 1086     uint8_t     uuid[16];       /* the 128-bit uuid */
 1087 };
 1088 
 1089 /*
 1090  * The rpath_command contains a path which at runtime should be added to
 1091  * the current run path used to find @rpath prefixed dylibs.
 1092  */
 1093 struct rpath_command {
 1094     uint32_t     cmd;           /* LC_RPATH */
 1095     uint32_t     cmdsize;       /* includes string */
 1096     union lc_str path;          /* path to add to run path */
 1097 };
 1098 
 1099 /*
 1100  * The linkedit_data_command contains the offsets and sizes of a blob
 1101  * of data in the __LINKEDIT segment.  
 1102  */
 1103 struct linkedit_data_command {
 1104     uint32_t    cmd;            /* LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO */
 1105     uint32_t    cmdsize;        /* sizeof(struct linkedit_data_command) */
 1106     uint32_t    dataoff;        /* file offset of data in __LINKEDIT segment */
 1107     uint32_t    datasize;       /* file size of data in __LINKEDIT segment  */
 1108 };
 1109 
 1110 /*
 1111  * The symseg_command contains the offset and size of the GNU style
 1112  * symbol table information as described in the header file <symseg.h>.
 1113  * The symbol roots of the symbol segments must also be aligned properly
 1114  * in the file.  So the requirement of keeping the offsets aligned to a
 1115  * multiple of a 4 bytes translates to the length field of the symbol
 1116  * roots also being a multiple of a long.  Also the padding must again be
 1117  * zeroed. (THIS IS OBSOLETE and no longer supported).
 1118  */
 1119 struct symseg_command {
 1120         uint32_t        cmd;            /* LC_SYMSEG */
 1121         uint32_t        cmdsize;        /* sizeof(struct symseg_command) */
 1122         uint32_t        offset;         /* symbol segment offset */
 1123         uint32_t        size;           /* symbol segment size in bytes */
 1124 };
 1125 
 1126 /*
 1127  * The ident_command contains a free format string table following the
 1128  * ident_command structure.  The strings are null terminated and the size of
 1129  * the command is padded out with zero bytes to a multiple of 4 bytes/
 1130  * (THIS IS OBSOLETE and no longer supported).
 1131  */
 1132 struct ident_command {
 1133         uint32_t cmd;           /* LC_IDENT */
 1134         uint32_t cmdsize;       /* strings that follow this command */
 1135 };
 1136 
 1137 /*
 1138  * The fvmfile_command contains a reference to a file to be loaded at the
 1139  * specified virtual address.  (Presently, this command is reserved for
 1140  * internal use.  The kernel ignores this command when loading a program into
 1141  * memory).
 1142  */
 1143 struct fvmfile_command {
 1144         uint32_t cmd;                   /* LC_FVMFILE */
 1145         uint32_t cmdsize;               /* includes pathname string */
 1146         union lc_str    name;           /* files pathname */
 1147         uint32_t        header_addr;    /* files virtual address */
 1148 };
 1149 
 1150 #endif /* _MACHO_LOADER_H_ */

Cache object: b3abb256b1c9be95cf5d9e6470eef657


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.