textfiles

Various textfiles on technical topics
git clone https://git.bracken.jp/textfiles.git
Log | Files | Refs

ELF.txt (105567B)


      1 		 Notes on the Flat-Text Transcription
      2 
      3 The content of this transcription differs from the content of the
      4 original document in the following ways.
      5 
      6 1. Page breaks and pagination have been omitted.
      7 2. As a result of the above, the page numbers have been left out of
      8    the table of contents, and the index has been omitted entirely.
      9    (Unlike a Postscript document, a text file can be searched.)
     10 3. The contents of the title page and the footer text has been placed
     11    at the beginning.
     12 4. The lines and boxes in the original figures and tables have been
     13    adapted.
     14 5. Differing fonts have, of necessity, been elided. For the most part,
     15    the context is sufficient to understand the meaning. In a few
     16    places, however, the original document used italics to implicitly
     17    indicate that the text stood for a variable string. In these cases,
     18    I have used <angle brackets> around the text to indicate this.
     19    There are no occurrences of angle brackets in the original.
     20 6. The original contains three errors which are not immediately
     21    obvious as such upon a casual reading, but which can be
     22    unambiguously identified as such and the proper contents
     23    determined. I have taken the liberty to correct these errors. Their
     24    locations are marked in the text by a {*}. Any other (seeming)
     25    errors I have let stand.
     26 
     27 Any other differences between the contents of this file and the
     28 original are my responsibility. Direct notices of such errors to
     29 breadbox@muppetlabs.com.
     30 
     31 Brian Raiter
     32 [Last edited Fri Jul 23 1999]
     33 
     34    ________________________________________________________________
     35 
     36 
     37 		 EXECUTABLE AND LINKABLE FORMAT (ELF)
     38 
     39 	     Portable Formats Specification, Version 1.1
     40 		    Tool Interface Standards (TIS)
     41 
     42    ________________________________________________________________
     43 
     44 
     45    =========================== Contents ===========================
     46 
     47 
     48    PREFACE
     49 1. OBJECT FILES
     50    Introduction
     51    ELF Header
     52    Sections
     53    String Table
     54    Symbol Table
     55    Relocation
     56 2. PROGRAM LOADING AND DYNAMIC LINKING
     57    Introduction
     58    Program Header
     59    Program Loading
     60    Dynamic Linking
     61 3. C LIBRARY
     62    C Library
     63 
     64    ________________________________________________________________
     65 
     66 
     67 			       PREFACE
     68 
     69    ________________________________________________________________
     70 
     71 
     72 		  ELF: Executable and Linking Format
     73 
     74 The Executable and Linking Format was originally developed and
     75 published by UNIX System Laboratories (USL) as part of the Application
     76 Binary Interface (ABI). The Tool Interface Standards committee (TIS)
     77 has selected the evolving ELF standard as a portable object file
     78 format that works on 32-bit Intel Architecture environments for a
     79 variety of operating systems.
     80 
     81 The ELF standard is intended to streamline software development by
     82 providing developers with a set of binary interface definitions that
     83 extend across multiple operating environments. This should reduce the
     84 number of different interface implementations, thereby reducing the
     85 need for recoding and recompiling code.
     86 
     87 
     88 			 About This Document
     89 
     90 This document is intended for developers who are creating object or
     91 executable files on various 32-bit environment operating systems. It
     92 is divided into the following three parts:
     93 
     94 * Part 1, ``Object Files'' describes the ELF object file format for
     95   the three main types of object files.
     96 * Part 2, ``Program Loading and Dynamic Linking'' describes the object
     97   file information and system actions that create running programs.
     98 * Part 3, ``C Library'' lists the symbols contained in libsys, the
     99   standard ANSI C and libc routines, and the global data symbols
    100   required by the libc routines.
    101 
    102 NOTE: References to X86 architecture have been changed to Intel
    103 Architecture.
    104 
    105    ________________________________________________________________
    106 
    107 
    108 			   1. OBJECT FILES
    109 
    110    ________________________________________________________________
    111 
    112 
    113    ========================= Introduction =========================
    114 
    115 
    116 Part 1 describes the iABI object file format, called ELF (Executable
    117 and Linking Format). There are three main types of object files.
    118 
    119 * A relocatable file holds code and data suitable for linking with
    120   other object files to create an executable or a shared object file.
    121 * An executable file holds a program suitable for execution; the file
    122   specifies how exec(BA_OS) creates a program's process image.
    123 * A shared object file holds code and data suitable for linking in two
    124   contexts. First, the link editor [see ld(SD_CMD)] may process it
    125   with other relocatable and shared object files to create another
    126   object file. Second, the dynamic linker combines it with an
    127   executable file and other shared objects to create a process image.
    128 
    129 Created by the assembler and link editor, object files are binary
    130 representations of programs intended to execute directly on a
    131 processor. Programs that require other abstract machines, such as
    132 shell scripts, are excluded.
    133 
    134 After the introductory material, Part 1 focuses on the file format and
    135 how it pertains to building programs. Part 2 also describes parts of
    136 the object file, concentrating on the information necessary to execute
    137 a program.
    138 
    139 
    140 			     File Format
    141 
    142 Object files participate in program linking (building a program) and
    143 program execution (running a program). For convenience and efficiency,
    144 the object file format provides parallel views of a file's contents,
    145 reflecting the differing needs of these activities. Figure 1-1 shows
    146 an object file's organization.
    147 
    148 + Figure 1-1: Object File Format
    149 
    150   Linking View                      Execution View
    151   ============                      ==============
    152   ELF header                        ELF header
    153   Program header table (optional)   Program header table
    154   Section 1                         Segment 1
    155   ...                               Segment 2
    156   Section n                         ...
    157   Section header table              Section header table (optional)
    158 
    159 An ELF header resides at the beginning and holds a ``road map''
    160 describing the file's organization. Sections hold the bulk of object
    161 file information for the linking view: instructions, data, symbol
    162 table, relocation information, and so on. Descriptions of special
    163 sections appear later in Part 1. Part 2 discusses segments and the
    164 program execution view of the file.
    165 
    166 A program header table, if present, tells the system how to create a
    167 process image. Files used to build a process image (execute a program)
    168 must have a program header table; relocatable files do not need one. A
    169 section header table contains information describing the file's
    170 sections. Every section has an entry in the table; each entry gives
    171 information such as the section name, the section size, etc. Files
    172 used during linking must have a section header table; other object
    173 files may or may not have one.
    174 
    175 NOTE: Although the figure shows the program header table immediately
    176 after the ELF header, and the section header table following the
    177 sections, actual files may differ. Moreover, sections and segments
    178 have no specified order. Only the ELF header has a fixed position in
    179 the file.
    180 
    181 
    182 			 Data Representation
    183 
    184 As described here, the object file format supports various processors
    185 with 8-bit bytes and 32-bit architectures. Nevertheless, it is
    186 intended to be extensible to larger (or smaller) architectures.
    187 Object files therefore represent some control data with a
    188 machine-independent format, making it possible to identify object
    189 files and interpret their contents in a common way. Remaining data in
    190 an object file use the encoding of the target processor, regardless of
    191 the machine on which the file was created.
    192 
    193 + Figure 1-2: 32-Bit Data Types
    194 
    195   Name           Size Alignment   Purpose
    196   ====           ==== =========   =======
    197   Elf32_Addr      4       4       Unsigned program address
    198   Elf32_Half      2       2       Unsigned medium integer
    199   Elf32_Off       4       4       Unsigned file offset
    200   Elf32_Sword     4       4       Signed large integer
    201   Elf32_Word      4       4       Unsigned large integer
    202   unsigned char   1       1       Unsigned small integer
    203 
    204 All data structures that the object file format defines follow the
    205 ``natural'' size and alignment guidelines for the relevant class. If
    206 necessary, data structures contain explicit padding to ensure 4-byte
    207 alignment for 4-byte objects, to force structure sizes to a multiple
    208 of 4, etc. Data also have suitable alignment from the beginning of the
    209 file. Thus, for example, a structure containing an Elf32_Addr member
    210 will be aligned on a 4-byte boundary within the file.
    211 
    212 For portability reasons, ELF uses no bit-fields.
    213 
    214 
    215    ========================== ELF Header ==========================
    216 
    217 
    218 Some object file control structures can grow, because the ELF header
    219 contains their actual sizes. If the object file format changes, a
    220 program may encounter control structures that are larger or smaller
    221 than expected. Programs might therefore ignore``extra'' information.
    222 The treatment of ``missing'' information depends on context and will
    223 be specified when and if extensions are defined.
    224 
    225 + Figure 1-3: ELF Header
    226 
    227   #define EI_NIDENT       16
    228 
    229   typedef struct {
    230       unsigned char       e_ident[EI_NIDENT];
    231       Elf32_Half          e_type;
    232       Elf32_Half          e_machine;
    233       Elf32_Word          e_version;
    234       Elf32_Addr          e_entry;
    235       Elf32_Off           e_phoff;
    236       Elf32_Off           e_shoff;
    237       Elf32_Word          e_flags;
    238       Elf32_Half          e_ehsize;
    239       Elf32_Half          e_phentsize;
    240       Elf32_Half          e_phnum;
    241       Elf32_Half          e_shentsize;
    242       Elf32_Half          e_shnum;
    243       Elf32_Half          e_shstrndx;
    244   } Elf32_Ehdr;
    245 
    246 * e_ident
    247 
    248   The initial bytes mark the file as an object file and provide
    249   machine-independent data with which to decode and interpret the
    250   file's contents. Complete descriptions appear below, in ``ELF
    251   Identification.''
    252 
    253 * e_type
    254 
    255   This member identifies the object file type.
    256 
    257                Name        Value  Meaning
    258                ====        =====  =======
    259                ET_NONE         0  No file type
    260                ET_REL          1  Relocatable file
    261                ET_EXEC         2  Executable file
    262                ET_DYN          3  Shared object file
    263 	       ET_CORE         4  Core file
    264 	       ET_LOPROC  0xff00  Processor-specific
    265 	       ET_HIPROC  0xffff  Processor-specific
    266 
    267   Although the core file contents are unspecified, type ET_CORE is
    268   reserved to mark the file. Values from ET_LOPROC through ET_HIPROC
    269   (inclusive) are reserved for processor-specific semantics. Other
    270   values are reserved and will be assigned to new object file types as
    271   necessary.
    272 
    273 * e_machine
    274 
    275   This member's value specifies the required architecture for an
    276   individual file.
    277 
    278                     Name      Value  Meaning
    279 	            ====      =====  =======
    280                     EM_NONE       0  No machine
    281 		    EM_M32        1  AT&T WE 32100
    282                     EM_SPARC      2  SPARC
    283                     EM_386        3  Intel 80386
    284                     EM_68K        4  Motorola 68000
    285                     EM_88K        5  Motorola 88000
    286                     EM_860        7  Intel 80860
    287                     EM_MIPS       8  MIPS RS3000
    288 
    289   Other values are reserved and will be assigned to new machines as
    290   necessary. Processor-specific ELF names use the machine name to
    291   distinguish them. For example, the flags mentioned below use the
    292   prefix EF_; a flag named WIDGET for the EM_XYZ machine would be
    293   called EF_XYZ_WIDGET.
    294 
    295 * e_version
    296 
    297   This member identifies the object file version.
    298 
    299                  Name         Value  Meaning
    300                  ====         =====  =======
    301                  EV_NONE          0  Invalid version
    302 		 EV_CURRENT       1  Current version
    303 
    304   The value 1 signifies the original file format; extensions will
    305   create new versions with higher numbers. The value of EV_CURRENT,
    306   though given as 1 above, will change as necessary to reflect the
    307   current version number.
    308 
    309 * e_entry
    310 
    311   This member gives the virtual address to which the system first
    312   transfers control, thus starting the process. If the file has no
    313   associated entry point, this member holds zero.
    314 
    315 * e_phoff
    316 
    317   This member holds the program header table's file offset in bytes.
    318   If the file has no program header table, this member holds zero.
    319 
    320 * e_shoff
    321 
    322   This member holds the section header table's file offset in bytes.
    323   If the file has no section header table, this member holds zero.
    324 
    325 * e_flags
    326 
    327   This member holds processor-specific flags associated with the file.
    328   Flag names take the form EF_<machine>_<flag>. See ``Machine
    329   Information'' for flag definitions.
    330 
    331 * e_ehsize
    332 
    333   This member holds the ELF header's size in bytes.
    334 
    335 * e_phentsize
    336 
    337   This member holds the size in bytes of one entry in the file's
    338   program header table; all entries are the same size.
    339 
    340 * e_phnum
    341 
    342   This member holds the number of entries in the program header
    343   table. Thus the product of e_phentsize and e_phnum gives the table's
    344   size in bytes. If a file has no program header table, e_phnum holds
    345   the value zero.
    346 
    347 * e_shentsize
    348 
    349   This member holds a section header's size in bytes. A section header
    350   is one entry in the section header table; all entries are the same
    351   size.
    352 
    353 * e_shnum
    354 
    355   This member holds the number of entries in the section header table.
    356   Thus the product of e_shentsize and e_shnum gives the section header
    357   table's size in bytes. If a file has no section header table,
    358   e_shnum holds the value zero.
    359 
    360 * e_shstrndx
    361 
    362   This member holds the section header table index of the entry
    363   associated with the section name string table. If the file has no
    364   section name string table, this member holds the value SHN_UNDEF.
    365   See ``Sections'' and ``String Table'' below for more information.
    366 
    367 
    368 			  ELF Identification
    369 
    370 As mentioned above, ELF provides an object file framework to support
    371 multiple processors, multiple data encodings, and multiple classes of
    372 machines. To support this object file family, the initial bytes of the
    373 file specify how to interpret the file, independent of the processor
    374 on which the inquiry is made and independent of the file's remaining
    375 contents.
    376 
    377 The initial bytes of an ELF header (and an object file) correspond to
    378 the e_ident member.
    379 
    380 + Figure 1-4: e_ident[] Identification Indexes
    381 
    382   Name           Value  Purpose
    383   ====           =====  =======
    384   EI_MAG0	     0  File identification
    385   EI_MAG1	     1  File identification
    386   EI_MAG2	     2  File identification
    387   EI_MAG3	     3  File identification
    388   EI_CLASS	     4  File class
    389   EI_DATA	     5  Data encoding
    390   EI_VERSION	     6  File version
    391   EI_PAD	     7  Start of padding bytes
    392   EI_NIDENT	    16  Size of e_ident[]
    393 
    394 These indexes access bytes that hold the following values.
    395 
    396 * EI_MAG0 to EI_MAG3
    397 
    398   A file's first 4 bytes hold a ``magic number,'' identifying the file
    399   as an ELF object file.
    400 
    401                   Name       Value  Position
    402                   ====       =====  ========
    403 		  ELFMAG0    0x7f   e_ident[EI_MAG0]
    404                   ELFMAG1    'E'    e_ident[EI_MAG1]
    405                   ELFMAG2    'L'    e_ident[EI_MAG2]
    406                   ELFMAG3    'F'    e_ident[EI_MAG3]
    407 
    408 * EI_CLASS
    409 
    410   The next byte, e_ident[EI_CLASS], identifies the file's class, or
    411   capacity.
    412 
    413                  Name           Value  Meaning
    414                  ====           =====  =======
    415                  ELFCLASSNONE       0  Invalid class
    416                  ELFCLASS32         1  32-bit objects
    417 		 ELFCLASS64         2  64-bit objects
    418 
    419   The file format is designed to be portable among machines of various
    420   sizes, without imposing the sizes of the largest machine on the
    421   smallest. Class ELFCLASS32 supports machines with files and virtual
    422   address spaces up to 4 gigabytes; it uses the basic types defined
    423   above.
    424 
    425   Class ELFCLASS64 is reserved for 64-bit architectures. Its
    426   appearance here shows how the object file may change, but the 64-bit
    427   format is otherwise unspecified. Other classes will be defined as
    428   necessary, with different basic types and sizes for object file
    429   data.
    430 
    431 * EI_DATA
    432 
    433   Byte e_ident[EI_DATA] specifies the data encoding of the
    434   processor-specific data in the object file. The following encodings
    435   are currently defined.
    436 
    437              Name           Value  Meaning
    438              ====           =====  =======
    439 	     ELFDATANONE        0  Invalid data encoding
    440              ELFDATA2LSB        1  See below
    441              ELFDATA2MSB        2  See below
    442 
    443   More information on these encodings appears below. Other values are
    444   reserved and will be assigned to new encodings as necessary.
    445 
    446 * EI_VERSION
    447 
    448   Byte e_ident[EI_VERSION] specifies the ELF header version number.
    449   Currently this, value must be EV_CURRENT, as explained above for
    450   e_version.
    451 
    452 * EI_PAD
    453 
    454   This value marks the beginning of the unused bytes in e_ident. These
    455   bytes are reserved and set to zero; programs that read object files
    456   should ignore them.  The value of EI_PAD will change in the future
    457   if currently unused bytes are given meanings.
    458 
    459 A file's data encoding specifies how to interpret the basic objects in
    460 a file. As described above, class ELFCLASS32 files use objects that
    461 occupy 1, 2, and 4 bytes. Under the defined encodings, objects are
    462 represented as shown below. Byte numbers appear in the upper left
    463 corners.
    464 
    465 Encoding ELFDATA2LSB specifies 2's complement values, with the least
    466 significant byte occupying the lowest address.
    467 
    468 + Figure 1-5: Data Encoding ELFDATA2LSB
    469 
    470                0------+
    471       0x0102   |  01  |
    472                +------+
    473                0------1------+
    474     0x010204   |  02  |  01  |
    475                +------+------+
    476                0------1------2------3------+
    477   0x01020304   |  04  |  03  |  02  |  01  |
    478                +------+------+------+------+
    479 
    480 ELFDATA2MSB specifies 2's complement values, with the most significant
    481 byte occupying the lowest address.
    482 
    483 + Figure 1-6: Data Encoding ELFDATA2MSB
    484 
    485                0------+
    486       0x0102   |  01  |
    487                +------+
    488                0------1------+
    489     0x010204   |  01  |  02  |
    490                +------+------+
    491                0------1------2------3------+
    492   0x01020304   |  01  |  02  |  03  |  04  |
    493                +------+------+------+------+
    494 
    495 
    496 			 Machine Information
    497 
    498 For file identification in e_ident, the 32-bit Intel Architecture
    499 requires the following values.
    500 
    501 + Figure 1-7: 32-bit Intel Architecture Identification, e_ident 
    502 
    503   Position           Value
    504   ========           =====
    505   e_ident[EI_CLASS]  ELFCLASS32
    506   e_ident[EI_DATA]   ELFDATA2LSB
    507 
    508 Processor identification resides in the ELF header's e_machine member
    509 and must have the value EM_386.
    510 
    511 The ELF header's e_flags member holds bit flags associated with the
    512 file. The 32-bit Intel Architecture defines no flags; so this member
    513 contains zero.
    514 
    515 
    516    =========================== Sections ===========================
    517 
    518 
    519 An object file's section header table lets one locate all the file's
    520 sections. The section header table is an array of Elf32_Shdr
    521 structures as described below. A section header table index is a
    522 subscript into this array. The ELF header's e_shoff member gives the
    523 byte offset from the beginning of the file to the section header
    524 table; e_shnum tells how many entries the section header table
    525 contains; e_shentsize gives the size in bytes of each entry.
    526 
    527 Some section header table indexes are reserved; an object file will
    528 not have sections for these special indexes.
    529 
    530 + Figure 1-8: Special Section Indexes
    531 
    532   Name             Value
    533   ====             =====
    534   SHN_UNDEF            0
    535   SHN_LORESERVE   0xff00
    536   SHN_LOPROC      0xff00
    537   SHN_HIPROC      0xff1f
    538   SHN_ABS         0xfff1
    539   SHN_COMMON      0xfff2
    540   SHN_HIRESERVE   0xffff
    541 
    542 * SHN_UNDEF
    543 
    544   This value marks an undefined, missing, irrelevant, or otherwise
    545   meaningless section reference. For example, a symbol ``defined''
    546   relative to section number SHN_UNDEF is an undefined symbol.
    547 
    548 NOTE: Although index 0 is reserved as the undefined value, the section
    549 header table contains an entry for index 0. That is, if the e_shnum
    550 member of the ELF header says a file has 6 entries in the section
    551 header table, they have the indexes 0 through 5. The contents of the
    552 initial entry are specified later in this section.
    553 
    554 * SHN_LORESERVE
    555 
    556   This value specifies the lower bound of the range of reserved
    557   indexes.
    558 
    559 * SHN_LOPROC through SHN_HIPROC
    560 
    561   Values in this inclusive range are reserved for processor-specific
    562   semantics.
    563 
    564 * SHN_ABS
    565 
    566   This value specifies absolute values for the corresponding
    567   reference. For example, symbols defined relative to section number
    568   SHN_ABS have absolute values and are not affected by relocation.
    569 
    570 * SHN_COMMON
    571 
    572   Symbols defined relative to this section are common symbols, such as
    573   FORTRAN COMMON or unallocated C external variables.
    574 
    575 * SHN_HIRESERVE
    576 
    577   This value specifies the upper bound of the range of reserved
    578   indexes. The system reserves indexes between SHN_LORESERVE and
    579   SHN_HIRESERVE, inclusive; the values do not reference the section
    580   header table. That is, the section header table does not contain
    581   entries for the reserved indexes.
    582 
    583 Sections contain all information in an object file, except the ELF
    584 header, the program header table, and the section header
    585 table. Moreover, object files' sections satisfy several conditions.
    586 
    587 * Every section in an object file has exactly one section header
    588   describing it. Section headers may exist that do not have a section.
    589 * Each section occupies one contiguous (possibly empty) sequence of
    590   bytes within a file.
    591 * Sections in a file may not overlap. No byte in a file resides in
    592   more than one section.
    593 * An object file may have inactive space. The various headers and the
    594   sections might not ``cover'' every byte in an object file. The
    595   contents of the inactive data are unspecified.
    596 
    597 A section header has the following structure.
    598 
    599 + Figure 1-9: Section Header
    600 
    601   typedef struct {
    602       Elf32_Word	sh_name;
    603       Elf32_Word	sh_type;
    604       Elf32_Word	sh_flags;
    605       Elf32_Addr	sh_addr;
    606       Elf32_Off		sh_offset;
    607       Elf32_Word	sh_size;
    608       Elf32_Word	sh_link;
    609       Elf32_Word	sh_info;
    610       Elf32_Word	sh_addralign;
    611       Elf32_Word	sh_entsize;
    612   } Elf32_Shdr;
    613 
    614 * sh_name
    615 
    616   This member specifies the name of the section. Its value is an index
    617   into the section header string table section [see ``String Table''
    618   below], giving the location of a null-terminated string.
    619 
    620 * sh_type
    621 
    622   This member categorizes the section's contents and semantics.
    623   Section types and their descriptions appear below.
    624 
    625 * sh_flags
    626 
    627   Sections support 1-bit flags that describe miscellaneous attributes.
    628   Flag definitions appear below.
    629 
    630 * sh_addr
    631 
    632   If the section will appear in the memory image of a process, this
    633   member gives the address at which the section's first byte should
    634   reside. Otherwise, the member contains 0.
    635 
    636 * sh_offset
    637 
    638   This member's value gives the byte offset from the beginning of the
    639   file to the first byte in the section. One section type, SHT_NOBITS
    640   described below, occupies no space in the file, and its sh_offset
    641   member locates the conceptual placement in the file.
    642 
    643 * sh_size
    644 
    645   This member gives the section's size in bytes.  Unless the section
    646   type is SHT_NOBITS, the section occupies sh_size bytes in the file.
    647   A section of type SHT_NOBITS may have a non-zero size, but it
    648   occupies no space in the file.
    649 
    650 * sh_link
    651 
    652   This member holds a section header table index link, whose
    653   interpretation depends on the section type. A table below describes
    654   the values.
    655 
    656 * sh_info
    657 
    658   This member holds extra information, whose interpretation depends on
    659   the section type. A table below describes the values.
    660 
    661 * sh_addralign
    662 
    663   Some sections have address alignment constraints. For example, if a
    664   section holds a doubleword, the system must ensure doubleword
    665   alignment for the entire section. That is, the value of sh_addr must
    666   be congruent to 0, modulo the value of sh_addralign. Currently, only
    667   0 and positive integral powers of two are allowed. Values 0 and 1
    668   mean the section has no alignment constraints.
    669 
    670 * sh_entsize
    671 
    672   Some sections hold a table of fixed-size entries, such as a symbol
    673   table. For such a section, this member gives the size in bytes of
    674   each entry. The member contains 0 if the section does not hold a
    675   table of fixed-size entries.
    676 
    677 A section header's sh_type member specifies the section's semantics.
    678 
    679 + Figure 1-10: Section Types, sh_type
    680 
    681   Name               Value
    682   ====               =====
    683   SHT_NULL               0
    684   SHT_PROGBITS           1
    685   SHT_SYMTAB             2
    686   SHT_STRTAB	         3
    687   SHT_RELA	         4
    688   SHT_HASH	         5
    689   SHT_DYNAMIC            6
    690   SHT_NOTE	         7
    691   SHT_NOBITS	         8
    692   SHT_REL	         9
    693   SHT_SHLIB             10
    694   SHT_DYNSYM            11
    695   SHT_LOPROC    0x70000000
    696   SHT_HIPROC    0x7fffffff
    697   SHT_LOUSER    0x80000000
    698   SHT_HIUSER    0xffffffff
    699 
    700 * SHT_NULL
    701 
    702   This value marks the section header as inactive; it does not have an
    703   associated section. Other members of the section header have
    704   undefined values.
    705 
    706 * SHT_PROGBITS
    707 
    708   The section holds information defined by the program, whose format
    709   and meaning are determined solely by the program.
    710 
    711 * SHT_SYMTAB and SHT_DYNSYM
    712 
    713   These sections hold a symbol table. Currently, an object file may
    714   have only one section of each type, but this restriction may be
    715   relaxed in the future. Typically, SHT_SYMTAB provides symbols for
    716   link editing, though it may also be used for dynamic linking. As a
    717   complete symbol table, it may contain many symbols unnecessary for
    718   dynamic linking. Consequently, an object file may also contain a
    719   SHT_DYNSYM section, which holds a minimal set of dynamic linking
    720   symbols, to save space. See ``Symbol Table'' below for details.
    721 
    722 * SHT_STRTAB
    723 
    724   The section holds a string table. An object file may have multiple
    725   string table sections. See ``String Table'' below for details.
    726 
    727 * SHT_RELA
    728 
    729   The section holds relocation entries with explicit addends, such as
    730   type Elf32_Rela for the 32-bit class of object files. An object file
    731   may have multiple relocation sections.  See ``Relocation'' below for
    732   details.
    733 
    734 * SHT_HASH
    735 
    736   The section holds a symbol hash table. All objects participating in
    737   dynamic linking must contain a symbol hash table. Currently, an
    738   object file may have only one hash table, but this restriction may
    739   be relaxed in the future. See ``Hash Table'' in Part 2 for details.
    740 
    741 * SHT_DYNAMIC
    742 
    743   The section holds information for dynamic linking. Currently, an
    744   object file may have only one dynamic section, but this restriction
    745   may be relaxed in the future. See ``Dynamic Section'' in Part 2 for
    746   details.
    747 
    748 * SHT_NOTE
    749 
    750   The section holds information that marks the file in some way. See
    751   ``Note Section'' in Part 2 for details.
    752 
    753 * SHT_NOBITS
    754 
    755   A section of this type occupies no space in the file but otherwise
    756   resembles SHT_PROGBITS. Although this section contains no bytes, the
    757   sh_offset member contains the conceptual file offset.
    758 
    759 * SHT_REL
    760 
    761   The section holds relocation entries without explicit addends, such
    762   as type Elf32_Rel for the 32-bit class of object files. An object
    763   file may have multiple relocation sections. See ``Relocation'' below
    764   for details.
    765 
    766 * SHT_SHLIB
    767 
    768   This section type is reserved but has unspecified
    769   semantics. Programs that contain a section of this type do not
    770   conform to the ABI.
    771 
    772 * SHT_LOPROC through SHT_HIPROC
    773 
    774   Values in this inclusive range are reserved for processor-specific
    775   semantics.
    776 
    777 * SHT_LOUSER
    778 
    779   This value specifies the lower bound of the range of indexes
    780   reserved for application programs.
    781 
    782 * SHT_HIUSER
    783 
    784   This value specifies the upper bound of the range of indexes
    785   reserved for application programs. Section types between SHT_LOUSER
    786   and SHT_HIUSER may be used by the application, without conflicting
    787   with current or future system-defined section types.
    788 
    789 Other section type values are reserved. As mentioned before, the
    790 section header for index 0 (SHN_UNDEF) exists, even though the index
    791 marks undefined section references. This entry holds the following.
    792 
    793 + Figure 1-11: Section Header Table Entry: Index 0
    794 
    795   Name            Value    Note
    796   ====            =====    ====
    797   sh_name           0      No name
    798   sh_type        SHT_NULL  Inactive
    799   sh_flags          0      No flags
    800   sh_addr           0      No address
    801   sh_offset         0      No file offset
    802   sh_size           0      No size
    803   sh_link	SHN_UNDEF  No link information
    804   sh_info	    0      No auxiliary information
    805   sh_addralign	    0      No alignment
    806   sh_entsize        0      No entries
    807 
    808 A section header's sh_flags member holds 1-bit flags that describe the
    809 section's attributes. Defined values appear below; other values are
    810 reserved.
    811 
    812 + Figure 1-12: Section Attribute Flags, sh_flags
    813 
    814   Name                Value
    815   ====                =====
    816   SHF_WRITE             0x1
    817   SHF_ALLOC             0x2
    818   SHF_EXECINSTR         0x4
    819   SHF_MASKPROC   0xf0000000
    820 
    821 If a flag bit is set in sh_flags, the attribute is ``on'' for the
    822 section. Otherwise, the attribute is ``off'' or does not apply.
    823 Undefined attributes are set to zero.
    824 
    825 * SHF_WRITE
    826 
    827   The section contains data that should be writable during process
    828   execution.
    829 
    830 * SHF_ALLOC
    831 
    832   The section occupies memory during process execution. Some control
    833   sections do not reside in the memory image of an object file; this
    834   attribute is off for those sections.
    835 
    836 * SHF_EXECINSTR
    837 
    838   The section contains executable machine instructions.
    839 
    840 * SHF_MASKPROC
    841 
    842   All bits included in this mask are reserved for processor-specific
    843   semantics.
    844 
    845 Two members in the section header, sh_link and sh_info, hold special
    846 information, depending on section type.
    847 
    848 + Figure 1-13: sh_link and sh_info Interpretation
    849 
    850   sh_type      sh_link                        sh_info
    851   =======      =======                        =======
    852   SHT_DYNAMIC  The section header index of    0
    853                the string table used by
    854                entries in the section.
    855   SHT_HASH     The section header index of    0
    856                the symbol table to which the
    857                hash table applies.
    858   SHT_REL,     The section header index of    The section header index of
    859   SHT_RELA     the associated symbol table.   the section to which the
    860                                               relocation applies.
    861   SHT_SYMTAB,  The section header index of    One greater than the symbol
    862   SHT_DYNSYM   the associated string table.   table index of the last local
    863                                               symbol (binding STB_LOCAL).
    864   other        SHN_UNDEF                      0
    865 
    866 
    867 			   Special Sections
    868 
    869 Various sections hold program and control information. Sections in the
    870 list below are used by the system and have the indicated types and
    871 attributes.
    872 
    873 + Figure 1-14: Special Sections
    874 
    875   Name         Type           Attributes
    876   ====         ====           ==========
    877   .bss         SHT_NOBITS     SHF_ALLOC+SHF_WRITE
    878   .comment     SHT_PROGBITS   none
    879   .data        SHT_PROGBITS   SHF_ALLOC+SHF_WRITE
    880   .data1       SHT_PROGBITS   SHF_ALLOC+SHF_WRITE
    881   .debug       SHT_PROGBITS   none
    882   .dynamic     SHT_DYNAMIC    see below
    883   .dynstr      SHT_STRTAB     SHF_ALLOC
    884   .dynsym      SHT_DYNSYM     SHF_ALLOC
    885   .fini        SHT_PROGBITS   SHF_ALLOC+SHF_EXECINSTR
    886   .got         SHT_PROGBITS   see below
    887   .hash        SHT_HASH       SHF_ALLOC
    888   .init        SHT_PROGBITS   SHF_ALLOC+SHF_EXECINSTR
    889   .interp      SHT_PROGBITS   see below
    890   .line        SHT_PROGBITS   none
    891   .note        SHT_NOTE       none
    892   .plt         SHT_PROGBITS   see below
    893   .rel<name>   SHT_REL        see below
    894   .rela<name>  SHT_RELA       see below
    895   .rodata      SHT_PROGBITS   SHF_ALLOC
    896   .rodata1     SHT_PROGBITS   SHF_ALLOC
    897   .shstrtab    SHT_STRTAB     none
    898   .strtab      SHT_STRTAB     see below
    899   .symtab      SHT_SYMTAB     see below
    900   .text        SHT_PROGBITS   SHF_ALLOC+SHF_EXECINSTR
    901 
    902 * .bss
    903 
    904   This section holds uninitialized data that contribute to the
    905   program's memory image. By definition, the system initializes the
    906   data with zeros when the program begins to run. The section occupies
    907   no file space, as indicated by the section type, SHT_NOBITS.
    908 
    909 * .comment
    910 
    911   This section holds version control information.
    912 
    913 * .data and .data1
    914 
    915   These sections hold initialized data that contribute to the
    916   program's memory image.
    917 
    918 * .debug
    919 
    920   This section holds information for symbolic debugging. The contents
    921   are unspecified.
    922 
    923 * .dynamic
    924 
    925   This section holds dynamic linking information. The section's
    926   attributes will include the SHF_ALLOC bit. Whether the SHF_WRITE bit
    927   is set is processor specific. See Part 2 for more information.
    928 
    929 * .dynstr
    930 
    931   This section holds strings needed for dynamic linking, most commonly
    932   the strings that represent the names associated with symbol table
    933   entries. See Part 2 for more information.
    934 
    935 * .dynsym
    936 
    937   This section holds the dynamic linking symbol table, as ``Symbol
    938   Table'' describes. See Part 2 for more information.
    939 
    940 * .fini
    941 
    942   This section holds executable instructions that contribute to the
    943   process termination code. That is, when a program exits normally,
    944   the system arranges to execute the code in this section.
    945 
    946 * .got
    947 
    948   This section holds the global offset table. See ``Special Sections''
    949   in Part 1 and ``Global Offset Table'' in Part 2 for more
    950   information.
    951 
    952 * .hash
    953 
    954   This section holds a symbol hash table. See ``Hash Table'' in Part 2
    955   for more information.
    956 
    957 * .init
    958 
    959   This section holds executable instructions that contribute to the
    960   process initialization code. That is, when a program starts to run,
    961   the system arranges to execute the code in this section before
    962   calling the main program entry point (called main for C programs).
    963 
    964 * .interp
    965 
    966   This section holds the path name of a program interpreter. If the
    967   file has a loadable segment that includes the section, the section's
    968   attributes will include the SHF_ALLOC bit; otherwise, that bit will
    969   be off. See Part 2 for more information.
    970 
    971 * .line
    972 
    973   This section holds line number information for symbolic debugging,
    974   which describes the correspondence between the source program and
    975   the machine code. The contents are unspecified.
    976 
    977 * .note
    978 
    979   This section holds information in the format that ``Note Section''
    980   in Part 2 describes.
    981 
    982 * .plt
    983 
    984   This section holds the procedure linkage table. See ``Special
    985   Sections'' in Part 1 and ``Procedure Linkage Table'' in Part 2 for
    986   more information.
    987 
    988 * .rel<name> and .rela<name>
    989 
    990   These sections hold relocation information, as ``Relocation'' below
    991   describes. If the file has a loadable segment that includes
    992   relocation, the sections' attributes will include the SHF_ALLOC bit;
    993   otherwise, that bit will be off. Conventionally, <name> is supplied
    994   by the section to which the relocations apply. Thus a relocation
    995   section for .text normally would have the name .rel.text or
    996   .rela.text.
    997 
    998 * .rodata and .rodata1
    999 
   1000   These sections hold read-only data that typically contribute to a
   1001   non-writable segment in the process image. See ``Program Header'' in
   1002   Part 2 for more information.
   1003 
   1004 * .shstrtab
   1005 
   1006   This section holds section names.
   1007 
   1008 * .strtab
   1009 
   1010   This section holds strings, most commonly the strings that represent
   1011   the names associated with symbol table entries. If the file has a
   1012   loadable segment that includes the symbol string table, the
   1013   section's attributes will include the SHF_ALLOC bit; otherwise, that
   1014   bit will be off.
   1015 
   1016 * .symtab
   1017 
   1018   This section holds a symbol table, as ``Symbol Table'' in this
   1019   section describes. If the file has a loadable segment that includes
   1020   the symbol table, the section's attributes will include the
   1021   SHF_ALLOC bit; otherwise, that bit will be off.
   1022 
   1023 * .text
   1024 
   1025   This section holds the ``text,'' or executable instructions, of a
   1026   program.
   1027 
   1028 Section names with a dot (.) prefix are reserved for the system,
   1029 although applications may use these sections if their existing
   1030 meanings are satisfactory. Applications may use names without the
   1031 prefix to avoid conflicts with system sections. The object file format
   1032 lets one define sections not in the list above. An object file may
   1033 have more than one section with the same name.
   1034 
   1035 Section names reserved for a processor architecture are formed by
   1036 placing an abbreviation of the architecture name ahead of the section
   1037 name. The name should be taken from the architecture names used for
   1038 e_machine. For instance .FOO.psect is the psect section defined by the
   1039 FOO architecture. Existing extensions are called by their historical
   1040 names.
   1041 
   1042 		       Pre-existing Extensions
   1043 		       =======================
   1044 			 .sdata     .tdesc
   1045 			 .sbss      .lit4
   1046 			 .lit8      .reginfo
   1047 			 .gptab     .liblist
   1048 			 .conflict
   1049 
   1050 
   1051    ========================= String Table =========================
   1052 
   1053 
   1054 String table sections hold null-terminated character sequences,
   1055 commonly called strings. The object file uses these strings to
   1056 represent symbol and section names. One references a string as an
   1057 index into the string table section. The first byte, which is index
   1058 zero, is defined to hold a null character. Likewise, a string table's
   1059 last byte is defined to hold a null character, ensuring null
   1060 termination for all strings. A string whose index is zero specifies
   1061 either no name or a null name, depending on the context. An empty
   1062 string table section is permitted; its section header's sh_size member
   1063 would contain zero. Non-zero indexes are invalid for an empty string
   1064 table.
   1065 
   1066 A section header's sh_name member holds an index into the section
   1067 header string table section, as designated by the e_shstrndx member of
   1068 the ELF header. The following figures show a string table with 25
   1069 bytes and the strings associated with various indexes.
   1070 
   1071        Index   +0   +1   +2   +3   +4   +5   +6   +7   +8   +9
   1072        =====   ==   ==   ==   ==   ==   ==   ==   ==   ==   ==
   1073           0    \0   n    a    m    e    .    \0   V    a    r     
   1074          10    i    a    b    l    e    \0   a    b    l    e
   1075          20    \0   \0   x    x    \0
   1076 
   1077 
   1078 + Figure 1-15: String Table Indexes
   1079 
   1080   Index   String
   1081   =====   ======
   1082       0   none
   1083       1   "name."
   1084       7   "Variable"
   1085      11   "able"
   1086      16   "able"
   1087      24   null string
   1088 
   1089 As the example shows, a string table index may refer to any byte in
   1090 the section. A string may appear more than once; references to
   1091 substrings may exist; and a single string may be referenced multiple
   1092 times. Unreferenced strings also are allowed.
   1093 
   1094 
   1095    ========================= Symbol Table =========================
   1096 
   1097 
   1098 An object file's symbol table holds information needed to locate and
   1099 relocate a program's symbolic definitions and references. A symbol
   1100 table index is a subscript into this array. Index 0 both designates
   1101 the first entry in the table and serves as the undefined symbol
   1102 index. The contents of the initial entry are specified later in this
   1103 section.
   1104 
   1105                              Name       Value
   1106                              ====       =====
   1107 			     STN_UNDEF      0
   1108 
   1109 A symbol table entry has the following format.
   1110 
   1111 + Figure 1-16: Symbol Table Entry
   1112 
   1113   typedef struct {
   1114       Elf32_Word	st_name;
   1115       Elf32_Addr	st_value;
   1116       Elf32_Word	st_size;
   1117       unsigned char	st_info;
   1118       unsigned char	st_other;
   1119       Elf32_Half	st_shndx;
   1120   } Elf32_Sym;
   1121 
   1122 * st_name
   1123 
   1124   This member holds an index into the object file's symbol string
   1125   table, which holds the character representations of the symbol
   1126   names. If the value is non-zero, it represents a string table index
   1127   that gives the symbol name. Otherwise, the symbol table entry has no
   1128   name.
   1129 
   1130 NOTE: External C symbols have the same names in C and object files'
   1131 symbol tables.
   1132 
   1133 * st_value
   1134 
   1135   This member gives the value of the associated symbol. Depending on
   1136   the context, this may be an absolute value, an address, etc.;
   1137   details appear below.
   1138 
   1139 * st_size
   1140 
   1141   Many symbols have associated sizes. For example, a data object's
   1142   size is the number of bytes contained in the object. This member
   1143   holds 0 if the symbol has no size or an unknown size.
   1144 
   1145 * st_info
   1146 
   1147   This member specifies the symbol's type and binding attributes.  A
   1148   list of the values and meanings appears below. The following code
   1149   shows how to manipulate the values.
   1150 
   1151     #define ELF32_ST_BIND(i)	((i)>>4)
   1152     #define ELF32_ST_TYPE(i)	((i)&0xf)
   1153     #define ELF32_ST_INFO(b, t)	(((b)<<4)+((t)&0xf))
   1154 
   1155 * st_other
   1156 
   1157   This member currently holds 0 and has no defined meaning.
   1158 
   1159 * st_shndx
   1160 
   1161   Every symbol table entry is ``defined'' in relation to some section;
   1162   this member holds the relevant section header table index. As Figure
   1163   1-8 {*} and the related text describe, some section indexes indicate
   1164   special meanings.
   1165 
   1166 A symbol's binding determines the linkage visibility and behavior.
   1167 
   1168 + Figure 1-17: Symbol Binding, ELF32_ST_BIND
   1169 
   1170   Name        Value
   1171   ====        =====
   1172   STB_LOCAL       0
   1173   STB_GLOBAL      1
   1174   STB_WEAK        2
   1175   STB_LOPROC     13
   1176   STB_HIPROC     15
   1177 
   1178 * STB_LOCAL
   1179 
   1180   Local symbols are not visible outside the object file containing
   1181   their definition. Local symbols of the same name may exist in
   1182   multiple files without interfering with each other.
   1183 
   1184 * STB_GLOBAL
   1185 
   1186   Global symbols are visible to all object files being combined. One
   1187   file's definition of a global symbol will satisfy another file's
   1188   undefined reference to the same global symbol.
   1189 
   1190 * STB_WEAK
   1191 
   1192   Weak symbols resemble global symbols, but their definitions have
   1193   lower precedence.
   1194 
   1195 * STB_LOPROC through STB_HIPROC
   1196 
   1197   Values in this inclusive range are reserved for processor-specific
   1198   semantics.
   1199 
   1200 Global and weak symbols differ in two major ways.
   1201 
   1202 * When the link editor combines several relocatable object files, it
   1203   does not allow multiple definitions of STB_GLOBAL symbols with the
   1204   same name. On the other hand, if a defined global symbol exists, the
   1205   appearance of a weak symbol with the same name will not cause an
   1206   error. The link editor honors the global definition and ignores the
   1207   weak ones. Similarly, if a common symbol exists (i.e., a symbol
   1208   whose st_shndx field holds SHN_COMMON), the appearance of a weak
   1209   symbol with the same name will not cause an error. The link editor
   1210   honors the common definition and ignores the weak ones.
   1211 
   1212 * When the link editor searches archive libraries, it extracts archive
   1213   members that contain definitions of undefined global symbols. The
   1214   member's definition may be either a global or a weak symbol. The
   1215   link editor does not extract archive members to resolve undefined
   1216   weak symbols. Unresolved weak symbols have a zero value.
   1217 
   1218 In each symbol table, all symbols with STB_LOCAL binding precede the
   1219 weak and global symbols. As ``Sections'' above describes, a symbol
   1220 table section's sh_info section header member holds the symbol table
   1221 index for the first non-local symbol.
   1222 
   1223 A symbol's type provides a general classification for the associated
   1224 entity.
   1225 
   1226 + Figure 1-18: Symbol Types, ELF32_ST_TYPE
   1227 
   1228   Name         Value
   1229   ====         =====
   1230   STT_NOTYPE       0
   1231   STT_OBJECT       1
   1232   STT_FUNC         2
   1233   STT_SECTION      3
   1234   STT_FILE         4
   1235   STT_LOPROC      13
   1236   STT_HIPROC      15
   1237 
   1238 * STT_NOTYPE
   1239 
   1240   The symbol's type is not specified.
   1241 
   1242 * STT_OBJECT
   1243 
   1244   The symbol is associated with a data object, such as a variable, an
   1245   array, etc.
   1246 
   1247 * STT_FUNC
   1248 
   1249   The symbol is associated with a function or other executable code.
   1250 
   1251 * STT_SECTION
   1252 
   1253   The symbol is associated with a section. Symbol table entries of
   1254   this type exist primarily for relocation and normally have STB_LOCAL
   1255   binding.
   1256 
   1257 * STT_FILE
   1258 
   1259   Conventionally, the symbol's name gives the name of the source file
   1260   associated with the object file. A file symbol has STB_LOCAL
   1261   binding, its section index is SHN_ABS, and it precedes the other
   1262   STB_LOCAL symbols for the file, if it is present.
   1263 
   1264 * STT_LOPROC through STT_HIPROC
   1265 
   1266   Values in this inclusive range are reserved for processor-specific
   1267   semantics.
   1268 
   1269 Function symbols (those with type STT_FUNC) in shared object files
   1270 have special significance. When another object file references a
   1271 function from a shared object, the link editor automatically creates a
   1272 procedure linkage table entry for the referenced symbol. Shared object
   1273 symbols with types other than STT_FUNC will not be referenced
   1274 automatically through the procedure linkage table.
   1275 
   1276 If a symbol's value refers to a specific location within a section,
   1277 its section index member, st_shndx, holds an index into the section
   1278 header table. As the section moves during relocation, the symbol's
   1279 value changes as well, and references to the symbol continue to
   1280 ``point'' to the same location in the program. Some special section
   1281 index values give other semantics.
   1282 
   1283 * SHN_ABS
   1284 
   1285   The symbol has an absolute value that will not change because of
   1286   relocation.
   1287 
   1288 * SHN_COMMON
   1289 
   1290   The symbol labels a common block that has not yet been allocated.
   1291   The symbol's value gives alignment constraints, similar to a
   1292   section's sh_addralign member. That is, the link editor will
   1293   allocate the storage for the symbol at an address that is a multiple
   1294   of st_value. The symbol's size tells how many bytes are required.
   1295 
   1296 * SHN_UNDEF
   1297 
   1298   This section table index means the symbol is undefined. When the
   1299   link editor combines this object file with another that defines the
   1300   indicated symbol, this file's references to the symbol will be
   1301   linked to the actual definition.
   1302 
   1303 As mentioned above, the symbol table entry for index 0 (STN_UNDEF) is
   1304 reserved; it holds the following.
   1305 
   1306 + Figure 1-19: Symbol Table Entry: Index 0
   1307 
   1308   Name        Value    Note
   1309   ====        =====    ====
   1310   st_name       0      No name
   1311   st_value      0      Zero value
   1312   st_size       0      No size
   1313   st_info       0      No type, local binding
   1314   st_other      0
   1315   st_shndx  SHN_UNDEF  No section
   1316 
   1317 
   1318 			    Symbol Values
   1319 
   1320 Symbol table entries for different object file types have slightly
   1321 different interpretations for the st_value member.
   1322 
   1323 * In relocatable files, st_value holds alignment constraints for a
   1324   symbol whose section index is SHN_COMMON.
   1325 * In relocatable files, st_value holds a section offset for a defined
   1326   symbol. That is, st_value is an offset from the beginning of the
   1327   section that st_shndx identifies.
   1328 * In executable and shared object files, st_value holds a virtual
   1329   address. To make these files' symbols more useful for the dynamic
   1330   linker, the section offset (file interpretation) gives way to a
   1331   virtual address (memory interpretation) for which the section number
   1332   is irrelevant.
   1333 
   1334 Although the symbol table values have similar meanings for different
   1335 object files, the data allow efficient access by the appropriate
   1336 programs.
   1337 
   1338 
   1339    ========================== Relocation ==========================
   1340 
   1341 
   1342 Relocation is the process of connecting symbolic references with
   1343 symbolic definitions. For example, when a program calls a function,
   1344 the associated call instruction must transfer control to the proper
   1345 destination address at execution. In other words, relocatable files
   1346 must have information that describes how to modify their section
   1347 contents, thus allowing executable and shared object files to hold the
   1348 right information for a process's program image. Relocation entries
   1349 are these data.
   1350 
   1351 + Figure 1-20: Relocation Entries
   1352 
   1353   typedef struct {
   1354       Elf32_Addr	r_offset;
   1355       Elf32_Word	r_info;
   1356   } Elf32_Rel;
   1357 
   1358   typedef struct {
   1359       Elf32_Addr	r_offset;
   1360       Elf32_Word	r_info;
   1361       Elf32_Sword	r_addend;
   1362   } Elf32_Rela;
   1363 
   1364 * r_offset
   1365 
   1366   This member gives the location at which to apply the relocation
   1367   action. For a relocatable file, the value is the byte offset from
   1368   the beginning of the section to the storage unit affected by the
   1369   relocation. For an executable file or a shared object, the value is
   1370   the virtual address of the storage unit affected by the relocation.
   1371 
   1372 * r_info
   1373 
   1374   This member gives both the symbol table index with respect to which
   1375   the relocation must be made, and the type of relocation to apply.
   1376   For example, a call instruction's relocation entry would hold the
   1377   symbol table index of the function being called. If the index is
   1378   STN_UNDEF, the undefined symbol index, the relocation uses 0 as the
   1379   ``symbol value.'' Relocation types are processor-specific. When the
   1380   text refers to a relocation entry's relocation type or symbol table
   1381   index, it means the result of applying ELF32_R_TYPE or ELF32_R_SYM,
   1382   respectively, to the entry's r_info member.
   1383 
   1384     #define ELF32_R_SYM(i)	((i)>>8)
   1385     #define ELF32_R_TYPE(i)	((unsigned char)(i))
   1386     #define ELF32_R_INFO(s, t)	((s)<<8+(unsigned char)(t))
   1387 
   1388 * r_addend
   1389 
   1390   This member specifies a constant addend used to compute the value to
   1391   be stored into the relocatable field.
   1392 
   1393 As shown above, only Elf32_Rela entries contain an explicit
   1394 addend. Entries of type Elf32_Rel store an implicit addend in the
   1395 location to be modified. Depending on the processor architecture, one
   1396 form or the other might be necessary or more convenient. Consequently,
   1397 an implementation for a particular machine may use one form
   1398 exclusively or either form depending on context.
   1399 
   1400 A relocation section references two other sections: a symbol table and
   1401 a section to modify. The section header's sh_info and sh_link members,
   1402 described in ``Sections'' above, specify these relationships.
   1403 Relocation entries for different object files have slightly different
   1404 interpretations for the r_offset member.
   1405 
   1406 * In relocatable files, r_offset holds a section offset. That is, the
   1407   relocation section itself describes how to modify another section in
   1408   the file; relocation offsets designate a storage unit within the
   1409   second section.
   1410 * In executable and shared object files, r_offset holds a virtual
   1411   address. To make these files' relocation entries more useful for the
   1412   dynamic linker, the section offset (file interpretation) gives way
   1413   to a virtual address (memory interpretation).
   1414 
   1415 Although the interpretation of r_offset changes for different object
   1416 files to allow efficient access by the relevant programs, the
   1417 relocation types' meanings stay the same.
   1418 
   1419 
   1420 			   Relocation Types
   1421 
   1422 Relocation entries describe how to alter the following instruction and
   1423 data fields (bit numbers appear inthe lower box corners).
   1424 
   1425 + Figure 1-21: Relocatable Fields 
   1426 
   1427     +---------------------------+
   1428     |          word32           |
   1429    31---------------------------0
   1430 
   1431 
   1432 * word32
   1433 
   1434   This specifies a 32-bit field occupying 4 bytes with arbitrary byte
   1435   alignment. These values use the same byte order as other word values
   1436   in the 32-bit Intel Architecture.
   1437 
   1438                            3------2------1------0------+
   1439 	     0x01020304    |  01  |  02  |  03  |  04  |
   1440                           31------+------+------+------0
   1441 
   1442 Calculations below assume the actions are transforming a relocatable
   1443 file into either an executable or a shared object file. Conceptually,
   1444 the link editor merges one or more relocatable files to form the
   1445 output. It first decides how to combine and locate the input files,
   1446 then updates the symbol values, and finally performs the relocation.
   1447 Relocations applied to executable or shared object files are similar
   1448 and accomplish the same result. Descriptions below use the following
   1449 notation.
   1450 
   1451 * A
   1452 
   1453   This means the addend used to compute the value of the relocatable
   1454   field.
   1455 
   1456 * B
   1457 
   1458   This means the base address at which a shared object has been loaded
   1459   into memory during execution. Generally, a shared object file is
   1460   built with a 0 base virtual address, but the execution address will
   1461   be different.
   1462 
   1463 * G
   1464 
   1465   This means the offset into the global offset table at which the
   1466   address of the relocation entry's symbol will reside during
   1467   execution. See ``Global Offset Table'' in Part 2 for more
   1468   information.
   1469 
   1470 * GOT
   1471 
   1472   This means the address of the global offset table. See ``Global
   1473   Offset Table'' in Part 2 for more information.
   1474 
   1475 * L
   1476 
   1477   This means the place (section offset or address) of the procedure
   1478   linkage table entry for a symbol. A procedure linkage table entry
   1479   redirects a function call to the proper destination. The link editor
   1480   builds the initial procedure linkage table, and the dynamic linker
   1481   modifies the entries during execution. See ``Procedure Linkage
   1482   Table'' in Part 2 for more information.
   1483 
   1484 * P
   1485 
   1486   This means the place (section offset or address) of the storage unit
   1487   being relocated (computed using r_offset).
   1488 
   1489 * S
   1490 
   1491   This means the value of the symbol whose index resides in the
   1492   relocation entry.
   1493 
   1494 A relocation entry's r_offset value designates the offset or virtual
   1495 address of the first byte of the affected storage unit. The relocation
   1496 type specifies which bits to change and how to calculate their
   1497 values. The SYSTEM V architecture uses only Elf32_Rel relocation
   1498 entries, the field to be relocated holds the addend. In all cases, the
   1499 addend and the computed result use the same byte order.
   1500 
   1501 + Figure 1-22: Relocation Types
   1502 
   1503   Name            Value  Field   Calculation
   1504   ====            =====  =====   ===========
   1505   R_386_NONE        0    none    none
   1506   R_386_32	    1    word32  S + A
   1507   R_386_PC32	    2    word32  S + A - P
   1508   R_386_GOT32	    3    word32  G + A - P
   1509   R_386_PLT32	    4    word32  L + A - P
   1510   R_386_COPY	    5    none    none
   1511   R_386_GLOB_DAT    6    word32  S
   1512   R_386_JMP_SLOT    7    word32  S
   1513   R_386_RELATIVE    8    word32  B + A
   1514   R_386_GOTOFF	    9    word32  S + A - GOT
   1515   R_386_GOTPC	   10    word32  GOT + A - P
   1516 
   1517 Some relocation types have semantics beyond simple calculation.
   1518 
   1519 * R_386_GOT32
   1520 
   1521   This relocation type computes the distance from the base of the
   1522   global offset table to the symbol's global offset table entry. It
   1523   additionally instructs the link editor to build a global offset
   1524   table.
   1525 
   1526 * R_386_PLT32
   1527 
   1528   This relocation type computes the address of the symbol's procedure
   1529   linkage table entry and additionally instructs the link editor to
   1530   build a procedure linkage table.
   1531 
   1532 * R_386_COPY
   1533 
   1534   The link editor creates this relocation type for dynamic linking.
   1535   Its offset member refers to a location in a writable segment. The
   1536   symbol table index specifies a symbol that should exist both in the
   1537   current object file and in a shared object. During execution, the
   1538   dynamic linker copies data associated with shared object's symbol to
   1539   the location specified by the offset.
   1540 
   1541 * R_386_GLOB_DAT
   1542 
   1543   This relocation type is used to set a global offset table entry to
   1544   the address of the specified symbol. The special relocation type
   1545   allows one to determine the correspondence between symbols and
   1546   global offset table entries.
   1547 
   1548 * R_386_JMP_SLOT {*}
   1549 
   1550   The link editor creates this relocation type for dynamic linking.
   1551   Its offset member gives the location of a procedure linkage table
   1552   entry. The dynamic linker modifies the procedure linkage table entry
   1553   to transfer control to the designated symbol's address [see
   1554   ``Procedure Linkage Table'' in Part 2].
   1555 
   1556 * R_386_RELATIVE
   1557 
   1558   The link editor creates this relocation type for dynamic linking.
   1559   Its offset member gives a location within a shared object that
   1560   contains a value representing a relative address. The dynamic linker
   1561   computes the corresponding virtual address by adding the virtual
   1562   address at which the shared object was loaded to the relative
   1563   address. Relocation entries for this type must specify 0 for the
   1564   symbol table index.
   1565 
   1566 * R_386_GOTOFF
   1567 
   1568   This relocation type computes the difference between a symbol's
   1569   value and the address of the global offset table. It additionally
   1570   instructs the link editor to build the global offset table.
   1571 
   1572 
   1573 * R_386_GOTPC
   1574 
   1575   This relocation type resembles R_386_PC32, except it uses the
   1576   address of the global offset table in its calculation. The symbol
   1577   referenced in this relocation normally is _GLOBAL_OFFSET_TABLE_,
   1578   which additionally instructs the link editor to build the global
   1579   offset table.
   1580 
   1581    ________________________________________________________________
   1582 
   1583 
   1584 		2. PROGRAM LOADING AND DYNAMIC LINKING
   1585 
   1586    ________________________________________________________________
   1587 
   1588 
   1589    ========================= Introduction =========================
   1590 
   1591 
   1592 Part 2 describes the object file information and system actions that
   1593 create running programs. Some information here applies to all systems;
   1594 other information is processor-specific.
   1595 
   1596 Executable and shared object files statically represent programs. To
   1597 execute such programs, the system uses the files to create dynamic
   1598 program representations, or process images. A process image has
   1599 segments that hold its text, data, stack, and so on. The major
   1600 sections in this part discuss the following.
   1601 
   1602 * Program header. This section complements Part 1, describing object
   1603   file structures that relate directly to program execution. The
   1604   primary data structure, a program header table, locates segment
   1605   images within the file and contains other information necessary to
   1606   create the memory image for the program.
   1607 * Program loading. Given an object file, the system must load it into
   1608   memory for the program to run.
   1609 * Dynamic linking. After the system loads the program, it must
   1610   complete the process image by resolving symbolic references among
   1611   the object files that compose the process.
   1612 
   1613 NOTE: There are naming conventions for ELF constants that have
   1614 specified processor ranges. Names such as DT_, PT_, for
   1615 processor-specific extensions, incorporate the name of the processor:
   1616 DT_M32_SPECIAL, for example. Pre-existing processor extensions not
   1617 using this convention will be supported.
   1618 
   1619 		       Pre-existing Extensions
   1620 		       =======================
   1621 			      DT_JMP_REL
   1622 
   1623 
   1624    ======================== Program Header ========================
   1625 
   1626 
   1627 An executable or shared object file's program header table is an array
   1628 of structures, each describing a segment or other information the
   1629 system needs to prepare the program for execution. An object file
   1630 segment contains one or more sections, as ``Segment Contents''
   1631 describes below. Program headers are meaningful only for executable
   1632 and shared object files. A file specifies its own program header size
   1633 with the ELF header's e_phentsize and e_phnum members [see ``ELF
   1634 Header'' in Part 1].
   1635 
   1636 + Figure 2-1: Program Header
   1637 
   1638   typedef struct {
   1639       Elf32_Word	p_type;
   1640       Elf32_Off		p_offset;
   1641       Elf32_Addr	p_vaddr;
   1642       Elf32_Addr	p_paddr;
   1643       Elf32_Word	p_filesz;
   1644       Elf32_Word	p_memsz;
   1645       Elf32_Word	p_flags;
   1646       Elf32_Word	p_align;
   1647   } Elf32_Phdr;
   1648 
   1649 * p_type
   1650 
   1651   This member tells what kind of segment this array element describes
   1652   or how to interpret the array element's information. Type values and
   1653   their meanings appear below.
   1654 
   1655 * p_offset
   1656 
   1657   This member gives the offset from the beginning of the file at which
   1658   the first byte of the segment resides.
   1659 
   1660 * p_vaddr
   1661 
   1662   This member gives the virtual address at which the first byte of the
   1663   segment resides in memory.
   1664 
   1665 * p_paddr
   1666 
   1667   On systems for which physical addressing is relevant, this member is
   1668   reserved for the segment's physical address. Because System V
   1669   ignores physical addressing for application programs, this member
   1670   has unspecified contents for executable files and shared objects.
   1671 
   1672 * p_filesz
   1673 
   1674   This member gives the number of bytes in the file image of the
   1675   segment; it may be zero.
   1676 
   1677 * p_memsz
   1678 
   1679   This member gives the number of bytes in the memory image of the
   1680   segment; it may be zero.
   1681 
   1682 * p_flags
   1683 
   1684   This member gives flags relevant to the segment. Defined flag values
   1685   appear below.
   1686 
   1687 * p_align
   1688 
   1689   As ``Program Loading'' later in this part describes, loadable
   1690   process segments must have congruent values for p_vaddr and
   1691   p_offset, modulo the page size. This member gives the value to which
   1692   the segments are aligned in memory and in the file. Values 0 and 1
   1693   mean no alignment is required. Otherwise, p_align should be a
   1694   positive, integral power of 2, and p_vaddr should equal p_offset,
   1695   modulo p_align.
   1696 
   1697 Some entries describe process segments; others give supplementary
   1698 information and do not contribute to the process image.  Defined
   1699 entries may appear in any order, except as explicitly noted
   1700 below. Segment type values follow; other values are reserved for
   1701 future use.
   1702 
   1703 + Figure 2-2: Segment Types, p_type
   1704 
   1705   Name             Value
   1706   ====             =====
   1707   PT_NULL              0
   1708   PT_LOAD              1
   1709   PT_DYNAMIC           2
   1710   PT_INTERP            3
   1711   PT_NOTE              4
   1712   PT_SHLIB             5
   1713   PT_PHDR              6
   1714   PT_LOPROC   0x70000000
   1715   PT_HIPROC   0x7fffffff
   1716 
   1717 * PT_NULL
   1718 
   1719   The array element is unused; other members' values are undefined.
   1720   This type lets the program header table have ignored entries.
   1721 
   1722 * PT_LOAD
   1723 
   1724   The array element specifies a loadable segment, described by
   1725   p_filesz and p_memsz. The bytes from the file are mapped to the
   1726   beginning of the memory segment. If the segment's memory size
   1727   (p_memsz) is larger than the file size (p_filesz), the ``extra''
   1728   bytes are defined to hold the value 0 and to follow the segment's
   1729   initialized area. The file size may not be larger than the memory
   1730   size. Loadable segment entries in the program header table appear in
   1731   ascending order, sorted on the p_vaddr member.
   1732 
   1733 * PT_DYNAMIC
   1734 
   1735   The array element specifies dynamic linking information. See
   1736   ``Dynamic Section'' below for more information.
   1737 
   1738 * PT_INTERP
   1739 
   1740   The array element specifies the location and size of a
   1741   null-terminated path name to invoke as an interpreter. This segment
   1742   type is meaningful only for executable files (though it may occur
   1743   for shared objects); it may not occur more than once in a file. If
   1744   it is present, it must precede any loadable segment entry. See
   1745   ``Program Interpreter'' below for further information.
   1746 
   1747 * PT_NOTE
   1748 
   1749   The array element specifies the location and size of auxiliary
   1750   information. See ``Note Section'' below for details.
   1751 
   1752 * PT_SHLIB
   1753 
   1754   This segment type is reserved but has unspecified semantics.
   1755   Programs that contain an array element of this type do not conform
   1756   to the ABI.
   1757 
   1758 * PT_PHDR
   1759 
   1760   The array element, if present, specifies the location and size of
   1761   the program header table itself, both in the file and in the memory
   1762   image of the program. This segment type may not occur more than once
   1763   in a file. Moreover, it may occur only if the program header table
   1764   is part of the memory image of the program. If it is present, it
   1765   must precede any loadable segment entry. See ``Program Interpreter''
   1766   below for further information.
   1767 
   1768 * PT_LOPROC through PT_HIPROC
   1769 
   1770   Values in this inclusive range are reserved for processor-specific
   1771   semantics.
   1772 
   1773 NOTE: Unless specifically required elsewhere, all program header
   1774 segment types are optional. That is, a file's program header table may
   1775 contain only those elements relevant to its contents.
   1776 
   1777 
   1778 			     Base Address
   1779 
   1780 Executable and shared object files have a base address, which is the
   1781 lowest virtual address associated with the memory image of the
   1782 program's object file. One use of the base address is to relocate the
   1783 memory image of the program during dynamic linking.
   1784 
   1785 An executable or shared object file's base address is calculated
   1786 during execution from three values: the memory load address, the
   1787 maximum page size, and the lowest virtual address of a program's
   1788 loadable segment. As ``Program Loading'' in this chapter describes,
   1789 the virtual addresses in the program headers might not represent the
   1790 actual virtual addresses of the program's memory image. To compute the
   1791 base address, one determines the memory address associated with the
   1792 lowest p_vaddr value for a PT_LOAD segment. One then obtains the base
   1793 address by truncating the memory address to the nearest multiple of
   1794 the maximum page size. Depending on the kind of file being loaded into
   1795 memory, the memory address might or might not match the p_vaddr
   1796 values.
   1797 
   1798 As ``Sections'' in Part 1 describes, the .bss section has the type
   1799 SHT_NOBITS. Although it occupies no space in the file, it contributes
   1800 to the segment's memory image. Normally, these uninitialized data
   1801 reside at the end of the segment, thereby making p_memsz larger than
   1802 p_filesz in the associated program header element.
   1803 
   1804 
   1805 			     Note Section
   1806 
   1807 Sometimes a vendor or system builder needs to mark an object file with
   1808 special information that other programs will check for conformance,
   1809 compatibility, etc. Sections of type SHT_NOTE and program header
   1810 elements of type PT_NOTE can be used for this purpose. The note
   1811 information in sections and program header elements holds any number
   1812 of entries, each of which is an array of 4-byte words in the format of
   1813 the target processor. Labels appear below to help explain note
   1814 information organization, but they are not part of the specification.
   1815 
   1816 + Figure 2-3: Note Information
   1817 
   1818   namesz
   1819   descsz
   1820   type
   1821   name ...
   1822   desc ...
   1823 
   1824 * namesz and name
   1825 
   1826   The first namesz bytes in name contain a null-terminated character
   1827   representation of the entry's owner or originator. There is no
   1828   formal mechanism for avoiding name conflicts. By convention, vendors
   1829   use their own name, such as ``XYZ Computer Company,'' as the
   1830   identifier. If no name is present, namesz contains 0. Padding is
   1831   present, if necessary, to ensure 4-byte alignment for the
   1832   descriptor. Such padding is not included in namesz.
   1833 
   1834 * descsz and desc
   1835 
   1836   The first descsz bytes in desc hold the note descriptor. The ABI
   1837   places no constraints on a descriptor's contents. If no descriptor
   1838   is present, descsz contains 0. Padding is present, if necessary, to
   1839   ensure 4-byte alignment for the next note entry. Such padding is not
   1840   included in descsz.
   1841 
   1842 * type
   1843 
   1844   This word gives the interpretation of the descriptor. Each
   1845   originator controls its own types; multiple interpretations of a
   1846   single type value may exist. Thus, a program must recognize both the
   1847   name and the type to ``understand'' a descriptor. Types currently
   1848   must be non-negative. The ABI does not define what descriptors mean.
   1849 
   1850 To illustrate, the following note segment holds two entries.
   1851 
   1852 + Figure 2-4: Example Note Segment
   1853 
   1854            +0   +1   +2   +3
   1855           -------------------
   1856   namesz           7
   1857   descsz           0           No descriptor
   1858     type           1
   1859     name   X    Y    Z    spc 
   1860            C    o    \0   pad
   1861   namesz           7
   1862   descsz           8
   1863     type           3
   1864     name   X    Y    Z    spc
   1865            C    o    \0   pad
   1866     desc         word0
   1867                  word1
   1868 
   1869 NOTE: The system reserves note information with no name (namesz==0)
   1870 and with a zero-length name (name[0]=='\0') but currently defines no
   1871 types. All other names must have at least one non-null character.
   1872 
   1873 NOTE: Note information is optional. The presence of note information
   1874 does not affect a program's ABI conformance, provided the information
   1875 does not affect the program's execution behavior. Otherwise, the
   1876 program does not conform to the ABI and has undefined behavior.
   1877 
   1878 
   1879    ======================= Program Loading ========================
   1880 
   1881 
   1882 As the system creates or augments a process image, it logically copies
   1883 a file's segment to a virtual memory segment. When--and if--the system
   1884 physically reads the file depends on the program's execution behavior,
   1885 system load, etc. A process does not require a physical page unless it
   1886 references the logical page during execution, and processes commonly
   1887 leave many pages unreferenced. Therefore delaying physical reads
   1888 frequently obviates them, improving system performance. To obtain this
   1889 efficiency in practice, executable and shared object files must have
   1890 segment images whose file offsets and virtual addresses are congruent,
   1891 modulo the page size.
   1892 
   1893 Virtual addresses and file offsets for the SYSTEM V architecture
   1894 segments are congruent modulo 4 KB (0x1000) or larger powers of 2.
   1895 Because 4 KB is the maximum page size, the files will be suitable for
   1896 paging regardless of physical page size.
   1897 
   1898 + Figure 2-5: Executable File
   1899 
   1900            File Offset   File                  Virtual Address
   1901            ===========   ====                  ===============
   1902                      0   ELF header
   1903   Program header table
   1904                          Other information
   1905                  0x100   Text segment          0x8048100
   1906                          ...
   1907                          0x2be00 bytes         0x8073eff
   1908                0x2bf00   Data segment          0x8074f00
   1909                          ...
   1910                          0x4e00 bytes          0x8079cff
   1911                0x30d00   Other information
   1912                          ...
   1913 
   1914 + Figure 2-6: Program Header Segments
   1915 
   1916   Member    Text	 Data
   1917   ======    ====         ====
   1918   p_type    PT_LOAD      PT_LOAD
   1919   p_offset  0x100	 0x2bf00
   1920   p_vaddr   0x8048100	 0x8074f00
   1921   p_paddr   unspecified	 unspecified
   1922   p_filesz  0x2be00	 0x4e00
   1923   p_memsz   0x2be00	 0x5e24
   1924   p_flags   PF_R+PF_X    PF_R+PF_W+PF_X
   1925   p_align   0x1000	 0x1000
   1926 
   1927 Although the example's file offsets and virtual addresses are
   1928 congruent modulo 4 KB for both text and data, up to four file pages
   1929 hold impure text or data (depending on page size and file system block
   1930 size).
   1931 
   1932 * The first text page contains the ELF header, the program header
   1933   table, and other information.
   1934 * The last text page holds a copy of the beginning of data.
   1935 * The first data page has a copy of the end of text.
   1936 * The last data page may contain file information not relevant to the
   1937   running process.
   1938 
   1939 Logically, the system enforces the memory permissions as if each
   1940 segment were complete and separate; segments' addresses are adjusted
   1941 to ensure each logical page in the address space has a single set of
   1942 permissions. In the example above, the region of the file holding the
   1943 end of text and the beginning of data will be mapped twice: at one
   1944 virtual address for text and at a different virtual address for data.
   1945 
   1946 The end of the data segment requires special handling for
   1947 uninitialized data, which the system defines to begin with zero
   1948 values. Thus if a file's last data page includes information not in
   1949 the logical memory page, the extraneous data must be set to zero, not
   1950 the unknown contents of the executable file. ``Impurities'' in the
   1951 other three pages are not logically part of the process image; whether
   1952 the system expunges them is unspecified. The memory image for this
   1953 program follows, assuming 4 KB (0x1000) pages.
   1954 
   1955 + Figure 2-7: Process Image Segments
   1956 
   1957   Virtual Address  Contents            Segment
   1958   ===============  ========            =======
   1959         0x8048000  Header padding      Text
   1960                    0x100 bytes
   1961         0x8048100  Text segment
   1962                    ...
   1963                    0x2be00 bytes
   1964         0x8073f00  Data padding
   1965                    0x100 bytes
   1966         0x8074000  Text padding        Data
   1967                    0xf00 bytes
   1968         0x8074f00  Data segment
   1969                    ...
   1970                    0x4e00 bytes
   1971         0x8079d00  Uninitialized data
   1972                    0x1024 zero bytes
   1973         0x807ad24  Page padding
   1974                    0x2dc zero bytes
   1975 
   1976 One aspect of segment loading differs between executable files and
   1977 shared objects. Executable file segments typically contain absolute
   1978 code. To let the process execute correctly, the segments must reside
   1979 at the virtual addresses used to build the executable file. Thus the
   1980 system uses the p_vaddr values unchanged as virtual addresses.
   1981 
   1982 On the other hand, shared object segments typically contain
   1983 position-independent code. This lets a segment's virtual address
   1984 change from one process to another, without invalidating execution
   1985 behavior. Though the system chooses virtual addresses for individual
   1986 processes, it maintains the segments' relative positions. Because
   1987 position-independent code uses relative addressing between segments,
   1988 the difference between virtual addresses in memory must match the
   1989 difference between virtual addresses in the file. The following table
   1990 shows possible shared object virtual address assignments for several
   1991 processes, illustrating constant relative positioning. The table also
   1992 illustrates the base address computations.
   1993 
   1994 + Figure 2-8: Example Shared Object Segment Addresses
   1995 
   1996   Sourc             Text        Data  Base Address
   1997   =====             ====        ====  ============
   1998   File             0x200     0x2a400           0x0
   1999   Process 1   0x80000200  0x8002a400    0x80000000
   2000   Process 2   0x80081200  0x800ab400    0x80081000
   2001   Process 3   0x900c0200  0x900ea400    0x900c0000
   2002   Process 4   0x900c6200  0x900f0400    0x900c6000
   2003 
   2004 
   2005    ======================= Dynamic Linking ========================
   2006 
   2007 
   2008 			 Program Interpreter
   2009 
   2010 An executable file may have one PT_INTERP program header element.
   2011 During exec(BA_OS), the system retrieves a path name from the
   2012 PT_INTERP segment and creates the initial process image from the
   2013 interpreter file's segments. That is, instead of using the original
   2014 executable file's segment images, the system composes a memory image
   2015 for the interpreter. It then is the interpreter's responsibility to
   2016 receive control from the system and provide an environment for the
   2017 application program.
   2018 
   2019 The interpreter receives control in one of two ways. First, it may
   2020 receive a file descriptor to read the executable file, positioned at
   2021 the beginning. It can use this file descriptor to read and/or map the
   2022 executable file's segments into memory. Second, depending on the
   2023 executable file format, the system may load the executable file into
   2024 memory instead of giving the interpreter an open file descriptor. With
   2025 the possible exception of the file descriptor, the interpreter's
   2026 initial process state matches what the executable file would have
   2027 received. The interpreter itself may not require a second interpreter.
   2028 An interpreter may be either a shared object or an executable file.
   2029 
   2030 * A shared object (the normal case) is loaded as position-independent,
   2031   with addresses that may vary from one process to another; the system
   2032   creates its segments in the dynamic segment area used by mmap(KE_OS)
   2033   and related services. Consequently, a shared object interpreter
   2034   typically will not conflict with the original executable file's
   2035   original segment addresses.
   2036 
   2037 * An executable file is loaded at fixed addresses; the system creates
   2038   its segments using the virtual addresses from the program header
   2039   table. Consequently, an executable file interpreter's virtual
   2040   addresses may collide with the first executable file; the
   2041   interpreter is responsible for resolving conflicts.
   2042 
   2043 
   2044 			    Dynamic Linker
   2045 
   2046 When building an executable file that uses dynamic linking, the link
   2047 editor adds a program header element of type PT_INTERP to an
   2048 executable file, telling the system to invoke the dynamic linker as
   2049 the program interpreter.
   2050 
   2051 NOTE: The locations of the system provided dynamic linkers are
   2052 processor-specific.
   2053 
   2054 Exec(BA_OS) and the dynamic linker cooperate to create the process
   2055 image for the program, which entails the following actions:
   2056 
   2057 * Adding the executable file's memory segments to the process image;
   2058 * Adding shared object memory segments to the process image;
   2059 * Performing relocations for the executable file and its shared
   2060   objects;
   2061 * Closing the file descriptor that was used to read the executable
   2062   file, if one was given to the dynamic linker;
   2063 * Transferring control to the program, making it look as if the
   2064   program had received control directly from exec(BA_OS).
   2065 
   2066 The link editor also constructs various data that assist the dynamic
   2067 linker for executable and shared object files. As shown above in
   2068 ``Program Header,'' these data reside in loadable segments, making
   2069 them available during execution. (Once again, recall the exact segment
   2070 contents are processor-specific. See the processor supplement for
   2071 complete information.)
   2072 
   2073 * A .dynamic section with type SHT_DYNAMIC holds various data. The
   2074   structure residing at the beginning of the section holds the
   2075   addresses of other dynamic linking information.
   2076 
   2077 * The .hash section with type SHT_HASH holds a symbol hash table.
   2078 
   2079 * The .got and .plt sections with type SHT_PROGBITS hold two separate
   2080   tables: the global offset table and the procedure linkage table.
   2081   Sections below explain how the dynamic linker uses and changes the
   2082   tables to create memory images for object files.
   2083 
   2084 Because every ABI-conforming program imports the basic system services
   2085 from a shared object library, the dynamic linker participates in every
   2086 ABI-conforming program execution.
   2087 
   2088 As ``Program Loading'' explains in the processor supplement, shared
   2089 objects may occupy virtual memory addresses that are different from
   2090 the addresses recorded in the file's program header table. The dynamic
   2091 linker relocates the memory image, updating absolute addresses before
   2092 the application gains control. Although the absolute address values
   2093 would be correct if the library were loaded at the addresses specified
   2094 in the program header table, this normally is not the case.
   2095 
   2096 If the process environment [see exec(BA_OS)] contains a variable named
   2097 LD_BIND_NOW with a non-null value, the dynamic linker processes all
   2098 relocation before transferring control to the program. For example,
   2099 all the following environment entries would specify this behavior.
   2100 
   2101 * LD_BIND_NOW=1
   2102 * LD_BIND_NOW=on
   2103 * LD_BIND_NOW=off
   2104 
   2105 Otherwise, LD_BIND_NOW either does not occur in the environment or has
   2106 a null value. The dynamic linker is permitted to evaluate procedure
   2107 linkage table entries lazily, thus avoiding symbol resolution and
   2108 relocation overhead for functions that are not called. See ``Procedure
   2109 Linkage Table'' in this part for more information.
   2110 
   2111 
   2112 			   Dynamic Section
   2113 
   2114 If an object file participates in dynamic linking, its program header
   2115 table will have an element of type PT_DYNAMIC. This ``segment''
   2116 contains the .dynamic section. A special symbol, _DYNAMIC, labels the
   2117 section, which contains an array of the following structures.
   2118 
   2119 + Figure 2-9: Dynamic Structure
   2120 
   2121   typedef struct {
   2122       Elf32_Sword d_tag;
   2123       union {
   2124           Elf32_Sword	d_val;
   2125           Elf32_Addr	d_ptr;
   2126       } d_un;
   2127   } Elf32_Dyn;
   2128 
   2129   extern Elf32_Dyn _DYNAMIC[];
   2130 
   2131 For each object with this type, d_tag controls the interpretation of
   2132 d_un.
   2133 
   2134 * d_val
   2135 
   2136   These Elf32_Word objects represent integer values with various
   2137   interpretations.
   2138 
   2139 * d_ptr
   2140 
   2141   These Elf32_Addr objects represent program virtual addresses. As
   2142   mentioned previously, a file's virtual addresses might not match the
   2143   memory virtual addresses during execution. When interpreting
   2144   addresses contained in the dynamic structure, the dynamic linker
   2145   computes actual addresses, based on the original file value and the
   2146   memory base address. For consistency, files do not contain
   2147   relocation entries to ``correct'' addresses in the dynamic
   2148   structure.
   2149 
   2150 The following table summarizes the tag requirements for executable and
   2151 shared object files. If a tag is marked ``mandatory,'' then the
   2152 dynamic linking array for an ABI-conforming file must have an entry of
   2153 that type. Likewise, ``optional'' means an entry for the tag may
   2154 appear but is not required.
   2155 
   2156 + Figure 2-10: Dynamic Array Tags, d_tag
   2157 
   2158   Name               Value  d_un         Executable   Shared Object
   2159   ====               =====  ====         ==========   =============
   2160   DT_NULL                0  ignored	 mandatory    mandatory
   2161   DT_NEEDED		 1  d_val	 optional     optional
   2162   DT_PLTRELSZ		 2  d_val	 optional     optional
   2163   DT_PLTGOT		 3  d_ptr	 optional     optional
   2164   DT_HASH		 4  d_ptr	 mandatory    mandatory
   2165   DT_STRTAB		 5  d_ptr	 mandatory    mandatory
   2166   DT_SYMTAB		 6  d_ptr	 mandatory    mandatory
   2167   DT_RELA		 7  d_ptr	 mandatory    optional
   2168   DT_RELASZ		 8  d_val	 mandatory    optional
   2169   DT_RELAENT		 9  d_val	 mandatory    optional
   2170   DT_STRSZ		10  d_val	 mandatory    mandatory
   2171   DT_SYMENT		11  d_val	 mandatory    mandatory
   2172   DT_INIT		12  d_ptr	 optional     optional
   2173   DT_FINI		13  d_ptr	 optional     optional
   2174   DT_SONAME		14  d_val	 ignored      optional
   2175   DT_RPATH		15  d_val	 optional     ignored
   2176   DT_SYMBOLIC		16  ignored	 ignored      optional
   2177   DT_REL		17  d_ptr	 mandatory    optional
   2178   DT_RELSZ		18  d_val	 mandatory    optional
   2179   DT_RELENT		19  d_val	 mandatory    optional
   2180   DT_PLTREL		20  d_val	 optional     optional
   2181   DT_DEBUG		21  d_ptr	 optional     ignored
   2182   DT_TEXTREL		22  ignored	 optional     optional
   2183   DT_JMPREL		23  d_ptr	 optional     optional
   2184   DT_LOPROC     0x70000000  unspecified  unspecified  unspecified
   2185   DT_HIPROC     0x7fffffff  unspecified  unspecified  unspecified
   2186 
   2187 * DT_NULL
   2188 
   2189   An entry with a DT_NULL tag marks the end of the _DYNAMIC array.
   2190 
   2191 * DT_NEEDED
   2192 
   2193   This element holds the string table offset of a null-terminated
   2194   string, giving the name of a needed library. The offset is an index
   2195   into the table recorded in the DT_STRTAB entry. See ``Shared Object
   2196   Dependencies'' for more information about these names. The dynamic
   2197   array may contain multiple entries with this type. These entries'
   2198   relative order is significant, though their relation to entries of
   2199   other types is not.
   2200 
   2201 * DT_PLTRELSZ
   2202 
   2203   This element holds the total size, in bytes, of the relocation
   2204   entries associated with the procedure linkage table. If an entry of
   2205   type DT_JMPREL is present, a DT_PLTRELSZ must accompany it.
   2206 
   2207 * DT_PLTGOT
   2208 
   2209   This element holds an address associated with the procedure linkage
   2210   table and/or the global offset table. See this section in the
   2211   processor supplement for details.
   2212 
   2213 * DT_HASH
   2214 
   2215   This element holds the address of the symbol hash table, described
   2216   in ``Hash Table.'' This hash table refers to the symbol table
   2217   referenced by the DT_SYMTAB element.
   2218 
   2219 * DT_STRTAB
   2220 
   2221   This element holds the address of the string table, described in
   2222   Part 1. Symbol names, library names, and other strings reside in
   2223   this table.
   2224 
   2225 * DT_SYMTAB
   2226 
   2227   This element holds the address of the symbol table, described in
   2228   Part 1, with Elf32_Sym entries for the 32-bit class of files.
   2229 
   2230 * DT_RELA
   2231 
   2232   This element holds the address of a relocation table, described in
   2233   Part 1. Entries in the table have explicit addends, such as
   2234   Elf32_Rela for the 32-bit file class. An object file may have
   2235   multiple relocation sections. When building the relocation table for
   2236   an executable or shared object file, the link editor catenates those
   2237   sections to form a single table. Although the sections remain
   2238   independent in the object file, the dynamic linker sees a single
   2239   table. When the dynamic linker creates the process image for an
   2240   executable file or adds a shared object to the process image, it
   2241   reads the relocation table and performs the associated actions. If
   2242   this element is present, the dynamic structure must also have
   2243   DT_RELASZ and DT_RELAENT elements. When relocation is ``mandatory''
   2244   for a file, either DT_RELA or DT_REL may occur (both are permitted
   2245   but not required).
   2246 
   2247 * DT_RELASZ
   2248 
   2249   This element holds the total size, in bytes, of the DT_RELA
   2250   relocation table.
   2251 
   2252 * DT_RELAENT
   2253 
   2254   This element holds the size, in bytes, of the DT_RELA relocation
   2255   entry.
   2256 
   2257 * DT_STRSZ
   2258 
   2259   This element holds the size, in bytes, of the string table.
   2260 
   2261 * DT_SYMENT
   2262 
   2263   This element holds the size, in bytes, of a symbol table entry.
   2264 
   2265 * DT_INIT
   2266 
   2267   This element holds the address of the initialization function,
   2268   discussed in ``Initialization and Termination Functions'' below.
   2269 
   2270 * DT_FINI
   2271 
   2272   This element holds the address of the termination function,
   2273   discussed in ``Initialization and Termination Functions'' below.
   2274 
   2275 * DT_SONAME
   2276 
   2277   This element holds the string table offset of a null-terminated
   2278   string, giving the name of the shared object. The offset is an index
   2279   into the table recorded in the DT_STRTAB entry. See ``Shared Object
   2280   Dependencies'' below for more information about these names.
   2281 
   2282 * DT_RPATH
   2283 
   2284   This element holds the string table offset of a null-terminated
   2285   search library search path string, discussed in ``Shared Object
   2286   Dependencies.'' The offset is an index into the table recorded in
   2287   the DT_STRTAB entry.
   2288 
   2289 * DT_SYMBOLIC
   2290 
   2291   This element's presence in a shared object library alters the
   2292   dynamic linker's symbol resolution algorithm for references within
   2293   the library. Instead of starting a symbol search with the executable
   2294   file, the dynamic linker starts from the shared object itself. If
   2295   the shared object fails to supply the referenced symbol, the dynamic
   2296   linker then searches the executable file and other shared objects as
   2297   usual.
   2298 
   2299 * DT_REL
   2300 
   2301   This element is similar to DT_RELA, except its table has implicit
   2302   addends, such as Elf32_Rel for the 32-bit file class. If this
   2303   element is present, the dynamic structure must also have DT_RELSZ
   2304   and DT_RELENT elements.
   2305 
   2306 * DT_RELSZ
   2307 
   2308   This element holds the total size, in bytes, of the DT_REL
   2309   relocation table.
   2310 
   2311 * DT_RELENT
   2312 
   2313   This element holds the size, in bytes, of the DT_REL relocation
   2314   entry.
   2315 
   2316 * DT_PLTREL
   2317 
   2318   This member specifies the type of relocation entry to which the
   2319   procedure linkage table refers. The d_val member holds DT_REL or
   2320   DT_RELA, as appropriate. All relocations in a procedure linkage
   2321   table must use the same relocation.
   2322 
   2323 * DT_DEBUG
   2324 
   2325   This member is used for debugging. Its contents are not specified
   2326   for the ABI; programs that access this entry are not ABI-conforming.
   2327 
   2328 * DT_TEXTREL
   2329 
   2330   This member's absence signifies that no relocation entry should
   2331   cause a modification to a non-writable segment, as specified by the
   2332   segment permissions in the program header table. If this member is
   2333   present, one or more relocation entries might request modifications
   2334   to a non-writable segment, and the dynamic linker can prepare
   2335   accordingly.
   2336 
   2337 * DT_JMPREL
   2338 
   2339   If present, this entries's d_ptr member holds the address of
   2340   relocation entries associated solely with the procedure linkage
   2341   table. Separating these relocation entries lets the dynamic linker
   2342   ignore them during process initialization, if lazy binding is
   2343   enabled. If this entry is present, the related entries of types
   2344   DT_PLTRELSZ and DT_PLTREL must also be present.
   2345 
   2346 * DT_LOPROC through DT_HIPROC
   2347 
   2348   Values in this inclusive range are reserved for processor-specific
   2349   semantics.
   2350 
   2351 Except for the DT_NULL element at the end of the array, and the
   2352 relative order of DT_NEEDED elements, entries may appear in any order.
   2353 Tag values not appearing in the table are reserved.
   2354 
   2355 
   2356 		      Shared Object Dependencies
   2357 
   2358 When the link editor processes an archive library, it extracts library
   2359 members and copies them into the output object file. These statically
   2360 linked services are available during execution without involving the
   2361 dynamic linker. Shared objects also provide services, and the dynamic
   2362 linker must attach the proper shared object files to the process image
   2363 for execution. Thus executable and shared object files describe their
   2364 specific dependencies.
   2365 
   2366 When the dynamic linker creates the memory segments for an object
   2367 file, the dependencies (recorded in DT_NEEDED entries of the dynamic
   2368 structure) tell what shared objects are needed to supply the program's
   2369 services. By repeatedly connecting referenced shared objects and their
   2370 dependencies, the dynamic linker builds a complete process image. When
   2371 resolving symbolic references, the dynamic linker examines the symbol
   2372 tables with a breadth-first search. That is, it first looks at the
   2373 symbol table of the executable program itself, then at the symbol
   2374 tables of the DT_NEEDED entries (in order), then at the second level
   2375 DT_NEEDED entries, and so on. Shared object files must be readable by
   2376 the process; other permissions are not required.
   2377 
   2378 NOTE: Even when a shared object is referenced multiple times in the
   2379 dependency list, the dynamic linker will connect the object only once
   2380 to the process.
   2381 
   2382 Names in the dependency list are copies either of the DT_SONAME
   2383 strings or the path names of the shared objects used to build the
   2384 object file. For example, if the link editor builds an executable file
   2385 using one shared object with a DT_SONAME entry of lib1 and another
   2386 shared object library with the path name /usr/lib/lib2, the executable
   2387 file will contain lib1 and /usr/lib/lib2 in its dependency list.
   2388 
   2389 If a shared object name has one or more slash (/) characters anywhere
   2390 in the name, such as /usr/lib/lib2 above or directory/file, the
   2391 dynamic linker uses that string directly as the path name. If the name
   2392 has no slashes, such as lib1 above, three facilities specify shared
   2393 object path searching, with the following precedence.
   2394 
   2395 * First, the dynamic array tag DT_RPATH may give a string that holds a
   2396   list of directories, separated by colons (:). For example, the
   2397   string /home/dir/lib:/home/dir2/lib: tells the dynamic linker to
   2398   search first the directory /home/dir/lib, then /home/dir2/lib, and
   2399   then the current directory to find dependencies.
   2400 * Second, a variable called LD_LIBRARY_PATH in the process environment
   2401   [see exec(BA_OS)] may hold a list of directories as above,
   2402   optionally followed by a semicolon (;) and another directory list.
   2403   The following values would be equivalent to the previous example:
   2404     LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:
   2405     LD_LIBRARY_PATH=/home/dir/lib;/home/dir2/lib:
   2406     LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:;
   2407   All LD_LIBRARY_PATH directories are searched after those from
   2408   DT_RPATH. Although some programs (such as the link editor) treat the
   2409   lists before and after the semicolon differently, the dynamic linker
   2410   does not. Nevertheless, the dynamic linker accepts the semicolon
   2411   notation, with the semantics described above.
   2412 * Finally, if the other two groups of directories fail to locate the
   2413   desired library, the dynamic linker searches /usr/lib.
   2414 
   2415 NOTE: For security, the dynamic linker ignores environmental search
   2416 specifications (such as LD_LIBRARY_PATH) for set-user and set-group ID
   2417 programs. It does, however, search DT_RPATH directories and /usr/lib.
   2418 
   2419 
   2420 			 Global Offset Table
   2421 
   2422 Position-independent code cannot, in general, contain absolute virtual
   2423 addresses. Global offset tables hold absolute addresses in private
   2424 data, thus making the addresses available without compromising the
   2425 position-independence and sharability of a program's text. A program
   2426 references its global offset table using position-independent
   2427 addressing and extracts absolute values, thus redirecting
   2428 position-independent references to absolute locations.
   2429 
   2430 Initially, the global offset table holds information as required by
   2431 its relocation entries [see ``Relocation'' in Part 1]. After the
   2432 system creates memory segments for a loadable object file, the dynamic
   2433 linker processes the relocation entries, some of which will be type
   2434 R_386_GLOB_DAT referring to the global offset table. The dynamic
   2435 linker determines the associated symbol values, calculates their
   2436 absolute addresses, and sets the appropriate memory table entries to
   2437 the proper values. Although the absolute addresses are unknown when
   2438 the link editor builds an object file, the dynamic linker knows the
   2439 addresses of all memory segments and can thus calculate the absolute
   2440 addresses of the symbols contained therein.
   2441 
   2442 If a program requires direct access to the absolute address of a
   2443 symbol, that symbol will have a global offset table entry. Because the
   2444 executable file and shared objects have separate global offset tables,
   2445 a symbol's address may appear in several tables. The dynamic linker
   2446 processes all the global offset table relocations before giving
   2447 control to any code in the process image, thus ensuring the absolute
   2448 addresses are available during execution.
   2449 
   2450 The table's entry zero is reserved to hold the address of the dynamic
   2451 structure, referenced with the symbol _DYNAMIC. This allows a program,
   2452 such as the dynamic linker, to find its own dynamic structure without
   2453 having yet processed its relocation entries. This is especially
   2454 important for the dynamic linker, because it must initialize itself
   2455 without relying on other programs to relocate its memory image. On the
   2456 32-bit Intel Architecture, entries one and two in the global offset
   2457 table also are reserved. ``Procedure Linkage Table'' below describes
   2458 them.
   2459 
   2460 The system may choose different memory segment addresses for the same
   2461 shared object in different programs; it may even choose different
   2462 library addresses for different executions of the same program.
   2463 Nonetheless, memory segments do not change addresses once the process
   2464 image is established. As long as a process exists, its memory segments
   2465 reside at fixed virtual addresses.
   2466 
   2467 A global offset table's format and interpretation are
   2468 processor-specific. For the 32-bit Intel Architecture, the symbol
   2469 _GLOBAL_OFFSET_TABLE_ may be used to access the table.
   2470 
   2471 + Figure 2-11: Global Offset Table
   2472 
   2473   extern Elf32_Addr _GLOBAL_OFFSET_TABLE_[];
   2474 
   2475 The symbol _GLOBAL_OFFSET_TABLE_ may reside in the middle of the .got
   2476 section, allowing both negative and non-negative ``subscripts'' into
   2477 the array of addresses.
   2478 
   2479 
   2480 		       Procedure Linkage Table
   2481 
   2482 Much as the global offset table redirects position-independent address
   2483 calculations to absolute locations, the procedure linkage table
   2484 redirects position-independent function calls to absolute locations.
   2485 The link editor cannot resolve execution transfers (such as function
   2486 calls) from one executable or shared object to another. Consequently,
   2487 the link editor arranges to have the program transfer control to
   2488 entries in the procedure linkage table. On the SYSTEM V architecture,
   2489 procedure linkage tables reside in shared text, but they use addresses
   2490 in the private global offset table. The dynamic linker determines the
   2491 destinations' absolute addresses and modifies the global offset
   2492 table's memory image accordingly. The dynamic linker thus can redirect
   2493 the entries without compromising the position-independence and
   2494 sharability of the program's text. Executable files and shared object
   2495 files have separate procedure linkage tables.
   2496 
   2497 + Figure 2-12: Absolute Procedure Linkage Table {*}
   2498 
   2499   .PLT0:pushl   got_plus_4
   2500         jmp     *got_plus_8
   2501         nop; nop
   2502         nop; nop
   2503   .PLT1:jmp     *name1_in_GOT
   2504         pushl   $offset
   2505         jmp     .PLT0@PC
   2506   .PLT2:jmp     *name2_in_GOT
   2507         pushl   $offset
   2508         jmp     .PLT0@PC
   2509         ...
   2510 
   2511 + Figure 2-13: Position-Independent Procedure Linkage Table
   2512 
   2513   .PLT0:pushl   4(%ebx)
   2514         jmp     *8(%ebx)
   2515         nop; nop
   2516         nop; nop
   2517   .PLT1:jmp     *name1@GOT(%ebx)
   2518         pushl   $offset
   2519         jmp     .PLT0@PC
   2520   .PLT2:jmp     *name2@GOT(%ebx)
   2521         pushl   $offset
   2522         jmp     .PLT0@PC
   2523         ...
   2524 
   2525 NOTE: As the figures show, the procedure linkage table instructions
   2526 use different operand addressing modes for absolute code and for
   2527 position-independent code. Nonetheless, their interfaces to the
   2528 dynamic linker are the same.
   2529 
   2530 Following the steps below, the dynamic linker and the program
   2531 ``cooperate'' to resolve symbolic references through the procedure
   2532 linkage table and the global offset table.
   2533 
   2534 1. When first creating the memory image of the program, the dynamic
   2535    linker sets the second and the third entries in the global offset
   2536    table to special values. Steps below explain more about these
   2537    values.
   2538 2. If the procedure linkage table is position-independent, the address
   2539    of the global offset table must reside in %ebx. Each shared object
   2540    file in the process image has its own procedure linkage table, and
   2541    control transfers to a procedure linkage table entry only from
   2542    within the same object file. Consequently, the calling function is
   2543    responsible for setting the global offset table base register
   2544    before calling the procedure linkage table entry.
   2545 3. For illustration, assume the program calls name1, which transfers
   2546    control to the label .PLT1.
   2547 4. The first instruction jumps to the address in the global offset
   2548    table entry for name1. Initially, the global offset table holds the
   2549    address of the following pushl instruction, not the real address of
   2550    name1.
   2551 5. Consequently, the program pushes a relocation offset (offset) on
   2552    the stack. The relocation offset is a 32-bit, non-negative byte
   2553    offset into the relocation table. The designated relocation entry
   2554    will have type R_386_JMP_SLOT, and its offset will specify the
   2555    global offset table entry used in the previous jmp instruction. The
   2556    relocation entry also contains a symbol table index, thus telling
   2557    the dynamic linker what symbol is being referenced, name1 in this
   2558    case.
   2559 6. After pushing the relocation offset, the program then jumps to
   2560    .PLT0, the first entry in the procedure linkage table. The pushl
   2561    instruction places the value of the second global offset table
   2562    entry (got_plus_4 or 4(%ebx)) on the stack, thus giving the dynamic
   2563    linker one word of identifying information. The program then jumps
   2564    to the address in the third global offset table entry (got_plus_8
   2565    or 8(%ebx)), which transfers control to the dynamic linker.
   2566 7. When the dynamic linker receives control, it unwinds the stack,
   2567    looks at the designated relocation entry, finds the symbol's value,
   2568    stores the ``real'' address for name1 in its global offset table
   2569    entry, and transfers control to the desired destination.
   2570 8. Subsequent executions of the procedure linkage table entry will
   2571    transfer directly to name1, without calling the dynamic linker a
   2572    second time. That is, the jmp instruction at .PLT1 will transfer to
   2573    name1, instead of ``falling through'' to the pushl instruction.
   2574 
   2575 The LD_BIND_NOW environment variable can change dynamic linking
   2576 behavior. If its value is non-null, the dynamic linker evaluates
   2577 procedure linkage table entries before transferring control to the
   2578 program. That is, the dynamic linker processes relocation entries of
   2579 type R_386_JMP_SLOT during process initialization. Otherwise, the
   2580 dynamic linker evaluates procedure linkage table entries lazily,
   2581 delaying symbol resolution and relocation until the first execution of
   2582 a table entry.
   2583 
   2584 NOTE: Lazy binding generally improves overall application performance,
   2585 because unused symbols do not incur the dynamic linking overhead.
   2586 Nevertheless, two situations make lazy binding undesirable for some
   2587 applications. First, the initial reference to a shared object function
   2588 takes longer than subsequent calls, because the dynamic linker
   2589 intercepts the call to resolve the symbol. Some applications cannot
   2590 tolerate this unpredictability. Second, if an error occurs and the
   2591 dynamic linker cannot resolve the symbol, the dynamic linker will
   2592 terminate the program. Under lazy binding, this might occur at
   2593 arbitrary times. Once again, some applications cannot tolerate this
   2594 unpredictability. By turning off lazy binding, the dynamic linker
   2595 forces the failure to occur during process initialization, before the
   2596 application receives control.
   2597 
   2598 
   2599 			      Hash Table
   2600 
   2601 A hash table of Elf32_Word objects supports symbol table access.
   2602 Labels appear below to help explain the hash table organization, but
   2603 they are not part of the specification.
   2604 
   2605 + Figure 2-14: Symbol Hash Table
   2606 
   2607   nbucket
   2608   nchain
   2609   bucket[0]
   2610   ...
   2611   bucket[nbucket - 1]
   2612   chain[0]
   2613   ...
   2614   chain[nchain - 1]
   2615 
   2616 The bucket array contains nbucket entries, and the chain array
   2617 contains nchain entries; indexes start at 0. Both bucket and chain
   2618 hold symbol table indexes. Chain table entries parallel the symbol
   2619 table. The number of symbol table entries should equal nchain; so
   2620 symbol table indexes also select chain table entries. A hashing
   2621 function (shown below) accepts a symbol name and returns a value that
   2622 may be used to compute a bucket index. Consequently, if the hashing
   2623 function returns the value x for some name, bucket[x%nbucket] gives an
   2624 index, y, into both the symbol table and the chain table. If the
   2625 symbol table entry is not the one desired, chain[y] gives the next
   2626 symbol table entry with the same hash value. One can follow the chain
   2627 links until either the selected symbol table entry holds the desired
   2628 name or the chain entry contains the value STN_UNDEF.
   2629 
   2630 + Figure 2-15: Hashing Function
   2631 
   2632   unsigned long
   2633   elf_hash(const unsigned char *name)
   2634   {
   2635       unsigned long       h = 0, g;
   2636   
   2637       while (*name) {
   2638           h = (h << 4) + *name++;
   2639           if (g = h & 0xf0000000)
   2640               h ^= g >> 24;
   2641           h &= ~g;
   2642       }
   2643       return h;
   2644   }
   2645 
   2646 
   2647 	       Initialization and Termination Functions
   2648 
   2649 After the dynamic linker has built the process image and performed the
   2650 relocations, each shared object gets the opportunity to execute some
   2651 initialization code. These initialization functions are called in no
   2652 specified order, but all shared object initializations happen before
   2653 the executable file gains control.
   2654 
   2655 Similarly, shared objects may have termination functions, which are
   2656 executed with the atexit(BA_OS) mechanism after the base process
   2657 begins its termination sequence. Once again, the order in which the
   2658 dynamic linker calls termination functions is unspecified.
   2659 
   2660 Shared objects designate their initialization and termination
   2661 functions through the DT_INIT and DT_FINI entries in the dynamic
   2662 structure, described in ``Dynamic Section'' above. Typically, the code
   2663 for these functions resides in the .init and .fini sections, mentioned
   2664 in ``Sections'' of Part 1.
   2665 
   2666 NOTE: Although the atexit(BA_OS) termination processing normally will
   2667 be done, it is not guaranteed to have executed upon process death. In
   2668 particular, the process will not execute the termination processing if
   2669 it calls _exit [see exit(BA_OS)] or if the process dies because it
   2670 received a signal that it neither caught nor ignored.
   2671 
   2672    ________________________________________________________________
   2673 
   2674 
   2675 			     3. C LIBRARY
   2676 
   2677    ________________________________________________________________
   2678 
   2679 
   2680    ========================== C Library ===========================
   2681 
   2682 
   2683 The C library, libc, contains all of the symbols contained in libsys,
   2684 and, in addition, contains the routines listed in the following two
   2685 tables. The first table lists routines from the ANSI C standard.
   2686 
   2687 + Figure 3-1: libc Contents, Names without Synonyms
   2688 
   2689   abort        fputc        isprint      putc         strncmp
   2690   abs	       fputs        ispunct      putchar      strncpy
   2691   asctime      fread        isspace      puts         strpbrk
   2692   atof	       freopen      isupper      qsort        strrchr
   2693   atoi	       frexp        isxdigit     raise        strspn
   2694   atol	       fscanf       labs         rand         strstr
   2695   bsearch      fseek        ldexp        rewind       strtod
   2696   clearerr     fsetpos      ldiv         scanf        strtok
   2697   clock	       ftell        localtime    setbuf       strtol
   2698   ctime	       fwrite       longjmp      setjmp       strtoul
   2699   difftime     getc         mblen        setvbuf      tmpfile
   2700   div	       getchar      mbstowcs     sprintf      tmpnam
   2701   fclose       getenv       mbtowc       srand        tolower
   2702   feof	       gets         memchr       sscanf       toupper
   2703   ferror       gmtime       memcmp       strcat       ungetc
   2704   fflush       isalnum      memcpy       strchr       vfprintf
   2705   fgetc	       isalpha      memmove      strcmp       vprintf
   2706   fgetpos      iscntrl      memset       strcpy       vsprintf
   2707   fgets	       isdigit      mktime       strcspn      wcstombs
   2708   fopen	       isgraph      perror       strlen       wctomb
   2709   fprintf      islower      printf       strncat    
   2710 
   2711 Additionally, libc holds the following services.
   2712 
   2713 + Figure 3-2: libc Contents, Names with Synonyms
   2714 
   2715   __assert     getdate      lockf **     sleep        tell ** 
   2716   cfgetispeed  getopt       lsearch      strdup       tempnam
   2717   cfgetospeed  getpass      memccpy      swab         tfind
   2718   cfsetispeed  getsubopt    mkfifo       tcdrain      toascii
   2719   cfsetospeed  getw         mktemp       tcflow       _tolower
   2720   ctermid      hcreate      monitor      tcflush      tsearch
   2721   cuserid      hdestroy     nftw         tcgetattr    _toupper
   2722   dup2	       hsearch      nl_langinfo  tcgetpgrp    twalk
   2723   fdopen       isascii      pclose       tcgetsid     tzset
   2724   __filbuf     isatty       popen        tcsendbreak  _xftw
   2725   fileno       isnan        putenv       tcsetattr    
   2726   __flsbuf     isnand **    putw         tcsetpgrp    
   2727   fmtmsg **    lfind        setlabel     tdelete      
   2728 
   2729   ** = Function is at Level 2 in the SVID Issue 3 and therefore at
   2730        Level 2 in the ABI.
   2731 
   2732 Besides the symbols listed in the With Synonyms table above, synonyms
   2733 of the form _<name> exist for <name> entries that are not listed with
   2734 a leading underscore prepended to their name. Thus libc contains both
   2735 getopt and _getopt, for example.
   2736 
   2737 Of the routines listed above, the following are not defined elsewhere.
   2738 
   2739 int __filbuf(FILE *f);
   2740 	This function returns the next input character for f, filling
   2741 	its buffer as appropriate. It returns EOF if an error occurs.
   2742 
   2743 int __flsbuf(int x, FILE *f);
   2744 	This function flushes the output characters for f as if
   2745 	putc(x, f) had been called and then appends the value of x to
   2746 	the resulting output stream. It returns EOF if an error occurs
   2747 	and x otherwise.
   2748 
   2749 int _xftw(int, char *, int (*)(char *, struct stat *, int), int);
   2750 	Calls to the ftw(BA_LIB) function are mapped to this function
   2751 	when applications are compiled. This function is identical to
   2752 	ftw(BA_LIB), except that _xftw() takes an interposed first
   2753 	argument, which must have the value 2.
   2754 
   2755 See this chapter's other library sections for more SVID, ANSI C, and
   2756 POSIX facilities. See ``System Data Interfaces'' later in this chapter
   2757 for more information.
   2758 
   2759 
   2760 			 Global Data Symbols
   2761 
   2762 The libc library requires that some global external data symbols be
   2763 defined for its routines to work properly. All the data symbols
   2764 required for the libsys library must be provided by libc, as well as
   2765 the data symbols listed in the table below.
   2766 
   2767 For formal declarations of the data objects represented by these
   2768 symbols, see the System V Interface Definition, Third Edition or the
   2769 ``Data Definitions'' section of Chapter 6 in the appropriate processor
   2770 supplement to the System V ABI.
   2771 
   2772 For entries in the following table that are in <name>-_<name> form,
   2773 both symbols in each pair represent the same data. The underscore
   2774 synonyms are provided to satisfy the ANSI C standard.
   2775 
   2776 + Figure 3-3: libc Contents, Global External Data Symbols
   2777 
   2778   getdate_err		optarg
   2779   _getdate_err		opterr
   2780   __iob			optind
   2781 			optopt