Changeset 2957 for trunk


Ignore:
Timestamp:
Feb 9, 2007, 5:20:40 AM (19 years ago)
Author:
bird
Message:

Types and defines for the symbol table.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdrModMachO.h

    r2954 r2957  
    623623/** @todo ident_command (LC_IDENT)
    624624/** @todo fvmfile_command (LC_FVMFILE) */
     625
     626
     627
     628
     629
     630
     631/**
     632 * The 32-bit Mach-O version of the nlist structure.
     633 *
     634 * This differs from the a.out nlist struct in that the unused n_other field
     635 * was renamed to n_sect and used for keeping the relevant section number.
     636 * @remark  This structure is not name mach_nlist_32 in the Apple headers, but nlist.
     637 */
     638typedef struct macho_nlist_32
     639{
     640    union
     641    {
     642        int32_t n_strx;         /**< Offset (index) into the string table. 0 means "". */
     643    }           n_un;
     644    uint8_t     n_type;         /**< Symbol type. */
     645    uint8_t     n_sect;         /**< Section number of NO_SECT. */
     646    int16_t     n_desc;         /**< Type specific, debug info details mostly.*/
     647    uint32_t    n_value;        /**< The symbol value or stab offset. */
     648} macho_nlist_32_t;
     649
     650
     651/**
     652 * The 64-bit Mach-O version of the nlist structure.
     653 * @see macho_nlist_32
     654 */
     655typedef struct macho_nlist_64
     656{
     657    union
     658    {
     659        int32_t n_strx;         /**< Offset (index) into the string table. 0 means "". */
     660    }           n_un;
     661    uint8_t     n_type;         /**< Symbol type. */
     662    uint8_t     n_sect;         /**< Section number of NO_SECT. */
     663    int16_t     n_desc;         /**< Type specific, debug info details mostly.*/
     664    uint64_t    n_value;        /**< The symbol value or stab offset. */
     665} macho_nlist_64_t;
     666
     667
     668/** @name Symbol Type Constants (macho_nlist_32_t::n_type, macho_nlist_64_t::n_type)
     669 *
     670 * In the Mach-O world n_type is somewhat similar to a.out, meaning N_EXT, N_UNDF, N_ABS
     671 * and the debug symbols are essentially the same, but the remaining stuff is different.
     672 * The main reason for this is that the encoding of section has been moved to n_sect
     673 * to permit up to 255 sections instead of the fixed 3 a.out sections (not counting
     674 * the abs symbols and set vectors).
     675 *
     676 * To avoid confusion with a.out the Mach-O constants has been fitted with a MACHO_
     677 * prefix here.
     678 *
     679 * Common symbols (aka communal symbols and comdefs) are represented by
     680 * n_type = MACHO_N_EXT | MACHO_N_UNDF, n_sect = NO_SECT and n_value giving
     681 * the size.
     682 *
     683 *
     684 * Symbol table entries can be inserted directly in the assembly code using
     685 * this notation:
     686 * @code
     687 *      .stabs "n_name", n_type, n_sect, n_desc, n_value
     688 * @endcode
     689 *
     690 * (1) The line number is optional, GCC doesn't set it.
     691 * (2) The type is optional, GCC doesn't set it.
     692 * (3) The binutil header is "skeptical" about the line. I'm skeptical about the whole thing... :-)
     693 * (M) Mach-O specific?
     694 * (S) Sun specific?
     695 * @{
     696 */
     697
     698/* Base masks. */
     699#define MACHO_N_EXT     UINT8_C(0x01)   /**< External symbol (when set) (N_EXT). */
     700#define MACHO_N_TYPE    UINT8_C(0x0e)   /**< Symbol type (N_TYPE without the 8th bit). */
     701#define MACHO_N_PEXT    UINT8_C(0x10)   /**< Private extern symbol (when set). Mach-O specific. */
     702#define MACHO_N_STAB    UINT8_C(0xe0)   /**< Debug symbol mask (N_STAB). */
     703
     704/* MACHO_N_TYPE values. */
     705#define MACHO_N_UNDF    UINT8_C(0x00)   /**< MACHO_N_TYPE: Undefined symbol (N_UNDF). n_sect = NO_SECT. */
     706#define MACHO_N_ABS     UINT8_C(0x02)   /**< MACHO_N_TYPE: Absolute symbol (N_UNDF). n_sect = NO_SECT. */
     707#define MACHO_N_INDR    UINT8_C(0x0a)   /**< MACHO_N_TYPE: Indirect symbol, n_value is the index of the symbol. Mach-O specific. */
     708#define MACHO_N_PBUD    UINT8_C(0x0c)   /**< MACHO_N_TYPE: Prebound undefined symbo (defined in a dylib). Mach-O specific. */
     709#define MACHO_N_SECT    UINT8_C(0x0e)   /**< MACHO_N_TYPE: Defined in the section given by n_sects. Mach-O specific. */
     710
     711/* Debug symbols. */
     712#define MACHO_N_GSYM    UINT8_C(0x20)   /**< Global variable.       "name",, NO_SECT, type, 0       (2) */
     713#define MACHO_N_FNAME   UINT8_C(0x22)   /**< Function name (F77).   "name",, NO_SECT, 0, 0 */
     714#define MACHO_N_FUN     UINT8_C(0x24)   /**< Function / text var.   "name",, section, line, address (1) */
     715#define MACHO_N_STSYM   UINT8_C(0x26)   /**< Static data symbol.    "name",, section, type, address (2) */
     716#define MACHO_N_LCSYM   UINT8_C(0x28)   /**< static bss symbol.     "name",, section, type, address (2) */
     717    /* omits N_MAIN and N_ROSYM. */
     718#define MACHO_N_BNSYM   UINT8_C(0x2e)   /**< Begin nsect symbol.         0,, section, 0, address (M) */
     719#define MACHO_N_PC      UINT8_C(0x30)   /**< Global pascal symbol.  "name",, NO_SECT, subtype?, line (3) */
     720    /* omits N_NSYMS, N_NOMAP and N_OBJ. */
     721#define MACHO_N_OPT     UINT8_C(0x3c)   /**< Options for the debugger related to the language of the
     722                                             source file.           "options?",,,, */
     723#define MACHO_N_RSYM    UINT8_C(0x40)   /**< Register variable.     "name",, NO_SECT, type, register */
     724    /* omits N_M2C */
     725#define MACHO_N_SLINE   UINT8_C(0x44)   /**< Source line.                0,, section, line, address */
     726    /* omits N_DSLINE, N_BSLINE / N_BROWS, N_DEFD and N_FLINE. */
     727#define MACHO_N_ENSYM   UINT8_C(0x4e)   /**< End nsect symbol.           0,, section, 0, address (M) */
     728    /* omits N_EHDECL / N_MOD2 and N_CATCH. */
     729#define MACHO_N_SSYM    UINT8_C(0x60)   /**< Struct/union element.  "name",, NO_SECT, type, offset */
     730    /* omits N_ENDM */
     731#define MACHO_N_SO      UINT8_C(0x64)   /**< Source file name.      "fname",, section, 0, address */
     732#define MACHO_N_OSO     UINT8_C(0x66)   /**< Object file name.      "fname",, 0, 0, st_mtime (M?) */
     733    /* omits N_ALIAS */
     734#define MACHO_N_LSYM    UINT8_C(0x80)   /**< Stack variable.        "name",, NO_SECT, type, frame_offset */
     735#define MACHO_N_BINCL   UINT8_C(0x82)   /**< Begin #include.        "fname",, NO_SECT, 0, sum? */
     736#define MACHO_N_SOL     UINT8_C(0x84)   /**< #included file.        "fname",, section, 0, start_address (S) */
     737#define MACHO_N_PARAMS  UINT8_C(0x86)   /**< Compiler params.       "params",, NO_SECT, 0, 0 */
     738#define MACHO_N_VERSION UINT8_C(0x88)   /**< Compiler version.      "version",, NO_SECT, 0, 0 */
     739#define MACHO_N_OLEVEL  UINT8_C(0x8A)   /**< Compiler -O level.     "level",, NO_SECT, 0, 0 */
     740#define MACHO_N_PSYM    UINT8_C(0xa0)   /**< Parameter variable.    "name",, NO_SECT, type, frame_offset */
     741#define MACHO_N_EINCL   UINT8_C(0xa2)   /**< End #include.          "fname",, NO_SECT, 0, 0 (S) */
     742#define MACHO_N_ENTRY   UINT8_C(0xa4)   /**< Alternate entry point. "name",, section, line, address */
     743#define MACHO_N_LBRAC   UINT8_C(0xc0)   /**< Left bracket.               0,, NO_SECT, nesting_level, address */
     744#define MACHO_N_EXCL    UINT8_C(0xc2)   /**< Deleted include file.  "fname",, NO_SECT, 0, sum?  (S) */
     745    /* omits N_SCOPE */
     746#define MACHO_N_RBRAC   UINT8_C(0xe0)   /**< Right bracket.              0,, NO_SECT, nesting_level, address */
     747#define MACHO_N_BCOMM   UINT8_C(0xe2)   /**< Begin common.          "name",, NO_SECT?, 0, 0 */
     748#define MACHO_N_ECOMM   UINT8_C(0xe4)   /**< End common.            "name",, section, 0, 0 */
     749#define MACHO_N_ECOML   UINT8_C(0xe8)   /**< End local common.           0,, section, 0, address */
     750#define MACHO_N_LENG    UINT8_C(0xfe)   /**< Length-value of the preceding entry.
     751                                                                    "name",, NO_SECT, 0, length */
     752
     753/** @} */
     754
     755/** @name Symbol Description Bits (macho_nlist_32_t::n_desc, macho_nlist_64_t::n_desc)
     756 *
     757 * Mach-O puts the n_desc field to a number of uses, like lazy binding , library
     758 * ordinal numbers for -twolevel_namespace, stripping and weak symbol handling.
     759 *
     760 * @remark The REFERENCE_FLAGS_* are really not flags in the normal sense (bit),
     761 *         they are more like enum values.
     762 * @{
     763 */
     764
     765#define REFERENCE_TYPE                  UINT16_C(0x000f)    /**< The reference type mask. */
     766#define REFERENCE_FLAG_UNDEFINED_NON_LAZY             0     /**< Normal undefined symbol. */
     767#define REFERENCE_FLAG_UNDEFINED_LAZY                 1     /**< Lazy undefined symbol. */
     768#define REFERENCE_FLAG_DEFINED                        2     /**< Defined symbol (dynamic linking). */
     769#define REFERENCE_FLAG_PRIVATE_DEFINED                3     /**< Defined private symbol (dynamic linking). */
     770#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY     4     /**< Normal undefined private symbol. */
     771#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY         5     /**< Lazy undefined private symbol. */
     772
     773#define REFERENCED_DYNAMICALLY          UINT16_C(0x0010)    /**< Don't strip. */
     774
     775
     776/** Get the dynamic library ordinal. */
     777#define GET_LIBRARY_ORDINAL(n_desc)     \
     778    (((n_desc) >> 8) & 0xff)
     779/** Set the dynamic library ordinal. */
     780#define SET_LIBRARY_ORDINAL(n_desc, ordinal) \
     781    (n_desc) = (((n_desc) & 0xff) | (((ordinal) & 0xff) << 8))
     782#define SELF_LIBRARY_ORDINAL            0x00                /**< Special ordinal for refering to onself. */
     783#define MAX_LIBRARY_ORDINAL             0xfd                /**< Maximum ordinal number. */
     784#define DYNAMIC_LOOKUP_ORDINAL          0xfe                /**< Special ordinal number for dynamic lookup. (Mac OS X 10.3 and later) */
     785#define EXECUTABLE_ORDINAL              0xff                /**< Special ordinal number for the executable.  */
     786
     787
     788/** Only MH_OBJECT: Never dead strip me! */
     789#define N_NO_DEAD_STRIP                 UINT16_C(0x0020)
     790/** Not MH_OBJECT: Discarded symbol. */
     791#define N_DESC_DISCARDED                UINT16_C(0x0020)
     792/** Weak external symbol. Symbol can be missing, in which case it's will have the value 0. */
     793#define N_WEAK_REF                      UINT16_C(0x0040)
     794/** Weak symbol definition. The symbol can be overridden by another weak
     795 * symbol already present or by a non-weak (strong) symbol definition.
     796 * Currently only supported for coalesed symbols.
     797 * @remark This bit means something differently for undefined symbols, see N_REF_TO_WEAK.
     798 */
     799#define N_WEAK_DEF                      UINT16_C(0x0080)
     800/** Reference to a weak symbol, resolve using flat namespace searching.
     801 * @remark This bit means something differently for defined symbols, see N_WEAK_DEF. */
     802#define N_REF_TO_WEAK                   UINT16_C(0x0080)
     803
     804/** @} */
     805
    625806#endif
    626807
Note: See TracChangeset for help on using the changeset viewer.