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