]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man5/elf.5
hypot.3: srcfix: add some notes about the underflow case
[thirdparty/man-pages.git] / man5 / elf.5
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 .\" %%%LICENSE_START(PERMISSIVE_MISC)
6 .\"Redistribution and use in source and binary forms, with or without
7 .\"modification, are permitted provided that the following conditions
8 .\"are met:
9 .\"1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\"2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\"
15 .\"THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\"ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\"ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\"FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\"DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\"OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\"HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\"LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\"OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\"SUCH DAMAGE.
26 .\" %%%LICENSE_END
27 .\"
28 .\" $FreeBSD: src/share/man/man5/elf.5,v 1.21 2001/10/01 16:09:23 ru Exp $
29 .\"
30 .\" Slightly adapted - aeb, 2004-01-01
31 .\" 2005-07-15, Mike Frysinger <vapier@gentoo.org>, various fixes
32 .\" 2007-10-11, Mike Frysinger <vapier@gentoo.org>, various fixes
33 .\" 2007-12-08, mtk, Converted from mdoc to man macros
34 .\"
35 .TH ELF 5 2020-04-11 "Linux" "Linux Programmer's Manual"
36 .SH NAME
37 elf \- format of Executable and Linking Format (ELF) files
38 .SH SYNOPSIS
39 .nf
40 .\" .B #include <elf_abi.h>
41 .B #include <elf.h>
42 .fi
43 .SH DESCRIPTION
44 The header file
45 .I <elf.h>
46 defines the format of ELF executable binary files.
47 Amongst these files are
48 normal executable files, relocatable object files, core files, and shared
49 objects.
50 .PP
51 An executable file using the ELF file format consists of an ELF header,
52 followed by a program header table or a section header table, or both.
53 The ELF header is always at offset zero of the file.
54 The program header
55 table and the section header table's offset in the file are defined in the
56 ELF header.
57 The two tables describe the rest of the particularities of
58 the file.
59 .PP
60 .\" Applications which wish to process ELF binary files for their native
61 .\" architecture only should include
62 .\" .I <elf_abi.h>
63 .\" in their source code.
64 .\" These applications should need to refer to
65 .\" all the types and structures by their generic names
66 .\" "Elf_xxx"
67 .\" and to the macros by
68 .\" ELF_xxx".
69 .\" Applications written this way can be compiled on any architecture,
70 .\" regardless of whether the host is 32-bit or 64-bit.
71 .\" .PP
72 .\" Should an application need to process ELF files of an unknown
73 .\" architecture, then the application needs to explicitly use either
74 .\" "Elf32_xxx"
75 .\" or
76 .\" "Elf64_xxx"
77 .\" type and structure names.
78 .\" Likewise, the macros need to be identified by
79 .\" "ELF32_xxx"
80 .\" or
81 .\" "ELF64_xxx".
82 .\" .PP
83 This header file describes the above mentioned headers as C structures
84 and also includes structures for dynamic sections, relocation sections and
85 symbol tables.
86 .\"
87 .SS Basic types
88 The following types are used for N-bit architectures (N=32,64,
89 .I ElfN
90 stands for
91 .I Elf32
92 or
93 .IR Elf64 ,
94 .I uintN_t
95 stands for
96 .I uint32_t
97 or
98 .IR uint64_t ):
99 .PP
100 .in +4n
101 .EX
102 ElfN_Addr Unsigned program address, uintN_t
103 ElfN_Off Unsigned file offset, uintN_t
104 ElfN_Section Unsigned section index, uint16_t
105 ElfN_Versym Unsigned version symbol information, uint16_t
106 Elf_Byte unsigned char
107 ElfN_Half uint16_t
108 ElfN_Sword int32_t
109 ElfN_Word uint32_t
110 ElfN_Sxword int64_t
111 ElfN_Xword uint64_t
112 .\" Elf32_Size Unsigned object size
113 .EE
114 .in
115 .PP
116 (Note: the *BSD terminology is a bit different.
117 There,
118 .I Elf64_Half
119 is
120 twice as large as
121 .IR Elf32_Half ,
122 and
123 .I Elf64Quarter
124 is used for
125 .IR uint16_t .
126 In order to avoid confusion these types are replaced by explicit ones
127 in the below.)
128 .PP
129 All data structures that the file format defines follow the
130 "natural"
131 size and alignment guidelines for the relevant class.
132 If necessary,
133 data structures contain explicit padding to ensure 4-byte alignment
134 for 4-byte objects, to force structure sizes to a multiple of 4, and so on.
135 .\"
136 .SS ELF header (Ehdr)
137 The ELF header is described by the type
138 .I Elf32_Ehdr
139 or
140 .IR Elf64_Ehdr :
141 .PP
142 .in +4n
143 .EX
144 #define EI_NIDENT 16
145
146 typedef struct {
147 unsigned char e_ident[EI_NIDENT];
148 uint16_t e_type;
149 uint16_t e_machine;
150 uint32_t e_version;
151 ElfN_Addr e_entry;
152 ElfN_Off e_phoff;
153 ElfN_Off e_shoff;
154 uint32_t e_flags;
155 uint16_t e_ehsize;
156 uint16_t e_phentsize;
157 uint16_t e_phnum;
158 uint16_t e_shentsize;
159 uint16_t e_shnum;
160 uint16_t e_shstrndx;
161 } ElfN_Ehdr;
162 .EE
163 .in
164 .PP
165 The fields have the following meanings:
166 .\"
167 .nr l1_indent 7
168 .\"
169 .TP \n[l1_indent]
170 .IR e_ident
171 This array of bytes specifies how to interpret the file,
172 independent of the processor or the file's remaining contents.
173 Within this array everything is named by macros, which start with
174 the prefix
175 .BR EI_
176 and may contain values which start with the prefix
177 .BR ELF .
178 The following macros are defined:
179 .RS
180 .TP
181 .BR EI_MAG0
182 The first byte of the magic number.
183 It must be filled with
184 .BR ELFMAG0 .
185 (0: 0x7f)
186 .TP
187 .BR EI_MAG1
188 The second byte of the magic number.
189 It must be filled with
190 .BR ELFMAG1 .
191 (1: \(aqE\(aq)
192 .TP
193 .BR EI_MAG2
194 The third byte of the magic number.
195 It must be filled with
196 .BR ELFMAG2 .
197 (2: \(aqL\(aq)
198 .TP
199 .BR EI_MAG3
200 The fourth byte of the magic number.
201 It must be filled with
202 .BR ELFMAG3 .
203 (3: \(aqF\(aq)
204 .TP
205 .BR EI_CLASS
206 The fifth byte identifies the architecture for this binary:
207 .RS
208 .TP 14
209 .PD 0
210 .BR ELFCLASSNONE
211 This class is invalid.
212 .TP
213 .BR ELFCLASS32
214 This defines the 32-bit architecture.
215 It supports machines with files
216 and virtual address spaces up to 4 Gigabytes.
217 .TP
218 .BR ELFCLASS64
219 This defines the 64-bit architecture.
220 .PD
221 .RE
222 .TP
223 .BR EI_DATA
224 The sixth byte specifies the data encoding of the processor-specific
225 data in the file.
226 Currently, these encodings are supported:
227 .RS 9
228 .TP 14
229 .PD 0
230 .BR ELFDATANONE
231 Unknown data format.
232 .TP
233 .BR ELFDATA2LSB
234 Two's complement, little-endian.
235 .TP
236 .BR ELFDATA2MSB
237 Two's complement, big-endian.
238 .PD
239 .RE
240 .TP
241 .BR EI_VERSION
242 The seventh byte is the version number of the ELF specification:
243 .IP
244 .PD 0
245 .RS
246 .TP 14
247 .BR EV_NONE
248 Invalid version.
249 .TP
250 .BR EV_CURRENT
251 Current version.
252 .PD
253 .RE
254 .\".El
255 .TP
256 .BR EI_OSABI
257 The eighth byte identifies the operating system
258 and ABI to which the object is targeted.
259 Some fields in other ELF structures have flags
260 and values that have platform-specific meanings;
261 the interpretation of those fields is determined by the value of this byte.
262 For example:
263 .RS
264 .TP 21
265 .PD 0
266 .BR ELFOSABI_NONE
267 Same as ELFOSABI_SYSV
268 .\" 0
269 .TP
270 .BR ELFOSABI_SYSV
271 UNIX System V ABI
272 .\" 0
273 .\" synonym: ELFOSABI_NONE
274 .TP
275 .BR ELFOSABI_HPUX
276 HP-UX ABI
277 .\" 1
278 .TP
279 .BR ELFOSABI_NETBSD
280 NetBSD ABI
281 .\" 2
282 .TP
283 .BR ELFOSABI_LINUX
284 Linux ABI
285 .\" 3
286 .\" .TP
287 .\" .BR ELFOSABI_HURD
288 .\" Hurd ABI
289 .\" 4
290 .\" .TP
291 .\" .BR ELFOSABI_86OPEN
292 .\" 86Open Common IA32 ABI
293 .\" 5
294 .TP
295 .BR ELFOSABI_SOLARIS
296 Solaris ABI
297 .\" 6
298 .\" .TP
299 .\" .BR ELFOSABI_MONTEREY
300 .\" Monterey project ABI
301 .\" Now replaced by
302 .\" ELFOSABI_AIX
303 .\" 7
304 .TP
305 .BR ELFOSABI_IRIX
306 IRIX ABI
307 .\" 8
308 .TP
309 .BR ELFOSABI_FREEBSD
310 FreeBSD ABI
311 .\" 9
312 .TP
313 .BR ELFOSABI_TRU64
314 TRU64 UNIX ABI
315 .\" 10
316 .\" ELFOSABI_MODESTO
317 .\" 11
318 .\" ELFOSABI_OPENBSD
319 .\" 12
320 .TP
321 .BR ELFOSABI_ARM
322 ARM architecture ABI
323 .\" 97
324 .TP
325 .BR ELFOSABI_STANDALONE
326 Stand-alone (embedded) ABI
327 .\" 255
328 .PD
329 .RE
330 .TP
331 .BR EI_ABIVERSION
332 The ninth byte identifies the version of the ABI
333 to which the object is targeted.
334 This field is used to distinguish among incompatible versions of an ABI.
335 The interpretation of this version number
336 is dependent on the ABI identified by the
337 .B EI_OSABI
338 field.
339 Applications conforming to this specification use the value 0.
340 .TP
341 .BR EI_PAD
342 Start of padding.
343 These bytes are reserved and set to zero.
344 Programs
345 which read them should ignore them.
346 The value for
347 .B EI_PAD
348 will change in
349 the future if currently unused bytes are given meanings.
350 .\" As reported by Yuri Kozlov and confirmed by Mike Frysinger, EI_BRAND is
351 .\" not in GABI (http://www.sco.com/developers/gabi/latest/ch4.eheader.html)
352 .\" It looks to be a BSDism
353 .\" .TP
354 .\" .BR EI_BRAND
355 .\" Start of architecture identification.
356 .TP
357 .BR EI_NIDENT
358 The size of the
359 .I e_ident
360 array.
361 .RE
362 .TP
363 .IR e_type
364 This member of the structure identifies the object file type:
365 .RS
366 .TP 16
367 .PD 0
368 .BR ET_NONE
369 An unknown type.
370 .TP
371 .BR ET_REL
372 A relocatable file.
373 .TP
374 .BR ET_EXEC
375 An executable file.
376 .TP
377 .BR ET_DYN
378 A shared object.
379 .TP
380 .BR ET_CORE
381 A core file.
382 .PD
383 .RE
384 .TP
385 .IR e_machine
386 This member specifies the required architecture for an individual file.
387 For example:
388 .RS \n[l1_indent]
389 .TP 16
390 .PD 0
391 .BR EM_NONE
392 An unknown machine
393 .\" 0
394 .TP
395 .BR EM_M32
396 AT&T WE 32100
397 .\" 1
398 .TP
399 .BR EM_SPARC
400 Sun Microsystems SPARC
401 .\" 2
402 .TP
403 .BR EM_386
404 Intel 80386
405 .\" 3
406 .TP
407 .BR EM_68K
408 Motorola 68000
409 .\" 4
410 .TP
411 .BR EM_88K
412 Motorola 88000
413 .\" 5
414 .\" .TP
415 .\" .BR EM_486
416 .\" Intel 80486
417 .\" 6
418 .TP
419 .BR EM_860
420 Intel 80860
421 .\" 7
422 .TP
423 .BR EM_MIPS
424 MIPS RS3000 (big-endian only)
425 .\" 8
426 .\" EM_S370
427 .\" 9
428 .\" .TP
429 .\" .BR EM_MIPS_RS4_BE
430 .\" MIPS RS4000 (big-endian only). Deprecated
431 .\" 10
432 .\" EM_MIPS_RS3_LE (MIPS R3000 little-endian)
433 .\" 10
434 .TP
435 .BR EM_PARISC
436 HP/PA
437 .\" 15
438 .TP
439 .BR EM_SPARC32PLUS
440 SPARC with enhanced instruction set
441 .\" 18
442 .TP
443 .BR EM_PPC
444 PowerPC
445 .\" 20
446 .TP
447 .BR EM_PPC64
448 PowerPC 64-bit
449 .\" 21
450 .TP
451 .BR EM_S390
452 IBM S/390
453 .\" 22
454 .TP
455 .BR EM_ARM
456 Advanced RISC Machines
457 .\" 40
458 .TP
459 .BR EM_SH
460 Renesas SuperH
461 .\" 42
462 .TP
463 .BR EM_SPARCV9
464 SPARC v9 64-bit
465 .\" 43
466 .TP
467 .BR EM_IA_64
468 Intel Itanium
469 .\" 50
470 .TP
471 .BR EM_X86_64
472 AMD x86-64
473 .\" 62
474 .TP
475 .BR EM_VAX
476 DEC Vax
477 .\" 75
478 .\" EM_CRIS
479 .\" 76
480 .\" .TP
481 .\" .BR EM_ALPHA
482 .\" Compaq [DEC] Alpha
483 .\" .TP
484 .\" .BR EM_ALPHA_EXP
485 .\" Compaq [DEC] Alpha with enhanced instruction set
486 .PD
487 .RE
488 .TP
489 .IR e_version
490 This member identifies the file version:
491 .RS
492 .TP 16
493 .PD 0
494 .BR EV_NONE
495 Invalid version
496 .TP
497 .BR EV_CURRENT
498 Current version
499 .PD
500 .RE
501 .TP
502 .IR e_entry
503 This member gives the virtual address to which the system first transfers
504 control, thus starting the process.
505 If the file has no associated entry
506 point, this member holds zero.
507 .TP
508 .IR e_phoff
509 This member holds the program header table's file offset in bytes.
510 If
511 the file has no program header table, this member holds zero.
512 .TP
513 .IR e_shoff
514 This member holds the section header table's file offset in bytes.
515 If the
516 file has no section header table, this member holds zero.
517 .TP
518 .IR e_flags
519 This member holds processor-specific flags associated with the file.
520 Flag names take the form EF_`machine_flag'.
521 Currently, no flags have been defined.
522 .TP
523 .IR e_ehsize
524 This member holds the ELF header's size in bytes.
525 .TP
526 .IR e_phentsize
527 This member holds the size in bytes of one entry in the file's
528 program header table; all entries are the same size.
529 .TP
530 .IR e_phnum
531 This member holds the number of entries in the program header
532 table.
533 Thus the product of
534 .IR e_phentsize
535 and
536 .IR e_phnum
537 gives the table's size
538 in bytes.
539 If a file has no program header,
540 .IR e_phnum
541 holds the value zero.
542 .IP
543 If the number of entries in the program header table is
544 larger than or equal to
545 .\" This is a Linux extension, added in Linux 2.6.34.
546 .BR PN_XNUM
547 (0xffff), this member holds
548 .BR PN_XNUM
549 (0xffff) and the real number of entries in the program header table is held
550 in the
551 .IR sh_info
552 member of the initial entry in section header table.
553 Otherwise, the
554 .IR sh_info
555 member of the initial entry contains the value zero.
556 .RS \n[l1_indent]
557 .TP
558 .BR PN_XNUM
559 This is defined as 0xffff, the largest number
560 .IR e_phnum
561 can have, specifying where the actual number of program headers is assigned.
562 .PD
563 .RE
564 .IP
565 .TP
566 .IR e_shentsize
567 This member holds a sections header's size in bytes.
568 A section header is one
569 entry in the section header table; all entries are the same size.
570 .TP
571 .IR e_shnum
572 This member holds the number of entries in the section header table.
573 Thus
574 the product of
575 .IR e_shentsize
576 and
577 .IR e_shnum
578 gives the section header table's size in bytes.
579 If a file has no section
580 header table,
581 .IR e_shnum
582 holds the value of zero.
583 .IP
584 If the number of entries in the section header table is
585 larger than or equal to
586 .BR SHN_LORESERVE
587 (0xff00),
588 .IR e_shnum
589 holds the value zero and the real number of entries in the section header
590 table is held in the
591 .IR sh_size
592 member of the initial entry in section header table.
593 Otherwise, the
594 .IR sh_size
595 member of the initial entry in the section header table holds
596 the value zero.
597 .TP
598 .IR e_shstrndx
599 This member holds the section header table index of the entry associated
600 with the section name string table.
601 If the file has no section name string
602 table, this member holds the value
603 .BR SHN_UNDEF .
604 .IP
605 If the index of section name string table section is
606 larger than or equal to
607 .BR SHN_LORESERVE
608 (0xff00), this member holds
609 .BR SHN_XINDEX
610 (0xffff) and the real index of the section name string table section
611 is held in the
612 .IR sh_link
613 member of the initial entry in section header table.
614 Otherwise, the
615 .IR sh_link
616 member of the initial entry in section header table contains the value zero.
617 .\"
618 .SS Program header (Phdr)
619 An executable or shared object file's program header table is an array of
620 structures, each describing a segment or other information the system needs
621 to prepare the program for execution.
622 An object file
623 .IR segment
624 contains one or more
625 .IR sections .
626 Program headers are meaningful only for executable and shared object files.
627 A file specifies its own program header size with the ELF header's
628 .IR e_phentsize
629 and
630 .IR e_phnum
631 members.
632 The ELF program header is described by the type
633 .I Elf32_Phdr
634 or
635 .I Elf64_Phdr
636 depending on the architecture:
637 .PP
638 .in +4n
639 .EX
640 typedef struct {
641 uint32_t p_type;
642 Elf32_Off p_offset;
643 Elf32_Addr p_vaddr;
644 Elf32_Addr p_paddr;
645 uint32_t p_filesz;
646 uint32_t p_memsz;
647 uint32_t p_flags;
648 uint32_t p_align;
649 } Elf32_Phdr;
650 .EE
651 .in
652 .PP
653 .in +4n
654 .EX
655 typedef struct {
656 uint32_t p_type;
657 uint32_t p_flags;
658 Elf64_Off p_offset;
659 Elf64_Addr p_vaddr;
660 Elf64_Addr p_paddr;
661 uint64_t p_filesz;
662 uint64_t p_memsz;
663 uint64_t p_align;
664 } Elf64_Phdr;
665 .EE
666 .in
667 .PP
668 The main difference between the 32-bit and the 64-bit program header lies
669 in the location of the
670 .IR p_flags
671 member in the total struct.
672 .TP
673 .IR p_type
674 This member of the structure indicates what kind of segment this array
675 element describes or how to interpret the array element's information.
676 .RS 10
677 .TP
678 .BR PT_NULL
679 The array element is unused and the other members' values are undefined.
680 This lets the program header have ignored entries.
681 .TP
682 .BR PT_LOAD
683 The array element specifies a loadable segment, described by
684 .IR p_filesz
685 and
686 .IR p_memsz .
687 The bytes from the file are mapped to the beginning of the memory
688 segment.
689 If the segment's memory size
690 .IR p_memsz
691 is larger than the file size
692 .IR p_filesz ,
693 the
694 "extra"
695 bytes are defined to hold the value 0 and to follow the segment's
696 initialized area.
697 The file size may not be larger than the memory size.
698 Loadable segment entries in the program header table appear in ascending
699 order, sorted on the
700 .IR p_vaddr
701 member.
702 .TP
703 .BR PT_DYNAMIC
704 The array element specifies dynamic linking information.
705 .TP
706 .BR PT_INTERP
707 The array element specifies the location and size of a null-terminated
708 pathname to invoke as an interpreter.
709 This segment type is meaningful
710 only for executable files (though it may occur for shared objects).
711 However it may not occur more than once in a file.
712 If it is present, it must precede any loadable segment entry.
713 .TP
714 .BR PT_NOTE
715 The array element specifies the location of notes (ElfN_Nhdr).
716 .TP
717 .BR PT_SHLIB
718 This segment type is reserved but has unspecified semantics.
719 Programs that
720 contain an array element of this type do not conform to the ABI.
721 .TP
722 .BR PT_PHDR
723 The array element, if present,
724 specifies the location and size of the program header table itself,
725 both in the file and in the memory image of the program.
726 This segment type may not occur more than once in a file.
727 Moreover, it may
728 occur only if the program header table is part of the memory image of the
729 program.
730 If it is present, it must precede any loadable segment entry.
731 .TP
732 .BR PT_LOPROC ", " PT_HIPROC
733 Values in the inclusive range
734 .RB [ PT_LOPROC ", " PT_HIPROC ]
735 are reserved for processor-specific semantics.
736 .TP
737 .BR PT_GNU_STACK
738 GNU extension which is used by the Linux kernel to control the state of the
739 stack via the flags set in the
740 .IR p_flags
741 member.
742 .RE
743 .TP
744 .IR p_offset
745 This member holds the offset from the beginning of the file at which
746 the first byte of the segment resides.
747 .TP
748 .IR p_vaddr
749 This member holds the virtual address at which the first byte of the
750 segment resides in memory.
751 .TP
752 .IR p_paddr
753 On systems for which physical addressing is relevant, this member is
754 reserved for the segment's physical address.
755 Under
756 BSD
757 this member is
758 not used and must be zero.
759 .TP
760 .IR p_filesz
761 This member holds the number of bytes in the file image of the segment.
762 It may be zero.
763 .TP
764 .IR p_memsz
765 This member holds the number of bytes in the memory image of the segment.
766 It may be zero.
767 .TP
768 .IR p_flags
769 This member holds a bit mask of flags relevant to the segment:
770 .RS
771 .TP
772 .PD 0
773 .BR PF_X
774 An executable segment.
775 .TP
776 .BR PF_W
777 A writable segment.
778 .TP
779 .BR PF_R
780 A readable segment.
781 .PD
782 .RE
783 .IP
784 A text segment commonly has the flags
785 .BR PF_X
786 and
787 .BR PF_R .
788 A data segment commonly has
789 .BR PF_W
790 and
791 .BR PF_R .
792 .TP
793 .IR p_align
794 This member holds the value to which the segments are aligned in memory
795 and in the file.
796 Loadable process segments must have congruent values for
797 .IR p_vaddr
798 and
799 .IR p_offset ,
800 modulo the page size.
801 Values of zero and one mean no alignment is required.
802 Otherwise,
803 .IR p_align
804 should be a positive, integral power of two, and
805 .IR p_vaddr
806 should equal
807 .IR p_offset ,
808 modulo
809 .IR p_align .
810 .\"
811 .SS Section header (Shdr)
812 A file's section header table lets one locate all the file's sections.
813 The
814 section header table is an array of
815 .I Elf32_Shdr
816 or
817 .I Elf64_Shdr
818 structures.
819 The
820 ELF header's
821 .IR e_shoff
822 member gives the byte offset from the beginning of the file to the section
823 header table.
824 .IR e_shnum
825 holds the number of entries the section header table contains.
826 .IR e_shentsize
827 holds the size in bytes of each entry.
828 .PP
829 A section header table index is a subscript into this array.
830 Some section
831 header table indices are reserved:
832 the initial entry and the indices between
833 .B SHN_LORESERVE
834 and
835 .BR SHN_HIRESERVE .
836 The initial entry is used in ELF extensions for
837 .IR e_phnum ,
838 .IR e_shnum
839 and
840 .IR e_shstrndx ;
841 in other cases, each field in the initial entry is set to zero.
842 An object file does not have sections for
843 these special indices:
844 .TP
845 .BR SHN_UNDEF
846 This value marks an undefined, missing, irrelevant,
847 or otherwise meaningless section reference.
848 .TP
849 .BR SHN_LORESERVE
850 This value specifies the lower bound of the range of reserved indices.
851 .TP
852 .BR SHN_LOPROC ", " SHN_HIPROC
853 Values greater in the inclusive range
854 .RB [ SHN_LOPROC ", " SHN_HIPROC ]
855 are reserved for processor-specific semantics.
856 .TP
857 .BR SHN_ABS
858 This value specifies the absolute value for the corresponding reference.
859 For
860 example, a symbol defined relative to section number
861 .BR SHN_ABS
862 has an absolute value and is not affected by relocation.
863 .TP
864 .BR SHN_COMMON
865 Symbols defined relative to this section are common symbols,
866 such as FORTRAN COMMON or unallocated C external variables.
867 .TP
868 .BR SHN_HIRESERVE
869 This value specifies the upper bound of the range of reserved indices.
870 The
871 system reserves indices between
872 .BR SHN_LORESERVE
873 and
874 .BR SHN_HIRESERVE ,
875 inclusive.
876 The section header table does not contain entries for the
877 reserved indices.
878 .PP
879 The section header has the following structure:
880 .PP
881 .in +4n
882 .EX
883 typedef struct {
884 uint32_t sh_name;
885 uint32_t sh_type;
886 uint32_t sh_flags;
887 Elf32_Addr sh_addr;
888 Elf32_Off sh_offset;
889 uint32_t sh_size;
890 uint32_t sh_link;
891 uint32_t sh_info;
892 uint32_t sh_addralign;
893 uint32_t sh_entsize;
894 } Elf32_Shdr;
895 .EE
896 .in
897 .PP
898 .in +4n
899 .EX
900 typedef struct {
901 uint32_t sh_name;
902 uint32_t sh_type;
903 uint64_t sh_flags;
904 Elf64_Addr sh_addr;
905 Elf64_Off sh_offset;
906 uint64_t sh_size;
907 uint32_t sh_link;
908 uint32_t sh_info;
909 uint64_t sh_addralign;
910 uint64_t sh_entsize;
911 } Elf64_Shdr;
912 .EE
913 .in
914 .PP
915 No real differences exist between the 32-bit and 64-bit section headers.
916 .TP \n[l1_indent]
917 .IR sh_name
918 This member specifies the name of the section.
919 Its value is an index
920 into the section header string table section, giving the location of
921 a null-terminated string.
922 .TP
923 .IR sh_type
924 This member categorizes the section's contents and semantics.
925 .RS \n[l1_indent]
926 .TP
927 .BR SHT_NULL
928 This value marks the section header as inactive.
929 It does not
930 have an associated section.
931 Other members of the section header
932 have undefined values.
933 .TP
934 .BR SHT_PROGBITS
935 This section holds information defined by the program, whose
936 format and meaning are determined solely by the program.
937 .TP
938 .BR SHT_SYMTAB
939 This section holds a symbol table.
940 Typically,
941 .BR SHT_SYMTAB
942 provides symbols for link editing, though it may also be used
943 for dynamic linking.
944 As a complete symbol table, it may contain
945 many symbols unnecessary for dynamic linking.
946 An object file can
947 also contain a
948 .BR SHT_DYNSYM
949 section.
950 .TP
951 .BR SHT_STRTAB
952 This section holds a string table.
953 An object file may have multiple
954 string table sections.
955 .TP
956 .BR SHT_RELA
957 This section holds relocation entries with explicit addends, such
958 as type
959 .IR Elf32_Rela
960 for the 32-bit class of object files.
961 An object may have multiple
962 relocation sections.
963 .TP
964 .BR SHT_HASH
965 This section holds a symbol hash table.
966 An object participating in
967 dynamic linking must contain a symbol hash table.
968 An object file may
969 have only one hash table.
970 .TP
971 .BR SHT_DYNAMIC
972 This section holds information for dynamic linking.
973 An object file may
974 have only one dynamic section.
975 .TP
976 .BR SHT_NOTE
977 This section holds notes (ElfN_Nhdr).
978 .TP
979 .BR SHT_NOBITS
980 A section of this type occupies no space in the file but otherwise
981 resembles
982 .BR SHT_PROGBITS .
983 Although this section contains no bytes, the
984 .IR sh_offset
985 member contains the conceptual file offset.
986 .TP
987 .BR SHT_REL
988 This section holds relocation offsets without explicit addends, such
989 as type
990 .IR Elf32_Rel
991 for the 32-bit class of object files.
992 An object file may have multiple
993 relocation sections.
994 .TP
995 .BR SHT_SHLIB
996 This section is reserved but has unspecified semantics.
997 .TP
998 .BR SHT_DYNSYM
999 This section holds a minimal set of dynamic linking symbols.
1000 An
1001 object file can also contain a
1002 .BR SHT_SYMTAB
1003 section.
1004 .TP
1005 .BR SHT_LOPROC ", " SHT_HIPROC
1006 Values in the inclusive range
1007 .RB [ SHT_LOPROC ", " SHT_HIPROC ]
1008 are reserved for processor-specific semantics.
1009 .TP
1010 .BR SHT_LOUSER
1011 This value specifies the lower bound of the range of indices reserved for
1012 application programs.
1013 .TP
1014 .BR SHT_HIUSER
1015 This value specifies the upper bound of the range of indices reserved for
1016 application programs.
1017 Section types between
1018 .BR SHT_LOUSER
1019 and
1020 .BR SHT_HIUSER
1021 may be used by the application, without conflicting with current or future
1022 system-defined section types.
1023 .RE
1024 .TP
1025 .IR sh_flags
1026 Sections support one-bit flags that describe miscellaneous attributes.
1027 If a flag bit is set in
1028 .IR sh_flags ,
1029 the attribute is
1030 "on"
1031 for the section.
1032 Otherwise, the attribute is
1033 "off"
1034 or does not apply.
1035 Undefined attributes are set to zero.
1036 .RS \n[l1_indent]
1037 .TP
1038 .BR SHF_WRITE
1039 This section contains data that should be writable during process
1040 execution.
1041 .TP
1042 .BR SHF_ALLOC
1043 This section occupies memory during process execution.
1044 Some control
1045 sections do not reside in the memory image of an object file.
1046 This
1047 attribute is off for those sections.
1048 .TP
1049 .BR SHF_EXECINSTR
1050 This section contains executable machine instructions.
1051 .TP
1052 .BR SHF_MASKPROC
1053 All bits included in this mask are reserved for processor-specific
1054 semantics.
1055 .RE
1056 .TP
1057 .IR sh_addr
1058 If this section appears in the memory image of a process, this member
1059 holds the address at which the section's first byte should reside.
1060 Otherwise, the member contains zero.
1061 .TP
1062 .IR sh_offset
1063 This member's value holds the byte offset from the beginning of the file
1064 to the first byte in the section.
1065 One section type,
1066 .BR SHT_NOBITS ,
1067 occupies no space in the file, and its
1068 .IR sh_offset
1069 member locates the conceptual placement in the file.
1070 .TP
1071 .IR sh_size
1072 This member holds the section's size in bytes.
1073 Unless the section type
1074 is
1075 .BR SHT_NOBITS ,
1076 the section occupies
1077 .IR sh_size
1078 bytes in the file.
1079 A section of type
1080 .BR SHT_NOBITS
1081 may have a nonzero size, but it occupies no space in the file.
1082 .TP
1083 .IR sh_link
1084 This member holds a section header table index link, whose interpretation
1085 depends on the section type.
1086 .TP
1087 .IR sh_info
1088 This member holds extra information, whose interpretation depends on the
1089 section type.
1090 .TP
1091 .IR sh_addralign
1092 Some sections have address alignment constraints.
1093 If a section holds a
1094 doubleword, the system must ensure doubleword alignment for the entire
1095 section.
1096 That is, the value of
1097 .IR sh_addr
1098 must be congruent to zero, modulo the value of
1099 .IR sh_addralign .
1100 Only zero and positive integral powers of two are allowed.
1101 The value 0 or 1 means that the section has no alignment constraints.
1102 .TP
1103 .IR sh_entsize
1104 Some sections hold a table of fixed-sized entries, such as a symbol table.
1105 For such a section, this member gives the size in bytes for each entry.
1106 This member contains zero if the section does not hold a table of
1107 fixed-size entries.
1108 .PP
1109 Various sections hold program and control information:
1110 .TP \n[l1_indent]
1111 .IR .bss
1112 This section holds uninitialized data that contributes to the program's
1113 memory image.
1114 By definition, the system initializes the data with zeros
1115 when the program begins to run.
1116 This section is of type
1117 .BR SHT_NOBITS .
1118 The attribute types are
1119 .BR SHF_ALLOC
1120 and
1121 .BR SHF_WRITE .
1122 .TP
1123 .IR .comment
1124 This section holds version control information.
1125 This section is of type
1126 .BR SHT_PROGBITS .
1127 No attribute types are used.
1128 .TP
1129 .IR .ctors
1130 This section holds initialized pointers to the C++ constructor functions.
1131 This section is of type
1132 .BR SHT_PROGBITS .
1133 The attribute types are
1134 .BR SHF_ALLOC
1135 and
1136 .BR SHF_WRITE .
1137 .TP
1138 .IR .data
1139 This section holds initialized data that contribute to the program's
1140 memory image.
1141 This section is of type
1142 .BR SHT_PROGBITS .
1143 The attribute types are
1144 .BR SHF_ALLOC
1145 and
1146 .BR SHF_WRITE .
1147 .TP
1148 .IR .data1
1149 This section holds initialized data that contribute to the program's
1150 memory image.
1151 This section is of type
1152 .BR SHT_PROGBITS .
1153 The attribute types are
1154 .BR SHF_ALLOC
1155 and
1156 .BR SHF_WRITE .
1157 .TP
1158 .IR .debug
1159 This section holds information for symbolic debugging.
1160 The contents
1161 are unspecified.
1162 This section is of type
1163 .BR SHT_PROGBITS .
1164 No attribute types are used.
1165 .TP
1166 .IR .dtors
1167 This section holds initialized pointers to the C++ destructor functions.
1168 This section is of type
1169 .BR SHT_PROGBITS .
1170 The attribute types are
1171 .BR SHF_ALLOC
1172 and
1173 .BR SHF_WRITE .
1174 .TP
1175 .IR .dynamic
1176 This section holds dynamic linking information.
1177 The section's attributes
1178 will include the
1179 .BR SHF_ALLOC
1180 bit.
1181 Whether the
1182 .BR SHF_WRITE
1183 bit is set is processor-specific.
1184 This section is of type
1185 .BR SHT_DYNAMIC .
1186 See the attributes above.
1187 .TP
1188 .IR .dynstr
1189 This section holds strings needed for dynamic linking, most commonly
1190 the strings that represent the names associated with symbol table entries.
1191 This section is of type
1192 .BR SHT_STRTAB .
1193 The attribute type used is
1194 .BR SHF_ALLOC .
1195 .TP
1196 .IR .dynsym
1197 This section holds the dynamic linking symbol table.
1198 This section is of type
1199 .BR SHT_DYNSYM .
1200 The attribute used is
1201 .BR SHF_ALLOC .
1202 .TP
1203 .IR .fini
1204 This section holds executable instructions that contribute to the process
1205 termination code.
1206 When a program exits normally the system arranges to
1207 execute the code in this section.
1208 This section is of type
1209 .BR SHT_PROGBITS .
1210 The attributes used are
1211 .BR SHF_ALLOC
1212 and
1213 .BR SHF_EXECINSTR .
1214 .TP
1215 .IR .gnu.version
1216 This section holds the version symbol table, an array of
1217 .I ElfN_Half
1218 elements.
1219 This section is of type
1220 .BR SHT_GNU_versym .
1221 The attribute type used is
1222 .BR SHF_ALLOC .
1223 .TP
1224 .IR .gnu.version_d
1225 This section holds the version symbol definitions, a table of
1226 .I ElfN_Verdef
1227 structures.
1228 This section is of type
1229 .BR SHT_GNU_verdef .
1230 The attribute type used is
1231 .BR SHF_ALLOC .
1232 .TP
1233 .IR .gnu.version_r
1234 This section holds the version symbol needed elements, a table of
1235 .I ElfN_Verneed
1236 structures.
1237 This section is of
1238 type
1239 .BR SHT_GNU_versym .
1240 The attribute type used is
1241 .BR SHF_ALLOC .
1242 .TP
1243 .IR .got
1244 This section holds the global offset table.
1245 This section is of type
1246 .BR SHT_PROGBITS .
1247 The attributes are processor-specific.
1248 .TP
1249 .IR .hash
1250 This section holds a symbol hash table.
1251 This section is of type
1252 .BR SHT_HASH .
1253 The attribute used is
1254 .BR SHF_ALLOC .
1255 .TP
1256 .IR .init
1257 This section holds executable instructions that contribute to the process
1258 initialization code.
1259 When a program starts to run the system arranges to execute
1260 the code in this section before calling the main program entry point.
1261 This section is of type
1262 .BR SHT_PROGBITS .
1263 The attributes used are
1264 .BR SHF_ALLOC
1265 and
1266 .BR SHF_EXECINSTR .
1267 .TP
1268 .IR .interp
1269 This section holds the pathname of a program interpreter.
1270 If the file has
1271 a loadable segment that includes the section, the section's attributes will
1272 include the
1273 .BR SHF_ALLOC
1274 bit.
1275 Otherwise, that bit will be off.
1276 This section is of type
1277 .BR SHT_PROGBITS .
1278 .TP
1279 .IR .line
1280 This section holds line number information for symbolic debugging,
1281 which describes the correspondence between the program source and
1282 the machine code.
1283 The contents are unspecified.
1284 This section is of type
1285 .BR SHT_PROGBITS .
1286 No attribute types are used.
1287 .TP
1288 .IR .note
1289 This section holds various notes.
1290 This section is of type
1291 .BR SHT_NOTE .
1292 No attribute types are used.
1293 .TP
1294 .IR .note.ABI-tag
1295 This section is used to declare the expected run-time ABI of the ELF image.
1296 It may include the operating system name and its run-time versions.
1297 This section is of type
1298 .BR SHT_NOTE .
1299 The only attribute used is
1300 .BR SHF_ALLOC .
1301 .TP
1302 .IR .note.gnu.build-id
1303 This section is used to hold an ID that uniquely identifies
1304 the contents of the ELF image.
1305 Different files with the same build ID should contain the same executable
1306 content.
1307 See the
1308 .BR \-\-build\-id
1309 option to the GNU linker (\fBld\fR (1)) for more details.
1310 This section is of type
1311 .BR SHT_NOTE .
1312 The only attribute used is
1313 .BR SHF_ALLOC .
1314 .TP
1315 .IR .note.GNU-stack
1316 This section is used in Linux object files for declaring stack attributes.
1317 This section is of type
1318 .BR SHT_PROGBITS .
1319 The only attribute used is
1320 .BR SHF_EXECINSTR .
1321 This indicates to the GNU linker that the object file requires an
1322 executable stack.
1323 .TP
1324 .IR .note.openbsd.ident
1325 OpenBSD native executables usually contain this section
1326 to identify themselves so the kernel can bypass any compatibility
1327 ELF binary emulation tests when loading the file.
1328 .TP
1329 .IR .plt
1330 This section holds the procedure linkage table.
1331 This section is of type
1332 .BR SHT_PROGBITS .
1333 The attributes are processor-specific.
1334 .TP
1335 .IR .relNAME
1336 This section holds relocation information as described below.
1337 If the file
1338 has a loadable segment that includes relocation, the section's attributes
1339 will include the
1340 .BR SHF_ALLOC
1341 bit.
1342 Otherwise, the bit will be off.
1343 By convention,
1344 "NAME"
1345 is supplied by the section to which the relocations apply.
1346 Thus a relocation
1347 section for
1348 .BR .text
1349 normally would have the name
1350 .BR .rel.text .
1351 This section is of type
1352 .BR SHT_REL .
1353 .TP
1354 .IR .relaNAME
1355 This section holds relocation information as described below.
1356 If the file
1357 has a loadable segment that includes relocation, the section's attributes
1358 will include the
1359 .BR SHF_ALLOC
1360 bit.
1361 Otherwise, the bit will be off.
1362 By convention,
1363 "NAME"
1364 is supplied by the section to which the relocations apply.
1365 Thus a relocation
1366 section for
1367 .BR .text
1368 normally would have the name
1369 .BR .rela.text .
1370 This section is of type
1371 .BR SHT_RELA .
1372 .TP
1373 .IR .rodata
1374 This section holds read-only data that typically contributes to a
1375 nonwritable segment in the process image.
1376 This section is of type
1377 .BR SHT_PROGBITS .
1378 The attribute used is
1379 .BR SHF_ALLOC .
1380 .TP
1381 .IR .rodata1
1382 This section holds read-only data that typically contributes to a
1383 nonwritable segment in the process image.
1384 This section is of type
1385 .BR SHT_PROGBITS .
1386 The attribute used is
1387 .BR SHF_ALLOC .
1388 .TP
1389 .IR .shstrtab
1390 This section holds section names.
1391 This section is of type
1392 .BR SHT_STRTAB .
1393 No attribute types are used.
1394 .TP
1395 .IR .strtab
1396 This section holds strings, most commonly the strings that represent the
1397 names associated with symbol table entries.
1398 If the file has a loadable
1399 segment that includes the symbol string table, the section's attributes
1400 will include the
1401 .BR SHF_ALLOC
1402 bit.
1403 Otherwise, the bit will be off.
1404 This section is of type
1405 .BR SHT_STRTAB .
1406 .TP
1407 .IR .symtab
1408 This section holds a symbol table.
1409 If the file has a loadable segment
1410 that includes the symbol table, the section's attributes will include
1411 the
1412 .BR SHF_ALLOC
1413 bit.
1414 Otherwise, the bit will be off.
1415 This section is of type
1416 .BR SHT_SYMTAB .
1417 .TP
1418 .IR .text
1419 This section holds the
1420 "text",
1421 or executable instructions, of a program.
1422 This section is of type
1423 .BR SHT_PROGBITS .
1424 The attributes used are
1425 .BR SHF_ALLOC
1426 and
1427 .BR SHF_EXECINSTR .
1428 .\"
1429 .SS String and symbol tables
1430 String table sections hold null-terminated character sequences, commonly
1431 called strings.
1432 The object file uses these strings to represent symbol
1433 and section names.
1434 One references a string as an index into the string
1435 table section.
1436 The first byte, which is index zero, is defined to hold
1437 a null byte (\(aq\e0\(aq).
1438 Similarly, a string table's last byte is defined to
1439 hold a null byte, ensuring null termination for all strings.
1440 .PP
1441 An object file's symbol table holds information needed to locate and
1442 relocate a program's symbolic definitions and references.
1443 A symbol table
1444 index is a subscript into this array.
1445 .PP
1446 .in +4n
1447 .EX
1448 typedef struct {
1449 uint32_t st_name;
1450 Elf32_Addr st_value;
1451 uint32_t st_size;
1452 unsigned char st_info;
1453 unsigned char st_other;
1454 uint16_t st_shndx;
1455 } Elf32_Sym;
1456 .EE
1457 .in
1458 .PP
1459 .in +4n
1460 .EX
1461 typedef struct {
1462 uint32_t st_name;
1463 unsigned char st_info;
1464 unsigned char st_other;
1465 uint16_t st_shndx;
1466 Elf64_Addr st_value;
1467 uint64_t st_size;
1468 } Elf64_Sym;
1469 .EE
1470 .in
1471 .PP
1472 The 32-bit and 64-bit versions have the same members, just in a different
1473 order.
1474 .TP \n[l1_indent]
1475 .IR st_name
1476 This member holds an index into the object file's symbol string table,
1477 which holds character representations of the symbol names.
1478 If the value
1479 is nonzero, it represents a string table index that gives the symbol
1480 name.
1481 Otherwise, the symbol has no name.
1482 .TP
1483 .IR st_value
1484 This member gives the value of the associated symbol.
1485 .TP
1486 .IR st_size
1487 Many symbols have associated sizes.
1488 This member holds zero if the symbol
1489 has no size or an unknown size.
1490 .TP
1491 .IR st_info
1492 This member specifies the symbol's type and binding attributes:
1493 .RS \n[l1_indent]
1494 .TP
1495 .BR STT_NOTYPE
1496 The symbol's type is not defined.
1497 .TP
1498 .BR STT_OBJECT
1499 The symbol is associated with a data object.
1500 .TP
1501 .BR STT_FUNC
1502 The symbol is associated with a function or other executable code.
1503 .TP
1504 .BR STT_SECTION
1505 The symbol is associated with a section.
1506 Symbol table entries of
1507 this type exist primarily for relocation and normally have
1508 .BR STB_LOCAL
1509 bindings.
1510 .TP
1511 .BR STT_FILE
1512 By convention, the symbol's name gives the name of the source file
1513 associated with the object file.
1514 A file symbol has
1515 .BR STB_LOCAL
1516 bindings, its section index is
1517 .BR SHN_ABS ,
1518 and it precedes the other
1519 .BR STB_LOCAL
1520 symbols of the file, if it is present.
1521 .TP
1522 .BR STT_LOPROC ", " STT_HIPROC
1523 Values in the inclusive range
1524 .RB [ STT_LOPROC ", " STT_HIPROC ]
1525 are reserved for processor-specific semantics.
1526 .TP
1527 .BR STB_LOCAL
1528 Local symbols are not visible outside the object file containing their
1529 definition.
1530 Local symbols of the same name may exist in multiple files
1531 without interfering with each other.
1532 .TP
1533 .BR STB_GLOBAL
1534 Global symbols are visible to all object files being combined.
1535 One file's
1536 definition of a global symbol will satisfy another file's undefined
1537 reference to the same symbol.
1538 .TP
1539 .BR STB_WEAK
1540 Weak symbols resemble global symbols, but their definitions have lower
1541 precedence.
1542 .TP
1543 .BR STB_LOPROC ", " STB_HIPROC
1544 Values in the inclusive range
1545 .RB [ STB_LOPROC ", " STB_HIPROC ]
1546 are reserved for processor-specific semantics.
1547 .RE
1548 .IP
1549 There are macros for packing and unpacking the binding and type fields:
1550 .RS \n[l1_indent]
1551 .TP
1552 .BR ELF32_ST_BIND( \fIinfo\fP ) ", " ELF64_ST_BIND( \fIinfo\fP )
1553 Extract a binding from an
1554 .I st_info
1555 value.
1556 .TP
1557 .BR ELF32_ST_TYPE( \fIinfo ) ", " ELF64_ST_TYPE( \fIinfo\fP )
1558 Extract a type from an
1559 .I st_info
1560 value.
1561 .TP
1562 .BR ELF32_ST_INFO( \fIbind\fP ", " \fItype\fP ) ", " \
1563 ELF64_ST_INFO( \fIbind\fP ", " \fItype\fP )
1564 Convert a binding and a type into an
1565 .I st_info
1566 value.
1567 .RE
1568 .TP
1569 .IR st_other
1570 This member defines the symbol visibility.
1571 .RS \n[l1_indent]
1572 .TP
1573 .PD 0
1574 .BR STV_DEFAULT
1575 Default symbol visibility rules.
1576 Global and weak symbols are available to other modules;
1577 references in the local module can be interposed
1578 by definitions in other modules.
1579 .TP
1580 .BR STV_INTERNAL
1581 Processor-specific hidden class.
1582 .TP
1583 .BR STV_HIDDEN
1584 Symbol is unavailable to other modules;
1585 references in the local module always resolve to the local symbol
1586 (i.e., the symbol can't be interposed by definitions in other modules).
1587 .TP
1588 .BR STV_PROTECTED
1589 Symbol is available to other modules,
1590 but references in the local module always resolve to the local symbol.
1591 .PD
1592 .PP
1593 There are macros for extracting the visibility type:
1594 .PP
1595 .BR ELF32_ST_VISIBILITY (other)
1596 or
1597 .BR ELF64_ST_VISIBILITY (other)
1598 .RE
1599 .TP
1600 .IR st_shndx
1601 Every symbol table entry is
1602 "defined"
1603 in relation to some section.
1604 This member holds the relevant section
1605 header table index.
1606 .\"
1607 .SS Relocation entries (Rel & Rela)
1608 Relocation is the process of connecting symbolic references with
1609 symbolic definitions.
1610 Relocatable files must have information that
1611 describes how to modify their section contents, thus allowing executable
1612 and shared object files to hold the right information for a process's
1613 program image.
1614 Relocation entries are these data.
1615 .PP
1616 Relocation structures that do not need an addend:
1617 .PP
1618 .in +4n
1619 .EX
1620 typedef struct {
1621 Elf32_Addr r_offset;
1622 uint32_t r_info;
1623 } Elf32_Rel;
1624 .EE
1625 .in
1626 .PP
1627 .in +4n
1628 .EX
1629 typedef struct {
1630 Elf64_Addr r_offset;
1631 uint64_t r_info;
1632 } Elf64_Rel;
1633 .EE
1634 .in
1635 .PP
1636 Relocation structures that need an addend:
1637 .PP
1638 .in +4n
1639 .EX
1640 typedef struct {
1641 Elf32_Addr r_offset;
1642 uint32_t r_info;
1643 int32_t r_addend;
1644 } Elf32_Rela;
1645 .EE
1646 .in
1647 .PP
1648 .in +4n
1649 .EX
1650 typedef struct {
1651 Elf64_Addr r_offset;
1652 uint64_t r_info;
1653 int64_t r_addend;
1654 } Elf64_Rela;
1655 .EE
1656 .in
1657 .TP \n[l1_indent]
1658 .IR r_offset
1659 This member gives the location at which to apply the relocation action.
1660 For a relocatable file, the value is the byte offset from the beginning
1661 of the section to the storage unit affected by the relocation.
1662 For an
1663 executable file or shared object, the value is the virtual address of
1664 the storage unit affected by the relocation.
1665 .TP
1666 .IR r_info
1667 This member gives both the symbol table index with respect to which the
1668 relocation must be made and the type of relocation to apply.
1669 Relocation
1670 types are processor-specific.
1671 When the text refers to a relocation
1672 entry's relocation type or symbol table index, it means the result of
1673 applying
1674 .BR ELF[32|64]_R_TYPE
1675 or
1676 .BR ELF[32|64]_R_SYM ,
1677 respectively, to the entry's
1678 .IR r_info
1679 member.
1680 .TP
1681 .IR r_addend
1682 This member specifies a constant addend used to compute the value to be
1683 stored into the relocatable field.
1684 .\"
1685 .SS Dynamic tags (Dyn)
1686 The
1687 .I .dynamic
1688 section contains a series of structures that hold relevant
1689 dynamic linking information.
1690 The
1691 .I d_tag
1692 member controls the interpretation
1693 of
1694 .IR d_un .
1695 .PP
1696 .in +4n
1697 .EX
1698 typedef struct {
1699 Elf32_Sword d_tag;
1700 union {
1701 Elf32_Word d_val;
1702 Elf32_Addr d_ptr;
1703 } d_un;
1704 } Elf32_Dyn;
1705 extern Elf32_Dyn _DYNAMIC[];
1706 .EE
1707 .in
1708 .PP
1709 .in +4n
1710 .EX
1711 typedef struct {
1712 Elf64_Sxword d_tag;
1713 union {
1714 Elf64_Xword d_val;
1715 Elf64_Addr d_ptr;
1716 } d_un;
1717 } Elf64_Dyn;
1718 extern Elf64_Dyn _DYNAMIC[];
1719 .EE
1720 .in
1721 .TP \n[l1_indent]
1722 .IR d_tag
1723 This member may have any of the following values:
1724 .RS \n[l1_indent]
1725 .TP 12
1726 .BR DT_NULL
1727 Marks end of dynamic section
1728 .TP
1729 .BR DT_NEEDED
1730 String table offset to name of a needed library
1731 .TP
1732 .BR DT_PLTRELSZ
1733 Size in bytes of PLT relocation entries
1734 .TP
1735 .BR DT_PLTGOT
1736 Address of PLT and/or GOT
1737 .TP
1738 .BR DT_HASH
1739 Address of symbol hash table
1740 .TP
1741 .BR DT_STRTAB
1742 Address of string table
1743 .TP
1744 .BR DT_SYMTAB
1745 Address of symbol table
1746 .TP
1747 .BR DT_RELA
1748 Address of Rela relocation table
1749 .TP
1750 .BR DT_RELASZ
1751 Size in bytes of the Rela relocation table
1752 .TP
1753 .BR DT_RELAENT
1754 Size in bytes of a Rela relocation table entry
1755 .TP
1756 .BR DT_STRSZ
1757 Size in bytes of string table
1758 .TP
1759 .BR DT_SYMENT
1760 Size in bytes of a symbol table entry
1761 .TP
1762 .BR DT_INIT
1763 Address of the initialization function
1764 .TP
1765 .BR DT_FINI
1766 Address of the termination function
1767 .TP
1768 .BR DT_SONAME
1769 String table offset to name of shared object
1770 .TP
1771 .BR DT_RPATH
1772 String table offset to library search path (deprecated)
1773 .TP
1774 .BR DT_SYMBOLIC
1775 Alert linker to search this shared object before the executable for symbols
1776 .TP
1777 .BR DT_REL
1778 Address of Rel relocation table
1779 .TP
1780 .BR DT_RELSZ
1781 Size in bytes of Rel relocation table
1782 .TP
1783 .BR DT_RELENT
1784 Size in bytes of a Rel table entry
1785 .TP
1786 .BR DT_PLTREL
1787 Type of relocation entry to which the PLT refers (Rela or Rel)
1788 .TP
1789 .BR DT_DEBUG
1790 Undefined use for debugging
1791 .TP
1792 .BR DT_TEXTREL
1793 Absence of this entry indicates that no relocation entries should
1794 apply to a nonwritable segment
1795 .TP
1796 .BR DT_JMPREL
1797 Address of relocation entries associated solely with the PLT
1798 .TP
1799 .BR DT_BIND_NOW
1800 Instruct dynamic linker to process all relocations before
1801 transferring control to the executable
1802 .TP
1803 .BR DT_RUNPATH
1804 String table offset to library search path
1805 .TP
1806 .BR DT_LOPROC ", " DT_HIPROC
1807 Values in the inclusive range
1808 .RB [ DT_LOPROC ", " DT_HIPROC ]
1809 are reserved for processor-specific semantics
1810 .RE
1811 .TP
1812 .IR d_val
1813 This member represents integer values with various interpretations.
1814 .TP
1815 .IR d_ptr
1816 This member represents program virtual addresses.
1817 When interpreting
1818 these addresses, the actual address should be computed based on the
1819 original file value and memory base address.
1820 Files do not contain
1821 relocation entries to fixup these addresses.
1822 .TP
1823 .I _DYNAMIC
1824 Array containing all the dynamic structures in the
1825 .I .dynamic
1826 section.
1827 This is automatically populated by the linker.
1828 .\" GABI ELF Reference for Note Sections:
1829 .\" http://www.sco.com/developers/gabi/latest/ch5.pheader.html#note_section
1830 .\"
1831 .\" Note that it implies the sizes and alignments of notes depend on the ELF
1832 .\" size (e.g. 32-bit ELFs have three 4-byte words and use 4-byte alignment
1833 .\" while 64-bit ELFs use 8-byte words & alignment), but that is not the case
1834 .\" in the real world. Notes always have three 4-byte words as can be seen
1835 .\" in the source links below (remember that Elf64_Word is a 32-bit quantity).
1836 .\" glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/elf.h;h=9e59b3275917549af0cebe1f2de9ded3b7b10bf2#l1173
1837 .\" binutils: https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=274ddd17266aef6e4ad1f67af8a13a21500ff2af#l15943
1838 .\" Linux: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/elf.h?h=v4.8#n422
1839 .\" Solaris: https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html
1840 .\" FreeBSD: https://svnweb.freebsd.org/base/head/sys/sys/elf_common.h?revision=303677&view=markup#l33
1841 .\" NetBSD: https://www.netbsd.org/docs/kernel/elf-notes.html
1842 .\" OpenBSD: https://github.com/openbsd/src/blob/master/sys/sys/exec_elf.h#L533
1843 .\"
1844 .SS Notes (Nhdr)
1845 ELF notes allow for appending arbitrary information for the system to use.
1846 They are largely used by core files
1847 .RI ( e_type
1848 of
1849 .BR ET_CORE ),
1850 but many projects define their own set of extensions.
1851 For example,
1852 the GNU tool chain uses ELF notes to pass information from
1853 the linker to the C library.
1854 .PP
1855 Note sections contain a series of notes (see the
1856 .I struct
1857 definitions below).
1858 Each note is followed by the name field (whose length is defined in
1859 \fIn_namesz\fR) and then by the descriptor field (whose length is defined in
1860 \fIn_descsz\fR) and whose starting address has a 4 byte alignment.
1861 Neither field is defined in the note struct due to their arbitrary lengths.
1862 .PP
1863 An example for parsing out two consecutive notes should clarify their layout
1864 in memory:
1865 .PP
1866 .in +4n
1867 .EX
1868 void *memory, *name, *desc;
1869 Elf64_Nhdr *note, *next_note;
1870
1871 /* The buffer is pointing to the start of the section/segment */
1872 note = memory;
1873
1874 /* If the name is defined, it follows the note */
1875 name = note->n_namesz == 0 ? NULL : memory + sizeof(*note);
1876
1877 /* If the descriptor is defined, it follows the name
1878 (with alignment) */
1879
1880 desc = note->n_descsz == 0 ? NULL :
1881 memory + sizeof(*note) + ALIGN_UP(note->n_namesz, 4);
1882
1883 /* The next note follows both (with alignment) */
1884 next_note = memory + sizeof(*note) +
1885 ALIGN_UP(note->n_namesz, 4) +
1886 ALIGN_UP(note->n_descsz, 4);
1887 .EE
1888 .in
1889 .PP
1890 Keep in mind that the interpretation of
1891 .I n_type
1892 depends on the namespace defined by the
1893 .I n_namesz
1894 field.
1895 If the
1896 .I n_namesz
1897 field is not set (e.g., is 0), then there are two sets of notes:
1898 one for core files and one for all other ELF types.
1899 If the namespace is unknown, then tools will usually fallback to these sets
1900 of notes as well.
1901 .PP
1902 .in +4n
1903 .EX
1904 typedef struct {
1905 Elf32_Word n_namesz;
1906 Elf32_Word n_descsz;
1907 Elf32_Word n_type;
1908 } Elf32_Nhdr;
1909 .EE
1910 .in
1911 .PP
1912 .in +4n
1913 .EX
1914 typedef struct {
1915 Elf64_Word n_namesz;
1916 Elf64_Word n_descsz;
1917 Elf64_Word n_type;
1918 } Elf64_Nhdr;
1919 .EE
1920 .in
1921 .TP \n[l1_indent]
1922 .IR n_namesz
1923 The length of the name field in bytes.
1924 The contents will immediately follow this note in memory.
1925 The name is null terminated.
1926 For example, if the name is "GNU", then
1927 .I n_namesz
1928 will be set to 4.
1929 .TP
1930 .IR n_descsz
1931 The length of the descriptor field in bytes.
1932 The contents will immediately follow the name field in memory.
1933 .TP
1934 .IR n_type
1935 Depending on the value of the name field, this member may have any of the
1936 following values:
1937 .RS \n[l1_indent]
1938 .TP 5
1939 .B Core files (e_type = ET_CORE)
1940 Notes used by all core files.
1941 These are highly operating system or architecture specific and often require
1942 close coordination with kernels, C libraries, and debuggers.
1943 These are used when the namespace is the default (i.e.,
1944 .I n_namesz
1945 will be set to 0), or a fallback when the namespace is unknown.
1946 .RS
1947 .TP 21
1948 .PD 0
1949 .B NT_PRSTATUS
1950 prstatus struct
1951 .TP
1952 .B NT_FPREGSET
1953 fpregset struct
1954 .TP
1955 .B NT_PRPSINFO
1956 prpsinfo struct
1957 .TP
1958 .B NT_PRXREG
1959 prxregset struct
1960 .TP
1961 .B NT_TASKSTRUCT
1962 task structure
1963 .TP
1964 .B NT_PLATFORM
1965 String from sysinfo(SI_PLATFORM)
1966 .TP
1967 .B NT_AUXV
1968 auxv array
1969 .TP
1970 .B NT_GWINDOWS
1971 gwindows struct
1972 .TP
1973 .B NT_ASRS
1974 asrset struct
1975 .TP
1976 .B NT_PSTATUS
1977 pstatus struct
1978 .TP
1979 .B NT_PSINFO
1980 psinfo struct
1981 .TP
1982 .B NT_PRCRED
1983 prcred struct
1984 .TP
1985 .B NT_UTSNAME
1986 utsname struct
1987 .TP
1988 .B NT_LWPSTATUS
1989 lwpstatus struct
1990 .TP
1991 .B NT_LWPSINFO
1992 lwpinfo struct
1993 .TP
1994 .B NT_PRFPXREG
1995 fprxregset struct
1996 .TP
1997 .B NT_SIGINFO
1998 siginfo_t (size might increase over time)
1999 .TP
2000 .B NT_FILE
2001 Contains information about mapped files
2002 .TP
2003 .B NT_PRXFPREG
2004 user_fxsr_struct
2005 .TP
2006 .B NT_PPC_VMX
2007 PowerPC Altivec/VMX registers
2008 .TP
2009 .B NT_PPC_SPE
2010 PowerPC SPE/EVR registers
2011 .TP
2012 .B NT_PPC_VSX
2013 PowerPC VSX registers
2014 .TP
2015 .B NT_386_TLS
2016 i386 TLS slots (struct user_desc)
2017 .TP
2018 .B NT_386_IOPERM
2019 x86 io permission bitmap (1=deny)
2020 .TP
2021 .B NT_X86_XSTATE
2022 x86 extended state using xsave
2023 .TP
2024 .B NT_S390_HIGH_GPRS
2025 s390 upper register halves
2026 .TP
2027 .B NT_S390_TIMER
2028 s390 timer register
2029 .TP
2030 .B NT_S390_TODCMP
2031 s390 time-of-day (TOD) clock comparator register
2032 .TP
2033 .B NT_S390_TODPREG
2034 s390 time-of-day (TOD) programmable register
2035 .TP
2036 .B NT_S390_CTRS
2037 s390 control registers
2038 .TP
2039 .B NT_S390_PREFIX
2040 s390 prefix register
2041 .TP
2042 .B NT_S390_LAST_BREAK
2043 s390 breaking event address
2044 .TP
2045 .B NT_S390_SYSTEM_CALL
2046 s390 system call restart data
2047 .TP
2048 .B NT_S390_TDB
2049 s390 transaction diagnostic block
2050 .TP
2051 .B NT_ARM_VFP
2052 ARM VFP/NEON registers
2053 .TP
2054 .B NT_ARM_TLS
2055 ARM TLS register
2056 .TP
2057 .B NT_ARM_HW_BREAK
2058 ARM hardware breakpoint registers
2059 .TP
2060 .B NT_ARM_HW_WATCH
2061 ARM hardware watchpoint registers
2062 .TP
2063 .B NT_ARM_SYSTEM_CALL
2064 ARM system call number
2065 .PD
2066 .RE
2067 .TP
2068 .B n_name = GNU
2069 Extensions used by the GNU tool chain.
2070 .RS
2071 .TP
2072 .B NT_GNU_ABI_TAG
2073 Operating system (OS) ABI information.
2074 The desc field will be 4 words:
2075 .IP
2076 .PD 0
2077 .RS
2078 .IP \(bu 2
2079 word 0: OS descriptor
2080 (\fBELF_NOTE_OS_LINUX\fR, \fBELF_NOTE_OS_GNU\fR, and so on)`
2081 .IP \(bu
2082 word 1: major version of the ABI
2083 .IP \(bu
2084 word 2: minor version of the ABI
2085 .IP \(bu
2086 word 3: subminor version of the ABI
2087 .RE
2088 .PD
2089 .TP
2090 .B NT_GNU_HWCAP
2091 Synthetic hwcap information.
2092 The desc field begins with two words:
2093 .IP
2094 .PD 0
2095 .RS
2096 .IP \(bu 2
2097 word 0: number of entries
2098 .IP \(bu
2099 word 1: bit mask of enabled entries
2100 .RE
2101 .PD
2102 .IP
2103 Then follow variable-length entries, one byte followed by a null-terminated
2104 hwcap name string.
2105 The byte gives the bit number to test if enabled, (1U << bit) & bit mask.
2106 .TP
2107 .B NT_GNU_BUILD_ID
2108 Unique build ID as generated by the GNU
2109 .BR ld (1)
2110 .BR \-\-build\-id
2111 option.
2112 The desc consists of any nonzero number of bytes.
2113 .TP
2114 .B NT_GNU_GOLD_VERSION
2115 The desc contains the GNU Gold linker version used.
2116 .RE
2117 .TP
2118 .B Default/unknown namespace (e_type != ET_CORE)
2119 These are used when the namespace is the default (i.e.,
2120 .I n_namesz
2121 will be set to 0), or a fallback when the namespace is unknown.
2122 .RS
2123 .TP 21
2124 .PD 0
2125 .B NT_VERSION
2126 A version string of some sort.
2127 .TP
2128 .B NT_ARCH
2129 Architecture information.
2130 .PD
2131 .RE
2132 .PP
2133 .RE
2134 .SH NOTES
2135 .\" OpenBSD
2136 .\" ELF support first appeared in
2137 .\" OpenBSD 1.2,
2138 .\" although not all supported platforms use it as the native
2139 .\" binary file format.
2140 ELF first appeared in
2141 System V.
2142 The ELF format is an adopted standard.
2143 .PP
2144 The extensions for
2145 .IR e_phnum ,
2146 .IR e_shnum
2147 and
2148 .IR e_shstrndx
2149 respectively are
2150 Linux extensions.
2151 Sun, BSD and AMD64 also support them; for further information,
2152 look under SEE ALSO.
2153 .\" .SH AUTHORS
2154 .\" The original version of this manual page was written by
2155 .\" .An Jeroen Ruigrok van der Werven
2156 .\" .Aq asmodai@FreeBSD.org
2157 .\" with inspiration from BSDi's
2158 .\" .Bsx
2159 .\" .Nm elf
2160 .\" man page.
2161 .SH SEE ALSO
2162 .BR as (1),
2163 .BR elfedit (1),
2164 .BR gdb (1),
2165 .BR ld (1),
2166 .BR nm (1),
2167 .BR objdump (1),
2168 .BR patchelf (1),
2169 .BR readelf (1),
2170 .BR size (1),
2171 .BR strings (1),
2172 .BR strip (1),
2173 .BR execve (2),
2174 .BR dl_iterate_phdr (3),
2175 .BR core (5),
2176 .BR ld.so (8)
2177 .PP
2178 Hewlett-Packard,
2179 .IR "Elf-64 Object File Format" .
2180 .PP
2181 Santa Cruz Operation,
2182 .IR "System V Application Binary Interface" .
2183 .PP
2184 UNIX System Laboratories,
2185 "Object Files",
2186 .IR "Executable and Linking Format (ELF)" .
2187 .PP
2188 Sun Microsystems,
2189 .IR "Linker and Libraries Guide" .
2190 .PP
2191 AMD64 ABI Draft,
2192 .IR "System V Application Binary Interface AMD64 Architecture Processor Supplement" .
2193 .PP