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