OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[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 .TP
797 .BR PT_GNU_STACK
798 GNU extension which is used by the Linux kernel to control the state of the
799 stack via the flags set in the
800 .IR p_flags
801 member.
802 .\" .El
803 .RE
804 .TP
805 .IR p_offset
806 This member holds the offset from the beginning of the file at which
807 the first byte of the segment resides.
808 .TP
809 .IR p_vaddr
810 This member holds the virtual address at which the first byte of the
811 segment resides in memory.
812 .TP
813 .IR p_paddr
814 On systems for which physical addressing is relevant, this member is
815 reserved for the segment's physical address.
816 Under
817 BSD
818 this member is
819 not used and must be zero.
820 .TP
821 .IR p_filesz
822 This member holds the number of bytes in the file image of the segment.
823 It may be zero.
824 .TP
825 .IR p_memsz
826 This member holds the number of bytes in the memory image of the segment.
827 It may be zero.
828 .TP
829 .IR p_flags
830 This member holds a bitmask of flags relevant to the segment:
831 .\" .Bl -tag -width "PF_X" -compact
832 .RS 12
833 .TP
834 .PD 0
835 .BR PF_X
836 An executable segment.
837 .TP
838 .BR PF_W
839 A writable segment.
840 .TP
841 .BR PF_R
842 A readable segment.
843 .PD
844 .RE
845 .\" .El
846 .IP
847 A text segment commonly has the flags
848 .BR PF_X
849 and
850 .BR PF_R .
851 A data segment commonly has
852 .BR PF_X ,
853 .BR PF_W
854 and
855 .BR PF_R .
856 .TP
857 .IR p_align
858 This member holds the value to which the segments are aligned in memory
859 and in the file.
860 Loadable process segments must have congruent values for
861 .IR p_vaddr
862 and
863 .IR p_offset ,
864 modulo the page size.
865 Values of zero and one mean no alignment is required.
866 Otherwise,
867 .IR p_align
868 should be a positive, integral power of two, and
869 .IR p_vaddr
870 should equal
871 .IR p_offset ,
872 modulo
873 .IR p_align .
874 .\" .El
875 .PP
876 A file's section header table lets one locate all the file's sections.
877 The
878 section header table is an array of
879 .I Elf32_Shdr
880 or
881 .I Elf64_Shdr
882 structures.
883 The
884 ELF header's
885 .IR e_shoff
886 member gives the byte offset from the beginning of the file to the section
887 header table.
888 .IR e_shnum
889 holds the number of entries the section header table contains.
890 .IR e_shentsize
891 holds the size in bytes of each entry.
892 .PP
893 A section header table index is a subscript into this array.
894 Some section
895 header table indices are reserved:
896 the initial entry and the indices between
897 .B SHN_LORESERVE
898 and
899 .BR SHN_HIRESERVE .
900 The initial entry is used in ELF extensions for
901 .IR e_phnum ,
902 .IR e_shnum
903 and
904 .IR e_strndx ;
905 in other cases, each field in the initial entry is set to zero.
906 An object file does not have sections for
907 these special indices:
908 .\" .Bl -tag -width "SHN_LORESERVE"
909 .RS
910 .TP 14
911 .BR SHN_UNDEF
912 This value marks an undefined, missing, irrelevant or otherwise meaningless
913 section reference.
914 .TP
915 .BR SHN_LORESERVE
916 This value specifies the lower bound of the range of reserved indices.
917 .TP
918 .BR SHN_LOPROC
919 Values greater than or equal to
920 .BR SHN_HIPROC
921 are reserved for processor-specific semantics.
922 .TP
923 .BR SHN_HIPROC
924 Values less than or equal to
925 .BR SHN_LOPROC
926 are reserved for processor-specific semantics.
927 .TP
928 .BR SHN_ABS
929 This value specifies the absolute value for the corresponding reference.
930 For
931 example, a symbol defined relative to section number
932 .BR SHN_ABS
933 has an absolute value and is not affected by relocation.
934 .TP
935 .BR SHN_COMMON
936 Symbols defined relative to this section are common symbols, such as FORTRAN
937 COMMON or unallocated C external variables.
938 .TP
939 .BR SHN_HIRESERVE
940 This value specifies the upper bound of the range of reserved indices.
941 The
942 system reserves indices between
943 .BR SHN_LORESERVE
944 and
945 .BR SHN_HIRESERVE ,
946 inclusive.
947 The section header table does not contain entries for the
948 reserved indices.
949 .RE
950 .\" .El
951 .PP
952 The section header has the following structure:
953 .in +4n
954 .nf
955
956 typedef struct {
957     uint32_t   sh_name;
958     uint32_t   sh_type;
959     uint32_t   sh_flags;
960     Elf32_Addr sh_addr;
961     Elf32_Off  sh_offset;
962     uint32_t   sh_size;
963     uint32_t   sh_link;
964     uint32_t   sh_info;
965     uint32_t   sh_addralign;
966     uint32_t   sh_entsize;
967 } Elf32_Shdr;
968 .fi
969 .in
970 .in +4n
971 .nf
972
973 typedef struct {
974     uint32_t   sh_name;
975     uint32_t   sh_type;
976     uint64_t   sh_flags;
977     Elf64_Addr sh_addr;
978     Elf64_Off  sh_offset;
979     uint64_t   sh_size;
980     uint32_t   sh_link;
981     uint32_t   sh_info;
982     uint64_t   sh_addralign;
983     uint64_t   sh_entsize;
984 } Elf64_Shdr;
985 .fi
986 .in
987 .PP
988 No real differences exist between the 32-bit and 64-bit section headers.
989 .\" .Bl -tag -width "sh_addralign"
990 .TP 10
991 .IR sh_name
992 This member specifies the name of the section.
993 Its value is an index
994 into the section header string table section, giving the location of
995 a null-terminated string.
996 .TP
997 .IR sh_type
998 This member categorizes the section's contents and semantics.
999 .\" .Bl -tag -width "SHT_PROGBITS"
1000 .RS 10
1001 .TP 15
1002 .BR SHT_NULL
1003 This value marks the section header as inactive.
1004 It does not
1005 have an associated section.
1006 Other members of the section header
1007 have undefined values.
1008 .TP
1009 .BR SHT_PROGBITS
1010 This section holds information defined by the program, whose
1011 format and meaning are determined solely by the program.
1012 .TP
1013 .BR SHT_SYMTAB
1014 This section holds a symbol table.
1015 Typically,
1016 .BR SHT_SYMTAB
1017 provides symbols for link editing, though it may also be used
1018 for dynamic linking.
1019 As a complete symbol table, it may contain
1020 many symbols unnecessary for dynamic linking.
1021 An object file can
1022 also contain a
1023 .BR SHT_DYNSYM
1024 section.
1025 .TP
1026 .BR SHT_STRTAB
1027 This section holds a string table.
1028 An object file may have multiple
1029 string table sections.
1030 .TP
1031 .BR SHT_RELA
1032 This section holds relocation entries with explicit addends, such
1033 as type
1034 .IR Elf32_Rela
1035 for the 32-bit class of object files.
1036 An object may have multiple
1037 relocation sections.
1038 .TP
1039 .BR SHT_HASH
1040 This section holds a symbol hash table.
1041 An object participating in
1042 dynamic linking must contain a symbol hash table.
1043 An object file may
1044 have only one hash table.
1045 .TP
1046 .BR SHT_DYNAMIC
1047 This section holds information for dynamic linking.
1048 An object file may
1049 have only one dynamic section.
1050 .TP
1051 .BR SHT_NOTE
1052 This section holds information that marks the file in some way.
1053 .TP
1054 .BR SHT_NOBITS
1055 A section of this type occupies no space in the file but otherwise
1056 resembles
1057 .BR SHT_PROGBITS .
1058 Although this section contains no bytes, the
1059 .IR sh_offset
1060 member contains the conceptual file offset.
1061 .TP
1062 .BR SHT_REL
1063 This section holds relocation offsets without explicit addends, such
1064 as type
1065 .IR Elf32_Rel
1066 for the 32-bit class of object files.
1067 An object file may have multiple
1068 relocation sections.
1069 .TP
1070 .BR SHT_SHLIB
1071 This section is reserved but has unspecified semantics.
1072 .TP
1073 .BR SHT_DYNSYM
1074 This section holds a minimal set of dynamic linking symbols.
1075 An
1076 object file can also contain a
1077 .BR SHT_SYMTAB
1078 section.
1079 .TP
1080 .BR SHT_LOPROC
1081 This value up to and including
1082 .BR SHT_HIPROC
1083 is reserved for processor-specific semantics.
1084 .TP
1085 .BR SHT_HIPROC
1086 This value down to and including
1087 .BR SHT_LOPROC
1088 is reserved for processor-specific semantics.
1089 .TP
1090 .BR SHT_LOUSER
1091 This value specifies the lower bound of the range of indices reserved for
1092 application programs.
1093 .TP
1094 .BR SHT_HIUSER
1095 This value specifies the upper bound of the range of indices reserved for
1096 application programs.
1097 Section types between
1098 .BR SHT_LOUSER
1099 and
1100 .BR SHT_HIUSER
1101 may be used by the application, without conflicting with current or future
1102 system-defined section types.
1103 .\" .El
1104 .RE
1105 .TP
1106 .IR sh_flags
1107 Sections support one-bit flags that describe miscellaneous attributes.
1108 If a flag bit is set in
1109 .IR sh_flags ,
1110 the attribute is
1111 "on"
1112 for the section.
1113 Otherwise, the attribute is
1114 "off"
1115 or does not apply.
1116 Undefined attributes are set to zero.
1117 .\" .Bl -tag -width "SHF_EXECINSTR" -compact
1118 .RS 10
1119 .TP 15
1120 .BR SHF_WRITE
1121 This section contains data that should be writable during process
1122 execution.
1123 .TP
1124 .BR SHF_ALLOC
1125 This section occupies memory during process execution.
1126 Some control
1127 sections do not reside in the memory image of an object file.
1128 This
1129 attribute is off for those sections.
1130 .TP
1131 .BR SHF_EXECINSTR
1132 This section contains executable machine instructions.
1133 .TP
1134 .BR SHF_MASKPROC
1135 All bits included in this mask are reserved for processor-specific
1136 semantics.
1137 .RE
1138 .\" .El
1139 .TP
1140 .IR sh_addr
1141 If this section appears in the memory image of a process, this member
1142 holds the address at which the section's first byte should reside.
1143 Otherwise, the member contains zero.
1144 .TP
1145 .IR sh_offset
1146 This member's value holds the byte offset from the beginning of the file
1147 to the first byte in the section.
1148 One section type,
1149 .BR SHT_NOBITS ,
1150 occupies no space in the file, and its
1151 .IR sh_offset
1152 member locates the conceptual placement in the file.
1153 .TP
1154 .IR sh_size
1155 This member holds the section's size in bytes.
1156 Unless the section type
1157 is
1158 .BR SHT_NOBITS ,
1159 the section occupies
1160 .IR sh_size
1161 bytes in the file.
1162 A section of type
1163 .BR SHT_NOBITS
1164 may have a nonzero size, but it occupies no space in the file.
1165 .TP
1166 .IR sh_link
1167 This member holds a section header table index link, whose interpretation
1168 depends on the section type.
1169 .TP
1170 .IR sh_info
1171 This member holds extra information, whose interpretation depends on the
1172 section type.
1173 .TP
1174 .IR sh_addralign
1175 Some sections have address alignment constraints.
1176 If a section holds a
1177 doubleword, the system must ensure doubleword alignment for the entire
1178 section.
1179 That is, the value of
1180 .IR sh_addr
1181 must be congruent to zero, modulo the value of
1182 .IR sh_addralign .
1183 Only zero and positive integral powers of two are allowed.
1184 Values of zero
1185 or one mean the section has no alignment constraints.
1186 .TP
1187 .IR sh_entsize
1188 Some sections hold a table of fixed-sized entries, such as a symbol table.
1189 For such a section, this member gives the size in bytes for each entry.
1190 This member contains zero if the section does not hold a table of
1191 fixed-size entries.
1192 .\" .El
1193 .PP
1194 Various sections hold program and control information:
1195 .\" .Bl -tag -width ".shstrtab"
1196 .TP 10
1197 .IR .bss
1198 This section holds uninitialized data that contributes to the program's
1199 memory image.
1200 By definition, the system initializes the data with zeros
1201 when the program begins to run.
1202 This section is of type
1203 .BR SHT_NOBITS .
1204 The attribute types are
1205 .BR SHF_ALLOC
1206 and
1207 .BR SHF_WRITE .
1208 .TP
1209 .IR .comment
1210 This section holds version control information.
1211 This section is of type
1212 .BR SHT_PROGBITS .
1213 No attribute types are used.
1214 .TP
1215 .IR .ctors
1216 This section holds initialized pointers to the C++ constructor functions.
1217 This section is of type
1218 .BR SHT_PROGBITS .
1219 The attribute types are
1220 .BR SHF_ALLOC
1221 and
1222 .BR SHF_WRITE .
1223 .TP
1224 .IR .data
1225 This section holds initialized data that contribute to the program's
1226 memory image.
1227 This section is of type
1228 .BR SHT_PROGBITS .
1229 The attribute types are
1230 .BR SHF_ALLOC
1231 and
1232 .BR SHF_WRITE .
1233 .TP
1234 .IR .data1
1235 This section holds initialized data that contribute to the program's
1236 memory image.
1237 This section is of type
1238 .BR SHT_PROGBITS .
1239 The attribute types are
1240 .BR SHF_ALLOC
1241 and
1242 .BR SHF_WRITE .
1243 .TP
1244 .IR .debug
1245 This section holds information for symbolic debugging.
1246 The contents
1247 are unspecified.
1248 This section is of type
1249 .BR SHT_PROGBITS .
1250 No attribute types are used.
1251 .TP
1252 .IR .dtors
1253 This section holds initialized pointers to the C++ destructor functions.
1254 This section is of type
1255 .BR SHT_PROGBITS .
1256 The attribute types are
1257 .BR SHF_ALLOC
1258 and
1259 .BR SHF_WRITE .
1260 .TP
1261 .IR .dynamic
1262 This section holds dynamic linking information.
1263 The section's attributes
1264 will include the
1265 .BR SHF_ALLOC
1266 bit.
1267 Whether the
1268 .BR SHF_WRITE
1269 bit is set is processor-specific.
1270 This section is of type
1271 .BR SHT_DYNAMIC .
1272 See the attributes above.
1273 .TP
1274 .IR .dynstr
1275 This section holds strings needed for dynamic linking, most commonly
1276 the strings that represent the names associated with symbol table entries.
1277 This section is of type
1278 .BR SHT_STRTAB .
1279 The attribute type used is
1280 .BR SHF_ALLOC .
1281 .TP
1282 .IR .dynsym
1283 This section holds the dynamic linking symbol table.
1284 This section is of type
1285 .BR SHT_DYNSYM .
1286 The attribute used is
1287 .BR SHF_ALLOC .
1288 .TP
1289 .IR .fini
1290 This section holds executable instructions that contribute to the process
1291 termination code.
1292 When a program exits normally the system arranges to
1293 execute the code in this section.
1294 This section is of type
1295 .BR SHT_PROGBITS .
1296 The attributes used are
1297 .BR SHF_ALLOC
1298 and
1299 .BR SHF_EXECINSTR .
1300 .TP
1301 .IR .gnu.version
1302 This section holds the version symbol table, an array of
1303 .I ElfN_Half
1304 elements.
1305 This section is of type
1306 .BR SHT_GNU_versym .
1307 The attribute type used is
1308 .BR SHF_ALLOC .
1309 .TP
1310 .IR .gnu.version_d
1311 This section holds the version symbol definitions, a table of
1312 .I ElfN_Verdef
1313 structures.
1314 This section is of type
1315 .BR SHT_GNU_verdef .
1316 The attribute type used is
1317 .BR SHF_ALLOC .
1318 .TP
1319 .IR .gnu.version_r
1320 This section holds the version symbol needed elements, a table of
1321 .I ElfN_Verneed
1322 structures.
1323 This section is of
1324 type
1325 .BR SHT_GNU_versym .
1326 The attribute type used is
1327 .BR SHF_ALLOC .
1328 .TP
1329 .IR .got
1330 This section holds the global offset table.
1331 This section is of type
1332 .BR SHT_PROGBITS .
1333 The attributes are processor specific.
1334 .TP
1335 .IR .hash
1336 This section holds a symbol hash table.
1337 This section is of type
1338 .BR SHT_HASH .
1339 The attribute used is
1340 .BR SHF_ALLOC .
1341 .TP
1342 .IR .init
1343 This section holds executable instructions that contribute to the process
1344 initialization code.
1345 When a program starts to run the system arranges to
1346 execute the code in this section before calling the main program entry point.
1347 This section is of type
1348 .BR SHT_PROGBITS .
1349 The attributes used are
1350 .BR SHF_ALLOC
1351 and
1352 .BR SHF_EXECINSTR .
1353 .TP
1354 .IR .interp
1355 This section holds the pathname of a program interpreter.
1356 If the file has
1357 a loadable segment that includes the section, the section's attributes will
1358 include the
1359 .BR SHF_ALLOC
1360 bit.
1361 Otherwise, that bit will be off.
1362 This section is of type
1363 .BR SHT_PROGBITS .
1364 .TP
1365 .IR .line
1366 This section holds line number information for symbolic debugging, which
1367 describes the correspondence between the program source and the machine code.
1368 The contents are unspecified.
1369 This section is of type
1370 .BR SHT_PROGBITS .
1371 No attribute types are used.
1372 .TP
1373 .IR .note
1374 This section holds information in the
1375 "Note Section"
1376 format.
1377 This section is of type
1378 .BR SHT_NOTE .
1379 No attribute types are used.
1380 OpenBSD
1381 native executables usually contain a
1382 .I .note.openbsd.ident
1383 section to identify themselves, for the kernel to bypass any compatibility
1384 ELF binary emulation tests when loading the file.
1385 .TP
1386 .IR .note.GNU-stack
1387 This section is used in Linux object files for declaring stack attributes.
1388 This section is of type
1389 .BR SHT_PROGBITS .
1390 The only attribute used is
1391 .BR SHF_EXECINSTR .
1392 This indicates to the GNU linker that the object file requires an
1393 executable stack.
1394 .TP
1395 .IR .plt
1396 This section holds the procedure linkage table.
1397 This section is of type
1398 .BR SHT_PROGBITS .
1399 The attributes are processor specific.
1400 .TP
1401 .IR .relNAME
1402 This section holds relocation information as described below.
1403 If the file
1404 has a loadable segment that includes relocation, the section's attributes
1405 will include the
1406 .BR SHF_ALLOC
1407 bit.
1408 Otherwise the bit will be off.
1409 By convention,
1410 "NAME"
1411 is supplied by the section to which the relocations apply.
1412 Thus a relocation
1413 section for
1414 .BR .text
1415 normally would have the name
1416 .BR .rel.text .
1417 This section is of type
1418 .BR SHT_REL .
1419 .TP
1420 .IR .relaNAME
1421 This section holds relocation information as described below.
1422 If the file
1423 has a loadable segment that includes relocation, the section's attributes
1424 will include the
1425 .BR SHF_ALLOC
1426 bit.
1427 Otherwise the bit will be off.
1428 By convention,
1429 "NAME"
1430 is supplied by the section to which the relocations apply.
1431 Thus a relocation
1432 section for
1433 .BR .text
1434 normally would have the name
1435 .BR .rela.text .
1436 This section is of type
1437 .BR SHT_RELA .
1438 .TP
1439 .IR .rodata
1440 This section holds read-only data that typically contributes to a
1441 nonwritable segment in the process image.
1442 This section is of type
1443 .BR SHT_PROGBITS .
1444 The attribute used is
1445 .BR SHF_ALLOC .
1446 .TP
1447 .IR .rodata1
1448 This section holds read-only data that typically contributes to a
1449 nonwritable segment in the process image.
1450 This section is of type
1451 .BR SHT_PROGBITS .
1452 The attribute used is
1453 .BR SHF_ALLOC .
1454 .TP
1455 .IR .shstrtab
1456 This section holds section names.
1457 This section is of type
1458 .BR SHT_STRTAB .
1459 No attribute types are used.
1460 .TP
1461 .IR .strtab
1462 This section holds strings, most commonly the strings that represent the
1463 names associated with symbol table entries.
1464 If the file has a loadable
1465 segment that includes the symbol string table, the section's attributes
1466 will include the
1467 .BR SHF_ALLOC
1468 bit.
1469 Otherwise the bit will be off.
1470 This section is of type
1471 .BR SHT_STRTAB .
1472 .TP
1473 .IR .symtab
1474 This section holds a symbol table.
1475 If the file has a loadable segment
1476 that includes the symbol table, the section's attributes will include
1477 the
1478 .BR SHF_ALLOC
1479 bit.
1480 Otherwise the bit will be off.
1481 This section is of type
1482 .BR SHT_SYMTAB .
1483 .TP
1484 .IR .text
1485 This section holds the
1486 "text",
1487 or executable instructions, of a program.
1488 This section is of type
1489 .BR SHT_PROGBITS .
1490 The attributes used are
1491 .BR SHF_ALLOC
1492 and
1493 .BR SHF_EXECINSTR .
1494 .\" .El
1495 .PP
1496 String table sections hold null-terminated character sequences, commonly
1497 called strings.
1498 The object file uses these strings to represent symbol
1499 and section names.
1500 One references a string as an index into the string
1501 table section.
1502 The first byte, which is index zero, is defined to hold
1503 a null byte (\(aq\\0\(aq).
1504 Similarly, a string table's last byte is defined to
1505 hold a null byte, ensuring null termination for all strings.
1506 .PP
1507 An object file's symbol table holds information needed to locate and
1508 relocate a program's symbolic definitions and references.
1509 A symbol table
1510 index is a subscript into this array.
1511 .in +4n
1512 .nf
1513
1514 typedef struct {
1515     uint32_t      st_name;
1516     Elf32_Addr    st_value;
1517     uint32_t      st_size;
1518     unsigned char st_info;
1519     unsigned char st_other;
1520     uint16_t      st_shndx;
1521 } Elf32_Sym;
1522 .fi
1523 .in
1524 .in +4n
1525 .nf
1526
1527 typedef struct {
1528     uint32_t      st_name;
1529     unsigned char st_info;
1530     unsigned char st_other;
1531     uint16_t      st_shndx;
1532     Elf64_Addr    st_value;
1533     uint64_t      st_size;
1534 } Elf64_Sym;
1535 .fi
1536 .in
1537 .PP
1538 The 32-bit and 64-bit versions have the same members, just in a different
1539 order.
1540 .\" .Bl -tag -width "st_value"
1541 .TP 10
1542 .IR st_name
1543 This member holds an index into the object file's symbol string table,
1544 which holds character representations of the symbol names.
1545 If the value
1546 is nonzero, it represents a string table index that gives the symbol
1547 name.
1548 Otherwise, the symbol table has no name.
1549 .TP
1550 .IR st_value
1551 This member gives the value of the associated symbol.
1552 .TP
1553 .IR st_size
1554 Many symbols have associated sizes.
1555 This member holds zero if the symbol
1556 has no size or an unknown size.
1557 .TP
1558 .IR st_info
1559 This member specifies the symbol's type and binding attributes:
1560 .\" .Bl -tag -width "STT_SECTION"
1561 .RS 10
1562 .TP 12
1563 .BR STT_NOTYPE
1564 The symbol's type is not defined.
1565 .TP
1566 .BR STT_OBJECT
1567 The symbol is associated with a data object.
1568 .TP
1569 .BR STT_FUNC
1570 The symbol is associated with a function or other executable code.
1571 .TP
1572 .BR STT_SECTION
1573 The symbol is associated with a section.
1574 Symbol table entries of
1575 this type exist primarily for relocation and normally have
1576 .BR STB_LOCAL
1577 bindings.
1578 .TP
1579 .BR STT_FILE
1580 By convention, the symbol's name gives the name of the source file
1581 associated with the object file.
1582 A file symbol has
1583 .BR STB_LOCAL
1584 bindings, its section index is
1585 .BR SHN_ABS ,
1586 and it precedes the other
1587 .BR STB_LOCAL
1588 symbols of the file, if it is present.
1589 .TP
1590 .BR STT_LOPROC
1591 This value up to and including
1592 .BR STT_HIPROC
1593 is reserved for processor-specific semantics.
1594 .TP
1595 .BR STT_HIPROC
1596 This value down to and including
1597 .BR STT_LOPROC
1598 is reserved for processor-specific semantics.
1599 .\" .El
1600 .\" .Bl -tag -width "STB_GLOBAL"
1601 .TP
1602 .BR STB_LOCAL
1603 Local symbols are not visible outside the object file containing their
1604 definition.
1605 Local symbols of the same name may exist in multiple files
1606 without interfering with each other.
1607 .TP
1608 .BR STB_GLOBAL
1609 Global symbols are visible to all object files being combined.
1610 One file's
1611 definition of a global symbol will satisfy another file's undefined
1612 reference to the same symbol.
1613 .TP
1614 .BR STB_WEAK
1615 Weak symbols resemble global symbols, but their definitions have lower
1616 precedence.
1617 .TP
1618 .BR STB_LOPROC
1619 This value up to and including
1620 .BR STB_HIPROC
1621 is reserved for processor-specific semantics.
1622 .TP
1623 .BR STB_HIPROC
1624 This value down to and including
1625 .BR STB_LOPROC
1626 is reserved for processor-specific semantics.
1627 .IP
1628 There are macros for packing and unpacking the binding and type fields:
1629 .IP
1630 .BR ELF32_ST_BIND (info)
1631 or
1632 .BR ELF64_ST_BIND (info)
1633 extract a binding from an
1634 .I st_info
1635 value.
1636 .IP
1637 .BR ELF32_ST_TYPE (info)
1638 or
1639 .BR ELF64_ST_TYPE (info)
1640 .br
1641 extract a type from an
1642 .I st_info
1643 value.
1644 .IP
1645 .BR ELF32_ST_INFO "(bind, type)"
1646 or
1647 .BR ELF64_ST_INFO "(bind, type)"
1648 .br
1649 convert a binding and a type into an
1650 .I st_info
1651 value.
1652 .RE
1653 .\" .El
1654 .TP
1655 .IR st_other
1656 This member defines the symbol visibility.
1657 .\" .Bl -tag -width "STV_PROTECTED"
1658 .RS 10
1659 .TP 16
1660 .PD 0
1661 .BR STV_DEFAULT
1662 Default symbol visibility rules.
1663 .TP
1664 .BR STV_INTERNAL
1665 Processor-specific hidden class.
1666 .TP
1667 .BR STV_HIDDEN
1668 Symbol is unavailable in other modules.
1669 .TP
1670 .BR STV_PROTECTED
1671 Not preemptible, not exported.
1672 .PD
1673 .PP
1674 There are macros for extracting the visibility type:
1675 .PP
1676 .BR ELF32_ST_VISIBILITY (other)
1677 or
1678 .BR ELF64_ST_VISIBILITY (other)
1679 .RE
1680 .\" .El
1681 .TP
1682 .IR st_shndx
1683 Every symbol table entry is
1684 "defined"
1685 in relation to some section.
1686 This member holds the relevant section
1687 header table index.
1688 .\" .El
1689 .PP
1690 Relocation is the process of connecting symbolic references with
1691 symbolic definitions.
1692 Relocatable files must have information that
1693 describes how to modify their section contents, thus allowing executable
1694 and shared object files to hold the right information for a process's
1695 program image.
1696 Relocation entries are these data.
1697 .PP
1698 Relocation structures that do not need an addend:
1699 .in +4n
1700 .nf
1701
1702 typedef struct {
1703     Elf32_Addr r_offset;
1704     uint32_t   r_info;
1705 } Elf32_Rel;
1706 .fi
1707 .in
1708 .in +4n
1709 .nf
1710
1711 typedef struct {
1712     Elf64_Addr r_offset;
1713     uint64_t   r_info;
1714 } Elf64_Rel;
1715 .fi
1716 .in
1717 .PP
1718 Relocation structures that need an addend:
1719 .in +4n
1720 .nf
1721
1722 typedef struct {
1723     Elf32_Addr r_offset;
1724     uint32_t   r_info;
1725     int32_t    r_addend;
1726 } Elf32_Rela;
1727 .fi
1728 .in
1729 .in +4n
1730 .nf
1731
1732 typedef struct {
1733     Elf64_Addr r_offset;
1734     uint64_t   r_info;
1735     int64_t    r_addend;
1736 } Elf64_Rela;
1737 .fi
1738 .in
1739 .\" .Bl -tag -width "r_offset"
1740 .TP 12
1741 .IR r_offset
1742 This member gives the location at which to apply the relocation action.
1743 For a relocatable file, the value is the byte offset from the beginning
1744 of the section to the storage unit affected by the relocation.
1745 For an
1746 executable file or shared object, the value is the virtual address of
1747 the storage unit affected by the relocation.
1748 .TP
1749 .IR r_info
1750 This member gives both the symbol table index with respect to which the
1751 relocation must be made and the type of relocation to apply.
1752 Relocation
1753 types are processor specific.
1754 When the text refers to a relocation
1755 entry's relocation type or symbol table index, it means the result of
1756 applying
1757 .BR ELF_[32|64]_R_TYPE
1758 or
1759 .BR ELF[32|64]_R_SYM ,
1760 respectively, to the entry's
1761 .IR r_info
1762 member.
1763 .TP
1764 .IR r_addend
1765 This member specifies a constant addend used to compute the value to be
1766 stored into the relocatable field.
1767 .\" .El
1768 .PP
1769 The .dynamic section contains a series of structures that hold relevant
1770 dynamic linking information.
1771 The d_tag member controls the interpretation
1772 of d_un.
1773 .in +4n
1774 .nf
1775
1776 typedef struct {
1777     Elf32_Sword    d_tag;
1778     union {
1779         Elf32_Word d_val;
1780         Elf32_Addr d_ptr;
1781     } d_un;
1782 } Elf32_Dyn;
1783 extern Elf32_Dyn _DYNAMIC[];
1784 .fi
1785 .in
1786 .in +4n
1787 .nf
1788
1789 typedef struct {
1790     Elf64_Sxword    d_tag;
1791     union {
1792         Elf64_Xword d_val;
1793         Elf64_Addr  d_ptr;
1794     } d_un;
1795 } Elf64_Dyn;
1796 extern Elf64_Dyn _DYNAMIC[];
1797 .fi
1798 .in
1799 .\" .Bl -tag -width "d_tag"
1800 .TP 10
1801 .IR d_tag
1802 This member may have any of the following values:
1803 .\" .Bl -tag -width "DT_SYMBOLIC"
1804 .RS 10
1805 .TP 12
1806 .BR DT_NULL
1807 Marks end of dynamic section
1808 .TP
1809 .BR DT_NEEDED
1810 String table offset to name of a needed library
1811 .TP
1812 .BR DT_PLTRELSZ
1813 Size in bytes of PLT relocs
1814 .TP
1815 .BR DT_PLTGOT
1816 Address of PLT and/or GOT
1817 .TP
1818 .BR DT_HASH
1819 Address of symbol hash table
1820 .TP
1821 .BR DT_STRTAB
1822 Address of string table
1823 .TP
1824 .BR DT_SYMTAB
1825 Address of symbol table
1826 .TP
1827 .BR DT_RELA
1828 Address of Rela relocs table
1829 .TP
1830 .BR DT_RELASZ
1831 Size in bytes of Rela table
1832 .TP
1833 .BR DT_RELAENT
1834 Size in bytes of a Rela table entry
1835 .TP
1836 .BR DT_STRSZ
1837 Size in bytes of string table
1838 .TP
1839 .BR DT_SYMENT
1840 Size in bytes of a symbol table entry
1841 .TP
1842 .BR DT_INIT
1843 Address of the initialization function
1844 .TP
1845 .BR DT_FINI
1846 Address of the termination function
1847 .TP
1848 .BR DT_SONAME
1849 String table offset to name of shared object
1850 .TP
1851 .BR DT_RPATH
1852 String table offset to library search path (deprecated)
1853 .TP
1854 .BR DT_SYMBOLIC
1855 Alert linker to search this shared object before the executable for symbols
1856 .TP
1857 .BR DT_REL
1858 Address of Rel relocs table
1859 .TP
1860 .BR DT_RELSZ
1861 Size in bytes of Rel table
1862 .TP
1863 .BR DT_RELENT
1864 Size in bytes of a Rel table entry
1865 .TP
1866 .BR DT_PLTREL
1867 Type of reloc the PLT refers (Rela or Rel)
1868 .TP
1869 .BR DT_DEBUG
1870 Undefined use for debugging
1871 .TP
1872 .BR DT_TEXTREL
1873 Absence of this indicates no relocs should apply to a nonwritable segment
1874 .TP
1875 .BR DT_JMPREL
1876 Address of reloc entries solely for the PLT
1877 .TP
1878 .BR DT_BIND_NOW
1879 Instruct dynamic linker to process all relocs before transferring control to
1880 the executable
1881 .TP
1882 .BR DT_RUNPATH
1883 String table offset to library search path
1884 .TP
1885 .BR DT_LOPROC
1886 Start of processor-specific semantics
1887 .TP
1888 .BR DT_HIPROC
1889 End of processor-specific semantics
1890 .RE
1891 .\" .El
1892 .TP
1893 .IR d_val
1894 This member represents integer values with various interpretations.
1895 .TP
1896 .IR d_ptr
1897 This member represents program virtual addresses.
1898 When interpreting
1899 these addresses, the actual address should be computed based on the
1900 original file value and memory base address.
1901 Files do not contain
1902 relocation entries to fixup these addresses.
1903 .TP
1904 .I _DYNAMIC
1905 Array containing all the dynamic structures in the .dynamic section.
1906 This is automatically populated by the linker.
1907 .\" .El
1908 .SH NOTES
1909 .\" OpenBSD
1910 .\" ELF support first appeared in
1911 .\" OpenBSD 1.2,
1912 .\" although not all supported platforms use it as the native
1913 .\" binary file format.
1914 ELF first appeared in
1915 System V.
1916 The ELF format is an adopted standard.
1917 .PP
1918 The extensions for
1919 .IR e_phnum ,
1920 .IR e_shnum
1921 and
1922 .IR e_strndx
1923 respectively are
1924 Linux extensions.
1925 Sun, BSD and AMD64 also support them; for further information,
1926 look under SEE ALSO.
1927 .\" .SH AUTHORS
1928 .\" The original version of this manual page was written by
1929 .\" .An Jeroen Ruigrok van der Werven
1930 .\" .Aq asmodai@FreeBSD.org
1931 .\" with inspiration from BSDi's
1932 .\" .Bsx
1933 .\" .Nm elf
1934 .\" man page.
1935 .SH SEE ALSO
1936 .BR as (1),
1937 .BR gdb (1),
1938 .BR ld (1),
1939 .BR objdump (1),
1940 .BR execve (2),
1941 .BR core (5)
1942 .PP
1943 Hewlett-Packard,
1944 .IR "Elf-64 Object File Format" .
1945 .PP
1946 Santa Cruz Operation,
1947 .IR "System V Application Binary Interface" .
1948 .PP
1949 UNIX System Laboratories,
1950 "Object Files",
1951 .IR "Executable and Linking Format (ELF)" .
1952 .PP
1953 Sun Microsystems,
1954 .IR "Linker and Libraries Guide" .
1955 .PP
1956 AMD64 ABI Draft,
1957 .IR "System V Application Binary Interface AMD64 Architecture Processor Supplement" .
1958 .PP