Home | History | Annotate | Download | only in libelf
      1 /* This file defines generic ELF types, structures, and macros.
      2    Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007 Red Hat, Inc.
      3    This file is part of Red Hat elfutils.
      4 
      5    Red Hat elfutils is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by the
      7    Free Software Foundation; version 2 of the License.
      8 
      9    Red Hat elfutils is distributed in the hope that it will be useful, but
     10    WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12    General Public License for more details.
     13 
     14    You should have received a copy of the GNU General Public License along
     15    with Red Hat elfutils; if not, write to the Free Software Foundation,
     16    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     17 
     18    In addition, as a special exception, Red Hat, Inc. gives You the
     19    additional right to link the code of Red Hat elfutils with code licensed
     20    under any Open Source Initiative certified open source license
     21    (http://www.opensource.org/licenses/index.php) which requires the
     22    distribution of source code with any binary distribution and to
     23    distribute linked combinations of the two.  Non-GPL Code permitted under
     24    this exception must only link to the code of Red Hat elfutils through
     25    those well defined interfaces identified in the file named EXCEPTION
     26    found in the source code files (the "Approved Interfaces").  The files
     27    of Non-GPL Code may instantiate templates or use macros or inline
     28    functions from the Approved Interfaces without causing the resulting
     29    work to be covered by the GNU General Public License.  Only Red Hat,
     30    Inc. may make changes or additions to the list of Approved Interfaces.
     31    Red Hat's grant of this exception is conditioned upon your not adding
     32    any new exceptions.  If you wish to add a new Approved Interface or
     33    exception, please contact Red Hat.  You must obey the GNU General Public
     34    License in all respects for all of the Red Hat elfutils code and other
     35    code used in conjunction with Red Hat elfutils except the Non-GPL Code
     36    covered by this exception.  If you modify this file, you may extend this
     37    exception to your version of the file, but you are not obligated to do
     38    so.  If you do not wish to provide this exception without modification,
     39    you must delete this exception statement from your version and license
     40    this file solely under the GPL without exception.
     41 
     42    Red Hat elfutils is an included package of the Open Invention Network.
     43    An included package of the Open Invention Network is a package for which
     44    Open Invention Network licensees cross-license their patents.  No patent
     45    license is granted, either expressly or impliedly, by designation as an
     46    included package.  Should you wish to participate in the Open Invention
     47    Network licensing program, please visit www.openinventionnetwork.com
     48    <http://www.openinventionnetwork.com>.  */
     49 
     50 #ifndef _GELF_H
     51 #define	_GELF_H 1
     52 
     53 #include <libelf.h>
     54 
     55 
     56 #ifdef __cplusplus
     57 extern "C" {
     58 #endif
     59 
     60 /* Class independent type definitions.  Correctly speaking this is not
     61    true.  We assume that 64-bit binaries are the largest class and
     62    therefore all other classes can be represented without loss.  */
     63 
     64 /* Type for a 16-bit quantity.  */
     65 typedef Elf64_Half GElf_Half;
     66 
     67 /* Types for signed and unsigned 32-bit quantities.  */
     68 typedef Elf64_Word GElf_Word;
     69 typedef	Elf64_Sword GElf_Sword;
     70 
     71 /* Types for signed and unsigned 64-bit quantities.  */
     72 typedef Elf64_Xword GElf_Xword;
     73 typedef	Elf64_Sxword GElf_Sxword;
     74 
     75 /* Type of addresses.  */
     76 typedef Elf64_Addr GElf_Addr;
     77 
     78 /* Type of file offsets.  */
     79 typedef Elf64_Off GElf_Off;
     80 
     81 
     82 /* The ELF file header.  This appears at the start of every ELF file.  */
     83 typedef Elf64_Ehdr GElf_Ehdr;
     84 
     85 /* Section header.  */
     86 typedef Elf64_Shdr GElf_Shdr;
     87 
     88 /* Section index.  */
     89 /* XXX This should probably be a larger type in preparation of times when
     90    regular section indices can be larger.  */
     91 typedef Elf64_Section GElf_Section;
     92 
     93 /* Symbol table entry.  */
     94 typedef Elf64_Sym GElf_Sym;
     95 
     96 /* The syminfo section if available contains additional information about
     97    every dynamic symbol.  */
     98 typedef Elf64_Syminfo GElf_Syminfo;
     99 
    100 /* Relocation table entry without addend (in section of type SHT_REL).  */
    101 typedef Elf64_Rel GElf_Rel;
    102 
    103 /* Relocation table entry with addend (in section of type SHT_RELA).  */
    104 typedef Elf64_Rela GElf_Rela;
    105 
    106 /* Program segment header.  */
    107 typedef Elf64_Phdr GElf_Phdr;
    108 
    109 /* Dynamic section entry.  */
    110 typedef Elf64_Dyn GElf_Dyn;
    111 
    112 
    113 /* Version definition sections.  */
    114 typedef Elf64_Verdef GElf_Verdef;
    115 
    116 /* Auxialiary version information.  */
    117 typedef Elf64_Verdaux GElf_Verdaux;
    118 
    119 /* Version dependency section.  */
    120 typedef Elf64_Verneed GElf_Verneed;
    121 
    122 /* Auxiliary needed version information.  */
    123 typedef Elf64_Vernaux GElf_Vernaux;
    124 
    125 
    126 /* Type for version symbol information.  */
    127 typedef Elf64_Versym GElf_Versym;
    128 
    129 
    130 /* Auxiliary vector.  */
    131 typedef Elf64_auxv_t GElf_auxv_t;
    132 
    133 
    134 /* Note section contents.  */
    135 typedef Elf64_Nhdr GElf_Nhdr;
    136 
    137 
    138 /* Move structure.  */
    139 typedef Elf64_Move GElf_Move;
    140 
    141 
    142 /* Library list structure.  */
    143 typedef Elf64_Lib GElf_Lib;
    144 
    145 
    146 /* How to extract and insert information held in the st_info field.  */
    147 
    148 #define GELF_ST_BIND(val)		ELF64_ST_BIND (val)
    149 #define GELF_ST_TYPE(val)		ELF64_ST_TYPE (val)
    150 #define GELF_ST_INFO(bind, type)	ELF64_ST_INFO (bind, type)
    151 
    152 /* How to extract information held in the st_other field.  */
    153 
    154 #define GELF_ST_VISIBILITY(val)		ELF64_ST_VISIBILITY (val)
    155 
    156 
    157 /* How to extract and insert information held in the r_info field.  */
    158 
    159 #define GELF_R_SYM(info)		ELF64_R_SYM (info)
    160 #define GELF_R_TYPE(info)		ELF64_R_TYPE (info)
    161 #define GELF_R_INFO(sym, type)		ELF64_R_INFO (sym, type)
    162 
    163 
    164 /* How to extract and insert information held in the m_info field.  */
    165 #define GELF_M_SYM(info)		ELF64_M_SYM (info)
    166 #define GELF_M_SIZE(info)		ELF64_M_SIZE (info)
    167 #define GELF_M_INFO(sym, size)		ELF64_M_INFO (sym, size)
    168 
    169 
    170 /* Get class of the file associated with ELF.  */
    171 extern int gelf_getclass (Elf *__elf);
    172 
    173 
    174 /* Return size of array of COUNT elemeents of the type denoted by TYPE
    175    in the external representation.  The binary class is taken from ELF.
    176    The result is based on version VERSION of the ELF standard.  */
    177 extern size_t gelf_fsize (Elf *__elf, Elf_Type __type, size_t __count,
    178 			  unsigned int __version);
    179 
    180 /* Retrieve object file header.  */
    181 extern GElf_Ehdr *gelf_getehdr (Elf *__elf, GElf_Ehdr *__dest);
    182 
    183 /* Update the ELF header.  */
    184 extern int gelf_update_ehdr (Elf *__elf, GElf_Ehdr *__src);
    185 
    186 /* Create new ELF header if none exists.  */
    187 extern unsigned long int gelf_newehdr (Elf *__elf, int __class);
    188 
    189 /* Get section at OFFSET.  */
    190 extern Elf_Scn *gelf_offscn (Elf *__elf, GElf_Off __offset);
    191 
    192 /* Retrieve section header.  */
    193 extern GElf_Shdr *gelf_getshdr (Elf_Scn *__scn, GElf_Shdr *__dst);
    194 
    195 /* Update section header.  */
    196 extern int gelf_update_shdr (Elf_Scn *__scn, GElf_Shdr *__src);
    197 
    198 /* Retrieve program header table entry.  */
    199 extern GElf_Phdr *gelf_getphdr (Elf *__elf, int __ndx, GElf_Phdr *__dst);
    200 
    201 /* Update the program header.  */
    202 extern int gelf_update_phdr (Elf *__elf, int __ndx, GElf_Phdr *__src);
    203 
    204 /* Create new program header with PHNUM entries.  */
    205 extern unsigned long int gelf_newphdr (Elf *__elf, size_t __phnum);
    206 
    207 
    208 /* Convert data structure from the representation in the file represented
    209    by ELF to their memory representation.  */
    210 extern Elf_Data *gelf_xlatetom (Elf *__elf, Elf_Data *__dest,
    211 				const Elf_Data *__src, unsigned int __encode);
    212 
    213 /* Convert data structure from to the representation in memory
    214    represented by ELF file representation.  */
    215 extern Elf_Data *gelf_xlatetof (Elf *__elf, Elf_Data *__dest,
    216 				const Elf_Data *__src, unsigned int __encode);
    217 
    218 
    219 /* Retrieve REL relocation info at the given index.  */
    220 extern GElf_Rel *gelf_getrel (Elf_Data *__data, int __ndx, GElf_Rel *__dst);
    221 
    222 /* Retrieve RELA relocation info at the given index.  */
    223 extern GElf_Rela *gelf_getrela (Elf_Data *__data, int __ndx, GElf_Rela *__dst);
    224 
    225 /* Update REL relocation information at given index.  */
    226 extern int gelf_update_rel (Elf_Data *__dst, int __ndx, GElf_Rel *__src);
    227 
    228 /* Update RELA relocation information at given index.  */
    229 extern int gelf_update_rela (Elf_Data *__dst, int __ndx, GElf_Rela *__src);
    230 
    231 
    232 /* Retrieve symbol information from the symbol table at the given index.  */
    233 extern GElf_Sym *gelf_getsym (Elf_Data *__data, int __ndx, GElf_Sym *__dst);
    234 
    235 /* Update symbol information in the symbol table at the given index.  */
    236 extern int gelf_update_sym (Elf_Data *__data, int __ndx, GElf_Sym *__src);
    237 
    238 
    239 /* Retrieve symbol information and separate section index from the
    240    symbol table at the given index.  */
    241 extern GElf_Sym *gelf_getsymshndx (Elf_Data *__symdata, Elf_Data *__shndxdata,
    242 				   int __ndx, GElf_Sym *__sym,
    243 				   Elf32_Word *__xshndx);
    244 
    245 /* Update symbol information and separate section index in the symbol
    246    table at the given index.  */
    247 extern int gelf_update_symshndx (Elf_Data *__symdata, Elf_Data *__shndxdata,
    248 				 int __ndx, GElf_Sym *__sym,
    249 				 Elf32_Word __xshndx);
    250 
    251 
    252 /* Retrieve additional symbol information from the symbol table at the
    253    given index.  */
    254 extern GElf_Syminfo *gelf_getsyminfo (Elf_Data *__data, int __ndx,
    255 				      GElf_Syminfo *__dst);
    256 
    257 /* Update additional symbol information in the symbol table at the
    258    given index.  */
    259 extern int gelf_update_syminfo (Elf_Data *__data, int __ndx,
    260 				GElf_Syminfo *__src);
    261 
    262 
    263 /* Get information from dynamic table at the given index.  */
    264 extern GElf_Dyn *gelf_getdyn (Elf_Data *__data, int __ndx, GElf_Dyn *__dst);
    265 
    266 /* Update information in dynamic table at the given index.  */
    267 extern int gelf_update_dyn (Elf_Data *__dst, int __ndx, GElf_Dyn *__src);
    268 
    269 
    270 /* Get move structure at the given index.  */
    271 extern GElf_Move *gelf_getmove (Elf_Data *__data, int __ndx, GElf_Move *__dst);
    272 
    273 /* Update move structure at the given index.  */
    274 extern int gelf_update_move (Elf_Data *__data, int __ndx,
    275 			     GElf_Move *__src);
    276 
    277 
    278 /* Get library from table at the given index.  */
    279 extern GElf_Lib *gelf_getlib (Elf_Data *__data, int __ndx, GElf_Lib *__dst);
    280 
    281 /* Update library in table at the given index.  */
    282 extern int gelf_update_lib (Elf_Data *__data, int __ndx, GElf_Lib *__src);
    283 
    284 
    285 
    286 /* Retrieve symbol version information at given index.  */
    287 extern GElf_Versym *gelf_getversym (Elf_Data *__data, int __ndx,
    288 				    GElf_Versym *__dst);
    289 
    290 /* Update symbol version information.  */
    291 extern int gelf_update_versym (Elf_Data *__data, int __ndx,
    292 			       GElf_Versym *__src);
    293 
    294 
    295 /* Retrieve required symbol version information at given offset.  */
    296 extern GElf_Verneed *gelf_getverneed (Elf_Data *__data, int __offset,
    297 				      GElf_Verneed *__dst);
    298 
    299 /* Update required symbol version information.  */
    300 extern int gelf_update_verneed (Elf_Data *__data, int __offset,
    301 				GElf_Verneed *__src);
    302 
    303 /* Retrieve additional required symbol version information at given offset.  */
    304 extern GElf_Vernaux *gelf_getvernaux (Elf_Data *__data, int __offset,
    305 				      GElf_Vernaux *__dst);
    306 
    307 /* Update additional required symbol version information.  */
    308 extern int gelf_update_vernaux (Elf_Data *__data, int __offset,
    309 				GElf_Vernaux *__src);
    310 
    311 
    312 /* Retrieve symbol version definition information at given offset.  */
    313 extern GElf_Verdef *gelf_getverdef (Elf_Data *__data, int __offset,
    314 				    GElf_Verdef *__dst);
    315 
    316 /* Update symbol version definition information.  */
    317 extern int gelf_update_verdef (Elf_Data *__data, int __offset,
    318 			       GElf_Verdef *__src);
    319 
    320 /* Retrieve additional symbol version definition information at given
    321    offset.  */
    322 extern GElf_Verdaux *gelf_getverdaux (Elf_Data *__data, int __offset,
    323 				      GElf_Verdaux *__dst);
    324 
    325 /* Update additional symbol version definition information.  */
    326 extern int gelf_update_verdaux (Elf_Data *__data, int __offset,
    327 				GElf_Verdaux *__src);
    328 
    329 
    330 /* Get auxv entry at the given index.  */
    331 extern GElf_auxv_t *gelf_getauxv (Elf_Data *__data, int __ndx,
    332 				  GElf_auxv_t *__dst);
    333 
    334 /* Update auxv entry at the given index.  */
    335 extern int gelf_update_auxv (Elf_Data *__data, int __ndx, GElf_auxv_t *__src);
    336 
    337 
    338 /* Get note header at the given offset into the data, and the offsets of
    339    the note's name and descriptor data.  Returns the offset of the next
    340    note header, or 0 for an invalid offset or corrupt note header.  */
    341 extern size_t gelf_getnote (Elf_Data *__data, size_t __offset,
    342 			    GElf_Nhdr *__result,
    343 			    size_t *__name_offset, size_t *__desc_offset);
    344 
    345 
    346 /* Compute simple checksum from permanent parts of the ELF file.  */
    347 extern long int gelf_checksum (Elf *__elf);
    348 
    349 #ifdef __cplusplus
    350 }
    351 #endif
    352 
    353 #endif	/* gelf.h */
    354