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