Back to index

cell-binutils  2.17cvs20070401
external.h
Go to the documentation of this file.
00001 /* ELF support for BFD.
00002    Copyright 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2001, 2003, 2005
00003    Free Software Foundation, Inc.
00004 
00005    Written by Fred Fish @ Cygnus Support, from information published
00006    in "UNIX System V Release 4, Programmers Guide: ANSI C and
00007    Programming Support Tools".
00008 
00009 This file is part of BFD, the Binary File Descriptor library.
00010 
00011 This program is free software; you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation; either version 2 of the License, or
00014 (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00024 
00025 
00026 /* This file is part of ELF support for BFD, and contains the portions
00027    that describe how ELF is represented externally by the BFD library.
00028    I.E. it describes the in-file representation of ELF.  It requires
00029    the elf/common.h file which contains the portions that are common to
00030    both the internal and external representations. */
00031 
00032 /* The 64-bit stuff is kind of random.  Perhaps someone will publish a
00033    spec someday.  */
00034 
00035 #ifndef _ELF_EXTERNAL_H
00036 #define _ELF_EXTERNAL_H
00037 
00038 /* ELF Header (32-bit implementations) */
00039 
00040 typedef struct {
00041   unsigned char      e_ident[16];         /* ELF "magic number" */
00042   unsigned char      e_type[2];           /* Identifies object file type */
00043   unsigned char      e_machine[2];        /* Specifies required architecture */
00044   unsigned char      e_version[4];        /* Identifies object file version */
00045   unsigned char      e_entry[4];          /* Entry point virtual address */
00046   unsigned char      e_phoff[4];          /* Program header table file offset */
00047   unsigned char      e_shoff[4];          /* Section header table file offset */
00048   unsigned char      e_flags[4];          /* Processor-specific flags */
00049   unsigned char      e_ehsize[2];         /* ELF header size in bytes */
00050   unsigned char      e_phentsize[2];             /* Program header table entry size */
00051   unsigned char      e_phnum[2];          /* Program header table entry count */
00052   unsigned char      e_shentsize[2];             /* Section header table entry size */
00053   unsigned char      e_shnum[2];          /* Section header table entry count */
00054   unsigned char      e_shstrndx[2];              /* Section header string table index */
00055 } Elf32_External_Ehdr;
00056 
00057 typedef struct {
00058   unsigned char      e_ident[16];         /* ELF "magic number" */
00059   unsigned char      e_type[2];           /* Identifies object file type */
00060   unsigned char      e_machine[2];        /* Specifies required architecture */
00061   unsigned char      e_version[4];        /* Identifies object file version */
00062   unsigned char      e_entry[8];          /* Entry point virtual address */
00063   unsigned char      e_phoff[8];          /* Program header table file offset */
00064   unsigned char      e_shoff[8];          /* Section header table file offset */
00065   unsigned char      e_flags[4];          /* Processor-specific flags */
00066   unsigned char      e_ehsize[2];         /* ELF header size in bytes */
00067   unsigned char      e_phentsize[2];             /* Program header table entry size */
00068   unsigned char      e_phnum[2];          /* Program header table entry count */
00069   unsigned char      e_shentsize[2];             /* Section header table entry size */
00070   unsigned char      e_shnum[2];          /* Section header table entry count */
00071   unsigned char      e_shstrndx[2];              /* Section header string table index */
00072 } Elf64_External_Ehdr;
00073 
00074 /* Program header */
00075 
00076 typedef struct {
00077   unsigned char      p_type[4];           /* Identifies program segment type */
00078   unsigned char      p_offset[4];         /* Segment file offset */
00079   unsigned char      p_vaddr[4];          /* Segment virtual address */
00080   unsigned char      p_paddr[4];          /* Segment physical address */
00081   unsigned char      p_filesz[4];         /* Segment size in file */
00082   unsigned char      p_memsz[4];          /* Segment size in memory */
00083   unsigned char      p_flags[4];          /* Segment flags */
00084   unsigned char      p_align[4];          /* Segment alignment, file & memory */
00085 } Elf32_External_Phdr;
00086 
00087 typedef struct {
00088   unsigned char      p_type[4];           /* Identifies program segment type */
00089   unsigned char      p_flags[4];          /* Segment flags */
00090   unsigned char      p_offset[8];         /* Segment file offset */
00091   unsigned char      p_vaddr[8];          /* Segment virtual address */
00092   unsigned char      p_paddr[8];          /* Segment physical address */
00093   unsigned char      p_filesz[8];         /* Segment size in file */
00094   unsigned char      p_memsz[8];          /* Segment size in memory */
00095   unsigned char      p_align[8];          /* Segment alignment, file & memory */
00096 } Elf64_External_Phdr;
00097 
00098 /* Section header */
00099 
00100 typedef struct {
00101   unsigned char      sh_name[4];          /* Section name, index in string tbl */
00102   unsigned char      sh_type[4];          /* Type of section */
00103   unsigned char      sh_flags[4];         /* Miscellaneous section attributes */
00104   unsigned char      sh_addr[4];          /* Section virtual addr at execution */
00105   unsigned char      sh_offset[4];        /* Section file offset */
00106   unsigned char      sh_size[4];          /* Size of section in bytes */
00107   unsigned char      sh_link[4];          /* Index of another section */
00108   unsigned char      sh_info[4];          /* Additional section information */
00109   unsigned char      sh_addralign[4];     /* Section alignment */
00110   unsigned char      sh_entsize[4];              /* Entry size if section holds table */
00111 } Elf32_External_Shdr;
00112 
00113 typedef struct {
00114   unsigned char      sh_name[4];          /* Section name, index in string tbl */
00115   unsigned char      sh_type[4];          /* Type of section */
00116   unsigned char      sh_flags[8];         /* Miscellaneous section attributes */
00117   unsigned char      sh_addr[8];          /* Section virtual addr at execution */
00118   unsigned char      sh_offset[8];        /* Section file offset */
00119   unsigned char      sh_size[8];          /* Size of section in bytes */
00120   unsigned char      sh_link[4];          /* Index of another section */
00121   unsigned char      sh_info[4];          /* Additional section information */
00122   unsigned char      sh_addralign[8];     /* Section alignment */
00123   unsigned char      sh_entsize[8];              /* Entry size if section holds table */
00124 } Elf64_External_Shdr;
00125 
00126 /* Symbol table entry */
00127 
00128 typedef struct {
00129   unsigned char      st_name[4];          /* Symbol name, index in string tbl */
00130   unsigned char      st_value[4];         /* Value of the symbol */
00131   unsigned char      st_size[4];          /* Associated symbol size */
00132   unsigned char      st_info[1];          /* Type and binding attributes */
00133   unsigned char      st_other[1];         /* No defined meaning, 0 */
00134   unsigned char      st_shndx[2];         /* Associated section index */
00135 } Elf32_External_Sym;
00136 
00137 typedef struct {
00138   unsigned char      st_name[4];          /* Symbol name, index in string tbl */
00139   unsigned char      st_info[1];          /* Type and binding attributes */
00140   unsigned char      st_other[1];         /* No defined meaning, 0 */
00141   unsigned char      st_shndx[2];         /* Associated section index */
00142   unsigned char      st_value[8];         /* Value of the symbol */
00143   unsigned char      st_size[8];          /* Associated symbol size */
00144 } Elf64_External_Sym;
00145 
00146 typedef struct {
00147   unsigned char est_shndx[4];             /* Section index */
00148 } Elf_External_Sym_Shndx;
00149 
00150 /* Note segments */
00151 
00152 typedef struct {
00153   unsigned char      namesz[4];           /* Size of entry's owner string */
00154   unsigned char      descsz[4];           /* Size of the note descriptor */
00155   unsigned char      type[4];             /* Interpretation of the descriptor */
00156   char        name[1];             /* Start of the name+desc data */
00157 } Elf_External_Note;
00158 
00159 /* Relocation Entries */
00160 typedef struct {
00161   unsigned char r_offset[4];       /* Location at which to apply the action */
00162   unsigned char      r_info[4];    /* index and type of relocation */
00163 } Elf32_External_Rel;
00164 
00165 typedef struct {
00166   unsigned char r_offset[4];       /* Location at which to apply the action */
00167   unsigned char      r_info[4];    /* index and type of relocation */
00168   unsigned char      r_addend[4];  /* Constant addend used to compute value */
00169 } Elf32_External_Rela;
00170 
00171 typedef struct {
00172   unsigned char r_offset[8];       /* Location at which to apply the action */
00173   unsigned char      r_info[8];    /* index and type of relocation */
00174 } Elf64_External_Rel;
00175 
00176 typedef struct {
00177   unsigned char r_offset[8];       /* Location at which to apply the action */
00178   unsigned char      r_info[8];    /* index and type of relocation */
00179   unsigned char      r_addend[8];  /* Constant addend used to compute value */
00180 } Elf64_External_Rela;
00181 
00182 /* dynamic section structure */
00183 
00184 typedef struct {
00185   unsigned char      d_tag[4];            /* entry tag value */
00186   union {
00187     unsigned char    d_val[4];
00188     unsigned char    d_ptr[4];
00189   } d_un;
00190 } Elf32_External_Dyn;
00191 
00192 typedef struct {
00193   unsigned char      d_tag[8];            /* entry tag value */
00194   union {
00195     unsigned char    d_val[8];
00196     unsigned char    d_ptr[8];
00197   } d_un;
00198 } Elf64_External_Dyn;
00199 
00200 /* The version structures are currently size independent.  They are
00201    named without a 32 or 64.  If that ever changes, these structures
00202    will need to be renamed.  */
00203 
00204 /* This structure appears in a SHT_GNU_verdef section.  */
00205 
00206 typedef struct {
00207   unsigned char             vd_version[2];
00208   unsigned char             vd_flags[2];
00209   unsigned char             vd_ndx[2];
00210   unsigned char             vd_cnt[2];
00211   unsigned char             vd_hash[4];
00212   unsigned char             vd_aux[4];
00213   unsigned char             vd_next[4];
00214 } Elf_External_Verdef;
00215 
00216 /* This structure appears in a SHT_GNU_verdef section.  */
00217 
00218 typedef struct {
00219   unsigned char             vda_name[4];
00220   unsigned char             vda_next[4];
00221 } Elf_External_Verdaux;
00222 
00223 /* This structure appears in a SHT_GNU_verneed section.  */
00224 
00225 typedef struct {
00226   unsigned char             vn_version[2];
00227   unsigned char             vn_cnt[2];
00228   unsigned char             vn_file[4];
00229   unsigned char             vn_aux[4];
00230   unsigned char             vn_next[4];
00231 } Elf_External_Verneed;
00232 
00233 /* This structure appears in a SHT_GNU_verneed section.  */
00234 
00235 typedef struct {
00236   unsigned char             vna_hash[4];
00237   unsigned char             vna_flags[2];
00238   unsigned char             vna_other[2];
00239   unsigned char             vna_name[4];
00240   unsigned char             vna_next[4];
00241 } Elf_External_Vernaux;
00242 
00243 /* This structure appears in a SHT_GNU_versym section.  This is not a
00244    standard ELF structure; ELF just uses Elf32_Half.  */
00245 
00246 typedef struct {
00247   unsigned char             vs_vers[2];
00248 } ATTRIBUTE_PACKED  Elf_External_Versym;
00249 
00250 /* Structure for syminfo section.  */
00251 typedef struct
00252 {
00253   unsigned char             si_boundto[2];
00254   unsigned char             si_flags[2];
00255 } Elf_External_Syminfo;
00256 
00257 
00258 /* This structure appears on the stack and in NT_AUXV core file notes.  */
00259 typedef struct
00260 {
00261   unsigned char             a_type[4];
00262   unsigned char             a_val[4];
00263 } Elf32_External_Auxv;
00264 
00265 typedef struct
00266 {
00267   unsigned char             a_type[8];
00268   unsigned char             a_val[8];
00269 } Elf64_External_Auxv;
00270 
00271 /* Size of SHT_GROUP section entry.  */
00272 
00273 #define GRP_ENTRY_SIZE             4
00274 
00275 #endif /* _ELF_EXTERNAL_H */