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