home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / cctools / include / mach-o / nlist.h < prev    next >
C/C++ Source or Header  |  1995-02-03  |  6KB  |  146 lines

  1. #ifndef _MACHO_NLIST_H_
  2. #define _MACHO_NLIST_H_
  3. /*
  4.  * Copyright (c) 1980 Regents of the University of California.
  5.  * All rights reserved.  The Berkeley software License Agreement
  6.  * specifies the terms and conditions for redistribution.
  7.  *
  8.  *    @(#)nlist.h    5.1 (Berkeley) 5/30/85
  9.  */
  10.  
  11. /*
  12.  * Format of a symbol table entry of a Mach-O file.  Modified from the 4.3BSD
  13.  * format.  The modifications from the original format were changing n_other
  14.  * (an unused field) to n_sect and the addition of the N_SECT type.  These
  15.  * modifications are required to support symbols in an arbitrary number of
  16.  * sections not just the three sections (text, data and bss) in a 4.3BSD file.
  17.  */
  18. struct nlist {
  19.     union {
  20.         char *n_name;    /* for use when in-core */
  21.         long  n_strx;    /* index into the string table */
  22.     } n_un;
  23.     unsigned char n_type;    /* type flag, see below */
  24.     unsigned char n_sect;    /* section number or NO_SECT */
  25.     short          n_desc;    /* see <mach-o/stab.h> */
  26.     unsigned long n_value;    /* value of this symbol (or stab offset) */
  27. };
  28.  
  29. /*
  30.  * Symbols with a index into the string table of zero (n_un.n_strx == 0) are
  31.  * defined to have a null, "", name.  Therefore all string indexes to non null
  32.  * names must not have a zero string index.  This is bit historical information
  33.  * that has never been well documented.
  34.  */
  35.  
  36. /*
  37.  * The n_type field really contains three fields:
  38.  *    unsigned char N_STAB:3,
  39.  *              N_PEXT:1,
  40.  *              N_TYPE:3,
  41.  *              N_EXT:1;
  42.  * which are used via the following masks.
  43.  */
  44. #define    N_STAB    0xe0  /* if any of these bits set, a symbolic debugging entry */
  45. #define    N_PEXT    0x10  /* private external symbol bit */
  46. #define    N_TYPE    0x0e  /* mask for the type bits */
  47. #define    N_EXT    0x01  /* external symbol bit, set for external symbols */
  48.  
  49. /*
  50.  * Only symbolic debugging entries have some of the N_STAB bits set and if any
  51.  * of these bits are set then it is a symbolic debugging entry (a stab).  In
  52.  * which case then the values of the n_type field (the entire field) are given
  53.  * in <mach-o/stab.h>
  54.  */
  55.  
  56. /*
  57.  * Values for N_TYPE bits of the n_type field.
  58.  */
  59. #define    N_UNDF    0x0        /* undefined, n_sect == NO_SECT */
  60. #define    N_ABS    0x2        /* absolute, n_sect == NO_SECT */
  61. #define    N_SECT    0xe        /* defined in section number n_sect */
  62. #define    N_PBUD    0xc        /* prebound undefined (defined in a dylib) */
  63. #define N_INDR    0xa        /* indirect */
  64.  
  65. /* 
  66.  * If the type is N_INDR then the symbol is defined to be the same as another
  67.  * symbol.  In this case the n_value field is an index into the string table
  68.  * of the other symbol's name.  When the other symbol is defined then they both
  69.  * take on the defined type and value.
  70.  */
  71.  
  72. /*
  73.  * If the type is N_SECT then the n_sect field contains an ordinal of the
  74.  * section the symbol is defined in.  The sections are numbered from 1 and 
  75.  * refer to sections in order they appear in the load commands for the file
  76.  * they are in.  This means the same ordinal may very well refer to different
  77.  * sections in different files.
  78.  *
  79.  * The n_value field for all symbol table entries (including N_STAB's) gets
  80.  * updated by the link editor based on the value of it's n_sect field and where
  81.  * the section n_sect references gets relocated.  If the value of the n_sect 
  82.  * field is NO_SECT then it's n_value field is not changed by the link editor.
  83.  */
  84. #define    NO_SECT        0    /* symbol is not in any section */
  85. #define MAX_SECT    255    /* 1 thru 255 inclusive */
  86.  
  87. /*
  88.  * Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
  89.  * who's values (n_value) are non-zero.  In which case the value of the n_value
  90.  * field is the size (in bytes) of the common symbol.  The n_sect field is set
  91.  * to NO_SECT.
  92.  */
  93.  
  94. /*
  95.  * To support the lazy binding of undefined symbols in the dynamic link-editor,
  96.  * the undefined symbols in the symbol table (the nlist structures) are marked
  97.  * with the indication if the undefined reference is a lazy reference or
  98.  * non-lazy reference.  If both a non-lazy reference and a lazy reference is
  99.  * made to the same symbol the non-lazy reference takes precedence.  A reference
  100.  * is lazy only when all references to that symbol are made through a symbol
  101.  * pointer in a lazy symbol pointer section.
  102.  *
  103.  * The implementation of marking nlist structures in the symbol table for
  104.  * undefined symbols will be to use some of the bits of the n_desc field as a
  105.  * reference type.  The mask REFERENCE_TYPE will be applied to the n_desc field
  106.  * of an nlist structure for an undefined symbol to determine the type of
  107.  * undefined reference (lazy or non-lazy).
  108.  *
  109.  * The constants for the REFERENCE FLAGS are propagated to the reference table
  110.  * in a shared library file.  In that case the constant for a defined symbol,
  111.  * REFERENCE_FLAG_DEFINED, is also used.
  112.  */
  113. /* Reference type bits of the n_desc field of undefined symbols */
  114. #define REFERENCE_TYPE                0xf
  115. /* types of references */
  116. #define REFERENCE_FLAG_UNDEFINED_NON_LAZY        0
  117. #define REFERENCE_FLAG_UNDEFINED_LAZY            1
  118. #define REFERENCE_FLAG_DEFINED                2
  119. #define REFERENCE_FLAG_PRIVATE_DEFINED            3
  120. #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY    4
  121. #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY        5
  122.  
  123. /*
  124.  * To simplify stripping of objects that use are used with the dynamic link
  125.  * editor, the static link editor marks the symbols defined an object that are
  126.  * referenced by a dynamicly bound object (dynamic shared libraries, bundles).
  127.  * With this marking strip knows not to strip these symbols.
  128.  */
  129. #define REFERENCED_DYNAMICALLY    0x0010
  130.  
  131. /*
  132.  * The non-reference type bits of the n_desc field for global symbols are
  133.  * reserved for the dynamic link editor.  All of these bits must start out
  134.  * zero in the object file.
  135.  */
  136. #define N_DESC_DISCARDED 0x8000    /* symbol is discarded */
  137.  
  138. #ifndef __STRICT_BSD__
  139. /*
  140.  * The function nlist(3) from the C library.
  141.  */
  142. extern int nlist (const char *filename, struct nlist *list);
  143. #endif __STRICT_BSD__
  144.  
  145. #endif _MACHO_LIST_H_
  146.