OSDN Git Service

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