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