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