1/* This file defines generic ELF types, structures, and macros. 2 Copyright (C) 1999, 2000, 2001, 2002, 2004 Red Hat, Inc. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, version 2. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software Foundation, 15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 17#ifndef _GELF_H 18#define _GELF_H 1 19 20#include <libelf.h> 21 22 23#ifdef __cplusplus 24extern "C" { 25#endif 26 27/* Class independent type definitions. Correctly speaking this is not 28 true. We assume that 64-bit binaries are the largest class and 29 therefore all other classes can be represented without loss. */ 30 31/* Type for a 16-bit quantity. */ 32typedef Elf64_Half GElf_Half; 33 34/* Types for signed and unsigned 32-bit quantities. */ 35typedef Elf64_Word GElf_Word; 36typedef Elf64_Sword GElf_Sword; 37 38/* Types for signed and unsigned 64-bit quantities. */ 39typedef Elf64_Xword GElf_Xword; 40typedef Elf64_Sxword GElf_Sxword; 41 42/* Type of addresses. */ 43typedef Elf64_Addr GElf_Addr; 44 45/* Type of file offsets. */ 46typedef Elf64_Off GElf_Off; 47 48 49/* The ELF file header. This appears at the start of every ELF file. */ 50typedef Elf64_Ehdr GElf_Ehdr; 51 52/* Section header. */ 53typedef Elf64_Shdr GElf_Shdr; 54 55/* Section index. */ 56/* XXX This should probably be a larger type in preparation of times when 57 regular section indices can be larger. */ 58typedef Elf64_Section GElf_Section; 59 60/* Symbol table entry. */ 61typedef Elf64_Sym GElf_Sym; 62 63/* The syminfo section if available contains additional information about 64 every dynamic symbol. */ 65typedef Elf64_Syminfo GElf_Syminfo; 66 67/* Relocation table entry without addend (in section of type SHT_REL). */ 68typedef Elf64_Rel GElf_Rel; 69 70/* Relocation table entry with addend (in section of type SHT_RELA). */ 71typedef Elf64_Rela GElf_Rela; 72 73/* Program segment header. */ 74typedef Elf64_Phdr GElf_Phdr; 75 76/* Dynamic section entry. */ 77typedef Elf64_Dyn GElf_Dyn; 78 79 80/* Version definition sections. */ 81typedef Elf64_Verdef GElf_Verdef; 82 83/* Auxialiary version information. */ 84typedef Elf64_Verdaux GElf_Verdaux; 85 86/* Version dependency section. */ 87typedef Elf64_Verneed GElf_Verneed; 88 89/* Auxiliary needed version information. */ 90typedef Elf64_Vernaux GElf_Vernaux; 91 92 93/* Type for version symbol information. */ 94typedef Elf64_Versym GElf_Versym; 95 96 97/* Auxiliary vector. */ 98typedef Elf64_auxv_t GElf_auxv_t; 99 100 101/* Note section contents. */ 102typedef Elf64_Nhdr GElf_Nhdr; 103 104 105/* Move structure. */ 106typedef Elf64_Move GElf_Move; 107 108 109/* Library list structure. */ 110typedef Elf64_Lib GElf_Lib; 111 112 113/* How to extract and insert information held in the st_info field. */ 114 115#define GELF_ST_BIND(val) ELF64_ST_BIND (val) 116#define GELF_ST_TYPE(val) ELF64_ST_TYPE (val) 117#define GELF_ST_INFO(bind, type) ELF64_ST_INFO (bind, type) 118 119/* How to extract information held in the st_other field. */ 120 121#define GELF_ST_VISIBILITY(val) ELF64_ST_VISIBILITY (val) 122 123 124/* How to extract and insert information held in the r_info field. */ 125 126#define GELF_R_SYM(info) ELF64_R_SYM (info) 127#define GELF_R_TYPE(info) ELF64_R_TYPE (info) 128#define GELF_R_INFO(sym, type) ELF64_R_INFO (sym, type) 129 130 131/* How to extract and insert information held in the m_info field. */ 132#define GELF_M_SYM(info) ELF64_M_SYM (info) 133#define GELF_M_SIZE(info) ELF64_M_SIZE (info) 134#define GELF_M_INFO(sym, size) ELF64_M_INFO (sym, size) 135 136 137/* Get class of the file associated with ELF. */ 138extern int gelf_getclass (Elf *__elf); 139 140 141/* Return size of array of COUNT elemeents of the type denoted by TYPE 142 in the external representation. The binary class is taken from ELF. 143 The result is based on version VERSION of the ELF standard. */ 144extern size_t gelf_fsize (Elf *__elf, Elf_Type __type, size_t __count, 145 unsigned int __version); 146 147/* Retrieve object file header. */ 148extern GElf_Ehdr *gelf_getehdr (Elf *__elf, GElf_Ehdr *__dest); 149 150/* Update the ELF header. */ 151extern int gelf_update_ehdr (Elf *__elf, GElf_Ehdr *__src); 152 153/* Create new ELF header if none exists. */ 154extern unsigned long int gelf_newehdr (Elf *__elf, int __class); 155 156/* Retrieve section header. */ 157extern GElf_Shdr *gelf_getshdr (Elf_Scn *__scn, GElf_Shdr *__dst); 158 159/* Update section header. */ 160extern int gelf_update_shdr (Elf_Scn *__scn, GElf_Shdr *__src); 161 162/* Retrieve program header table entry. */ 163extern GElf_Phdr *gelf_getphdr (Elf *__elf, int __ndx, GElf_Phdr *__dst); 164 165/* Update the program header. */ 166extern int gelf_update_phdr (Elf *__elf, int __ndx, GElf_Phdr *__src); 167 168/* Create new program header with PHNUM entries. */ 169extern unsigned long int gelf_newphdr (Elf *__elf, size_t __phnum); 170 171 172/* Convert data structure from the representation in the file represented 173 by ELF to their memory representation. */ 174extern Elf_Data *gelf_xlatetom (Elf *__elf, Elf_Data *__dest, 175 const Elf_Data *__src, unsigned int __encode); 176 177/* Convert data structure from to the representation in memory 178 represented by ELF file representation. */ 179extern Elf_Data *gelf_xlatetof (Elf *__elf, Elf_Data *__dest, 180 const Elf_Data *__src, unsigned int __encode); 181 182 183/* Retrieve REL relocation info at the given index. */ 184extern GElf_Rel *gelf_getrel (Elf_Data *__data, int __ndx, GElf_Rel *__dst); 185 186/* Retrieve RELA relocation info at the given index. */ 187extern GElf_Rela *gelf_getrela (Elf_Data *__data, int __ndx, GElf_Rela *__dst); 188 189/* Update REL relocation information at given index. */ 190extern int gelf_update_rel (Elf_Data *__dst, int __ndx, GElf_Rel *__src); 191 192/* Update RELA relocation information at given index. */ 193extern int gelf_update_rela (Elf_Data *__dst, int __ndx, GElf_Rela *__src); 194 195 196/* Retrieve symbol information from the symbol table at the given index. */ 197extern GElf_Sym *gelf_getsym (Elf_Data *__data, int __ndx, GElf_Sym *__dst); 198 199/* Update symbol information in the symbol table at the given index. */ 200extern int gelf_update_sym (Elf_Data *__data, int __ndx, GElf_Sym *__src); 201 202 203/* Retrieve symbol information and separate section index from the 204 symbol table at the given index. */ 205extern GElf_Sym *gelf_getsymshndx (Elf_Data *__symdata, Elf_Data *__shndxdata, 206 int __ndx, GElf_Sym *__sym, 207 Elf32_Word *__xshndx); 208 209/* Update symbol information and separate section index in the symbol 210 table at the given index. */ 211extern int gelf_update_symshndx (Elf_Data *__symdata, Elf_Data *__shndxdata, 212 int __ndx, GElf_Sym *__sym, 213 Elf32_Word __xshndx); 214 215 216/* Retrieve additional symbol information from the symbol table at the 217 given index. */ 218extern GElf_Syminfo *gelf_getsyminfo (Elf_Data *__data, int __ndx, 219 GElf_Syminfo *__dst); 220 221/* Update additional symbol information in the symbol table at the 222 given index. */ 223extern int gelf_update_syminfo (Elf_Data *__data, int __ndx, 224 GElf_Syminfo *__src); 225 226 227/* Get information from dynamic table at the given index. */ 228extern GElf_Dyn *gelf_getdyn (Elf_Data *__data, int __ndx, GElf_Dyn *__dst); 229 230/* Update information in dynamic table at the given index. */ 231extern int gelf_update_dyn (Elf_Data *__dst, int __ndx, GElf_Dyn *__src); 232 233 234/* Get move structure at the given index. */ 235extern GElf_Move *gelf_getmove (Elf_Data *__data, int __ndx, GElf_Move *__dst); 236 237/* Update move structure at the given index. */ 238extern int gelf_update_move (Elf_Data *__data, int __ndx, 239 GElf_Move *__src); 240 241 242/* Get library from table at the given index. */ 243extern GElf_Lib *gelf_getlib (Elf_Data *__data, int __ndx, GElf_Lib *__dst); 244 245/* Update library in table at the given index. */ 246extern int gelf_update_lib (Elf_Data *__data, int __ndx, GElf_Lib *__src); 247 248 249 250/* Retrieve symbol version information at given index. */ 251extern GElf_Versym *gelf_getversym (Elf_Data *__data, int __ndx, 252 GElf_Versym *__dst); 253 254/* Update symbol version information. */ 255extern int gelf_update_versym (Elf_Data *__data, int __ndx, 256 GElf_Versym *__src); 257 258 259/* Retrieve required symbol version information at given offset. */ 260extern GElf_Verneed *gelf_getverneed (Elf_Data *__data, int __offset, 261 GElf_Verneed *__dst); 262 263/* Update required symbol version information. */ 264extern int gelf_update_verneed (Elf_Data *__data, int __offset, 265 GElf_Verneed *__src); 266 267/* Retrieve additional required symbol version information at given offset. */ 268extern GElf_Vernaux *gelf_getvernaux (Elf_Data *__data, int __offset, 269 GElf_Vernaux *__dst); 270 271/* Update additional required symbol version information. */ 272extern int gelf_update_vernaux (Elf_Data *__data, int __offset, 273 GElf_Vernaux *__src); 274 275 276/* Retrieve symbol version definition information at given offset. */ 277extern GElf_Verdef *gelf_getverdef (Elf_Data *__data, int __offset, 278 GElf_Verdef *__dst); 279 280/* Update symbol version definition information. */ 281extern int gelf_update_verdef (Elf_Data *__data, int __offset, 282 GElf_Verdef *__src); 283 284/* Retrieve additional symbol version definition information at given 285 offset. */ 286extern GElf_Verdaux *gelf_getverdaux (Elf_Data *__data, int __offset, 287 GElf_Verdaux *__dst); 288 289/* Update additional symbol version definition information. */ 290extern int gelf_update_verdaux (Elf_Data *__data, int __offset, 291 GElf_Verdaux *__src); 292 293 294/* Retrieve uninterpreted chunk of the file contents. */ 295extern char *gelf_rawchunk (Elf *__elf, GElf_Off __offset, GElf_Word __size); 296 297/* Release uninterpreted chunk of the file contents. */ 298extern void gelf_freechunk (Elf *__elf, char *__ptr); 299 300#ifdef __cplusplus 301} 302#endif 303 304#endif /* gelf.h */ 305