OSDN Git Service

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