]>
Commit | Line | Data |
---|---|---|
8d5bf179 MK |
1 | .\" $OpenBSD: elf.5,v 1.12 2003/10/27 20:23:58 jmc Exp $ |
2 | .\"Copyright (c) 1999 Jeroen Ruigrok van der Werven | |
3 | .\"All rights reserved. | |
4 | .\" | |
5 | .\"Redistribution and use in source and binary forms, with or without | |
6 | .\"modification, are permitted provided that the following conditions | |
7 | .\"are met: | |
8 | .\"1. Redistributions of source code must retain the above copyright | |
9 | .\" notice, this list of conditions and the following disclaimer. | |
10 | .\"2. Redistributions in binary form must reproduce the above copyright | |
11 | .\" notice, this list of conditions and the following disclaimer in the | |
12 | .\" documentation and/or other materials provided with the distribution. | |
13 | .\" | |
14 | .\"THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
15 | .\"ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 | .\"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
17 | .\"ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
18 | .\"FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
19 | .\"DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
20 | .\"OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
21 | .\"HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
22 | .\"LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
23 | .\"OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
24 | .\"SUCH DAMAGE. | |
25 | .\" | |
26 | .\" $FreeBSD: src/share/man/man5/elf.5,v 1.21 2001/10/01 16:09:23 ru Exp $ | |
27 | .\" | |
28 | .\" Slightly adapted - aeb, 2004-01-01 | |
29 | .\" 2005-07-15, Mike Frysinger <vapier@gentoo.org>, various fixes | |
dbdab2f4 | 30 | .\" 2007-10-11, Mike Frysinger <vapier@gentoo.org>, various fixes |
8d5bf179 | 31 | .\" |
33c6f374 | 32 | .Dd November 25, 2007 |
fea681da MK |
33 | .Dt ELF 5 |
34 | .Os | |
35 | .Sh NAME | |
36 | .Nm elf | |
28d979c8 | 37 | .Nd format of Executable and Linking Format (ELF) files |
fea681da MK |
38 | .Sh SYNOPSIS |
39 | .\" .Fd #include <elf_abi.h> | |
40 | .Fd #include <elf.h> | |
41 | .Sh DESCRIPTION | |
42 | The header file | |
43 | .\" .Aq Pa elf_abi.h | |
44 | .Aq Pa elf.h | |
45 | defines the format of ELF executable binary files. | |
46 | Amongst these files are | |
47 | normal executable files, relocatable object files, core files and shared | |
48 | libraries. | |
49 | .Pp | |
50 | An executable file using the ELF file format consists of an ELF header, | |
51 | followed by a program header table or a section header table, or both. | |
52 | The ELF header is always at offset zero of the file. | |
53 | The program header | |
54 | table and the section header table's offset in the file are defined in the | |
55 | ELF header. | |
56 | The two tables describe the rest of the particularities of | |
57 | the file. | |
58 | .Pp | |
59 | .\" Applications which wish to process ELF binary files for their native | |
60 | .\" architecture only should include | |
61 | .\" .Aq Pa elf_abi.h | |
62 | .\" in their source code. | |
63 | .\" These applications should need to refer to | |
64 | .\" all the types and structures by their generic names | |
65 | .\" .Dq Elf_xxx | |
66 | .\" and to the macros by | |
67 | .\" .Dq ELF_xxx . | |
68 | .\" Applications written this way can be compiled on any architecture, | |
69 | .\" regardless of whether the host is 32-bit or 64-bit. | |
70 | .\" .Pp | |
71 | .\" Should an application need to process ELF files of an unknown | |
72 | .\" architecture, then the application needs to explicitly use either | |
73 | .\" .Dq Elf32_xxx | |
74 | .\" or | |
75 | .\" .Dq Elf64_xxx | |
76 | .\" type and structure names. | |
77 | .\" Likewise, the macros need to be identified by | |
78 | .\" .Dq ELF32_xxx | |
79 | .\" or | |
80 | .\" .Dq ELF64_xxx . | |
81 | .\" .Pp | |
82 | This header file describes the above mentioned headers as C structures | |
83 | and also includes structures for dynamic sections, relocation sections and | |
84 | symbol tables. | |
85 | .Pp | |
86 | The following types are used for N-bit architectures (N=32,64, | |
87 | ElfN stands for Elf32 or Elf64, uintN_t stands for uint32_t or uint64_t): | |
88 | .Bd -literal -offset indent | |
89 | ElfN_Addr Unsigned program address, uintN_t | |
90 | ElfN_Off Unsigned file offset, uintN_t | |
91 | ElfN_Section Unsigned section index, uint16_t | |
92 | ElfN_Versym Unsigned version symbol information, uint16_t | |
93 | Elf_Byte unsigned char | |
94 | ElfN_Half uint16_t | |
95 | ElfN_Sword int32_t | |
96 | ElfN_Word uint32_t | |
97 | ElfN_Sxword int64_t | |
98 | ElfN_Xword uint64_t | |
99 | .\" Elf32_Size Unsigned object size | |
100 | .Ed | |
101 | .Pp | |
c13182ef MK |
102 | (Note: The *BSD terminology is a bit different. |
103 | There Elf64_Half is | |
fea681da MK |
104 | twice as large as Elf32_Half, and Elf64Quarter is used for uint16_t. |
105 | In order to avoid confusion these types are replaced by explicit ones | |
106 | in the below.) | |
107 | .Pp | |
108 | All data structures that the file format defines follow the | |
109 | .Dq natural | |
110 | size and alignment guidelines for the relevant class. | |
111 | If necessary, | |
112 | data structures contain explicit padding to ensure 4-byte alignment | |
113 | for 4-byte objects, to force structure sizes to a multiple of 4, etc. | |
114 | .Pp | |
115 | The ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr: | |
116 | .Bd -literal -offset indent | |
117 | #define EI_NIDENT 16 | |
118 | ||
119 | typedef struct { | |
dd0a09a5 MK |
120 | unsigned char e_ident[EI_NIDENT]; |
121 | uint16_t e_type; | |
122 | uint16_t e_machine; | |
123 | uint32_t e_version; | |
124 | ElfN_Addr e_entry; | |
125 | ElfN_Off e_phoff; | |
126 | ElfN_Off e_shoff; | |
127 | uint32_t e_flags; | |
128 | uint16_t e_ehsize; | |
129 | uint16_t e_phentsize; | |
130 | uint16_t e_phnum; | |
131 | uint16_t e_shentsize; | |
132 | uint16_t e_shnum; | |
133 | uint16_t e_shstrndx; | |
fea681da MK |
134 | } ElfN_Ehdr; |
135 | .Ed | |
136 | .Pp | |
137 | The fields have the following meanings: | |
dd0a09a5 | 138 | .Bl -tag -width "e_phentsize" |
8d5bf179 MK |
139 | .It Dv e_ident |
140 | This array of bytes specifies to interpret the file, | |
141 | independent of the processor or the file's remaining contents. | |
142 | Within this array everything is named by macros, which start with | |
143 | the prefix | |
144 | .Sy EI_ | |
145 | and may contain values which start with the prefix | |
146 | .Sy ELF . | |
147 | The following macros are defined: | |
148 | .Bl -tag -width "EI_VERSION" \" EI_ABIVERSION | |
149 | .It Dv EI_MAG0 | |
150 | The first byte of the magic number. | |
151 | It must be filled with | |
152 | .Sy ELFMAG0 . | |
153 | (0: 0x7f) | |
154 | .It Dv EI_MAG1 | |
155 | The second byte of the magic number. | |
156 | It must be filled with | |
157 | .Sy ELFMAG1 . | |
158 | (1: 'E') | |
159 | .It Dv EI_MAG2 | |
160 | The third byte of the magic number. | |
161 | It must be filled with | |
162 | .Sy ELFMAG2 . | |
163 | (2: 'L') | |
164 | .It Dv EI_MAG3 | |
165 | The fourth byte of the magic number. | |
166 | It must be filled with | |
167 | .Sy ELFMAG3 . | |
168 | (3: 'F') | |
169 | .It Dv EI_CLASS | |
170 | The fifth byte identifies the architecture for this binary: | |
171 | .Pp | |
172 | .Bl -tag -width "ELFCLASSNONE" -compact | |
173 | .It Dv ELFCLASSNONE | |
174 | This class is invalid. | |
175 | .It Dv ELFCLASS32 | |
176 | This defines the 32-bit architecture. | |
177 | It supports machines with files | |
178 | and virtual address spaces up to 4 Gigabytes. | |
179 | .It Dv ELFCLASS64 | |
180 | This defines the 64-bit architecture. | |
181 | .El | |
182 | .It Dv EI_DATA | |
183 | The sixth byte specifies the data encoding of the processor-specific | |
184 | data in the file. | |
185 | Currently these encodings are supported: | |
186 | .Pp | |
187 | .Bl -tag -width "ELFDATA2LSB" -compact | |
188 | .It Dv ELFDATANONE | |
189 | Unknown data format. | |
190 | .It Dv ELFDATA2LSB | |
191 | Two's complement, little-endian. | |
192 | .It Dv ELFDATA2MSB | |
193 | Two's complement, big-endian. | |
194 | .El | |
195 | .It Dv EI_VERSION | |
196 | The version number of the ELF specification: | |
197 | .Pp | |
198 | .Bl -tag -width "EV_CURRENT" -compact | |
199 | .It Dv EV_NONE | |
200 | Invalid version. | |
201 | .It Dv EV_CURRENT | |
202 | Current version. | |
203 | .El | |
204 | .It Dv EI_OSABI | |
205 | This byte identifies the operating system | |
206 | and ABI to which the object is targeted. | |
207 | Some fields in other ELF structures have flags | |
208 | and values that have platform specific meanings; | |
209 | the interpretation of those fields is determined by the value of this byte. | |
210 | E.g.: | |
211 | .Pp | |
212 | .Bl -tag -width "ELFOSABI_STANDALONE" -compact | |
213 | .It Dv ELFOSABI_NONE | |
214 | Same as ELFOSABI_SYSV | |
215 | .\" 0 | |
216 | .It Dv ELFOSABI_SYSV | |
217 | UNIX System V ABI. | |
218 | .\" 0 | |
219 | .\" synonym: ELFOSABI_NONE | |
220 | .It Dv ELFOSABI_HPUX | |
221 | HP-UX ABI. | |
222 | .\" 1 | |
223 | .It Dv ELFOSABI_NETBSD | |
224 | NetBSD ABI. | |
225 | .\" 2 | |
226 | .It Dv ELFOSABI_LINUX | |
227 | Linux ABI. | |
228 | .\" 3 | |
229 | .\" .It Dv ELFOSABI_HURD | |
230 | .\" Hurd ABI. | |
231 | .\" 4 | |
232 | .\" .It Dv ELFOSABI_86OPEN | |
233 | .\" 86Open Common IA32 ABI. | |
234 | .\" 5 | |
235 | .It Dv ELFOSABI_SOLARIS | |
236 | Solaris ABI. | |
237 | .\" 6 | |
238 | .\" .It Dv ELFOSABI_MONTEREY | |
239 | .\" Monterey project ABI. Now replaced by | |
240 | .\" ELFOSABI_AIX | |
241 | .\" 7 | |
242 | .It Dv ELFOSABI_IRIX | |
243 | IRIX ABI. | |
244 | .\" 8 | |
245 | .It Dv ELFOSABI_FREEBSD | |
246 | FreeBSD ABI. | |
247 | .\" 9 | |
248 | .It Dv ELFOSABI_TRU64 | |
249 | TRU64 UNIX ABI. | |
250 | .\" 10 | |
251 | .\" ELFOSABI_MODESTO | |
252 | .\" 11 | |
253 | .\" ELFOSABI_OPENBSD | |
254 | .\" 12 | |
255 | .It Dv ELFOSABI_ARM | |
256 | ARM architecture ABI. | |
257 | .\" 97 | |
258 | .It Dv ELFOSABI_STANDALONE | |
259 | Stand-alone (embedded) ABI. | |
260 | .\" 255 | |
261 | .El | |
262 | .It Dv EI_ABIVERSION | |
263 | This byte identifies the version of the ABI | |
264 | to which the object is targeted. | |
265 | This field is used to distinguish among incompatible versions of an ABI. | |
266 | The interpretation of this version number | |
267 | is dependent on the ABI identified by the EI_OSABI field. | |
268 | Applications conforming to this specification use the value 0. | |
269 | .It Dv EI_PAD | |
270 | Start of padding. | |
271 | These bytes are reserved and set to zero. | |
272 | Programs | |
273 | which read them should ignore them. | |
274 | The value for EI_PAD will change in | |
275 | the future if currently unused bytes are given meanings. | |
276 | .It Dv EI_BRAND | |
277 | Start of architecture identification. | |
278 | .It Dv EI_NIDENT | |
279 | The size of the e_ident array. | |
280 | .El | |
281 | .Pp | |
282 | .It Dv e_type | |
283 | This member of the structure identifies the object file type: | |
284 | .Pp | |
285 | .Bl -tag -width "ET_NONE" -compact | |
286 | .It Dv ET_NONE | |
287 | An unknown type. | |
288 | .It Dv ET_REL | |
289 | A relocatable file. | |
290 | .It Dv ET_EXEC | |
291 | An executable file. | |
292 | .It Dv ET_DYN | |
293 | A shared object. | |
294 | .It Dv ET_CORE | |
295 | A core file. | |
296 | .El | |
297 | .Pp | |
298 | .It Dv e_machine | |
299 | This member specifies the required architecture for an individual file. | |
300 | E.g.: | |
301 | .Pp | |
302 | .Bl -tag -width "EM_MIPS_RS4_BE" -compact | |
303 | .It Dv EM_NONE | |
304 | An unknown machine. | |
305 | .\" 0 | |
306 | .It Dv EM_M32 | |
307 | AT&T WE 32100. | |
308 | .\" 1 | |
309 | .It Dv EM_SPARC | |
310 | Sun Microsystems SPARC. | |
311 | .\" 2 | |
312 | .It Dv EM_386 | |
313 | Intel 80386. | |
314 | .\" 3 | |
315 | .It Dv EM_68K | |
316 | Motorola 68000. | |
317 | .\" 4 | |
318 | .It Dv EM_88K | |
319 | Motorola 88000. | |
320 | .\" 5 | |
321 | .\" .It Dv EM_486 | |
322 | .\" Intel 80486. | |
323 | .\" 6 | |
324 | .It Dv EM_860 | |
325 | Intel 80860. | |
326 | .\" 7 | |
327 | .It Dv EM_MIPS | |
328 | MIPS RS3000 (big-endian only). | |
329 | .\" 8 | |
330 | .\" EM_S370 | |
331 | .\" 9 | |
332 | .\" .It Dv EM_MIPS_RS4_BE | |
333 | .\" MIPS RS4000 (big-endian only). Deprecated. | |
334 | .\" 10 | |
335 | .\" EM_MIPS_RS3_LE (MIPS R3000 little-endian) | |
336 | .\" 10 | |
337 | .It Dv EM_PARISC | |
338 | HP/PA. | |
339 | .\" 15 | |
340 | .It Dv EM_SPARC32PLUS | |
341 | SPARC with enhanced instruction set. | |
342 | .\" 18 | |
343 | .It Dv EM_PPC | |
344 | PowerPC. | |
345 | .\" 20 | |
346 | .It Dv EM_PPC64 | |
347 | PowerPC 64-bit. | |
348 | .\" 21 | |
349 | .It Dv EM_S390 | |
350 | IBM S/390 | |
351 | .\" 22 | |
352 | .It Dv EM_ARM | |
353 | Advanced RISC Machines | |
354 | .\" 40 | |
355 | .It Dv EM_SH | |
356 | Renesas SuperH | |
357 | .\" 42 | |
358 | .It Dv EM_SPARCV9 | |
359 | SPARC v9 64-bit. | |
360 | .\" 43 | |
361 | .It Dv EM_IA_64 | |
362 | Intel Itanium | |
363 | .\" 50 | |
364 | .It Dv EM_X86_64 | |
365 | AMD x86-64 | |
366 | .\" 62 | |
367 | .It Dv EM_VAX | |
368 | DEC Vax. | |
369 | .\" 75 | |
370 | .\" EM_CRIS | |
371 | .\" 76 | |
372 | .\" .It Dv EM_ALPHA | |
373 | .\" Compaq [DEC] Alpha. | |
374 | .\" .It Dv EM_ALPHA_EXP | |
375 | .\" Compaq [DEC] Alpha with enhanced instruction set. | |
376 | .El | |
377 | .Pp | |
378 | .It Dv e_version | |
379 | This member identifies the file version: | |
380 | .Pp | |
381 | .Bl -tag -width "EV_CURRENT" -compact | |
382 | .It Dv EV_NONE | |
383 | Invalid version. | |
384 | .It Dv EV_CURRENT | |
385 | Current version. | |
386 | .El | |
387 | .It Dv e_entry | |
388 | This member gives the virtual address to which the system first transfers | |
389 | control, thus starting the process. | |
390 | If the file has no associated entry | |
391 | point, this member holds zero. | |
392 | .It Dv e_phoff | |
393 | This member holds the program header table's file offset in bytes. | |
394 | If | |
395 | the file has no program header table, this member holds zero. | |
396 | .It Dv e_shoff | |
397 | This member holds the section header table's file offset in bytes. | |
398 | If the | |
399 | file has no section header table this member holds zero. | |
400 | .It Dv e_flags | |
401 | This member holds processor-specific flags associated with the file. | |
402 | Flag names take the form EF_`machine_flag'. | |
403 | Currently no flags have been defined. | |
404 | .It Dv e_ehsize | |
405 | This member holds the ELF header's size in bytes. | |
406 | .It Dv e_phentsize | |
407 | This member holds the size in bytes of one entry in the file's program header | |
408 | table; all entries are the same size. | |
409 | .It Dv e_phnum | |
410 | This member holds the number of entries in the program header | |
411 | table. | |
412 | Thus the product of | |
413 | .Sy e_phentsize | |
414 | and | |
415 | .Sy e_phnum | |
416 | gives the table's size | |
417 | in bytes. | |
418 | If a file has no program header, | |
419 | .Sy e_phnum | |
420 | holds the value zero. | |
421 | .It Dv e_shentsize | |
422 | This member holds a sections header's size in bytes. | |
423 | A section header is one | |
424 | entry in the section header table; all entries are the same size. | |
425 | .It Dv e_shnum | |
426 | This member holds the number of entries in the section header table. | |
427 | Thus | |
428 | the product of | |
429 | .Sy e_shentsize | |
430 | and | |
431 | .Sy e_shnum | |
432 | gives the section header table's size in bytes. | |
433 | If a file has no section | |
434 | header table, | |
435 | .Sy e_shnum | |
436 | holds the value of zero. | |
437 | .It Dv e_shstrndx | |
438 | This member holds the section header table index of the entry associated | |
439 | with the section name string table. | |
440 | If the file has no section name string | |
441 | table, this member holds the value | |
442 | .Sy SHN_UNDEF . | |
443 | .Bl -tag -width "SHN_LORESERVE" | |
444 | .It Dv SHN_UNDEF | |
445 | This value marks an undefined, missing, irrelevant, or otherwise meaningless | |
446 | section reference. | |
447 | For example, a symbol | |
448 | .Dq defined | |
449 | relative to section number | |
450 | .Sy SHN_UNDEF | |
451 | is an undefined symbol. | |
452 | .It Dv SHN_LORESERVE | |
453 | This value specifies the lower bound of the range of reserved indices. | |
454 | .It Dv SHN_LOPROC | |
455 | Values greater than or equal to | |
456 | .Sy SHN_HIPROC | |
457 | are reserved for processor-specific semantics. | |
458 | .It Dv SHN_HIPROC | |
459 | Values less than or equal to | |
460 | .Sy SHN_LOPROC | |
461 | are reserved for processor-specific semantics. | |
462 | .It Dv SHN_ABS | |
463 | This value specifies absolute values for the corresponding reference. | |
464 | For | |
465 | example, symbols defined relative to section number | |
466 | .Sy SHN_ABS | |
467 | have absolute values and are not affected by relocation. | |
468 | .It Dv SHN_COMMON | |
469 | Symbols defined relative to this section are common symbols, such as Fortran | |
470 | COMMON or unallocated C external variables. | |
471 | .It Dv SHN_HIRESERVE | |
472 | This value specifies the upper bound of the range of reserved | |
473 | indices between | |
474 | .Sy SHN_LORESERVE | |
475 | and | |
476 | .Sy SHN_HIRESERVE , | |
477 | inclusive; the values do | |
478 | not reference the section header table. | |
479 | That is, the section header table | |
480 | does | |
481 | .Em not | |
482 | contain entries for the reserved indices. | |
483 | .El | |
484 | .El | |
485 | .Pp | |
486 | An executable or shared object file's program header table is an array of | |
487 | structures, each describing a segment or other information the system needs | |
488 | to prepare the program for execution. | |
489 | An object file | |
490 | .Em segment | |
491 | contains one or more | |
492 | .Em sections . | |
493 | Program headers are meaningful only for executable and shared object files. | |
494 | A file specifies its own program header size with the ELF header's | |
495 | .Sy e_phentsize | |
496 | and | |
497 | .Sy e_phnum | |
498 | members. | |
499 | The ELF program header is described by the type Elf32_Phdr or Elf64_Phdr | |
500 | depending on the architecture: | |
501 | .Bd -literal -offset indent | |
502 | typedef struct { | |
dd0a09a5 MK |
503 | uint32_t p_type; |
504 | Elf32_Off p_offset; | |
505 | Elf32_Addr p_vaddr; | |
506 | Elf32_Addr p_paddr; | |
507 | uint32_t p_filesz; | |
508 | uint32_t p_memsz; | |
509 | uint32_t p_flags; | |
510 | uint32_t p_align; | |
8d5bf179 MK |
511 | } Elf32_Phdr; |
512 | .Ed | |
513 | .Bd -literal -offset indent | |
514 | typedef struct { | |
dd0a09a5 MK |
515 | uint32_t p_type; |
516 | uint32_t p_flags; | |
517 | Elf64_Off p_offset; | |
518 | Elf64_Addr p_vaddr; | |
519 | Elf64_Addr p_paddr; | |
520 | uint64_t p_filesz; | |
521 | uint64_t p_memsz; | |
522 | uint64_t p_align; | |
8d5bf179 MK |
523 | } Elf64_Phdr; |
524 | .Ed | |
525 | .Pp | |
526 | The main difference between the 32-bit and the 64-bit program header lies | |
527 | in the location of the | |
528 | .Sy p_flags | |
529 | member in the total struct. | |
dd0a09a5 | 530 | .Bl -tag -width "p_offset" |
8d5bf179 MK |
531 | .It Dv p_type |
532 | This member of the Phdr struct tells what kind of segment this array | |
533 | element describes or how to interpret the array element's information. | |
534 | .Bl -tag -width "PT_DYNAMIC" | |
535 | .It Dv PT_NULL | |
536 | The array element is unused and the other members' values are undefined. | |
537 | This lets the program header have ignored entries. | |
538 | .It Dv PT_LOAD | |
539 | The array element specifies a loadable segment, described by | |
540 | .Sy p_filesz | |
541 | and | |
542 | .Sy p_memsz . | |
543 | The bytes from the file are mapped to the beginning of the memory | |
544 | segment. | |
545 | If the segment's memory size | |
546 | .Pq Sy p_memsz | |
547 | is larger than the file size | |
548 | .Pq Sy p_filesz , | |
549 | the | |
550 | .Dq extra | |
551 | bytes are defined to hold the value 0 and to follow the segment's | |
552 | initialized area. | |
553 | The file size may not be larger than the memory size. | |
554 | Loadable segment entries in the program header table appear in ascending | |
555 | order, sorted on the | |
556 | .Sy p_vaddr | |
557 | member. | |
558 | .It Dv PT_DYNAMIC | |
559 | The array element specifies dynamic linking information. | |
560 | .It Dv PT_INTERP | |
561 | The array element specifies the location and size of a null-terminated | |
2d7195b8 | 562 | pathname to invoke as an interpreter. |
8d5bf179 MK |
563 | This segment type is meaningful |
564 | only for executable files (though it may occur for shared objects). | |
565 | However it may not occur more than once in a file. | |
566 | If it is present, it must precede any loadable segment entry. | |
567 | .It Dv PT_NOTE | |
568 | The array element specifies the location and size for auxiliary information. | |
569 | .It Dv PT_SHLIB | |
570 | This segment type is reserved but has unspecified semantics. | |
571 | Programs that | |
572 | contain an array element of this type do not conform to the ABI. | |
573 | .It Dv PT_PHDR | |
574 | The array element, if present, specifies the location and size of the program | |
575 | header table itself, both in the file and in the memory image of the program. | |
576 | This segment type may not occur more than once in a file. | |
577 | Moreover, it may | |
578 | only occur if the program header table is part of the memory image of the | |
579 | program. | |
580 | If it is present, it must precede any loadable segment entry. | |
581 | .It Dv PT_LOPROC | |
582 | Values greater than or equal to | |
583 | .Sy PT_HIPROC | |
584 | are reserved for processor-specific semantics. | |
585 | .It Dv PT_HIPROC | |
586 | Values less than or equal to | |
587 | .Sy PT_LOPROC | |
588 | are reserved for processor-specific semantics. | |
dbdab2f4 MK |
589 | .It PT_GNU_STACK |
590 | GNU extension which is used by the Linux kernel to control the state of the | |
38f76cd2 | 591 | stack via the flags set in the |
dbdab2f4 MK |
592 | .Sy p_flags |
593 | member. | |
8d5bf179 MK |
594 | .El |
595 | .Pp | |
596 | .It Dv p_offset | |
597 | This member holds the offset from the beginning of the file at which | |
598 | the first byte of the segment resides. | |
599 | .It Dv p_vaddr | |
600 | This member holds the virtual address at which the first byte of the | |
601 | segment resides in memory. | |
602 | .It Dv p_paddr | |
603 | On systems for which physical addressing is relevant, this member is | |
604 | reserved for the segment's physical address. | |
605 | Under | |
606 | .Bx | |
607 | this member is | |
608 | not used and must be zero. | |
609 | .It Dv p_filesz | |
610 | This member holds the number of bytes in the file image of the segment. | |
611 | It may be zero. | |
612 | .It Dv p_memsz | |
613 | This member holds the number of bytes in the memory image of the segment. | |
614 | It may be zero. | |
615 | .It Dv p_flags | |
dbdab2f4 | 616 | This member holds a bitmask of flags relevant to the segment: |
8d5bf179 MK |
617 | .Pp |
618 | .Bl -tag -width "PF_X" -compact | |
619 | .It Dv PF_X | |
620 | An executable segment. | |
621 | .It Dv PF_W | |
622 | A writable segment. | |
623 | .It Dv PF_R | |
624 | A readable segment. | |
625 | .El | |
626 | .Pp | |
627 | A text segment commonly has the flags | |
628 | .Sy PF_X | |
629 | and | |
630 | .Sy PF_R . | |
631 | A data segment commonly has | |
632 | .Sy PF_X , | |
633 | .Sy PF_W | |
634 | and | |
635 | .Sy PF_R . | |
636 | .It Dv p_align | |
637 | This member holds the value to which the segments are aligned in memory | |
638 | and in the file. | |
639 | Loadable process segments must have congruent values for | |
640 | .Sy p_vaddr | |
641 | and | |
642 | .Sy p_offset , | |
643 | modulo the page size. | |
644 | Values of zero and one mean no alignment is required. | |
645 | Otherwise, | |
646 | .Sy p_align | |
647 | should be a positive, integral power of two, and | |
648 | .Sy p_vaddr | |
649 | should equal | |
650 | .Sy p_offset , | |
651 | modulo | |
652 | .Sy p_align . | |
653 | .El | |
654 | .Pp | |
655 | A file's section header table lets one locate all the file's sections. | |
656 | The | |
657 | section header table is an array of Elf32_Shdr or Elf64_Shdr structures. | |
658 | The | |
659 | ELF header's | |
660 | .Sy e_shoff | |
661 | member gives the byte offset from the beginning of the file to the section | |
662 | header table. | |
663 | .Sy e_shnum | |
664 | holds the number of entries the section header table contains. | |
665 | .Sy e_shentsize | |
666 | holds the size in bytes of each entry. | |
667 | .Pp | |
668 | A section header table index is a subscript into this array. | |
669 | Some section | |
670 | header table indices are reserved. | |
671 | An object file does not have sections for | |
672 | these special indices: | |
673 | .Bl -tag -width "SHN_LORESERVE" | |
674 | .It Dv SHN_UNDEF | |
675 | This value marks an undefined, missing, irrelevant or otherwise meaningless | |
676 | section reference. | |
677 | .It Dv SHN_LORESERVE | |
678 | This value specifies the lower bound of the range of reserved indices. | |
679 | .It Dv SHN_LOPROC | |
680 | Values greater than or equal to | |
681 | .Sy SHN_HIPROC | |
682 | are reserved for processor-specific semantics. | |
683 | .It Dv SHN_HIPROC | |
684 | Values less than or equal to | |
685 | .Sy SHN_LOPROC | |
686 | are reserved for processor-specific semantics. | |
687 | .It Dv SHN_ABS | |
688 | This value specifies the absolute value for the corresponding reference. | |
689 | For | |
690 | example, a symbol defined relative to section number | |
691 | .Sy SHN_ABS | |
692 | has an absolute value and is not affected by relocation. | |
693 | .It Dv SHN_COMMON | |
694 | Symbols defined relative to this section are common symbols, such as FORTRAN | |
695 | COMMON or unallocated C external variables. | |
696 | .It Dv SHN_HIRESERVE | |
697 | This value specifies the upper bound of the range of reserved indices. | |
698 | The | |
699 | system reserves indices between | |
700 | .Sy SHN_LORESERVE | |
701 | and | |
702 | .Sy SHN_HIRESERVE , | |
703 | inclusive. | |
704 | The section header table does not contain entries for the | |
705 | reserved indices. | |
706 | .El | |
707 | .Pp | |
708 | The section header has the following structure: | |
709 | .Bd -literal -offset indent | |
710 | typedef struct { | |
dd0a09a5 MK |
711 | uint32_t sh_name; |
712 | uint32_t sh_type; | |
713 | uint32_t sh_flags; | |
714 | Elf32_Addr sh_addr; | |
715 | Elf32_Off sh_offset; | |
716 | uint32_t sh_size; | |
717 | uint32_t sh_link; | |
718 | uint32_t sh_info; | |
719 | uint32_t sh_addralign; | |
720 | uint32_t sh_entsize; | |
8d5bf179 MK |
721 | } Elf32_Shdr; |
722 | .Ed | |
723 | .Bd -literal -offset indent | |
724 | typedef struct { | |
dd0a09a5 MK |
725 | uint32_t sh_name; |
726 | uint32_t sh_type; | |
727 | uint64_t sh_flags; | |
728 | Elf64_Addr sh_addr; | |
729 | Elf64_Off sh_offset; | |
730 | uint64_t sh_size; | |
731 | uint32_t sh_link; | |
732 | uint32_t sh_info; | |
733 | uint64_t sh_addralign; | |
734 | uint64_t sh_entsize; | |
8d5bf179 MK |
735 | } Elf64_Shdr; |
736 | .Ed | |
737 | .Pp | |
738 | No real differences exist between the 32-bit and 64-bit section headers. | |
dd0a09a5 | 739 | .Bl -tag -width "sh_addralign" |
8d5bf179 MK |
740 | .It Dv sh_name |
741 | This member specifies the name of the section. | |
742 | Its value is an index | |
743 | into the section header string table section, giving the location of | |
744 | a null-terminated string. | |
745 | .It Dv sh_type | |
746 | This member categorizes the section's contents and semantics. | |
747 | .Bl -tag -width "SHT_PROGBITS" | |
748 | .It Dv SHT_NULL | |
749 | This value marks the section header as inactive. | |
750 | It does not | |
751 | have an associated section. | |
752 | Other members of the section header | |
753 | have undefined values. | |
754 | .It Dv SHT_PROGBITS | |
755 | This section holds information defined by the program, whose | |
756 | format and meaning are determined solely by the program. | |
757 | .It Dv SHT_SYMTAB | |
758 | This section holds a symbol table. | |
759 | Typically, | |
760 | .Sy SHT_SYMTAB | |
761 | provides symbols for link editing, though it may also be used | |
762 | for dynamic linking. | |
763 | As a complete symbol table, it may contain | |
764 | many symbols unnecessary for dynamic linking. | |
765 | An object file can | |
766 | also contain a | |
767 | .Sy SHT_DYNSYM | |
768 | section. | |
769 | .It Dv SHT_STRTAB | |
770 | This section holds a string table. | |
771 | An object file may have multiple | |
772 | string table sections. | |
773 | .It Dv SHT_RELA | |
774 | This section holds relocation entries with explicit addends, such | |
775 | as type | |
776 | .Sy Elf32_Rela | |
777 | for the 32-bit class of object files. | |
778 | An object may have multiple | |
779 | relocation sections. | |
780 | .It Dv SHT_HASH | |
781 | This section holds a symbol hash table. | |
782 | An object participating in | |
783 | dynamic linking must contain a symbol hash table. | |
784 | An object file may | |
785 | have only one hash table. | |
786 | .It Dv SHT_DYNAMIC | |
787 | This section holds information for dynamic linking. | |
788 | An object file may | |
789 | have only one dynamic section. | |
790 | .It Dv SHT_NOTE | |
791 | This section holds information that marks the file in some way. | |
792 | .It Dv SHT_NOBITS | |
793 | A section of this type occupies no space in the file but otherwise | |
794 | resembles | |
795 | .Sy SHT_PROGBITS . | |
796 | Although this section contains no bytes, the | |
797 | .Sy sh_offset | |
798 | member contains the conceptual file offset. | |
799 | .It Dv SHT_REL | |
800 | This section holds relocation offsets without explicit addends, such | |
801 | as type | |
802 | .Sy Elf32_Rel | |
803 | for the 32-bit class of object files. | |
804 | An object file may have multiple | |
805 | relocation sections. | |
806 | .It Dv SHT_SHLIB | |
807 | This section is reserved but has unspecified semantics. | |
808 | .It Dv SHT_DYNSYM | |
809 | This section holds a minimal set of dynamic linking symbols. | |
810 | An | |
811 | object file can also contain a | |
812 | .Sy SHT_SYMTAB | |
813 | section. | |
814 | .It Dv SHT_LOPROC | |
815 | This value up to and including | |
816 | .Sy SHT_HIPROC | |
817 | is reserved for processor-specific semantics. | |
818 | .It Dv SHT_HIPROC | |
819 | This value down to and including | |
820 | .Sy SHT_LOPROC | |
821 | is reserved for processor-specific semantics. | |
822 | .It Dv SHT_LOUSER | |
823 | This value specifies the lower bound of the range of indices reserved for | |
824 | application programs. | |
825 | .It Dv SHT_HIUSER | |
826 | This value specifies the upper bound of the range of indices reserved for | |
827 | application programs. | |
828 | Section types between | |
829 | .Sy SHT_LOUSER | |
830 | and | |
831 | .Sy SHT_HIUSER | |
832 | may be used by the application, without conflicting with current or future | |
833 | system-defined section types. | |
834 | .El | |
835 | .Pp | |
836 | .It Dv sh_flags | |
837 | Sections support one-bit flags that describe miscellaneous attributes. | |
838 | If a flag bit is set in | |
839 | .Sy sh_flags , | |
840 | the attribute is | |
841 | .Dq on | |
842 | for the section. | |
843 | Otherwise, the attribute is | |
844 | .Dq off | |
845 | or does not apply. | |
846 | Undefined attributes are set to zero. | |
847 | .Pp | |
848 | .Bl -tag -width "SHF_EXECINSTR" -compact | |
849 | .It Dv SHF_WRITE | |
850 | This section contains data that should be writable during process | |
851 | execution. | |
852 | .It Dv SHF_ALLOC | |
853 | This section occupies memory during process execution. | |
854 | Some control | |
855 | sections do not reside in the memory image of an object file. | |
856 | This | |
857 | attribute is off for those sections. | |
858 | .It Dv SHF_EXECINSTR | |
859 | This section contains executable machine instructions. | |
860 | .It Dv SHF_MASKPROC | |
861 | All bits included in this mask are reserved for processor-specific | |
862 | semantics. | |
863 | .El | |
864 | .Pp | |
865 | .It Dv sh_addr | |
866 | If this section appears in the memory image of a process, this member | |
867 | holds the address at which the section's first byte should reside. | |
868 | Otherwise, the member contains zero. | |
869 | .It Dv sh_offset | |
870 | This member's value holds the byte offset from the beginning of the file | |
871 | to the first byte in the section. | |
872 | One section type, | |
873 | .Sy SHT_NOBITS , | |
874 | occupies no space in the file, and its | |
875 | .Sy sh_offset | |
876 | member locates the conceptual placement in the file. | |
877 | .It Dv sh_size | |
878 | This member holds the section's size in bytes. | |
879 | Unless the section type | |
880 | is | |
881 | .Sy SHT_NOBITS , | |
882 | the section occupies | |
883 | .Sy sh_size | |
884 | bytes in the file. | |
885 | A section of type | |
886 | .Sy SHT_NOBITS | |
887 | may have a non-zero size, but it occupies no space in the file. | |
888 | .It Dv sh_link | |
889 | This member holds a section header table index link, whose interpretation | |
890 | depends on the section type. | |
891 | .It Dv sh_info | |
892 | This member holds extra information, whose interpretation depends on the | |
893 | section type. | |
894 | .It Dv sh_addralign | |
895 | Some sections have address alignment constraints. | |
896 | If a section holds a | |
897 | doubleword, the system must ensure doubleword alignment for the entire | |
898 | section. | |
899 | That is, the value of | |
900 | .Sy sh_addr | |
901 | must be congruent to zero, modulo the value of | |
902 | .Sy sh_addralign . | |
903 | Only zero and positive integral powers of two are allowed. | |
904 | Values of zero | |
905 | or one mean the section has no alignment constraints. | |
906 | .It Dv sh_entsize | |
907 | Some sections hold a table of fixed-sized entries, such as a symbol table. | |
908 | For such a section, this member gives the size in bytes for each entry. | |
909 | This member contains zero if the section does not hold a table of | |
910 | fixed-size entries. | |
911 | .El | |
912 | .Pp | |
913 | Various sections hold program and control information: | |
dd0a09a5 | 914 | .Bl -tag -width ".shstrtab" |
8d5bf179 MK |
915 | .It .bss |
916 | This section holds uninitialized data that contributes to the program's | |
917 | memory image. | |
918 | By definition, the system initializes the data with zeros | |
919 | when the program begins to run. | |
920 | This section is of type | |
921 | .Sy SHT_NOBITS . | |
922 | The attribute types are | |
923 | .Sy SHF_ALLOC | |
924 | and | |
925 | .Sy SHF_WRITE . | |
926 | .It .comment | |
927 | This section holds version control information. | |
928 | This section is of type | |
929 | .Sy SHT_PROGBITS . | |
930 | No attribute types are used. | |
931 | .It .ctors | |
932 | This section holds initialized pointers to the C++ constructor functions. | |
933 | This section is of type | |
934 | .Sy SHT_PROGBITS . | |
935 | The attribute types are | |
936 | .Sy SHF_ALLOC | |
937 | and | |
938 | .Sy SHF_WRITE . | |
939 | .It .data | |
940 | This section holds initialized data that contribute to the program's | |
941 | memory image. | |
942 | This section is of type | |
943 | .Sy SHT_PROGBITS . | |
944 | The attribute types are | |
945 | .Sy SHF_ALLOC | |
946 | and | |
947 | .Sy SHF_WRITE . | |
948 | .It .data1 | |
949 | This section holds initialized data that contribute to the program's | |
950 | memory image. | |
951 | This section is of type | |
952 | .Sy SHT_PROGBITS . | |
953 | The attribute types are | |
954 | .Sy SHF_ALLOC | |
955 | and | |
956 | .Sy SHF_WRITE . | |
957 | .It .debug | |
958 | This section holds information for symbolic debugging. | |
959 | The contents | |
960 | are unspecified. | |
961 | This section is of type | |
962 | .Sy SHT_PROGBITS . | |
963 | No attribute types are used. | |
964 | .It .dtors | |
965 | This section holds initialized pointers to the C++ destructor functions. | |
966 | This section is of type | |
967 | .Sy SHT_PROGBITS . | |
968 | The attribute types are | |
969 | .Sy SHF_ALLOC | |
970 | and | |
971 | .Sy SHF_WRITE . | |
972 | .It .dynamic | |
973 | This section holds dynamic linking information. | |
974 | The section's attributes | |
975 | will include the | |
976 | .Sy SHF_ALLOC | |
977 | bit. | |
978 | Whether the | |
979 | .Sy SHF_WRITE | |
980 | bit is set is processor-specific. | |
981 | This section is of type | |
982 | .Sy SHT_DYNAMIC . | |
983 | See the attributes above. | |
984 | .It .dynstr | |
985 | This section holds strings needed for dynamic linking, most commonly | |
986 | the strings that represent the names associated with symbol table entries. | |
987 | This section is of type | |
988 | .Sy SHT_STRTAB . | |
989 | The attribute type used is | |
990 | .Sy SHF_ALLOC . | |
991 | .It .dynsym | |
992 | This section holds the dynamic linking symbol table. | |
993 | This section is of type | |
994 | .Sy SHT_DYNSYM . | |
995 | The attribute used is | |
996 | .Sy SHF_ALLOC . | |
997 | .It .fini | |
998 | This section holds executable instructions that contribute to the process | |
999 | termination code. | |
1000 | When a program exits normally the system arranges to | |
1001 | execute the code in this section. | |
1002 | This section is of type | |
1003 | .Sy SHT_PROGBITS . | |
1004 | The attributes used are | |
1005 | .Sy SHF_ALLOC | |
1006 | and | |
1007 | .Sy SHF_EXECINSTR . | |
dbdab2f4 MK |
1008 | .It .gnu.version |
1009 | This section holds the version symbol table, an array of ElfN_Half elements. | |
1010 | This section is of type | |
1011 | .Sy SHT_GNU_versym . | |
1012 | The attribute type used is | |
1013 | .Sy SHF_ALLOC . | |
1014 | .It .gnu.version_d | |
1015 | This section holds the version symbol definitons, a table of ElfN_Verdef | |
1016 | structures. This section is of type | |
1017 | .Sy SHT_GNU_verdef . | |
1018 | The attribute type used is | |
1019 | .Sy SHF_ALLOC . | |
1020 | .It .gnu.version_r | |
1021 | This section holds the version symbol needed elements, a table of | |
1022 | ElfN_Verneed structures. This section is of | |
1023 | type | |
1024 | .Sy SHT_GNU_versym . | |
1025 | The attribute type used is | |
1026 | .Sy SHF_ALLOC . | |
8d5bf179 MK |
1027 | .It .got |
1028 | This section holds the global offset table. | |
1029 | This section is of type | |
1030 | .Sy SHT_PROGBITS . | |
1031 | The attributes are processor-specific. | |
1032 | .It .hash | |
1033 | This section holds a symbol hash table. | |
1034 | This section is of type | |
1035 | .Sy SHT_HASH . | |
1036 | The attribute used is | |
1037 | .Sy SHF_ALLOC . | |
1038 | .It .init | |
1039 | This section holds executable instructions that contribute to the process | |
1040 | initialization code. | |
1041 | When a program starts to run the system arranges to | |
1042 | execute the code in this section before calling the main program entry point. | |
1043 | This section is of type | |
1044 | .Sy SHT_PROGBITS . | |
1045 | The attributes used are | |
1046 | .Sy SHF_ALLOC | |
1047 | and | |
1048 | .Sy SHF_EXECINSTR . | |
1049 | .It .interp | |
1050 | This section holds the pathname of a program interpreter. | |
1051 | If the file has | |
1052 | a loadable segment that includes the section, the section's attributes will | |
1053 | include the | |
1054 | .Sy SHF_ALLOC | |
1055 | bit. | |
1056 | Otherwise, that bit will be off. | |
1057 | This section is of type | |
1058 | .Sy SHT_PROGBITS . | |
1059 | .It .line | |
1060 | This section holds line number information for symbolic debugging, which | |
1061 | describes the correspondence between the program source and the machine code. | |
1062 | The contents are unspecified. | |
1063 | This section is of type | |
1064 | .Sy SHT_PROGBITS . | |
1065 | No attribute types are used. | |
1066 | .It .note | |
1067 | This section holds information in the | |
1068 | .Dq Note Section | |
1069 | format described below. | |
1070 | This section is of type | |
1071 | .Sy SHT_NOTE . | |
1072 | No attribute types are used. | |
1073 | .Ox | |
1074 | native executables usually contain a | |
1075 | .Sy .note.openbsd.ident | |
1076 | section to identify themselves, for the kernel to bypass any compatibility | |
1077 | ELF binary emulation tests when loading the file. | |
dbdab2f4 MK |
1078 | .It .note.GNU-stack |
1079 | This section is used in Linux object files for declaring stack attributes. | |
1080 | This section is of type | |
1081 | .Sy SHT_PROGBITS . | |
1082 | The only attribute used is | |
1083 | .Sy SHF_EXECINSTR . | |
1084 | This indicates to the GNU linker that the object file requires an | |
1085 | executable stack. | |
8d5bf179 MK |
1086 | .It .plt |
1087 | This section holds the procedure linkage table. | |
1088 | This section is of type | |
1089 | .Sy SHT_PROGBITS . | |
1090 | The attributes are processor-specific. | |
1091 | .It .relNAME | |
1092 | This section holds relocation information as described below. | |
1093 | If the file | |
1094 | has a loadable segment that includes relocation, the section's attributes | |
1095 | will include the | |
1096 | .Sy SHF_ALLOC | |
1097 | bit. | |
1098 | Otherwise the bit will be off. | |
1099 | By convention, | |
1100 | .Dq NAME | |
1101 | is supplied by the section to which the relocations apply. | |
1102 | Thus a relocation | |
1103 | section for | |
1104 | .Sy .text | |
1105 | normally would have the name | |
1106 | .Sy .rel.text . | |
1107 | This section is of type | |
1108 | .Sy SHT_REL . | |
1109 | .It .relaNAME | |
1110 | This section holds relocation information as described below. | |
1111 | If the file | |
1112 | has a loadable segment that includes relocation, the section's attributes | |
1113 | will include the | |
1114 | .Sy SHF_ALLOC | |
1115 | bit. | |
1116 | Otherwise the bit will be off. | |
1117 | By convention, | |
1118 | .Dq NAME | |
1119 | is supplied by the section to which the relocations apply. | |
1120 | Thus a relocation | |
1121 | section for | |
1122 | .Sy .text | |
1123 | normally would have the name | |
1124 | .Sy .rela.text . | |
1125 | This section is of type | |
1126 | .Sy SHT_RELA . | |
1127 | .It .rodata | |
1128 | This section holds read-only data that typically contributes to a | |
1129 | non-writable segment in the process image. | |
1130 | This section is of type | |
1131 | .Sy SHT_PROGBITS . | |
1132 | The attribute used is | |
1133 | .Sy SHF_ALLOC . | |
1134 | .It .rodata1 | |
1135 | This section holds read-only data that typically contributes to a | |
1136 | non-writable segment in the process image. | |
1137 | This section is of type | |
1138 | .Sy SHT_PROGBITS . | |
1139 | The attribute used is | |
1140 | .Sy SHF_ALLOC . | |
1141 | .It .shstrtab | |
1142 | This section holds section names. | |
1143 | This section is of type | |
1144 | .Sy SHT_STRTAB . | |
1145 | No attribute types are used. | |
1146 | .It .strtab | |
1147 | This section holds strings, most commonly the strings that represent the | |
1148 | names associated with symbol table entries. | |
1149 | If the file has a loadable | |
1150 | segment that includes the symbol string table, the section's attributes | |
1151 | will include the | |
1152 | .Sy SHF_ALLOC | |
1153 | bit. | |
1154 | Otherwise the bit will be off. | |
1155 | This section is of type | |
1156 | .Sy SHT_STRTAB . | |
1157 | .It .symtab | |
1158 | This section holds a symbol table. | |
1159 | If the file has a loadable segment | |
1160 | that includes the symbol table, the section's attributes will include | |
1161 | the | |
1162 | .Sy SHF_ALLOC | |
1163 | bit. | |
1164 | Otherwise the bit will be off. | |
1165 | This section is of type | |
1166 | .Sy SHT_SYMTAB . | |
1167 | .It .text | |
1168 | This section holds the | |
1169 | .Dq text , | |
1170 | or executable instructions, of a program. | |
1171 | This section is of type | |
1172 | .Sy SHT_PROGBITS . | |
1173 | The attributes used are | |
1174 | .Sy SHF_ALLOC | |
1175 | and | |
1176 | .Sy SHF_EXECINSTR . | |
1177 | .El | |
fea681da MK |
1178 | .Pp |
1179 | String table sections hold null-terminated character sequences, commonly | |
1180 | called strings. | |
1181 | The object file uses these strings to represent symbol | |
1182 | and section names. | |
1183 | One references a string as an index into the string | |
1184 | table section. | |
1185 | The first byte, which is index zero, is defined to hold | |
28d88c17 | 1186 | a null byte ('\\0'). |
fea681da | 1187 | Similarly, a string table's last byte is defined to |
28d88c17 | 1188 | hold a null byte, ensuring null termination for all strings. |
fea681da MK |
1189 | .Pp |
1190 | An object file's symbol table holds information needed to locate and | |
1191 | relocate a program's symbolic definitions and references. | |
1192 | A symbol table | |
1193 | index is a subscript into this array. | |
1194 | .Bd -literal -offset indent | |
1195 | typedef struct { | |
dd0a09a5 MK |
1196 | uint32_t st_name; |
1197 | Elf32_Addr st_value; | |
1198 | uint32_t st_size; | |
1199 | unsigned char st_info; | |
1200 | unsigned char st_other; | |
1201 | uint16_t st_shndx; | |
fea681da MK |
1202 | } Elf32_Sym; |
1203 | .Ed | |
1204 | .Bd -literal -offset indent | |
1205 | typedef struct { | |
dd0a09a5 MK |
1206 | uint32_t st_name; |
1207 | unsigned char st_info; | |
1208 | unsigned char st_other; | |
1209 | uint16_t st_shndx; | |
1210 | Elf64_Addr st_value; | |
1211 | uint64_t st_size; | |
fea681da MK |
1212 | } Elf64_Sym; |
1213 | .Ed | |
28d979c8 | 1214 | .Pp |
c13182ef | 1215 | The 32-bit and 64-bit versions have the same members, just in a different |
28d979c8 | 1216 | order. |
dd0a09a5 | 1217 | .Bl -tag -width "st_value" |
fea681da MK |
1218 | .It Dv st_name |
1219 | This member holds an index into the object file's symbol string table, | |
1220 | which holds character representations of the symbol names. | |
1221 | If the value | |
1222 | is non-zero, it represents a string table index that gives the symbol | |
1223 | name. | |
1224 | Otherwise, the symbol table has no name. | |
1225 | .It Dv st_value | |
1226 | This member gives the value of the associated symbol. | |
1227 | .It Dv st_size | |
1228 | Many symbols have associated sizes. | |
1229 | This member holds zero if the symbol | |
1230 | has no size or an unknown size. | |
1231 | .It Dv st_info | |
1232 | This member specifies the symbol's type and binding attributes: | |
8d5bf179 MK |
1233 | .Bl -tag -width "STT_SECTION" |
1234 | .It Dv STT_NOTYPE | |
1235 | The symbol's type is not defined. | |
1236 | .It Dv STT_OBJECT | |
1237 | The symbol is associated with a data object. | |
1238 | .It Dv STT_FUNC | |
1239 | The symbol is associated with a function or other executable code. | |
1240 | .It Dv STT_SECTION | |
1241 | The symbol is associated with a section. | |
1242 | Symbol table entries of | |
1243 | this type exist primarily for relocation and normally have | |
1244 | .Sy STB_LOCAL | |
1245 | bindings. | |
1246 | .It Dv STT_FILE | |
1247 | By convention, the symbol's name gives the name of the source file | |
1248 | associated with the object file. | |
1249 | A file symbol has | |
1250 | .Sy STB_LOCAL | |
1251 | bindings, its section index is | |
1252 | .Sy SHN_ABS , | |
1253 | and it precedes the other | |
1254 | .Sy STB_LOCAL | |
1255 | symbols of the file, if it is present. | |
1256 | .It Dv STT_LOPROC | |
1257 | This value up to and including | |
1258 | .Sy STT_HIPROC | |
1259 | is reserved for processor-specific semantics. | |
1260 | .It Dv STT_HIPROC | |
1261 | This value down to and including | |
1262 | .Sy STT_LOPROC | |
1263 | is reserved for processor-specific semantics. | |
1264 | .El | |
1265 | .Bl -tag -width "STB_GLOBAL" | |
1266 | .It Dv STB_LOCAL | |
1267 | Local symbols are not visible outside the object file containing their | |
1268 | definition. | |
1269 | Local symbols of the same name may exist in multiple files | |
1270 | without interfering with each other. | |
1271 | .It Dv STB_GLOBAL | |
1272 | Global symbols are visible to all object files being combined. | |
1273 | One file's | |
1274 | definition of a global symbol will satisfy another file's undefined | |
1275 | reference to the same symbol. | |
1276 | .It Dv STB_WEAK | |
1277 | Weak symbols resemble global symbols, but their definitions have lower | |
1278 | precedence. | |
1279 | .It Dv STB_LOPROC | |
1280 | This value up to and including | |
1281 | .Sy STB_HIPROC | |
1282 | is reserved for processor-specific semantics. | |
1283 | .It Dv STB_HIPROC | |
1284 | This value down to and including | |
1285 | .Sy STB_LOPROC | |
1286 | is reserved for processor-specific semantics. | |
1287 | .Pp | |
1288 | There are macros for packing and unpacking the binding and type fields: | |
1289 | .Pp | |
1290 | .Fn ELF32_ST_BIND info | |
1291 | or | |
1292 | .Fn ELF64_ST_BIND info | |
1293 | extract a binding from an st_info value. | |
1294 | .Pp | |
1295 | .Fn ELF32_ST_TYPE info | |
1296 | or | |
1297 | .Fn ELF64_ST_TYPE info | |
1298 | .br | |
1299 | extract a type from an st_info value. | |
1300 | .Pp | |
1301 | .Fn ELF32_ST_INFO bind type | |
1302 | or | |
1303 | .Fn ELF64_ST_INFO bind type | |
1304 | .br | |
1305 | convert a binding and a type into an st_info value. | |
1306 | .El | |
1307 | .Pp | |
1308 | .It Dv st_other | |
dbdab2f4 MK |
1309 | This member defines the symbol visibility. |
1310 | .Bl -tag -width "STV_PROTECTED" | |
1311 | .It Dv STV_DEFAULT | |
1312 | Default symbol visibility rules. | |
1313 | .It Dv STV_INTERNAL | |
1314 | Processor specific hidden class. | |
1315 | .It Dv STV_HIDDEN | |
1316 | Symbol is unavailable in other modules. | |
1317 | .It Dv STV_PROTECTED | |
1318 | Not preemptible, not exported. | |
1319 | .Pp | |
1320 | There are macros for extracting the visibility type: | |
1321 | .Pp | |
1322 | .Fn ELF32_ST_VISIBILITY other | |
1323 | or | |
1324 | .Fn ELF64_ST_VISIBILITY other | |
1325 | .El | |
8d5bf179 MK |
1326 | .It Dv st_shndx |
1327 | Every symbol table entry is | |
1328 | .Dq defined | |
1329 | in relation to some section. | |
1330 | This member holds the relevant section | |
1331 | header table index. | |
fea681da MK |
1332 | .El |
1333 | .Pp | |
1334 | Relocation is the process of connecting symbolic references with | |
1335 | symbolic definitions. | |
1336 | Relocatable files must have information that | |
1337 | describes how to modify their section contents, thus allowing executable | |
1338 | and shared object files to hold the right information for a process' | |
1339 | program image. | |
1340 | Relocation entries are these data. | |
1341 | .Pp | |
1342 | Relocation structures that do not need an addend: | |
1343 | .Bd -literal -offset indent | |
1344 | typedef struct { | |
dd0a09a5 MK |
1345 | Elf32_Addr r_offset; |
1346 | uint32_t r_info; | |
fea681da MK |
1347 | } Elf32_Rel; |
1348 | .Ed | |
1349 | .Bd -literal -offset indent | |
1350 | typedef struct { | |
dd0a09a5 MK |
1351 | Elf64_Addr r_offset; |
1352 | uint64_t r_info; | |
fea681da MK |
1353 | } Elf64_Rel; |
1354 | .Ed | |
1355 | .Pp | |
1356 | Relocation structures that need an addend: | |
1357 | .Bd -literal -offset indent | |
1358 | typedef struct { | |
dd0a09a5 MK |
1359 | Elf32_Addr r_offset; |
1360 | uint32_t r_info; | |
1361 | int32_t r_addend; | |
fea681da MK |
1362 | } Elf32_Rela; |
1363 | .Ed | |
1364 | .Bd -literal -offset indent | |
1365 | typedef struct { | |
dd0a09a5 MK |
1366 | Elf64_Addr r_offset; |
1367 | uint64_t r_info; | |
1368 | int64_t r_addend; | |
fea681da MK |
1369 | } Elf64_Rela; |
1370 | .Ed | |
dd0a09a5 | 1371 | .Bl -tag -width "r_offset" |
8d5bf179 MK |
1372 | .It Dv r_offset |
1373 | This member gives the location at which to apply the relocation action. | |
1374 | For a relocatable file, the value is the byte offset from the beginning | |
1375 | of the section to the storage unit affected by the relocation. | |
1376 | For an | |
1377 | executable file or shared object, the value is the virtual address of | |
1378 | the storage unit affected by the relocation. | |
1379 | .It Dv r_info | |
1380 | This member gives both the symbol table index with respect to which the | |
1381 | relocation must be made and the type of relocation to apply. | |
1382 | Relocation | |
1383 | types are processor-specific. | |
1384 | When the text refers to a relocation | |
1385 | entry's relocation type or symbol table index, it means the result of | |
1386 | applying | |
1387 | .Sy ELF_[32|64]_R_TYPE | |
1388 | or | |
1389 | .Sy ELF[32|64]_R_SYM , | |
1390 | respectively, to the entry's | |
1391 | .Sy r_info | |
1392 | member. | |
1393 | .It Dv r_addend | |
1394 | This member specifies a constant addend used to compute the value to be | |
1395 | stored into the relocatable field. | |
1396 | .El | |
1397 | .Pp | |
c13182ef MK |
1398 | The .dynamic section contains a series of structures that hold relevant |
1399 | dynamic linking information. | |
1400 | The d_tag member controls the interpretation | |
8d5bf179 MK |
1401 | of d_un. |
1402 | .Bd -literal -offset indent | |
1403 | typedef struct { | |
dd0a09a5 MK |
1404 | Elf32_Sword d_tag; |
1405 | union { | |
1406 | Elf32_Word d_val; | |
1407 | Elf32_Addr d_ptr; | |
1408 | } d_un; | |
8d5bf179 MK |
1409 | } Elf32_Dyn; |
1410 | extern Elf32_Dyn _DYNAMIC[]; | |
1411 | .Ed | |
1412 | .Bd -literal -offset indent | |
1413 | typedef struct { | |
dd0a09a5 MK |
1414 | Elf64_Sxword d_tag; |
1415 | union { | |
1416 | Elf64_Xword d_val; | |
1417 | Elf64_Addr d_ptr; | |
1418 | } d_un; | |
8d5bf179 MK |
1419 | } Elf64_Dyn; |
1420 | extern Elf64_Dyn _DYNAMIC[]; | |
1421 | .Ed | |
dd0a09a5 | 1422 | .Bl -tag -width "d_tag" |
8d5bf179 MK |
1423 | .It Dv d_tag |
1424 | This member may have any of the following values: | |
1425 | .Bl -tag -width "DT_SYMBOLIC" | |
1426 | .It Dv DT_NULL | |
1427 | Marks end of dynamic section | |
1428 | .It Dv DT_NEEDED | |
1429 | String table offset to name of a needed library | |
1430 | .It Dv DT_PLTRELSZ | |
1431 | Size in bytes of PLT relocs | |
1432 | .It Dv DT_PLTGOT | |
1433 | Address of PLT and/or GOT | |
1434 | .It Dv DT_HASH | |
1435 | Address of symbol hash table | |
1436 | .It Dv DT_STRTAB | |
1437 | Address of string table | |
1438 | .It Dv DT_SYMTAB | |
1439 | Address of symbol table | |
1440 | .It Dv DT_RELA | |
1441 | Address of Rela relocs table | |
1442 | .It Dv DT_RELASZ | |
1443 | Size in bytes of Rela table | |
1444 | .It Dv DT_RELAENT | |
1445 | Size in bytes of a Rela table entry | |
1446 | .It Dv DT_STRSZ | |
1447 | Size in bytes of string table | |
1448 | .It Dv DT_SYMENT | |
1449 | Size in bytes of a symbol table entry | |
1450 | .It Dv DT_INIT | |
1451 | Address of the initialization function | |
1452 | .It Dv DT_FINI | |
1453 | Address of the termination function | |
1454 | .It Dv DT_SONAME | |
1455 | String table offset to name of shared object | |
1456 | .It Dv DT_RPATH | |
1457 | String table offset to library search path (deprecated) | |
1458 | .It Dv DT_SYMBOLIC | |
1459 | Alert linker to search this shared object before the executable for symbols | |
1460 | .It Dv DT_REL | |
1461 | Address of Rel relocs table | |
1462 | .It Dv DT_RELSZ | |
1463 | Size in bytes of Rel table | |
1464 | .It Dv DT_RELENT | |
1465 | Size in bytes of a Rel table entry | |
1466 | .It Dv DT_PLTREL | |
1467 | Type of reloc the PLT refers (Rela or Rel) | |
1468 | .It Dv DT_DEBUG | |
1469 | Undefined use for debugging | |
1470 | .It Dv DT_TEXTREL | |
1471 | Absence of this indicates no relocs should apply to a non-writable segment | |
1472 | .It Dv DT_JMPREL | |
1473 | Address of reloc entries solely for the PLT | |
1474 | .It Dv DT_BIND_NOW | |
c13182ef | 1475 | Instruct dynamic linker to process all relocs before transferring control to |
8d5bf179 MK |
1476 | the executable |
1477 | .It Dv DT_RUNPATH | |
1478 | String table offset to library search path | |
1479 | .It Dv DT_LOPROC | |
1480 | Start of processor-specific semantics | |
1481 | .It Dv DT_HIPROC | |
1482 | End of processor-specific semantics | |
1483 | .El | |
1484 | .It Dv d_val | |
1485 | This member represents integer values with various interpretations. | |
1486 | .It Dv d_ptr | |
c13182ef MK |
1487 | This member represents program virtual addresses. |
1488 | When interpreting | |
1489 | these addresses, the actual address should be computed based on the | |
1490 | original file value and memory base address. | |
1491 | Files do not contain | |
8d5bf179 MK |
1492 | relocation entries to fixup these addresses. |
1493 | .It Dv _DYNAMIC | |
c13182ef | 1494 | Array containing all the dynamic structures in the .dynamic section. |
8d5bf179 MK |
1495 | This is automatically populated by the linker. |
1496 | .El | |
75434268 MK |
1497 | .Sh NOTES |
1498 | .\" .Ox | |
1499 | .\" ELF support first appeared in | |
1500 | .\" .Ox 1.2 , | |
1501 | .\" although not all supported platforms use it as the native | |
1502 | .\" binary file format. | |
1503 | ELF first appeared in | |
e37e3282 MK |
1504 | .At V . |
1505 | The ELF format is an adopted standard. | |
d2dc6294 MK |
1506 | .\" .Sh AUTHORS |
1507 | .\" The original version of this manual page was written by | |
1508 | .\" .An Jeroen Ruigrok van der Werven | |
1509 | .\" .Aq asmodai@FreeBSD.org | |
1510 | .\" with inspiration from BSDi's | |
1511 | .\" .Bsx | |
1512 | .\" .Nm elf | |
1513 | .\" man page. | |
fea681da MK |
1514 | .Sh SEE ALSO |
1515 | .Xr as 1 , | |
1516 | .Xr gdb 1 , | |
1517 | .Xr ld 1 , | |
1518 | .Xr objdump 1 , | |
d57d1b90 | 1519 | .Xr execve 2 , |
e1a9bc1b | 1520 | .Xr core 5 |
fea681da MK |
1521 | .Rs |
1522 | .%A Hewlett-Packard | |
1523 | .%B Elf-64 Object File Format | |
1524 | .Re | |
1525 | .Rs | |
1526 | .%A Santa Cruz Operation | |
1527 | .%B System V Application Binary Interface | |
1528 | .Re | |
1529 | .Rs | |
1530 | .%A Unix System Laboratories | |
1531 | .%T Object Files | |
1532 | .%B "Executable and Linking Format (ELF)" | |
1533 | .Re |