Debian Codegraph @

upstream/debian-unstable/man5/elf.5

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