home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / mach-o / reloc.h < prev    next >
C/C++ Source or Header  |  1992-03-06  |  6KB  |  123 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)a.out.h    5.1 (Berkeley) 5/30/85
  7.  *
  8.  * The structure this file describes was originally taken from the above file
  9.  * and the above copyright has been carried over to this file.
  10.  */
  11.  
  12. #ifndef _MACHO_RELOC_H_
  13. #define _MACHO_RELOC_H_
  14.  
  15. /*
  16.  * Format of a relocation entry of a Mach-O file.  Modified from the 4.3BSD
  17.  * format.  The modifications from the original format were changing the value
  18.  * of the r_symbolnum field for "local" (r_extern == 0) relocation entries.
  19.  * This modification is required to support symbols in an arbitrary number of
  20.  * sections not just the three sections (text, data and bss) in a 4.3BSD file.
  21.  * Also the last 4 bits have had the r_type tag added to them.
  22.  */
  23. struct relocation_info {
  24.    long        r_address;    /* offset in the section to what is being
  25.                    relocated */
  26.    unsigned int r_symbolnum:24,    /* symbol index if r_extern == 1 or section
  27.                    ordinal if r_extern == 0 */
  28.         r_pcrel:1,     /* was relocated pc relative already */
  29.         r_length:2,    /* 0=byte, 1=word, 2=long */
  30.         r_extern:1,    /* does not include value of sym referenced */
  31.         r_type:4;    /* if not 0, machine specific relocation type */
  32. };
  33. #define    R_ABS    0        /* absolute relocation type for Mach-O files */
  34.  
  35. /*
  36.  * The r_address is not really the address as it's name indicates but an offset.
  37.  * In 4.3BSD a.out objects this offset is from the start of the "segment" for
  38.  * which relocation entry is for (text or data).  For Mach-O object files it is
  39.  * also an offset but from the start of the "section" for which the relocation
  40.  * entry is for.
  41.  * 
  42.  * In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal
  43.  * for the segment the symbol being relocated is in.  These ordinals are the
  44.  * symbol types N_TEXT, N_DATA, N_BSS or N_ABS.  In Mach-O object files these
  45.  * ordinals refer to the sections in the object file in the order their section
  46.  * structures appear in the headers of the object file they are in.  The first
  47.  * section has the ordinal 1, the second 2, and so on.  This means that the
  48.  * same ordinal in two different object files could refer to two different
  49.  * sections.  And further could have still different ordinals when combined
  50.  * by the link-editor.  The value R_ABS is used for relocation entries for
  51.  * absolute symbols which need no further relocation.
  52.  */
  53.  
  54. /*
  55.  * To make scattered loading by the link editor work correctly "local"
  56.  * relocation entries can't be used when the item to be relocated is the value
  57.  * of a symbol plus an offset (where the resulting expresion is outside the
  58.  * block the link editor is moving, a blocks are divided at symbol addresses).
  59.  * In this case. where the item is a symbol value plus offset, the link editor
  60.  * needs to know more than just the section the symbol was defined.  What is
  61.  * needed is the actual value of the symbol without the offset so it can do the
  62.  * relocation correctly based on where the value of the symbol got relocated to
  63.  * not the value of the expression (with the offset added to the symbol value).
  64.  * So for the NeXT 2.0 release no "local" relocation entries are ever used when
  65.  * there is a non-zero offset added to a symbol.  The "external" and "local"
  66.  * relocation entries remain unchanged.
  67.  *
  68.  * The implemention is quite messy given the compatiblity with the existing
  69.  * relocation entry format.  The ASSUMPTION is that a section will never be
  70.  * bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes.  This assumption
  71.  * allows the r_address (which is really an offset) to fit in 24 bits and high
  72.  * bit of the r_address field in the relocation_info structure to indicate
  73.  * it is really a scattered_relocation_info structure.  Since these are only
  74.  * used in places where "local" relocation entries are used and not where
  75.  * "external" relocation entries are used the r_extern field has been removed.
  76.  *
  77.  * For scattered loading to work on a RISC machine where some of the references
  78.  * are split across two instructions the link editor needs to be assured that
  79.  * each reference has a unique 32 bit reference (that more than one reference is
  80.  * NOT sharing the same high 16 bits for example) so it move each referenced
  81.  * item independent of each other.  Some compilers guarantees this but the
  82.  * compilers don't so scattered loading can be done on those that do guarantee
  83.  * this.
  84.  */
  85. #if defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)
  86. /*
  87.  * The reason for the ifdef's of __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are that
  88.  * when stattered relocation entries were added the mistake of using a mask
  89.  * against a structure that is made up of bit fields was used.  To make this
  90.  * design work this structure must be laid out in memory the same way so the
  91.  * mask can be applied can check the same bit each time (r_scattered).
  92.  */
  93. #endif /* defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) */
  94. #define R_SCATTERED 0x80000000    /* mask to be applied to the r_address field 
  95.                    of a relocation_info structure to tell that
  96.                    is is really a scattered_relocation_info
  97.                    stucture */
  98. struct scattered_relocation_info {
  99. #ifdef __BIG_ENDIAN__
  100.    unsigned int r_scattered:1,    /* 1=scattered, 0=non-scattered (see above) */
  101.         r_pcrel:1,     /* was relocated pc relative already */
  102.         r_length:2,    /* 0=byte, 1=word, 2=long */
  103.         r_type:4,    /* if not 0, machine specific relocation type */
  104.            r_address:24;    /* offset in the section to what is being
  105.                    relocated */
  106.    long        r_value;    /* the value the item to be relocated is
  107.                    refering to (without any offset added) */
  108. #endif /* __BIG_ENDIAN__ */
  109. #ifdef __LITTLE_ENDIAN__
  110.    unsigned int
  111.            r_address:24,    /* offset in the section to what is being
  112.                    relocated */
  113.         r_type:4,    /* if not 0, machine specific relocation type */
  114.         r_length:2,    /* 0=byte, 1=word, 2=long */
  115.         r_pcrel:1,     /* was relocated pc relative already */
  116.         r_scattered:1;    /* 1=scattered, 0=non-scattered (see above) */
  117.    long        r_value;    /* the value the item to be relocated is
  118.                    refering to (without any offset added) */
  119. #endif /* __LITTLE_ENDIAN__ */
  120. };
  121.  
  122. #endif /* _MACHO_RELOC_H_ */
  123.