Debian Codegraph @

upstream/debian-trixie/man5/elf.5

raw
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 <[email protected]>, various fixes
32 .\" 2007-10-11, Mike Frysinger <[email protected]>, various fixes
33 .\" 2007-12-08, mtk, Converted from mdoc to man macros
34 .\"
35 .TH ELF 5 2024-06-15 "Linux man-pages 6.9.1"
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 .P
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 .P
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 .\" .P
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 .\" .P
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 .P
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 .P
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 .P
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 .P
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 .P
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: \[aq]E\[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: \[aq]L\[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: \[aq]F\[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 .P
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 .P
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 .P
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 .B PT_LOPROC
731 .TQ
732 .B PT_HIPROC
733 Values in the inclusive range
734 .RB [ PT_LOPROC ,
735 .BR PT_HIPROC ]
736 are reserved for processor-specific semantics.
737 .TP
738 .B PT_GNU_STACK
739 GNU extension which is used by the Linux kernel to control the state of the
740 stack via the flags set in the
741 .I p_flags
742 member.
743 .RE
744 .TP
745 .I p_offset
746 This member holds the offset from the beginning of the file at which
747 the first byte of the segment resides.
748 .TP
749 .I p_vaddr
750 This member holds the virtual address at which the first byte of the
751 segment resides in memory.
752 .TP
753 .I p_paddr
754 On systems for which physical addressing is relevant, this member is
755 reserved for the segment's physical address.
756 Under
757 BSD
758 this member is
759 not used and must be zero.
760 .TP
761 .I p_filesz
762 This member holds the number of bytes in the file image of the segment.
763 It may be zero.
764 .TP
765 .I p_memsz
766 This member holds the number of bytes in the memory image of the segment.
767 It may be zero.
768 .TP
769 .I p_flags
770 This member holds a bit mask of flags relevant to the segment:
771 .RS
772 .TP
773 .PD 0
774 .B PF_X
775 An executable segment.
776 .TP
777 .B PF_W
778 A writable segment.
779 .TP
780 .B PF_R
781 A readable segment.
782 .PD
783 .RE
784 .IP
785 A text segment commonly has the flags
786 .B PF_X
787 and
788 .BR PF_R .
789 A data segment commonly has
790 .B PF_W
791 and
792 .BR PF_R .
793 .TP
794 .I p_align
795 This member holds the value to which the segments are aligned in memory
796 and in the file.
797 Loadable process segments must have congruent values for
798 .I p_vaddr
799 and
800 .IR p_offset ,
801 modulo the page size.
802 Values of zero and one mean no alignment is required.
803 Otherwise,
804 .I p_align
805 should be a positive, integral power of two, and
806 .I p_vaddr
807 should equal
808 .IR p_offset ,
809 modulo
810 .IR p_align .
811 .\"
812 .SS Section header (Shdr)
813 A file's section header table lets one locate all the file's sections.
814 The
815 section header table is an array of
816 .I Elf32_Shdr
817 or
818 .I Elf64_Shdr
819 structures.
820 The
821 ELF header's
822 .I e_shoff
823 member gives the byte offset from the beginning of the file to the section
824 header table.
825 .I e_shnum
826 holds the number of entries the section header table contains.
827 .I e_shentsize
828 holds the size in bytes of each entry.
829 .P
830 A section header table index is a subscript into this array.
831 Some section
832 header table indices are reserved:
833 the initial entry and the indices between
834 .B SHN_LORESERVE
835 and
836 .BR SHN_HIRESERVE .
837 The initial entry is used in ELF extensions for
838 .IR e_phnum ,
839 .IR e_shnum ,
840 and
841 .IR e_shstrndx ;
842 in other cases, each field in the initial entry is set to zero.
843 An object file does not have sections for
844 these special indices:
845 .TP
846 .B SHN_UNDEF
847 This value marks an undefined, missing, irrelevant,
848 or otherwise meaningless section reference.
849 .TP
850 .B SHN_LORESERVE
851 This value specifies the lower bound of the range of reserved indices.
852 .TP
853 .B SHN_LOPROC
854 .TQ
855 .B SHN_HIPROC
856 Values greater in the inclusive range
857 .RB [ SHN_LOPROC ,
858 .BR SHN_HIPROC ]
859 are reserved for processor-specific semantics.
860 .TP
861 .B SHN_ABS
862 This value specifies the absolute value for the corresponding reference.
863 For
864 example, a symbol defined relative to section number
865 .B SHN_ABS
866 has an absolute value and is not affected by relocation.
867 .TP
868 .B SHN_COMMON
869 Symbols defined relative to this section are common symbols,
870 such as FORTRAN COMMON or unallocated C external variables.
871 .TP
872 .B SHN_HIRESERVE
873 This value specifies the upper bound of the range of reserved indices.
874 The
875 system reserves indices between
876 .B SHN_LORESERVE
877 and
878 .BR SHN_HIRESERVE ,
879 inclusive.
880 The section header table does not contain entries for the
881 reserved indices.
882 .P
883 The section header has the following structure:
884 .P
885 .in +4n
886 .EX
887 typedef struct {
888 uint32_t sh_name;
889 uint32_t sh_type;
890 uint32_t sh_flags;
891 Elf32_Addr sh_addr;
892 Elf32_Off sh_offset;
893 uint32_t sh_size;
894 uint32_t sh_link;
895 uint32_t sh_info;
896 uint32_t sh_addralign;
897 uint32_t sh_entsize;
898 } Elf32_Shdr;
899 .EE
900 .in
901 .P
902 .in +4n
903 .EX
904 typedef struct {
905 uint32_t sh_name;
906 uint32_t sh_type;
907 uint64_t sh_flags;
908 Elf64_Addr sh_addr;
909 Elf64_Off sh_offset;
910 uint64_t sh_size;
911 uint32_t sh_link;
912 uint32_t sh_info;
913 uint64_t sh_addralign;
914 uint64_t sh_entsize;
915 } Elf64_Shdr;
916 .EE
917 .in
918 .P
919 No real differences exist between the 32-bit and 64-bit section headers.
920 .TP
921 .I sh_name
922 This member specifies the name of the section.
923 Its value is an index
924 into the section header string table section, giving the location of
925 a null-terminated string.
926 .TP
927 .I sh_type
928 This member categorizes the section's contents and semantics.
929 .RS
930 .TP
931 .B SHT_NULL
932 This value marks the section header as inactive.
933 It does not
934 have an associated section.
935 Other members of the section header
936 have undefined values.
937 .TP
938 .B SHT_PROGBITS
939 This section holds information defined by the program, whose
940 format and meaning are determined solely by the program.
941 .TP
942 .B SHT_SYMTAB
943 This section holds a symbol table.
944 Typically,
945 .B SHT_SYMTAB
946 provides symbols for link editing, though it may also be used
947 for dynamic linking.
948 As a complete symbol table, it may contain
949 many symbols unnecessary for dynamic linking.
950 An object file can
951 also contain a
952 .B SHT_DYNSYM
953 section.
954 .TP
955 .B SHT_STRTAB
956 This section holds a string table.
957 An object file may have multiple
958 string table sections.
959 .TP
960 .B SHT_RELA
961 This section holds relocation entries with explicit addends, such
962 as type
963 .I Elf32_Rela
964 for the 32-bit class of object files.
965 An object may have multiple
966 relocation sections.
967 .TP
968 .B SHT_HASH
969 This section holds a symbol hash table.
970 An object participating in
971 dynamic linking must contain a symbol hash table.
972 An object file may
973 have only one hash table.
974 .TP
975 .B SHT_DYNAMIC
976 This section holds information for dynamic linking.
977 An object file may
978 have only one dynamic section.
979 .TP
980 .B SHT_NOTE
981 This section holds notes (ElfN_Nhdr).
982 .TP
983 .B SHT_NOBITS
984 A section of this type occupies no space in the file but otherwise
985 resembles
986 .BR SHT_PROGBITS .
987 Although this section contains no bytes, the
988 .I sh_offset
989 member contains the conceptual file offset.
990 .TP
991 .B SHT_REL
992 This section holds relocation offsets without explicit addends, such
993 as type
994 .I Elf32_Rel
995 for the 32-bit class of object files.
996 An object file may have multiple
997 relocation sections.
998 .TP
999 .B SHT_SHLIB
1000 This section is reserved but has unspecified semantics.
1001 .TP
1002 .B SHT_DYNSYM
1003 This section holds a minimal set of dynamic linking symbols.
1004 An
1005 object file can also contain a
1006 .B SHT_SYMTAB
1007 section.
1008 .TP
1009 .B SHT_LOPROC
1010 .TQ
1011 .B SHT_HIPROC
1012 Values in the inclusive range
1013 .RB [ SHT_LOPROC ,
1014 .BR SHT_HIPROC ]
1015 are reserved for processor-specific semantics.
1016 .TP
1017 .B SHT_LOUSER
1018 This value specifies the lower bound of the range of indices reserved for
1019 application programs.
1020 .TP
1021 .B SHT_HIUSER
1022 This value specifies the upper bound of the range of indices reserved for
1023 application programs.
1024 Section types between
1025 .B SHT_LOUSER
1026 and
1027 .B SHT_HIUSER
1028 may be used by the application, without conflicting with current or future
1029 system-defined section types.
1030 .RE
1031 .TP
1032 .I sh_flags
1033 Sections support one-bit flags that describe miscellaneous attributes.
1034 If a flag bit is set in
1035 .IR sh_flags ,
1036 the attribute is
1037 "on"
1038 for the section.
1039 Otherwise, the attribute is
1040 "off"
1041 or does not apply.
1042 Undefined attributes are set to zero.
1043 .RS
1044 .TP
1045 .B SHF_WRITE
1046 This section contains data that should be writable during process
1047 execution.
1048 .TP
1049 .B SHF_ALLOC
1050 This section occupies memory during process execution.
1051 Some control
1052 sections do not reside in the memory image of an object file.
1053 This
1054 attribute is off for those sections.
1055 .TP
1056 .B SHF_EXECINSTR
1057 This section contains executable machine instructions.
1058 .TP
1059 .B SHF_MASKPROC
1060 All bits included in this mask are reserved for processor-specific
1061 semantics.
1062 .RE
1063 .TP
1064 .I sh_addr
1065 If this section appears in the memory image of a process, this member
1066 holds the address at which the section's first byte should reside.
1067 Otherwise, the member contains zero.
1068 .TP
1069 .I sh_offset
1070 This member's value holds the byte offset from the beginning of the file
1071 to the first byte in the section.
1072 One section type,
1073 .BR SHT_NOBITS ,
1074 occupies no space in the file, and its
1075 .I sh_offset
1076 member locates the conceptual placement in the file.
1077 .TP
1078 .I sh_size
1079 This member holds the section's size in bytes.
1080 Unless the section type
1081 is
1082 .BR SHT_NOBITS ,
1083 the section occupies
1084 .I sh_size
1085 bytes in the file.
1086 A section of type
1087 .B SHT_NOBITS
1088 may have a nonzero size, but it occupies no space in the file.
1089 .TP
1090 .I sh_link
1091 This member holds a section header table index link, whose interpretation
1092 depends on the section type.
1093 .TP
1094 .I sh_info
1095 This member holds extra information, whose interpretation depends on the
1096 section type.
1097 .TP
1098 .I sh_addralign
1099 Some sections have address alignment constraints.
1100 If a section holds a
1101 doubleword, the system must ensure doubleword alignment for the entire
1102 section.
1103 That is, the value of
1104 .I sh_addr
1105 must be congruent to zero, modulo the value of
1106 .IR sh_addralign .
1107 Only zero and positive integral powers of two are allowed.
1108 The value 0 or 1 means that the section has no alignment constraints.
1109 .TP
1110 .I sh_entsize
1111 Some sections hold a table of fixed-sized entries, such as a symbol table.
1112 For such a section, this member gives the size in bytes for each entry.
1113 This member contains zero if the section does not hold a table of
1114 fixed-size entries.
1115 .P
1116 Various sections hold program and control information:
1117 .TP
1118 .I .bss
1119 This section holds uninitialized data that contributes to the program's
1120 memory image.
1121 By definition, the system initializes the data with zeros
1122 when the program begins to run.
1123 This section is of type
1124 .BR SHT_NOBITS .
1125 The attribute types are
1126 .B SHF_ALLOC
1127 and
1128 .BR SHF_WRITE .
1129 .TP
1130 .I .comment
1131 This section holds version control information.
1132 This section is of type
1133 .BR SHT_PROGBITS .
1134 No attribute types are used.
1135 .TP
1136 .I .ctors
1137 This section holds initialized pointers to the C++ constructor functions.
1138 This section is of type
1139 .BR SHT_PROGBITS .
1140 The attribute types are
1141 .B SHF_ALLOC
1142 and
1143 .BR SHF_WRITE .
1144 .TP
1145 .I .data
1146 This section holds initialized data that contribute to the program's
1147 memory image.
1148 This section is of type
1149 .BR SHT_PROGBITS .
1150 The attribute types are
1151 .B SHF_ALLOC
1152 and
1153 .BR SHF_WRITE .
1154 .TP
1155 .I .data1
1156 This section holds initialized data that contribute to the program's
1157 memory image.
1158 This section is of type
1159 .BR SHT_PROGBITS .
1160 The attribute types are
1161 .B SHF_ALLOC
1162 and
1163 .BR SHF_WRITE .
1164 .TP
1165 .I .debug
1166 This section holds information for symbolic debugging.
1167 The contents
1168 are unspecified.
1169 This section is of type
1170 .BR SHT_PROGBITS .
1171 No attribute types are used.
1172 .TP
1173 .I .dtors
1174 This section holds initialized pointers to the C++ destructor functions.
1175 This section is of type
1176 .BR SHT_PROGBITS .
1177 The attribute types are
1178 .B SHF_ALLOC
1179 and
1180 .BR SHF_WRITE .
1181 .TP
1182 .I .dynamic
1183 This section holds dynamic linking information.
1184 The section's attributes
1185 will include the
1186 .B SHF_ALLOC
1187 bit.
1188 Whether the
1189 .B SHF_WRITE
1190 bit is set is processor-specific.
1191 This section is of type
1192 .BR SHT_DYNAMIC .
1193 See the attributes above.
1194 .TP
1195 .I .dynstr
1196 This section holds strings needed for dynamic linking, most commonly
1197 the strings that represent the names associated with symbol table entries.
1198 This section is of type
1199 .BR SHT_STRTAB .
1200 The attribute type used is
1201 .BR SHF_ALLOC .
1202 .TP
1203 .I .dynsym
1204 This section holds the dynamic linking symbol table.
1205 This section is of type
1206 .BR SHT_DYNSYM .
1207 The attribute used is
1208 .BR SHF_ALLOC .
1209 .TP
1210 .I .fini
1211 This section holds executable instructions that contribute to the process
1212 termination code.
1213 When a program exits normally the system arranges to
1214 execute the code in this section.
1215 This section is of type
1216 .BR SHT_PROGBITS .
1217 The attributes used are
1218 .B SHF_ALLOC
1219 and
1220 .BR SHF_EXECINSTR .
1221 .TP
1222 .I .gnu.version
1223 This section holds the version symbol table, an array of
1224 .I ElfN_Half
1225 elements.
1226 This section is of type
1227 .BR SHT_GNU_versym .
1228 The attribute type used is
1229 .BR SHF_ALLOC .
1230 .TP
1231 .I .gnu.version_d
1232 This section holds the version symbol definitions, a table of
1233 .I ElfN_Verdef
1234 structures.
1235 This section is of type
1236 .BR SHT_GNU_verdef .
1237 The attribute type used is
1238 .BR SHF_ALLOC .
1239 .TP
1240 .I .gnu.version_r
1241 This section holds the version symbol needed elements, a table of
1242 .I ElfN_Verneed
1243 structures.
1244 This section is of
1245 type
1246 .BR SHT_GNU_versym .
1247 The attribute type used is
1248 .BR SHF_ALLOC .
1249 .TP
1250 .I .got
1251 This section holds the global offset table.
1252 This section is of type
1253 .BR SHT_PROGBITS .
1254 The attributes are processor-specific.
1255 .TP
1256 .I .hash
1257 This section holds a symbol hash table.
1258 This section is of type
1259 .BR SHT_HASH .
1260 The attribute used is
1261 .BR SHF_ALLOC .
1262 .TP
1263 .I .init
1264 This section holds executable instructions that contribute to the process
1265 initialization code.
1266 When a program starts to run the system arranges to execute
1267 the code in this section before calling the main program entry point.
1268 This section is of type
1269 .BR SHT_PROGBITS .
1270 The attributes used are
1271 .B SHF_ALLOC
1272 and
1273 .BR SHF_EXECINSTR .
1274 .TP
1275 .I .interp
1276 This section holds the pathname of a program interpreter.
1277 If the file has
1278 a loadable segment that includes the section, the section's attributes will
1279 include the
1280 .B SHF_ALLOC
1281 bit.
1282 Otherwise, that bit will be off.
1283 This section is of type
1284 .BR SHT_PROGBITS .
1285 .TP
1286 .I .line
1287 This section holds line number information for symbolic debugging,
1288 which describes the correspondence between the program source and
1289 the machine code.
1290 The contents are unspecified.
1291 This section is of type
1292 .BR SHT_PROGBITS .
1293 No attribute types are used.
1294 .TP
1295 .I .note
1296 This section holds various notes.
1297 This section is of type
1298 .BR SHT_NOTE .
1299 No attribute types are used.
1300 .TP
1301 .I .note.ABI\-tag
1302 This section is used to declare the expected run-time ABI of the ELF image.
1303 It may include the operating system name and its run-time versions.
1304 This section is of type
1305 .BR SHT_NOTE .
1306 The only attribute used is
1307 .BR SHF_ALLOC .
1308 .TP
1309 .I .note.gnu.build\-id
1310 This section is used to hold an ID that uniquely identifies
1311 the contents of the ELF image.
1312 Different files with the same build ID should contain the same executable
1313 content.
1314 See the
1315 .B \-\-build\-id
1316 option to the GNU linker (\fBld\fR (1)) 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 \fIn_namesz\fR) and then by the descriptor field (whose length is defined in
1881 \fIn_descsz\fR) and whose starting address has a 4 byte alignment.
1882 Neither field is defined in the note struct due to their arbitrary lengths.
1883 .P
1884 An example for parsing out two consecutive notes should clarify their layout
1885 in memory:
1886 .P
1887 .in +4n
1888 .EX
1889 void *memory, *name, *desc;
1890 Elf64_Nhdr *note, *next_note;
1891 \&
1892 /* The buffer is pointing to the start of the section/segment. */
1893 note = memory;
1894 \&
1895 /* If the name is defined, it follows the note. */
1896 name = note\->n_namesz == 0 ? NULL : memory + sizeof(*note);
1897 \&
1898 /* If the descriptor is defined, it follows the name
1899 (with alignment). */
1900 \&
1901 desc = note\->n_descsz == 0 ? NULL :
1902 memory + sizeof(*note) + ALIGN_UP(note\->n_namesz, 4);
1903 \&
1904 /* The next note follows both (with alignment). */
1905 next_note = memory + sizeof(*note) +
1906 ALIGN_UP(note\->n_namesz, 4) +
1907 ALIGN_UP(note\->n_descsz, 4);
1908 .EE
1909 .in
1910 .P
1911 Keep in mind that the interpretation of
1912 .I n_type
1913 depends on the namespace defined by the
1914 .I n_namesz
1915 field.
1916 If the
1917 .I n_namesz
1918 field is not set (e.g., is 0), then there are two sets of notes:
1919 one for core files and one for all other ELF types.
1920 If the namespace is unknown, then tools will usually fallback to these sets
1921 of notes as well.
1922 .P
1923 .in +4n
1924 .EX
1925 typedef struct {
1926 Elf32_Word n_namesz;
1927 Elf32_Word n_descsz;
1928 Elf32_Word n_type;
1929 } Elf32_Nhdr;
1930 .EE
1931 .in
1932 .P
1933 .in +4n
1934 .EX
1935 typedef struct {
1936 Elf64_Word n_namesz;
1937 Elf64_Word n_descsz;
1938 Elf64_Word n_type;
1939 } Elf64_Nhdr;
1940 .EE
1941 .in
1942 .TP
1943 .I n_namesz
1944 The length of the name field in bytes.
1945 The contents will immediately follow this note in memory.
1946 The name is null terminated.
1947 For example, if the name is "GNU", then
1948 .I n_namesz
1949 will be set to 4.
1950 .TP
1951 .I n_descsz
1952 The length of the descriptor field in bytes.
1953 The contents will immediately follow the name field in memory.
1954 .TP
1955 .I n_type
1956 Depending on the value of the name field, this member may have any of the
1957 following values:
1958 .RS
1959 .TP 5
1960 .B Core files (e_type = ET_CORE)
1961 Notes used by all core files.
1962 These are highly operating system or architecture specific and often require
1963 close coordination with kernels, C libraries, and debuggers.
1964 These are used when the namespace is the default (i.e.,
1965 .I n_namesz
1966 will be set to 0), or a fallback when the namespace is unknown.
1967 .RS
1968 .TP 21
1969 .PD 0
1970 .B NT_PRSTATUS
1971 prstatus struct
1972 .TP
1973 .B NT_FPREGSET
1974 fpregset struct
1975 .TP
1976 .B NT_PRPSINFO
1977 prpsinfo struct
1978 .TP
1979 .B NT_PRXREG
1980 prxregset struct
1981 .TP
1982 .B NT_TASKSTRUCT
1983 task structure
1984 .TP
1985 .B NT_PLATFORM
1986 String from sysinfo(SI_PLATFORM)
1987 .TP
1988 .B NT_AUXV
1989 auxv array
1990 .TP
1991 .B NT_GWINDOWS
1992 gwindows struct
1993 .TP
1994 .B NT_ASRS
1995 asrset struct
1996 .TP
1997 .B NT_PSTATUS
1998 pstatus struct
1999 .TP
2000 .B NT_PSINFO
2001 psinfo struct
2002 .TP
2003 .B NT_PRCRED
2004 prcred struct
2005 .TP
2006 .B NT_UTSNAME
2007 utsname struct
2008 .TP
2009 .B NT_LWPSTATUS
2010 lwpstatus struct
2011 .TP
2012 .B NT_LWPSINFO
2013 lwpinfo struct
2014 .TP
2015 .B NT_PRFPXREG
2016 fprxregset struct
2017 .TP
2018 .B NT_SIGINFO
2019 siginfo_t (size might increase over time)
2020 .TP
2021 .B NT_FILE
2022 Contains information about mapped files
2023 .TP
2024 .B NT_PRXFPREG
2025 user_fxsr_struct
2026 .TP
2027 .B NT_PPC_VMX
2028 PowerPC Altivec/VMX registers
2029 .TP
2030 .B NT_PPC_SPE
2031 PowerPC SPE/EVR registers
2032 .TP
2033 .B NT_PPC_VSX
2034 PowerPC VSX registers
2035 .TP
2036 .B NT_386_TLS
2037 i386 TLS slots (struct user_desc)
2038 .TP
2039 .B NT_386_IOPERM
2040 x86 io permission bitmap (1=deny)
2041 .TP
2042 .B NT_X86_XSTATE
2043 x86 extended state using xsave
2044 .TP
2045 .B NT_S390_HIGH_GPRS
2046 s390 upper register halves
2047 .TP
2048 .B NT_S390_TIMER
2049 s390 timer register
2050 .TP
2051 .B NT_S390_TODCMP
2052 s390 time-of-day (TOD) clock comparator register
2053 .TP
2054 .B NT_S390_TODPREG
2055 s390 time-of-day (TOD) programmable register
2056 .TP
2057 .B NT_S390_CTRS
2058 s390 control registers
2059 .TP
2060 .B NT_S390_PREFIX
2061 s390 prefix register
2062 .TP
2063 .B NT_S390_LAST_BREAK
2064 s390 breaking event address
2065 .TP
2066 .B NT_S390_SYSTEM_CALL
2067 s390 system call restart data
2068 .TP
2069 .B NT_S390_TDB
2070 s390 transaction diagnostic block
2071 .TP
2072 .B NT_ARM_VFP
2073 ARM VFP/NEON registers
2074 .TP
2075 .B NT_ARM_TLS
2076 ARM TLS register
2077 .TP
2078 .B NT_ARM_HW_BREAK
2079 ARM hardware breakpoint registers
2080 .TP
2081 .B NT_ARM_HW_WATCH
2082 ARM hardware watchpoint registers
2083 .TP
2084 .B NT_ARM_SYSTEM_CALL
2085 ARM system call number
2086 .PD
2087 .RE
2088 .TP
2089 .B n_name = GNU
2090 Extensions used by the GNU tool chain.
2091 .RS
2092 .TP
2093 .B NT_GNU_ABI_TAG
2094 Operating system (OS) ABI information.
2095 The desc field will be 4 words:
2096 .IP
2097 .PD 0
2098 .RS
2099 .IP [0] 5
2100 OS descriptor
2101 (\fBELF_NOTE_OS_LINUX\fR, \fBELF_NOTE_OS_GNU\fR, and so on)`
2102 .IP [1]
2103 major version of the ABI
2104 .IP [2]
2105 minor version of the ABI
2106 .IP [3]
2107 subminor version of the ABI
2108 .RE
2109 .PD
2110 .TP
2111 .B NT_GNU_HWCAP
2112 Synthetic hwcap information.
2113 The desc field begins with two words:
2114 .IP
2115 .PD 0
2116 .RS
2117 .IP [0] 5
2118 number of entries
2119 .IP [1]
2120 bit mask of enabled entries
2121 .RE
2122 .PD
2123 .IP
2124 Then follow variable-length entries, one byte followed by a null-terminated
2125 hwcap name string.
2126 The byte gives the bit number to test if enabled, (1U << bit) & bit mask.
2127 .TP
2128 .B NT_GNU_BUILD_ID
2129 Unique build ID as generated by the GNU
2130 .BR ld (1)
2131 .B \-\-build\-id
2132 option.
2133 The desc consists of any nonzero number of bytes.
2134 .TP
2135 .B NT_GNU_GOLD_VERSION
2136 The desc contains the GNU Gold linker version used.
2137 .RE
2138 .TP
2139 .B Default/unknown namespace (e_type != ET_CORE)
2140 These are used when the namespace is the default (i.e.,
2141 .I n_namesz
2142 will be set to 0), or a fallback when the namespace is unknown.
2143 .RS
2144 .TP 12
2145 .PD 0
2146 .B NT_VERSION
2147 A version string of some sort.
2148 .TP
2149 .B NT_ARCH
2150 Architecture information.
2151 .PD
2152 .RE
2153 .RE
2154 .SH NOTES
2155 .\" OpenBSD
2156 .\" ELF support first appeared in
2157 .\" OpenBSD 1.2,
2158 .\" although not all supported platforms use it as the native
2159 .\" binary file format.
2160 ELF first appeared in
2161 System V.
2162 The ELF format is an adopted standard.
2163 .P
2164 The extensions for
2165 .IR e_phnum ,
2166 .IR e_shnum ,
2167 and
2168 .I e_shstrndx
2169 respectively are
2170 Linux extensions.
2171 Sun, BSD, and AMD64 also support them; for further information,
2172 look under SEE ALSO.
2173 .\" .SH AUTHORS
2174 .\" The original version of this manual page was written by
2175 .\" .An Jeroen Ruigrok van der Werven
2176 .\" .Aq [email protected]
2177 .\" with inspiration from BSDi's
2178 .\" .Bsx
2179 .\" .Nm elf
2180 .\" man page.
2181 .SH SEE ALSO
2182 .BR as (1),
2183 .BR elfedit (1),
2184 .BR gdb (1),
2185 .BR ld (1),
2186 .BR nm (1),
2187 .BR objcopy (1),
2188 .BR objdump (1),
2189 .BR patchelf (1),
2190 .BR readelf (1),
2191 .BR size (1),
2192 .BR strings (1),
2193 .BR strip (1),
2194 .BR execve (2),
2195 .BR dl_iterate_phdr (3),
2196 .BR core (5),
2197 .BR ld.so (8)
2198 .P
2199 Hewlett-Packard,
2200 .IR "Elf-64 Object File Format" .
2201 .P
2202 Santa Cruz Operation,
2203 .IR "System V Application Binary Interface" .
2204 .P
2205 UNIX System Laboratories,
2206 "Object Files",
2207 .IR "Executable and Linking Format (ELF)" .
2208 .P
2209 Sun Microsystems,
2210 .IR "Linker and Libraries Guide" .
2211 .P
2212 AMD64 ABI Draft,
2213 .IR "System V Application Binary Interface AMD64 Architecture Processor Supplement" .