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