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