-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibelf.3.html
391 lines (391 loc) · 14.1 KB
/
libelf.3.html
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="mandoc.css" type="text/css" media="all"/>
<title>LIBELF(3)</title>
</head>
<body>
<table class="head">
<tr>
<td class="head-ltitle">LIBELF(3)</td>
<td class="head-vol">Libelf Programmer's Manual</td>
<td class="head-rtitle">LIBELF(3)</td>
</tr>
</table>
<div class="manual-text">
<p class="Pp"></p>
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp">libelf - a library for accessing and manipulating ELF (Executable
and Linkable Format) files</p>
</section>
<section class="Sh">
<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
<p class="Pp">Elfutils library (<b>libelf</b>, <b>libelf.so</b>,
<b>-lelf</b>)</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<pre><b>#include <libelf.h></b>
</pre>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The <b>libelf</b> library provides an API for reading, writing,
and manipulating ELF (Executable and Linkable Format) files. ELF is a
standard format for object files, shared libraries, core dumps, and
executables. See <b>elf</b>(5) for more information regarding ELF.</p>
<p class="Pp"><b>libelf</b> provides routines for working with ELF object file
headers, sections, symbol tables, relocation entries, and other key
components.</p>
<p class="Pp">The core of the library is based on <i>Elf</i> file descriptors
representing ELF files, which can be read from, written to, or updated
in-place. The <b>elf_begin</b> function initializes access to an ELF object,
while additional functions like <b>elf_getscn</b>, <b>elf_getdata</b>, and
<b>elf_ndxscn</b> provide access to specific parts of the ELF file.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="FILE_VS_MEMORY_REPRESENTATION"><a class="permalink" href="#FILE_VS_MEMORY_REPRESENTATION">FILE
VS MEMORY REPRESENTATION</a></h1>
<p class="Pp">The <b>libelf</b> library distinguishes between the file
representation of an ELF file and its memory representation.</p>
<p class="Pp"></p>
<p class="Pp">File Representation refers to the format in which an ELF file is
stored on disk. The fields in the file may use specific sizes, alignment,
and byte ordering (endianness) that could be different from the native
format used by the host system.</p>
<p class="Pp"></p>
<p class="Pp">Memory Representation refers to the way the ELF data is organized
when loaded into an application's memory. In memory, the data structures are
typically converted into the native format of the host system (e.g., the
system's endianness, word size, and alignment).</p>
<p class="Pp"></p>
<p class="Pp"><b>libelf</b> provides the following functions to translate ELF
data between file and memory representations: <b>elf32_xlatetom</b>,
<b>elf64_xlatetom</b>, <b>elf32_xlatetof</b>, and <b>elf64_xlatetof</b>.</p>
<p class="Pp">See <b>elf32_xlatetom</b>(3) for more information.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="ELF_VERSION"><a class="permalink" href="#ELF_VERSION">ELF
VERSION</a></h1>
<p class="Pp">To account for the possibility of multiple versions of the ELF
specification, the ELF version number must be specified with the
<b>elf_version</b> function before any other <b>libelf</b> functions. This
function sets <b>libelf</b>'s ELF version to the specified value. At this
time the only supported ELF version is <b>EV_CURRENT</b>.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTORS"><a class="permalink" href="#DESCRIPTORS">DESCRIPTORS</a></h1>
<p class="Pp"><i>Elf</i> descriptors the central <b>libelf</b> object for
accessing and manipulating ELF files. They are created with the
<b>elf_begin</b>, <b>elf_clone</b>, and <b>elf_memory</b> functions and
closed with the <b>elf_end</b> function.</p>
<p class="Pp"><b>libelf</b> also provides <i>Elf_Scn</i> and <i>Elf_Data</i>
descriptors for ELF sections and section contents, respectively. Members of
the <i>Elf_Data</i> struct are described below. Members of the <i>Elf</i>
and <i>Elf_Scn</i> structs are hidden from applications.</p>
<p class="Pp">These descriptors can be acquired and modified using various
functions provided by <b>libelf</b>. See <b>libelf.h</b> for a complete
list.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="ERROR_HANDLING"><a class="permalink" href="#ERROR_HANDLING">ERROR
HANDLING</a></h1>
<p class="Pp">If a <b>libelf</b> function encounters an error it will set an
internal error code that can be retrieved with <b>elf_errno</b>. Each thread
maintains its own separate error code. The meaning of each error code can be
determined with <b>elf_errmsg,</b> which returns a string describing the
error.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="MEMORY_MANAGEMENT"><a class="permalink" href="#MEMORY_MANAGEMENT">MEMORY
MANAGEMENT</a></h1>
<p class="Pp"><b>libelf</b> manages all of the memory it allocates and frees it
with <b>elf_end</b>. The application must not call <b>free</b> on any memory
allocated by <b>libelf</b>.</p>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="NAMESPACE"><a class="permalink" href="#NAMESPACE">NAMESPACE</a></h1>
<p class="Pp"><b>libelf</b> uses the following prefix format. See
<b>libelf.h</b> for more information.</p>
<p class="Pp"></p>
<div class="Bd-indent">
<dl class="Bl-tag">
<dt id="elf_"><a class="permalink" href="#elf_"><b>elf_</b></a></dt>
<dd>Functions usable with both 32-bit and 64-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="elf32_"><a class="permalink" href="#elf32_"><b>elf32_</b></a></dt>
<dd>Functions usable with 32-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="elf64_"><a class="permalink" href="#elf64_"><b>elf64_</b></a></dt>
<dd>Functions usable with 64-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="Elf_"><a class="permalink" href="#Elf_"><b>Elf_</b></a></dt>
<dd>Type that represents data for both 32-bit and 64-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="Elf32_"><a class="permalink" href="#Elf32_"><b>Elf32_</b></a></dt>
<dd>Type that represents data for 32-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="Elf64_"><a class="permalink" href="#Elf64_"><b>Elf64_</b></a></dt>
<dd>Type that represents data for 64-bit ELF files.
<p class="Pp"></p>
</dd>
<dt id="ELF_C_"><a class="permalink" href="#ELF_C_"><b>ELF_C_</b></a></dt>
<dd><i>Elf_Cmd</i> values used in functions such as <b>elf_flagset</b> and
<b>elf_cntl</b>.
<p class="Pp"></p>
</dd>
<dt id="ELF_F_"><a class="permalink" href="#ELF_F_"><b>ELF_F_</b></a></dt>
<dd>Flags for ELF structures.
<p class="Pp"></p>
</dd>
<dt id="ELF_K_"><a class="permalink" href="#ELF_K_"><b>ELF_K_</b></a></dt>
<dd><i>Elf_Kind</i> Identification values for recognized object file types.
<p class="Pp"></p>
</dd>
<dt id="ELF_T_"><a class="permalink" href="#ELF_T_"><b>ELF_T_</b></a></dt>
<dd><i>Elf_Type</i> values representing the known types of ELF data such as
<b>ELF_T_BYTE</b>, (unsigned char) <b>ELF_T_REL</b>, (relocation entry) or
<b>ELF_T_SYM</b> (symbol record).
<br/>
</dd>
</dl>
</div>
<p class="Pp"></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DATA_STRUCTURES"><a class="permalink" href="#DATA_STRUCTURES">DATA
STRUCTURES</a></h1>
<p class="Pp"><b>libelf</b> implements the following data structures, in
addition to including the data structures given in the ELF specification
(see <b>elf</b>(5) for more information).</p>
<p class="Pp"></p>
<section class="Ss">
<h2 class="Ss" id="Section_Compression_Header"><a class="permalink" href="#Section_Compression_Header">Section
Compression Header</a></h2>
<pre>
<br/>
typedef struct {
<br/>
Elf32_Word ch_type;
<br/>
Elf32_Word ch_size;
<br/>
Elf32_Word ch_addralign;
} Elf32_Chdr;
typedef struct {
<br/>
Elf64_Word ch_type;
<br/>
Elf64_Word ch_reserved;
<br/>
Elf64_Xword ch_size;
<br/>
Elf64_Xword ch_addralign;
<br/>
} Elf64_Chdr;</pre>
<p class="Pp"></p>
<dl class="Bl-tag">
<dt id="ch_type"><a class="permalink" href="#ch_type"><i>ch_type</i></a></dt>
<dd>Compression format type. Legal values include <b>ELFCOMPRESS_ZLIB</b>,
<b>ELFCOMPRESS_ZSTD</b>, the inclusive range between
<b>ELFCOMPRESS_LOOS</b> to <b>ELFCOMPRESS_HIOS</b> as well as the
inclusive range between <b>ELFCOMPRESS_LOPROC</b> and
<b>ELFCOMPRESS_HIPROC</b>
<p class="Pp"></p>
</dd>
</dl>
<div class="Bd-indent">
<dl class="Bl-tag">
<dt><b>ELFCOMPRESS_ZLIB</b></dt>
<dd>ZLIB/DEFLATE algorithm.</dd>
<dt id="ELFCOMPRESS_ZSTD"><a class="permalink" href="#ELFCOMPRESS_ZSTD"><b>ELFCOMPRESS_ZSTD</b></a></dt>
<dd>Zstandard algorithm.</dd>
<dt id="ELFCOMPRESS_LOOS"><a class="permalink" href="#ELFCOMPRESS_LOOS"><b>ELFCOMPRESS_LOOS</b></a></dt>
<dd>Start of OS-specific compression types.</dd>
<dt id="ELFCOMPRESS_HIOS"><a class="permalink" href="#ELFCOMPRESS_HIOS"><b>ELFCOMPRESS_HIOS</b></a></dt>
<dd>End of OS-specific compression types.</dd>
<dt id="ELFCOMPRESS_LOPROC"><a class="permalink" href="#ELFCOMPRESS_LOPROC"><b>ELFCOMPRESS_LOPROC</b></a></dt>
<dd>Start of processor-specific compression types.</dd>
<dt id="ELFCOMPRESS_HIPROC"><a class="permalink" href="#ELFCOMPRESS_HIPROC"><b>ELFCOMPRESS_HIPROC</b></a></dt>
<dd>End of processor-specific compression types.</dd>
</dl>
</div>
<p class="Pp"></p>
<dl class="Bl-tag">
<dt id="ch_reserved"><a class="permalink" href="#ch_reserved"><i>ch_reserved</i></a></dt>
<dd>Space reserved for use by <b>libelf</b>.
<p class="Pp"></p>
</dd>
<dt id="ch_size"><a class="permalink" href="#ch_size"><i>ch_size</i></a></dt>
<dd>Data size of uncompressed section.
<p class="Pp"></p>
</dd>
<dt id="ch_addralign"><a class="permalink" href="#ch_addralign"><i>ch_addralign</i></a></dt>
<dd>Alignment of uncompressed section.
<p class="Pp"></p>
<p class="Pp"></p>
</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Section_Data"><a class="permalink" href="#Section_Data">Section
Data</a></h2>
<pre>
<br/>
typedef struct {
<br/>
void *d_buf;
<br/>
Elf_Type d_type;
<br/>
unsigned int d_version;
<br/>
size_t d_size;
<br/>
int64_t d_off;
<br/>
size_t d_align;
} Elf_Data;</pre>
<p class="Pp"></p>
<dl class="Bl-tag">
<dt id="d_buf"><a class="permalink" href="#d_buf"><i>d_buf</i></a></dt>
<dd>Pointer to the actual data. Use <b>elf_getdata</b> to retrieve data in
memory representation and <b>elf_rawdata</b> to retrieve data in file
representation.
<p class="Pp"></p>
</dd>
<dt id="d_type"><a class="permalink" href="#d_type"><i>d_type</i></a></dt>
<dd>The <i>Elf_Type</i> of this piece of data. See the <i>Elf_Type</i> enum in
<b>libelf.h</b> for descriptions of each value.
<p class="Pp"></p>
</dd>
<dt id="d_version"><a class="permalink" href="#d_version"><i>d_version</i></a></dt>
<dd>The ELF version for this data.
<p class="Pp"></p>
</dd>
<dt id="d_size"><a class="permalink" href="#d_size"><i>d_size</i></a></dt>
<dd>The size in bytes of this data.
<p class="Pp"></p>
</dd>
<dt id="d_off"><a class="permalink" href="#d_off"><i>d_off</i></a></dt>
<dd>The section offset of this data.
<p class="Pp"></p>
</dd>
<dt id="d_align"><a class="permalink" href="#d_align"><i>d_align</i></a></dt>
<dd>The section alignment of this data.
<p class="Pp"></p>
</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Archive_Member_Header"><a class="permalink" href="#Archive_Member_Header">Archive
Member Header</a></h2>
<pre>
<br/>
typedef struct {
<br/>
char *ar_name;
<br/>
time_t ar_date;
<br/>
uid_t ar_uid;
<br/>
gid_t ar_gid;
<br/>
mode_t ar_mode;
<br/>
int64_t ar_size;
<br/>
char *ar_rawname;
} Elf_Arhdr;</pre>
<p class="Pp"></p>
<dl class="Bl-tag">
<dt id="ar_name"><a class="permalink" href="#ar_name"><i>ar_name</i></a></dt>
<dd>Name of archive member.
<p class="Pp"></p>
</dd>
<dt id="ar_data"><a class="permalink" href="#ar_data"><i>ar_data</i></a></dt>
<dd>File date.
<p class="Pp"></p>
</dd>
<dt id="ar_uid"><a class="permalink" href="#ar_uid"><i>ar_uid</i></a></dt>
<dd>User ID.
<p class="Pp"></p>
</dd>
<dt id="ar_gid"><a class="permalink" href="#ar_gid"><i>ar_gid</i></a></dt>
<dd>Group ID.
<p class="Pp"></p>
</dd>
<dt id="ar_mode"><a class="permalink" href="#ar_mode"><i>ar_mode</i></a></dt>
<dd>File mode.
<p class="Pp"></p>
</dd>
<dt id="ar_size"><a class="permalink" href="#ar_size"><i>ar_size</i></a></dt>
<dd>File size.
<p class="Pp"></p>
</dd>
<dt id="ar_rawname"><a class="permalink" href="#ar_rawname"><i>ar_rawname</i></a></dt>
<dd>Original name of archive member.
<p class="Pp"></p>
</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Archive_Symbol_Table_Entry"><a class="permalink" href="#Archive_Symbol_Table_Entry">Archive
Symbol Table Entry</a></h2>
<pre>
<br/>
typedef struct {
<br/>
char *as_name;
<br/>
size_t as_off;
<br/>
unsigned long int as_hash;
} Elf_Arsym;</pre>
<p class="Pp"></p>
<dl class="Bl-tag">
<dt id="as_name"><a class="permalink" href="#as_name"><i>as_name</i></a></dt>
<dd>Symbol name.
<p class="Pp"></p>
</dd>
<dt id="as_off"><a class="permalink" href="#as_off"><i>as_off</i></a></dt>
<dd>Offset for this file in the archive.
<p class="Pp"></p>
</dd>
<dt id="as_hash"><a class="permalink" href="#as_hash"><i>as_hash</i></a></dt>
<dd>Hash value of the name.
<p class="Pp"></p>
</dd>
</dl>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="REPORTING_BUGS"><a class="permalink" href="#REPORTING_BUGS">REPORTING
BUGS</a></h1>
<p class="Pp">Report bugs to <[email protected]> or
https://sourceware.org/bugzilla/.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">2024-10-18</td>
<td class="foot-os">Libelf</td>
</tr>
</table>
</body>
</html>