xref: /freebsd/share/man/man5/elf.5 (revision ffc4f93e960d38b6f70d59409127f7562e40f916)
1ea14e5c3SBrian Feldman.\" Copyright (c) 1999 Jeroen Ruigrok van der Werven
2ea14e5c3SBrian Feldman.\" All rights reserved.
3ea14e5c3SBrian Feldman.\"
4ea14e5c3SBrian Feldman.\" Redistribution and use in source and binary forms, with or without
5ea14e5c3SBrian Feldman.\" modification, are permitted provided that the following conditions
6ea14e5c3SBrian Feldman.\" are met:
7ea14e5c3SBrian Feldman.\" 1. Redistributions of source code must retain the above copyright
8ea14e5c3SBrian Feldman.\"    notice, this list of conditions and the following disclaimer.
9ea14e5c3SBrian Feldman.\" 2. Redistributions in binary form must reproduce the above copyright
10ea14e5c3SBrian Feldman.\"    notice, this list of conditions and the following disclaimer in the
11ea14e5c3SBrian Feldman.\"    documentation and/or other materials provided with the distribution.
12ea14e5c3SBrian Feldman.\"
13ea14e5c3SBrian Feldman.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14ea14e5c3SBrian Feldman.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15ea14e5c3SBrian Feldman.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16ea14e5c3SBrian Feldman.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17ea14e5c3SBrian Feldman.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18ea14e5c3SBrian Feldman.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19ea14e5c3SBrian Feldman.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20ea14e5c3SBrian Feldman.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21ea14e5c3SBrian Feldman.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22ea14e5c3SBrian Feldman.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23ea14e5c3SBrian Feldman.\" SUCH DAMAGE.
24ea14e5c3SBrian Feldman.\"
2505b6744cSEd Maste.Dd July 25, 2022
26ea14e5c3SBrian Feldman.Dt ELF 5
273d45e180SRuslan Ermilov.Os
28ea14e5c3SBrian Feldman.Sh NAME
29ea14e5c3SBrian Feldman.Nm elf
30ea14e5c3SBrian Feldman.Nd format of ELF executable binary files
31ea14e5c3SBrian Feldman.Sh SYNOPSIS
3232eef9aeSRuslan Ermilov.In elf.h
33ea14e5c3SBrian Feldman.Sh DESCRIPTION
34ea14e5c3SBrian FeldmanThe header file
35fe08efe6SRuslan Ermilov.In elf.h
364e86fcacSSheldon Hearndefines the format of ELF executable binary files.
374e86fcacSSheldon HearnAmongst these files are
38ea14e5c3SBrian Feldmannormal executable files, relocatable object files, core files and shared
39ea14e5c3SBrian Feldmanlibraries.
40ea14e5c3SBrian Feldman.Pp
41ea14e5c3SBrian FeldmanAn executable file using the ELF file format consists of an ELF header,
42ea14e5c3SBrian Feldmanfollowed by a program header table or a section header table, or both.
434e86fcacSSheldon HearnThe ELF header is always at offset zero of the file.
444e86fcacSSheldon HearnThe program header
45ea14e5c3SBrian Feldmantable and the section header table's offset in the file are defined in the
464e86fcacSSheldon HearnELF header.
474e86fcacSSheldon HearnThe two tables describe the rest of the particularities of
48ea14e5c3SBrian Feldmanthe file.
49ea14e5c3SBrian Feldman.Pp
50ea14e5c3SBrian FeldmanApplications which wish to process ELF binary files for their native
51ea14e5c3SBrian Feldmanarchitecture only should include
52743d5d51SRuslan Ermilov.In elf.h
534e86fcacSSheldon Hearnin their source code.
544e86fcacSSheldon HearnThese applications should need to refer to
55ea14e5c3SBrian Feldmanall the types and structures by their generic names
56ea14e5c3SBrian Feldman.Dq Elf_xxx
57ea14e5c3SBrian Feldmanand to the macros by
58ea14e5c3SBrian Feldman.Dq ELF_xxx .
59ea14e5c3SBrian FeldmanApplications written this way can be compiled on any architecture,
60ea14e5c3SBrian Feldmanregardless whether the host is 32-bit or 64-bit.
61ea14e5c3SBrian Feldman.Pp
62ea14e5c3SBrian FeldmanShould an application need to process ELF files of an unknown
63ea14e5c3SBrian Feldmanarchitecture then the application needs to include both
64743d5d51SRuslan Ermilov.In sys/elf32.h
65ea14e5c3SBrian Feldmanand
66743d5d51SRuslan Ermilov.In sys/elf64.h
67ea14e5c3SBrian Feldmaninstead of
68743d5d51SRuslan Ermilov.In elf.h .
69ea14e5c3SBrian FeldmanFurthermore, all types and structures need to be identified by either
70ea14e5c3SBrian Feldman.Dq Elf32_xxx
71ea14e5c3SBrian Feldmanor
72ea14e5c3SBrian Feldman.Dq Elf64_xxx .
73ea14e5c3SBrian FeldmanThe macros need to be identified by
74ea14e5c3SBrian Feldman.Dq ELF32_xxx
75ea14e5c3SBrian Feldmanor
76ea14e5c3SBrian Feldman.Dq ELF64_xxx .
77ea14e5c3SBrian Feldman.Pp
78ea14e5c3SBrian FeldmanWhatever the system's architecture is, it will always include
79743d5d51SRuslan Ermilov.In sys/elf_common.h
80ea14e5c3SBrian Feldmanas well as
81743d5d51SRuslan Ermilov.In sys/elf_generic.h .
82ea14e5c3SBrian Feldman.Pp
83ea14e5c3SBrian FeldmanThese header files describe the above mentioned headers as C structures
84ea14e5c3SBrian Feldmanand also include structures for dynamic sections, relocation sections and
85ea14e5c3SBrian Feldmansymbol tables.
86ea14e5c3SBrian Feldman.Pp
87ea14e5c3SBrian FeldmanThe following types are being used for 32-bit architectures:
88ea14e5c3SBrian Feldman.Bd -literal -offset indent
89757686b1SMarcel MoolenaarElf32_Addr	Unsigned 32-bit program address
90757686b1SMarcel MoolenaarElf32_Half	Unsigned 16-bit field
91fb59cdf6SJoseph KoshyElf32_Lword	Unsigned 64-bit field
92757686b1SMarcel MoolenaarElf32_Off	Unsigned 32-bit file offset
93757686b1SMarcel MoolenaarElf32_Sword	Signed 32-bit field or integer
94757686b1SMarcel MoolenaarElf32_Word	Unsigned 32-bit field or integer
95ea14e5c3SBrian Feldman.Ed
96ea14e5c3SBrian Feldman.Pp
97ea14e5c3SBrian FeldmanFor 64-bit architectures we have the following types:
98ea14e5c3SBrian Feldman.Bd -literal -offset indent
99757686b1SMarcel MoolenaarElf64_Addr	Unsigned 64-bit program address
100757686b1SMarcel MoolenaarElf64_Half	Unsigned 16-bit field
101fb59cdf6SJoseph KoshyElf64_Lword	Unsigned 64-bit field
102757686b1SMarcel MoolenaarElf64_Off	Unsigned 64-bit file offset
103757686b1SMarcel MoolenaarElf64_Sword	Signed 32-bit field
104757686b1SMarcel MoolenaarElf64_Sxword	Signed 64-bit field or integer
105fb59cdf6SJoseph KoshyElf64_Word	Unsigned 32-bit field
106757686b1SMarcel MoolenaarElf64_Xword	Unsigned 64-bit field or integer
107ea14e5c3SBrian Feldman.Ed
108ea14e5c3SBrian Feldman.Pp
109ea14e5c3SBrian FeldmanAll data structures that the file format defines follow the
110ea14e5c3SBrian Feldman.Dq natural
1114e86fcacSSheldon Hearnsize and alignment guidelines for the relevant class.
1124e86fcacSSheldon HearnIf necessary,
113ea14e5c3SBrian Feldmandata structures contain explicit padding to ensure 4-byte alignment
114ea14e5c3SBrian Feldmanfor 4-byte objects, to force structure sizes to a multiple of 4, etc.
115ea14e5c3SBrian Feldman.Pp
116ea14e5c3SBrian FeldmanThe ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
117ea14e5c3SBrian Feldman.Bd -literal -offset indent
118ea14e5c3SBrian Feldmantypedef struct {
119ea14e5c3SBrian Feldman        unsigned char   e_ident[EI_NIDENT];
120ea14e5c3SBrian Feldman        Elf32_Half      e_type;
121ea14e5c3SBrian Feldman        Elf32_Half      e_machine;
122ea14e5c3SBrian Feldman        Elf32_Word      e_version;
123ea14e5c3SBrian Feldman        Elf32_Addr      e_entry;
124ea14e5c3SBrian Feldman        Elf32_Off       e_phoff;
125ea14e5c3SBrian Feldman        Elf32_Off       e_shoff;
126ea14e5c3SBrian Feldman        Elf32_Word      e_flags;
127ea14e5c3SBrian Feldman        Elf32_Half      e_ehsize;
128ea14e5c3SBrian Feldman        Elf32_Half      e_phentsize;
129ea14e5c3SBrian Feldman        Elf32_Half      e_phnum;
130ea14e5c3SBrian Feldman        Elf32_Half      e_shentsize;
131ea14e5c3SBrian Feldman        Elf32_Half      e_shnum;
132ea14e5c3SBrian Feldman        Elf32_Half      e_shstrndx;
133ea14e5c3SBrian Feldman} Elf32_Ehdr;
134ea14e5c3SBrian Feldman.Ed
135ea14e5c3SBrian Feldman.Bd -literal -offset indent
136ea14e5c3SBrian Feldmantypedef struct {
137ea14e5c3SBrian Feldman	unsigned char   e_ident[EI_NIDENT];
138757686b1SMarcel Moolenaar	Elf64_Half      e_type;
139757686b1SMarcel Moolenaar	Elf64_Half      e_machine;
140757686b1SMarcel Moolenaar	Elf64_Word      e_version;
141ea14e5c3SBrian Feldman	Elf64_Addr      e_entry;
142ea14e5c3SBrian Feldman	Elf64_Off       e_phoff;
143ea14e5c3SBrian Feldman	Elf64_Off       e_shoff;
144757686b1SMarcel Moolenaar	Elf64_Word      e_flags;
145757686b1SMarcel Moolenaar	Elf64_Half      e_ehsize;
146757686b1SMarcel Moolenaar	Elf64_Half      e_phentsize;
147757686b1SMarcel Moolenaar	Elf64_Half      e_phnum;
148757686b1SMarcel Moolenaar	Elf64_Half      e_shentsize;
149757686b1SMarcel Moolenaar	Elf64_Half      e_shnum;
150757686b1SMarcel Moolenaar	Elf64_Half      e_shstrndx;
151ea14e5c3SBrian Feldman} Elf64_Ehdr;
152ea14e5c3SBrian Feldman.Ed
153ea14e5c3SBrian Feldman.Pp
154ea14e5c3SBrian FeldmanThe fields have the following meanings:
155ea14e5c3SBrian Feldman.Pp
156ea14e5c3SBrian Feldman.Bl -tag -width "e_phentsize" -compact -offset indent
157ea14e5c3SBrian Feldman.It Dv e_ident
158ea14e5c3SBrian FeldmanThis array of bytes specifies to interpret the file,
159ea14e5c3SBrian Feldmanindependent of the processor or the file's remaining contents.
160ea14e5c3SBrian FeldmanWithin this array everything is named by macros, which start with
161ea14e5c3SBrian Feldmanthe prefix
162ea14e5c3SBrian Feldman.Sy EI_
163ea14e5c3SBrian Feldmanand may contain values which start with the prefix
164ea14e5c3SBrian Feldman.Sy ELF .
165ea14e5c3SBrian FeldmanThe following macros are defined:
166ea14e5c3SBrian Feldman.Pp
1670d59faf6SJeroen Ruigrok van der Werven.Bl -tag -width "EI_ABIVERSION" -compact
168ea14e5c3SBrian Feldman.It Dv EI_MAG0
1694e86fcacSSheldon HearnThe first byte of the magic number.
1704e86fcacSSheldon HearnIt must be filled with
171ea14e5c3SBrian Feldman.Sy ELFMAG0 .
172ea14e5c3SBrian Feldman.It Dv EI_MAG1
1734e86fcacSSheldon HearnThe second byte of the magic number.
1744e86fcacSSheldon HearnIt must be filled with
175ea14e5c3SBrian Feldman.Sy ELFMAG1 .
176ea14e5c3SBrian Feldman.It Dv EI_MAG2
1774e86fcacSSheldon HearnThe third byte of the magic number.
1784e86fcacSSheldon HearnIt must be filled with
179ea14e5c3SBrian Feldman.Sy ELFMAG2 .
180ea14e5c3SBrian Feldman.It Dv EI_MAG3
1814e86fcacSSheldon HearnThe fourth byte of the magic number.
1824e86fcacSSheldon HearnIt must be filled with
183ea14e5c3SBrian Feldman.Sy ELFMAG3 .
184ea14e5c3SBrian Feldman.It Dv EI_CLASS
185ea14e5c3SBrian FeldmanThe fifth byte identifies the architecture for this binary:
186ea14e5c3SBrian Feldman.Pp
187ea14e5c3SBrian Feldman.Bl -tag -width "ELFCLASSNONE" -compact
188ea14e5c3SBrian Feldman.It Dv ELFCLASSNONE
189ea14e5c3SBrian FeldmanThis class is invalid.
190ea14e5c3SBrian Feldman.It Dv ELFCLASS32
1914e86fcacSSheldon HearnThis defines the 32-bit architecture.
1924e86fcacSSheldon HearnIt supports machines with files
193ea14e5c3SBrian Feldmanand virtual address spaces up to 4 Gigabytes.
194ea14e5c3SBrian Feldman.It Dv ELFCLASS64
195ea14e5c3SBrian FeldmanThis defines the 64-bit architecture.
196ea14e5c3SBrian Feldman.El
197ea14e5c3SBrian Feldman.It Dv EI_DATA
198ea14e5c3SBrian FeldmanThe sixth byte specifies the data encoding of the processor-specific
1994e86fcacSSheldon Hearndata in the file.
2004e86fcacSSheldon HearnCurrently these encodings are supported:
201ea14e5c3SBrian Feldman.Pp
202ea14e5c3SBrian Feldman.Bl -tag -width "ELFDATA2LSB" -compact
203ea14e5c3SBrian Feldman.It Dv ELFDATANONE
204ea14e5c3SBrian FeldmanUnknown data format.
205ea14e5c3SBrian Feldman.It Dv ELFDATA2LSB
206ea14e5c3SBrian FeldmanTwo's complement, little-endian.
207ea14e5c3SBrian Feldman.It Dv ELFDATA2MSB
208ea14e5c3SBrian FeldmanTwo's complement, big-endian.
209ea14e5c3SBrian Feldman.El
210ea14e5c3SBrian Feldman.It Dv EI_VERSION
211ea14e5c3SBrian FeldmanThe version number of the ELF specification:
212ea14e5c3SBrian Feldman.Pp
213ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact
214ea14e5c3SBrian Feldman.It Dv EV_NONE
215ea14e5c3SBrian FeldmanInvalid version.
216ea14e5c3SBrian Feldman.It Dv EV_CURRENT
217ea14e5c3SBrian FeldmanCurrent version.
218ea14e5c3SBrian Feldman.El
2190d59faf6SJeroen Ruigrok van der Werven.It Dv EI_OSABI
2200d59faf6SJeroen Ruigrok van der WervenThis byte identifies the operating system
2210d59faf6SJeroen Ruigrok van der Wervenand ABI to which the object is targeted.
2220d59faf6SJeroen Ruigrok van der WervenSome fields in other ELF structures have flags
2230d59faf6SJeroen Ruigrok van der Wervenand values that have platform specific meanings;
2240d59faf6SJeroen Ruigrok van der Werventhe interpretation of those fields is determined by the value of this byte.
2250d59faf6SJeroen Ruigrok van der WervenThe following values are currently defined:
2260d59faf6SJeroen Ruigrok van der Werven.Pp
2270d59faf6SJeroen Ruigrok van der Werven.Bl -tag -width "ELFOSABI_STANDALONE" -compact
2280d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_SYSV
2290d59faf6SJeroen Ruigrok van der WervenUNIX System V ABI.
2300d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_HPUX
2310d59faf6SJeroen Ruigrok van der WervenHP-UX operating system ABI.
2320d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_NETBSD
233d013e3f5SRuslan Ermilov.Nx
234d013e3f5SRuslan Ermilovoperating system ABI.
2350d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_LINUX
2360d59faf6SJeroen Ruigrok van der WervenGNU/Linux operating system ABI.
2370d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_HURD
2380d59faf6SJeroen Ruigrok van der WervenGNU/Hurd operating system ABI.
2390d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_86OPEN
2400d59faf6SJeroen Ruigrok van der Werven86Open Common IA32 ABI.
2410d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_SOLARIS
2420d59faf6SJeroen Ruigrok van der WervenSolaris operating system ABI.
2430d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_MONTEREY
2440d59faf6SJeroen Ruigrok van der WervenMonterey project ABI.
2450d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_IRIX
2460d59faf6SJeroen Ruigrok van der WervenIRIX operating system ABI.
2470d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_FREEBSD
248c5e7e03aSRuslan Ermilov.Fx
249c5e7e03aSRuslan Ermilovoperating system ABI.
2500d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_TRU64
2510d59faf6SJeroen Ruigrok van der WervenTRU64 UNIX operating system ABI.
2520d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_ARM
2530d59faf6SJeroen Ruigrok van der WervenARM architecture ABI.
2540d59faf6SJeroen Ruigrok van der Werven.It Dv ELFOSABI_STANDALONE
2550d59faf6SJeroen Ruigrok van der WervenStandalone (embedded) ABI.
2560d59faf6SJeroen Ruigrok van der Werven.El
2570d59faf6SJeroen Ruigrok van der Werven.It Dv EI_ABIVERSION
2580d59faf6SJeroen Ruigrok van der WervenThis byte identifies the version of the ABI
2590d59faf6SJeroen Ruigrok van der Wervento which the object is targeted.
2600d59faf6SJeroen Ruigrok van der WervenThis field is used to distinguish among incompatible versions of an ABI.
2610d59faf6SJeroen Ruigrok van der WervenThe interpretation of this version number
2620d59faf6SJeroen Ruigrok van der Wervenis dependent on the ABI identified by the EI_OSABI field.
2630d59faf6SJeroen Ruigrok van der WervenApplications conforming to this specification use the value 0.
264ea14e5c3SBrian Feldman.It Dv EI_PAD
2654e86fcacSSheldon HearnStart of padding.
2664e86fcacSSheldon HearnThese bytes are reserved and set to zero.
2674e86fcacSSheldon HearnPrograms
2684e86fcacSSheldon Hearnwhich read them should ignore them.
2694e86fcacSSheldon HearnThe value for EI_PAD will change in
270ea14e5c3SBrian Feldmanthe future if currently unused bytes are given meanings.
271ea14e5c3SBrian Feldman.It Dv EI_BRAND
272ea14e5c3SBrian FeldmanStart of architecture identification.
273ea14e5c3SBrian Feldman.It Dv EI_NIDENT
274ea14e5c3SBrian FeldmanThe size of the e_ident array.
275ea14e5c3SBrian Feldman.El
276ea14e5c3SBrian Feldman.Pp
277ea14e5c3SBrian Feldman.It Dv e_type
278ea14e5c3SBrian FeldmanThis member of the structure identifies the object file type:
279ea14e5c3SBrian Feldman.Pp
280ea14e5c3SBrian Feldman.Bl -tag -width "ET_NONE" -compact
281ea14e5c3SBrian Feldman.It Dv ET_NONE
282ea14e5c3SBrian FeldmanAn unknown type.
283ea14e5c3SBrian Feldman.It Dv ET_REL
284ea14e5c3SBrian FeldmanA relocatable file.
285ea14e5c3SBrian Feldman.It Dv ET_EXEC
286ea14e5c3SBrian FeldmanAn executable file.
287ea14e5c3SBrian Feldman.It Dv ET_DYN
288ea14e5c3SBrian FeldmanA shared object.
289ea14e5c3SBrian Feldman.It Dv ET_CORE
290ea14e5c3SBrian FeldmanA core file.
291ea14e5c3SBrian Feldman.El
292ea14e5c3SBrian Feldman.Pp
293ea14e5c3SBrian Feldman.It Dv e_machine
294ea14e5c3SBrian FeldmanThis member specifies the required architecture for an individual file:
295ea14e5c3SBrian Feldman.Pp
296ea14e5c3SBrian Feldman.Bl -tag -width "EM_MIPS_RS4_BE" -compact
297ea14e5c3SBrian Feldman.It Dv EM_NONE
298ea14e5c3SBrian FeldmanAn unknown machine.
299ea14e5c3SBrian Feldman.It Dv EM_M32
300ea14e5c3SBrian FeldmanAT&T WE 32100.
301ea14e5c3SBrian Feldman.It Dv EM_SPARC
302ea14e5c3SBrian FeldmanSun Microsystems SPARC.
303ea14e5c3SBrian Feldman.It Dv EM_386
304ea14e5c3SBrian FeldmanIntel 80386.
305ea14e5c3SBrian Feldman.It Dv EM_68K
306ea14e5c3SBrian FeldmanMotorola 68000.
307ea14e5c3SBrian Feldman.It Dv EM_88K
308ea14e5c3SBrian FeldmanMotorola 88000.
309ea14e5c3SBrian Feldman.It Dv EM_486
310ea14e5c3SBrian FeldmanIntel 80486.
311ea14e5c3SBrian Feldman.It Dv EM_860
312ea14e5c3SBrian FeldmanIntel 80860.
313ea14e5c3SBrian Feldman.It Dv EM_MIPS
314ea14e5c3SBrian FeldmanMIPS RS3000 (big-endian only).
315ea14e5c3SBrian Feldman.It Dv EM_MIPS_RS4_BE
316ea14e5c3SBrian FeldmanMIPS RS4000 (big-endian only).
317ea14e5c3SBrian Feldman.It Dv EM_SPARC64
318ea14e5c3SBrian FeldmanSPARC v9 64-bit unofficial.
319ea14e5c3SBrian Feldman.It Dv EM_PARISC
320ea14e5c3SBrian FeldmanHPPA.
321ea14e5c3SBrian Feldman.It Dv EM_PPC
322ea14e5c3SBrian FeldmanPowerPC.
323ea14e5c3SBrian Feldman.It Dv EM_ALPHA
324ea14e5c3SBrian FeldmanCompaq [DEC] Alpha.
325ea14e5c3SBrian Feldman.El
326ea14e5c3SBrian Feldman.Pp
327ea14e5c3SBrian Feldman.It Dv e_version
328ea14e5c3SBrian FeldmanThis member identifies the file version:
329ea14e5c3SBrian Feldman.Pp
330ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact
331ea14e5c3SBrian Feldman.It Dv EV_NONE
332ea14e5c3SBrian FeldmanInvalid version
333ea14e5c3SBrian Feldman.It Dv EV_CURRENT
334ea14e5c3SBrian FeldmanCurrent version
335ea14e5c3SBrian Feldman.El
336ea14e5c3SBrian Feldman.It Dv e_entry
337ea14e5c3SBrian FeldmanThis member gives the virtual address to which the system first transfers
3384e86fcacSSheldon Hearncontrol, thus starting the process.
3394e86fcacSSheldon HearnIf the file has no associated entry
340ea14e5c3SBrian Feldmanpoint, this member holds zero.
341ea14e5c3SBrian Feldman.It Dv e_phoff
3424e86fcacSSheldon HearnThis member holds the program header table's file offset in bytes.
3434e86fcacSSheldon HearnIf
344ea14e5c3SBrian Feldmanthe file has no program header table, this member holds zero.
345ea14e5c3SBrian Feldman.It Dv e_shoff
3464e86fcacSSheldon HearnThis member holds the section header table's file offset in bytes.
3474e86fcacSSheldon HearnIf the
348ea14e5c3SBrian Feldmanfile has no section header table this member holds zero.
349ea14e5c3SBrian Feldman.It Dv e_flags
3504e86fcacSSheldon HearnThis member holds processor-specific flags associated with the file.
3514e86fcacSSheldon HearnFlag
3525203edcdSRuslan Ermilovnames take the form EF_`machine_flag'.
3535203edcdSRuslan ErmilovCurrently no flags have been defined.
354ea14e5c3SBrian Feldman.It Dv e_ehsize
355ea14e5c3SBrian FeldmanThis member holds the ELF header's size in bytes.
356ea14e5c3SBrian Feldman.It Dv e_phentsize
357ea14e5c3SBrian FeldmanThis member holds the size in bytes of one entry in the file's program header
358ea14e5c3SBrian Feldmantable; all entries are the same size.
359ea14e5c3SBrian Feldman.It Dv e_phnum
360f3a2511aSChris CostelloThis member holds the number of entries in the program header
3614e86fcacSSheldon Hearntable.
362e0195199SJoseph KoshyIf the file is using extended program header numbering, then the
363ea14e5c3SBrian Feldman.Sy e_phnum
364e0195199SJoseph Koshymember will contain the value
365e0195199SJoseph Koshy.Dv PN_XNUM
366e0195199SJoseph Koshyand the actual number of program header table entries will be stored
367e0195199SJoseph Koshyin the
368e0195199SJoseph Koshy.Sy sh_info
369e0195199SJoseph Koshymember of the section header at index
370e0195199SJoseph Koshy.Dv SHN_UNDEF .
371e0195199SJoseph KoshyThe product of
372e0195199SJoseph Koshy.Sy e_phentsize
373e0195199SJoseph Koshyand the number of program header table entries gives the program
374e0195199SJoseph Koshyheader table's size in bytes.
3754e86fcacSSheldon HearnIf a file has no program header,
376ea14e5c3SBrian Feldman.Sy e_phnum
377ea14e5c3SBrian Feldmanholds the value zero.
378ea14e5c3SBrian Feldman.It Dv e_shentsize
3794e86fcacSSheldon HearnThis member holds a sections header's size in bytes.
3804e86fcacSSheldon HearnA section header is one
381ea14e5c3SBrian Feldmanentry in the section header table; all entries are the same size.
382ea14e5c3SBrian Feldman.It Dv e_shnum
3834e86fcacSSheldon HearnThis member holds the number of entries in the section header table.
384fb59cdf6SJoseph KoshyIf the file is using extended section numbering, then the
385fb59cdf6SJoseph Koshy.Sy e_shnum
386e0195199SJoseph Koshymember will be zero and the actual section number will be stored in the
387fb59cdf6SJoseph Koshy.Sy sh_size
388fb59cdf6SJoseph Koshymember of the section header at index
389fb59cdf6SJoseph Koshy.Dv SHN_UNDEF .
390fb59cdf6SJoseph KoshyIf a file has no section header table, both the
391fb59cdf6SJoseph Koshy.Sy e_shnum
392fb59cdf6SJoseph Koshyand the
393fb59cdf6SJoseph Koshy.Sy e_shoff
394fb59cdf6SJoseph Koshyfields of the ELF header will be zero.
395fb59cdf6SJoseph KoshyThe product of
396ea14e5c3SBrian Feldman.Sy e_shentsize
397fb59cdf6SJoseph Koshyand the number of sections in the file gives the section header
398fb59cdf6SJoseph Koshytable's size in bytes.
399ea14e5c3SBrian Feldman.It Dv e_shstrndx
400ea14e5c3SBrian FeldmanThis member holds the section header table index of the entry associated
4014e86fcacSSheldon Hearnwith the section name string table.
402fb59cdf6SJoseph KoshyIf extended section numbering is being used, this field will hold the
403fb59cdf6SJoseph Koshyvalue
404fb59cdf6SJoseph Koshy.Sy SHN_XINDEX ,
405fb59cdf6SJoseph Koshyand the actual section header table index will be present in the
406fb59cdf6SJoseph Koshy.Sy sh_link
407fb59cdf6SJoseph Koshyfield of the section header entry at index
408fb59cdf6SJoseph Koshy.Dv SHN_UNDEF .
4094e86fcacSSheldon HearnIf the file has no section name string
410ea14e5c3SBrian Feldmantable, this member holds the value
411ea14e5c3SBrian Feldman.Sy SHN_UNDEF .
412ea14e5c3SBrian Feldman.El
413ea14e5c3SBrian Feldman.Pp
414ea14e5c3SBrian FeldmanAn executable or shared object file's program header table is an array of
415ea14e5c3SBrian Feldmanstructures, each describing a segment or other information the system needs
4164e86fcacSSheldon Hearnto prepare the program for execution.
4174e86fcacSSheldon HearnAn object file
418ea14e5c3SBrian Feldman.Em segment
419ea14e5c3SBrian Feldmancontains one or more
420ea14e5c3SBrian Feldman.Em sections .
421ea14e5c3SBrian FeldmanProgram headers are meaningful only for executable and shared object files.
422ea14e5c3SBrian FeldmanA file specifies its own program header size with the ELF header's
423ea14e5c3SBrian Feldman.Sy e_phentsize
424ea14e5c3SBrian Feldmanand
425ea14e5c3SBrian Feldman.Sy e_phnum
4264e86fcacSSheldon Hearnmembers.
4274e86fcacSSheldon HearnAs with the Elf executable header, the program header
428ea14e5c3SBrian Feldmanalso has different versions depending on the architecture:
429ea14e5c3SBrian Feldman.Bd -literal -offset indent
430ea14e5c3SBrian Feldmantypedef struct {
431ea14e5c3SBrian Feldman        Elf32_Word      p_type;
432ea14e5c3SBrian Feldman        Elf32_Off       p_offset;
433ea14e5c3SBrian Feldman        Elf32_Addr      p_vaddr;
434ea14e5c3SBrian Feldman        Elf32_Addr      p_paddr;
435757686b1SMarcel Moolenaar        Elf32_Word      p_filesz;
436757686b1SMarcel Moolenaar        Elf32_Word      p_memsz;
437ea14e5c3SBrian Feldman        Elf32_Word      p_flags;
438757686b1SMarcel Moolenaar        Elf32_Word      p_align;
439ea14e5c3SBrian Feldman} Elf32_Phdr;
440ea14e5c3SBrian Feldman.Ed
441ea14e5c3SBrian Feldman.Bd -literal -offset indent
442ea14e5c3SBrian Feldmantypedef struct {
443757686b1SMarcel Moolenaar        Elf64_Word      p_type;
444757686b1SMarcel Moolenaar        Elf64_Word      p_flags;
445ea14e5c3SBrian Feldman        Elf64_Off       p_offset;
446ea14e5c3SBrian Feldman        Elf64_Addr      p_vaddr;
447ea14e5c3SBrian Feldman        Elf64_Addr      p_paddr;
448757686b1SMarcel Moolenaar        Elf64_Xword     p_filesz;
449757686b1SMarcel Moolenaar        Elf64_Xword     p_memsz;
450757686b1SMarcel Moolenaar        Elf64_Xword     p_align;
451ea14e5c3SBrian Feldman} Elf64_Phdr;
452ea14e5c3SBrian Feldman.Ed
453ea14e5c3SBrian Feldman.Pp
454ea14e5c3SBrian FeldmanThe main difference between the 32-bit and the 64-bit program header lies
455ea14e5c3SBrian Feldmanonly in the location of a
456ea14e5c3SBrian Feldman.Sy p_flags
457ea14e5c3SBrian Feldmanmember in the total struct.
458ea14e5c3SBrian Feldman.Pp
459ea14e5c3SBrian Feldman.Bl -tag -width "p_offset" -compact -offset indent
460ea14e5c3SBrian Feldman.It Dv p_type
461ea14e5c3SBrian FeldmanThis member of the Phdr struct tells what kind of segment this array
462ea14e5c3SBrian Feldmanelement describes or how to interpret the array element's information.
463ea14e5c3SBrian Feldman.Pp
4642914feebSUlrich Spörlein.Bl -tag -width "PT_DYNAMIC" -compact
465ea14e5c3SBrian Feldman.It Dv PT_NULL
466ea14e5c3SBrian FeldmanThe array element is unused and the other members' values are undefined.
467ea14e5c3SBrian FeldmanThis lets the program header have ignored entries.
468ea14e5c3SBrian Feldman.It Dv PT_LOAD
469ea14e5c3SBrian FeldmanThe array element specifies a loadable segment, described by
470ea14e5c3SBrian Feldman.Sy p_filesz
471ea14e5c3SBrian Feldmanand
472ea14e5c3SBrian Feldman.Sy p_memsz .
473ea14e5c3SBrian FeldmanThe bytes from the file are mapped to the beginning of the memory
4744e86fcacSSheldon Hearnsegment.
4759232968eSDima DorfmanIf the segment's memory size
4769232968eSDima Dorfman.Pq Sy p_memsz
4779232968eSDima Dorfmanis larger than the file size
4789232968eSDima Dorfman.Pq Sy p_filesz ,
4799232968eSDima Dorfmanthe
480ea14e5c3SBrian Feldman.Dq extra
481ea14e5c3SBrian Feldmanbytes are defined to hold the value 0 and to follow the segment's
4824e86fcacSSheldon Hearninitialized area.
4834e86fcacSSheldon HearnThe file size may not be larger than the memory size.
484ea14e5c3SBrian FeldmanLoadable segment entries in the program header table appear in ascending
485ea14e5c3SBrian Feldmanorder, sorted on the
486ea14e5c3SBrian Feldman.Sy p_vaddr
487ea14e5c3SBrian Feldmanmember.
488ea14e5c3SBrian Feldman.It Dv PT_DYNAMIC
489ea14e5c3SBrian FeldmanThe array element specifies dynamic linking information.
490ea14e5c3SBrian Feldman.It Dv PT_INTERP
491ea14e5c3SBrian FeldmanThe array element specifies the location and size of a null-terminated
4924e86fcacSSheldon Hearnpath name to invoke as an interpreter.
4934e86fcacSSheldon HearnThis segment type is meaningful
4945203edcdSRuslan Ermilovonly for executable files (though it may occur for shared objects).
4955203edcdSRuslan ErmilovHowever
4964e86fcacSSheldon Hearnit may not occur more than once in a file.
4974e86fcacSSheldon HearnIf it is present it must precede
498ea14e5c3SBrian Feldmanany loadable segment entry.
499ea14e5c3SBrian Feldman.It Dv PT_NOTE
500ea14e5c3SBrian FeldmanThe array element specifies the location and size for auxiliary information.
501ea14e5c3SBrian Feldman.It Dv PT_SHLIB
5024e86fcacSSheldon HearnThis segment type is reserved but has unspecified semantics.
5034e86fcacSSheldon HearnPrograms that
504ea14e5c3SBrian Feldmancontain an array element of this type do not conform to the ABI.
505ea14e5c3SBrian Feldman.It Dv PT_PHDR
506ea14e5c3SBrian FeldmanThe array element, if present, specifies the location and size of the program
507ea14e5c3SBrian Feldmanheader table itself, both in the file and in the memory image of the program.
5084e86fcacSSheldon HearnThis segment type may not occur more than once in a file.
5094e86fcacSSheldon HearnMoreover, it may
510ea14e5c3SBrian Feldmanonly occur if the program header table is part of the memory image of the
5114e86fcacSSheldon Hearnprogram.
5124e86fcacSSheldon HearnIf it is present it must precede any loadable segment entry.
513ea14e5c3SBrian Feldman.It Dv PT_LOPROC
514ea14e5c3SBrian FeldmanThis value up to and including
515ea14e5c3SBrian Feldman.Sy PT_HIPROC
516ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
517ea14e5c3SBrian Feldman.It Dv PT_HIPROC
518ea14e5c3SBrian FeldmanThis value down to and including
519ea14e5c3SBrian Feldman.Sy PT_LOPROC
520ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
521ea14e5c3SBrian Feldman.El
522ea14e5c3SBrian Feldman.Pp
523ea14e5c3SBrian Feldman.It Dv p_offset
524ea14e5c3SBrian FeldmanThis member holds the offset from the beginning of the file at which
525f4c311e6SPeter Pentchevthe first byte of the segment resides.
526ea14e5c3SBrian Feldman.It Dv p_vaddr
527ea14e5c3SBrian FeldmanThis member holds the virtual address at which the first byte of the
528ea14e5c3SBrian Feldmansegment resides in memory.
529ea14e5c3SBrian Feldman.It Dv p_paddr
530ea14e5c3SBrian FeldmanOn systems for which physical addressing is relevant, this member is
5314e86fcacSSheldon Hearnreserved for the segment's physical address.
532753d686dSRuslan ErmilovUnder
533753d686dSRuslan Ermilov.Bx
534753d686dSRuslan Ermilovthis member is
535ea14e5c3SBrian Feldmannot used and must be zero.
536ea14e5c3SBrian Feldman.It Dv p_filesz
537ea14e5c3SBrian FeldmanThis member holds the number of bytes in the file image of the segment.
538ea14e5c3SBrian FeldmanIt may be zero.
539ea14e5c3SBrian Feldman.It Dv p_memsz
540ea14e5c3SBrian FeldmanThis member holds the number of bytes in the memory image of the segment.
541ea14e5c3SBrian FeldmanIt may be zero.
542ea14e5c3SBrian Feldman.It Dv p_flags
543ea14e5c3SBrian FeldmanThis member holds flags relevant to the segment:
544ea14e5c3SBrian Feldman.Pp
545ea14e5c3SBrian Feldman.Bl -tag -width "PF_X" -compact
546ea14e5c3SBrian Feldman.It Dv PF_X
547ea14e5c3SBrian FeldmanAn executable segment.
548ea14e5c3SBrian Feldman.It Dv PF_W
549ea14e5c3SBrian FeldmanA writable segment.
550ea14e5c3SBrian Feldman.It Dv PF_R
551ea14e5c3SBrian FeldmanA readable segment.
552ea14e5c3SBrian Feldman.El
553ea14e5c3SBrian Feldman.Pp
554ea14e5c3SBrian FeldmanA text segment commonly has the flags
555ea14e5c3SBrian Feldman.Sy PF_X
556ea14e5c3SBrian Feldmanand
557672300f7SRuslan Ermilov.Sy PF_R .
558ea14e5c3SBrian FeldmanA data segment commonly has
559ea14e5c3SBrian Feldman.Sy PF_X ,
560ea14e5c3SBrian Feldman.Sy PF_W
561ea14e5c3SBrian Feldmanand
562ea14e5c3SBrian Feldman.Sy PF_R .
563ea14e5c3SBrian Feldman.It Dv p_align
564ea14e5c3SBrian FeldmanThis member holds the value to which the segments are aligned in memory
5654e86fcacSSheldon Hearnand in the file.
5664e86fcacSSheldon HearnLoadable process segments must have congruent values for
567ea14e5c3SBrian Feldman.Sy p_vaddr
568ea14e5c3SBrian Feldmanand
569ea14e5c3SBrian Feldman.Sy p_offset ,
5704e86fcacSSheldon Hearnmodulo the page size.
5714e86fcacSSheldon HearnValues of zero and one mean no alignment is required.
572ea14e5c3SBrian FeldmanOtherwise,
573ea14e5c3SBrian Feldman.Sy p_align
574ea14e5c3SBrian Feldmanshould be a positive, integral power of two, and
575ea14e5c3SBrian Feldman.Sy p_vaddr
576ea14e5c3SBrian Feldmanshould equal
577ea14e5c3SBrian Feldman.Sy p_offset ,
578ea14e5c3SBrian Feldmanmodulo
579ea14e5c3SBrian Feldman.Sy p_align .
580ea14e5c3SBrian Feldman.El
581ea14e5c3SBrian Feldman.Pp
5824e86fcacSSheldon HearnAn file's section header table lets one locate all the file's sections.
5834e86fcacSSheldon HearnThe
5844e86fcacSSheldon Hearnsection header table is an array of Elf32_Shdr or Elf64_Shdr structures.
5854e86fcacSSheldon HearnThe
586ea14e5c3SBrian FeldmanELF header's
587ea14e5c3SBrian Feldman.Sy e_shoff
588ea14e5c3SBrian Feldmanmember gives the byte offset from the beginning of the file to the section
589ea14e5c3SBrian Feldmanheader table.
590ea14e5c3SBrian Feldman.Sy e_shnum
591ea14e5c3SBrian Feldmanholds the number of entries the section header table contains.
592ea14e5c3SBrian Feldman.Sy e_shentsize
593ea14e5c3SBrian Feldmanholds the size in bytes of each entry.
594ea14e5c3SBrian Feldman.Pp
5954e86fcacSSheldon HearnA section header table index is a subscript into this array.
5964e86fcacSSheldon HearnSome section
5974e86fcacSSheldon Hearnheader table indices are reserved.
5984e86fcacSSheldon HearnAn object file does not have sections for
599ea14e5c3SBrian Feldmanthese special indices:
600ea14e5c3SBrian Feldman.Pp
601ea14e5c3SBrian Feldman.Bl -tag -width "SHN_LORESERVE" -compact
602ea14e5c3SBrian Feldman.It Dv SHN_UNDEF
6037e1b2808SHiten PandyaThis value marks an undefined, missing, irrelevant, or otherwise meaningless
604ea14e5c3SBrian Feldmansection reference.
6057e1b2808SHiten PandyaFor example, a symbol
6067e1b2808SHiten Pandya.Dq defined
6077e1b2808SHiten Pandyarelative to section number
6087e1b2808SHiten Pandya.Sy SHN_UNDEF
6097e1b2808SHiten Pandyais an undefined symbol.
610ea14e5c3SBrian Feldman.It Dv SHN_LORESERVE
611ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of reserved indices.
612ea14e5c3SBrian Feldman.It Dv SHN_LOPROC
613ea14e5c3SBrian FeldmanThis value up to and including
614ea14e5c3SBrian Feldman.Sy SHN_HIPROC
615ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
616ea14e5c3SBrian Feldman.It Dv SHN_HIPROC
617ea14e5c3SBrian FeldmanThis value down to and including
618ea14e5c3SBrian Feldman.Sy SHN_LOPROC
619ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
620ea14e5c3SBrian Feldman.It Dv SHN_ABS
6214e86fcacSSheldon HearnThis value specifies absolute values for the corresponding reference.
6224e86fcacSSheldon HearnFor
623ea14e5c3SBrian Feldmanexample, symbols defined relative to section number
624ea14e5c3SBrian Feldman.Sy SHN_ABS
625ea14e5c3SBrian Feldmanhave absolute values and are not affected by relocation.
626ea14e5c3SBrian Feldman.It Dv SHN_COMMON
627ea14e5c3SBrian FeldmanSymbols defined relative to this section are common symbols, such as FORTRAN
628ea14e5c3SBrian FeldmanCOMMON or unallocated C external variables.
629ea14e5c3SBrian Feldman.It Dv SHN_HIRESERVE
6304e86fcacSSheldon HearnThis value specifies the upper bound of the range of reserved indices.
6314e86fcacSSheldon HearnThe
632ea14e5c3SBrian Feldmansystem reserves indices between
633ea14e5c3SBrian Feldman.Sy SHN_LORESERVE
634ea14e5c3SBrian Feldmanand
635ea14e5c3SBrian Feldman.Sy SHN_HIRESERVE ,
6364e86fcacSSheldon Hearninclusive.
6374e86fcacSSheldon HearnThe section header table does not contain entries for the
638ea14e5c3SBrian Feldmanreserved indices.
639ea14e5c3SBrian Feldman.El
640ea14e5c3SBrian Feldman.Pp
641ea14e5c3SBrian FeldmanThe section header has the following structure:
642ea14e5c3SBrian Feldman.Bd -literal -offset indent
643ea14e5c3SBrian Feldmantypedef struct {
644ea14e5c3SBrian Feldman	Elf32_Word      sh_name;
645ea14e5c3SBrian Feldman	Elf32_Word      sh_type;
646ea14e5c3SBrian Feldman	Elf32_Word      sh_flags;
647ea14e5c3SBrian Feldman	Elf32_Addr      sh_addr;
648ea14e5c3SBrian Feldman	Elf32_Off       sh_offset;
649757686b1SMarcel Moolenaar	Elf32_Word      sh_size;
650ea14e5c3SBrian Feldman	Elf32_Word      sh_link;
651ea14e5c3SBrian Feldman	Elf32_Word      sh_info;
652757686b1SMarcel Moolenaar	Elf32_Word      sh_addralign;
653757686b1SMarcel Moolenaar	Elf32_Word      sh_entsize;
654ea14e5c3SBrian Feldman} Elf32_Shdr;
655ea14e5c3SBrian Feldman.Ed
656ea14e5c3SBrian Feldman.Bd -literal -offset indent
657ea14e5c3SBrian Feldmantypedef struct {
658757686b1SMarcel Moolenaar	Elf64_Word      sh_name;
659757686b1SMarcel Moolenaar	Elf64_Word      sh_type;
660757686b1SMarcel Moolenaar	Elf64_Xword     sh_flags;
661ea14e5c3SBrian Feldman	Elf64_Addr      sh_addr;
662ea14e5c3SBrian Feldman	Elf64_Off       sh_offset;
663757686b1SMarcel Moolenaar	Elf64_Xword     sh_size;
664757686b1SMarcel Moolenaar	Elf64_Word      sh_link;
665757686b1SMarcel Moolenaar	Elf64_Word      sh_info;
666757686b1SMarcel Moolenaar	Elf64_Xword     sh_addralign;
667757686b1SMarcel Moolenaar	Elf64_Xword     sh_entsize;
668ea14e5c3SBrian Feldman} Elf64_Shdr;
669ea14e5c3SBrian Feldman.Ed
670ea14e5c3SBrian Feldman.Pp
671ea14e5c3SBrian Feldman.Bl -tag -width "sh_addralign" -compact
672ea14e5c3SBrian Feldman.It Dv sh_name
6734e86fcacSSheldon HearnThis member specifies the name of the section.
6744e86fcacSSheldon HearnIts value is an index
675ea14e5c3SBrian Feldmaninto the section header string table section, giving the location of
676ea14e5c3SBrian Feldmana null-terminated string.
677ea14e5c3SBrian Feldman.It Dv sh_type
6780757c960SBrian FeldmanThis member categorizes the section's contents and semantics.
679ea14e5c3SBrian Feldman.Pp
680ea14e5c3SBrian Feldman.Bl -tag -width "SHT_PROGBITS" -compact
681ea14e5c3SBrian Feldman.It Dv SHT_NULL
6824e86fcacSSheldon HearnThis value marks the section header as inactive.
6834e86fcacSSheldon HearnIt does not
6844e86fcacSSheldon Hearnhave an associated section.
6854e86fcacSSheldon HearnOther members of the section header
686ea14e5c3SBrian Feldmanhave undefined values.
687ea14e5c3SBrian Feldman.It Dv SHT_PROGBITS
688ea14e5c3SBrian FeldmanThe section holds information defined by the program, whose
689ea14e5c3SBrian Feldmanformat and meaning are determined solely by the program.
690ea14e5c3SBrian Feldman.It Dv SHT_SYMTAB
6914e86fcacSSheldon HearnThis section holds a symbol table.
6924e86fcacSSheldon HearnTypically,
693ea14e5c3SBrian Feldman.Sy SHT_SYMTAB
694ea14e5c3SBrian Feldmanprovides symbols for link editing, though it may also be used
6954e86fcacSSheldon Hearnfor dynamic linking.
6964e86fcacSSheldon HearnAs a complete symbol table, it may contain
6974e86fcacSSheldon Hearnmany symbols unnecessary for dynamic linking.
6984e86fcacSSheldon HearnAn object file can
699ea14e5c3SBrian Feldmanalso contain a
700ea14e5c3SBrian Feldman.Sy SHN_DYNSYM
701ea14e5c3SBrian Feldmansection.
702ea14e5c3SBrian Feldman.It Dv SHT_STRTAB
7034e86fcacSSheldon HearnThis section holds a string table.
7044e86fcacSSheldon HearnAn object file may have multiple
705ea14e5c3SBrian Feldmanstring table sections.
706ea14e5c3SBrian Feldman.It Dv SHT_RELA
707ea14e5c3SBrian FeldmanThis section holds relocation entries with explicit addends, such
708ea14e5c3SBrian Feldmanas type
709ea14e5c3SBrian Feldman.Sy Elf32_Rela
7104e86fcacSSheldon Hearnfor the 32-bit class of object files.
7114e86fcacSSheldon HearnAn object may have multiple
712ea14e5c3SBrian Feldmanrelocation sections.
713ea14e5c3SBrian Feldman.It Dv SHT_HASH
7144e86fcacSSheldon HearnThis section holds a symbol hash table.
7154e86fcacSSheldon HearnAll object participating in
7164e86fcacSSheldon Hearndynamic linking must contain a symbol hash table.
7174e86fcacSSheldon HearnAn object file may
718ea14e5c3SBrian Feldmanhave only one hash table.
719ea14e5c3SBrian Feldman.It Dv SHT_DYNAMIC
7204e86fcacSSheldon HearnThis section holds information for dynamic linking.
7214e86fcacSSheldon HearnAn object file may
722ea14e5c3SBrian Feldmanhave only one dynamic section.
723ea14e5c3SBrian Feldman.It Dv SHT_NOTE
724ea14e5c3SBrian FeldmanThis section holds information that marks the file in some way.
725ea14e5c3SBrian Feldman.It Dv SHT_NOBITS
726ea14e5c3SBrian FeldmanA section of this type occupies no space in the file but otherwise
727ea14e5c3SBrian Feldmanresembles
728ea14e5c3SBrian Feldman.Sy SHN_PROGBITS .
729ea14e5c3SBrian FeldmanAlthough this section contains no bytes, the
730ea14e5c3SBrian Feldman.Sy sh_offset
731ea14e5c3SBrian Feldmanmember contains the conceptual file offset.
732ea14e5c3SBrian Feldman.It Dv SHT_REL
733ea14e5c3SBrian FeldmanThis section holds relocation offsets without explicit addends, such
734ea14e5c3SBrian Feldmanas type
735ea14e5c3SBrian Feldman.Sy Elf32_Rel
7364e86fcacSSheldon Hearnfor the 32-bit class of object files.
7374e86fcacSSheldon HearnAn object file may have multiple
738ea14e5c3SBrian Feldmanrelocation sections.
739ea14e5c3SBrian Feldman.It Dv SHT_SHLIB
740ea14e5c3SBrian FeldmanThis section is reserved but has unspecified semantics.
741ea14e5c3SBrian Feldman.It Dv SHT_DYNSYM
7424e86fcacSSheldon HearnThis section holds a minimal set of dynamic linking symbols.
7434e86fcacSSheldon HearnAn
744ea14e5c3SBrian Feldmanobject file can also contain a
745ea14e5c3SBrian Feldman.Sy SHN_SYMTAB
746ea14e5c3SBrian Feldmansection.
747ea14e5c3SBrian Feldman.It Dv SHT_LOPROC
748ea14e5c3SBrian FeldmanThis value up to and including
749ea14e5c3SBrian Feldman.Sy SHT_HIPROC
750ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
751ea14e5c3SBrian Feldman.It Dv SHT_HIPROC
752ea14e5c3SBrian FeldmanThis value down to and including
753ea14e5c3SBrian Feldman.Sy SHT_LOPROC
754ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
755ea14e5c3SBrian Feldman.It Dv SHT_LOUSER
756ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of indices reserved for
757ea14e5c3SBrian Feldmanapplication programs.
758ea14e5c3SBrian Feldman.It Dv SHT_HIUSER
759ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of indices reserved for
7604e86fcacSSheldon Hearnapplication programs.
7614e86fcacSSheldon HearnSection types between
762ea14e5c3SBrian Feldman.Sy SHT_LOUSER
763ea14e5c3SBrian Feldmanand
764ea14e5c3SBrian Feldman.Sy SHT_HIUSER
765ea14e5c3SBrian Feldmanmay be used by the application, without conflicting with current or future
766ea14e5c3SBrian Feldmansystem-defined section types.
767ea14e5c3SBrian Feldman.El
768ea14e5c3SBrian Feldman.Pp
769ea14e5c3SBrian Feldman.It Dv sh_flags
770ea14e5c3SBrian FeldmanSections support one-bit flags that describe miscellaneous attributes.
771ea14e5c3SBrian FeldmanIf a flag bit is set in
772ea14e5c3SBrian Feldman.Sy sh_flags ,
773ea14e5c3SBrian Feldmanthe attribute is
774ea14e5c3SBrian Feldman.Dq on
7754e86fcacSSheldon Hearnfor the section.
7764e86fcacSSheldon HearnOtherwise, the attribute is
777ea14e5c3SBrian Feldman.Dq off
7784e86fcacSSheldon Hearnor does not apply.
7794e86fcacSSheldon HearnUndefined attributes are set to zero.
780ea14e5c3SBrian Feldman.Pp
781ea14e5c3SBrian Feldman.Bl -tag -width "SHF_EXECINSTR" -compact
782ea14e5c3SBrian Feldman.It Dv SHF_WRITE
783ea14e5c3SBrian FeldmanThis section contains data that should be writable during process
784ea14e5c3SBrian Feldmanexecution.
785ea14e5c3SBrian Feldman.It Dv SHF_ALLOC
7864e86fcacSSheldon HearnThe section occupies memory during process execution.
7874e86fcacSSheldon HearnSome control
7884e86fcacSSheldon Hearnsections do not reside in the memory image of an object file.
7894e86fcacSSheldon HearnThis
790ea14e5c3SBrian Feldmanattribute is off for those sections.
791ea14e5c3SBrian Feldman.It Dv SHF_EXECINSTR
792ea14e5c3SBrian FeldmanThe section contains executable machine instructions.
793ea14e5c3SBrian Feldman.It Dv SHF_MASKPROC
794ea14e5c3SBrian FeldmanAll bits included in this mask are reserved for processor-specific
795ea14e5c3SBrian Feldmansemantics.
796e0189cf6SMark Johnston.It Dv SHF_COMPRESSED
797e0189cf6SMark JohnstonThe section data is compressed.
798ea14e5c3SBrian Feldman.El
799ea14e5c3SBrian Feldman.Pp
800ea14e5c3SBrian Feldman.It Dv sh_addr
801ea14e5c3SBrian FeldmanIf the section will appear in the memory image of a process, this member
802ea14e5c3SBrian Feldmanholds the address at which the section's first byte should reside.
803ea14e5c3SBrian FeldmanOtherwise, the member contains zero.
804ea14e5c3SBrian Feldman.It Dv sh_offset
805ea14e5c3SBrian FeldmanThis member's value holds the byte offset from the beginning of the file
8064e86fcacSSheldon Hearnto the first byte in the section.
8074e86fcacSSheldon HearnOne section type,
808ea14e5c3SBrian Feldman.Sy SHT_NOBITS ,
809ea14e5c3SBrian Feldmanoccupies no space in the file, and its
810ea14e5c3SBrian Feldman.Sy sh_offset
811ea14e5c3SBrian Feldmanmember locates the conceptual placement in the file.
812ea14e5c3SBrian Feldman.It Dv sh_size
8134e86fcacSSheldon HearnThis member holds the section's size in bytes.
8144e86fcacSSheldon HearnUnless the section type
815ea14e5c3SBrian Feldmanis
816ea14e5c3SBrian Feldman.Sy SHT_NOBITS ,
817ea14e5c3SBrian Feldmanthe section occupies
818ea14e5c3SBrian Feldman.Sy sh_size
8194e86fcacSSheldon Hearnbytes in the file.
8204e86fcacSSheldon HearnA section of type
821ea14e5c3SBrian Feldman.Sy SHT_NOBITS
822ea14e5c3SBrian Feldmanmay have a non-zero size, but it occupies no space in the file.
823ea14e5c3SBrian Feldman.It Dv sh_link
824ea14e5c3SBrian FeldmanThis member holds a section header table index link, whose interpretation
825ea14e5c3SBrian Feldmandepends on the section type.
826ea14e5c3SBrian Feldman.It Dv sh_info
827ea14e5c3SBrian FeldmanThis member holds extra information, whose interpretation depends on the
828ea14e5c3SBrian Feldmansection type.
829ea14e5c3SBrian Feldman.It Dv sh_addralign
8304e86fcacSSheldon HearnSome sections have address alignment constraints.
8314e86fcacSSheldon HearnIf a section holds a
832ea14e5c3SBrian Feldmandoubleword, the system must ensure doubleword alignment for the entire
8334e86fcacSSheldon Hearnsection.
8344e86fcacSSheldon HearnThat is, the value of
835ea14e5c3SBrian Feldman.Sy sh_addr
836ea14e5c3SBrian Feldmanmust be congruent to zero, modulo the value of
837ea14e5c3SBrian Feldman.Sy sh_addralign .
8384e86fcacSSheldon HearnOnly zero and positive integral powers of two are allowed.
8394e86fcacSSheldon HearnValues of zero
840ea14e5c3SBrian Feldmanor one mean the section has no alignment constraints.
841ea14e5c3SBrian Feldman.It Dv sh_entsize
842ea14e5c3SBrian FeldmanSome sections hold a table of fixed-sized entries, such as a symbol table.
843ea14e5c3SBrian FeldmanFor such a section, this member gives the size in bytes for each entry.
844ea14e5c3SBrian FeldmanThis member contains zero if the section does not hold a table of
845ea14e5c3SBrian Feldmanfixed-size entries.
846ea14e5c3SBrian Feldman.El
847ea14e5c3SBrian Feldman.Pp
848ea14e5c3SBrian FeldmanVarious sections hold program and control information:
849ea14e5c3SBrian Feldman.Bl -tag -width ".shstrtab" -compact
850ea14e5c3SBrian Feldman.It .bss
8514f068961SRuslan Ermilov(Block Started by Symbol)
8520757c960SBrian FeldmanThis section holds uninitialized data that contributes to the program's
8534e86fcacSSheldon Hearnmemory image.
8544e86fcacSSheldon HearnBy definition, the system initializes the data with zeros
8554e86fcacSSheldon Hearnwhen the program begins to run.
8564e86fcacSSheldon HearnThis section is of type
857ea14e5c3SBrian Feldman.Sy SHT_NOBITS .
858ea14e5c3SBrian FeldmanThe attributes types are
859ea14e5c3SBrian Feldman.Sy SHF_ALLOC
860ea14e5c3SBrian Feldmanand
861ea14e5c3SBrian Feldman.Sy SHF_WRITE .
862ea14e5c3SBrian Feldman.It .comment
8634e86fcacSSheldon HearnThis section holds version control information.
8644e86fcacSSheldon HearnThis section is of type
865ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
866ea14e5c3SBrian FeldmanNo attribute types are used.
867ea14e5c3SBrian Feldman.It .data
8680757c960SBrian FeldmanThis section holds initialized data that contribute to the program's
8694e86fcacSSheldon Hearnmemory image.
8704e86fcacSSheldon HearnThis section is of type
871ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
872ea14e5c3SBrian FeldmanThe attribute types are
873ea14e5c3SBrian Feldman.Sy SHF_ALLOC
874ea14e5c3SBrian Feldmanand
875ea14e5c3SBrian Feldman.Sy SHF_WRITE .
876ea14e5c3SBrian Feldman.It .data1
8770757c960SBrian FeldmanThis section holds initialized data that contribute to the program's
8784e86fcacSSheldon Hearnmemory image.
8794e86fcacSSheldon HearnThis section is of type
880ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
881ea14e5c3SBrian FeldmanThe attribute types are
882ea14e5c3SBrian Feldman.Sy SHF_ALLOC
883ea14e5c3SBrian Feldmanand
884ea14e5c3SBrian Feldman.Sy SHF_WRITE .
885ea14e5c3SBrian Feldman.It .debug
8864e86fcacSSheldon HearnThis section holds information for symbolic debugging.
8874e86fcacSSheldon HearnThe contents
8884e86fcacSSheldon Hearnare unspecified.
8894e86fcacSSheldon HearnThis section is of type
890ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
891ea14e5c3SBrian FeldmanNo attribute types are used.
892ea14e5c3SBrian Feldman.It .dynamic
8934e86fcacSSheldon HearnThis section holds dynamic linking information.
8944e86fcacSSheldon HearnThe section's attributes
895ea14e5c3SBrian Feldmanwill include the
896ea14e5c3SBrian Feldman.Sy SHF_ALLOC
8974e86fcacSSheldon Hearnbit.
8984e86fcacSSheldon HearnWhether the
899ea14e5c3SBrian Feldman.Sy SHF_WRITE
9004e86fcacSSheldon Hearnbit is set is processor-specific.
9014e86fcacSSheldon HearnThis section is of type
902ea14e5c3SBrian Feldman.Sy SHT_DYNAMIC .
903ea14e5c3SBrian FeldmanSee the attributes above.
904ea14e5c3SBrian Feldman.It .dynstr
905ea14e5c3SBrian FeldmanThis section holds strings needed for dynamic linking, most commonly
906ea14e5c3SBrian Feldmanthe strings that represent the names associated with symbol table entries.
907ea14e5c3SBrian FeldmanThis section is of type
908ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
909ea14e5c3SBrian FeldmanThe attribute type used is
910ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
911ea14e5c3SBrian Feldman.It .dynsym
9124e86fcacSSheldon HearnThis section holds the dynamic linking symbol table.
9134e86fcacSSheldon HearnThis section is of type
914ea14e5c3SBrian Feldman.Sy SHT_DYNSYM .
915ea14e5c3SBrian FeldmanThe attribute used is
916ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
917ea14e5c3SBrian Feldman.It .fini
918ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process
9194e86fcacSSheldon Hearntermination code.
9204e86fcacSSheldon HearnWhen a program exits normally the system arranges to
9214e86fcacSSheldon Hearnexecute the code in this section.
9224e86fcacSSheldon HearnThis section is of type
923ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
924ea14e5c3SBrian FeldmanThe attributes used are
925ea14e5c3SBrian Feldman.Sy SHF_ALLOC
926ea14e5c3SBrian Feldmanand
927ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
928ea14e5c3SBrian Feldman.It .got
9294e86fcacSSheldon HearnThis section holds the global offset table.
9304e86fcacSSheldon HearnThis section is of type
931ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
932ea14e5c3SBrian FeldmanThe attributes are processor-specific.
933ea14e5c3SBrian Feldman.It .hash
9344e86fcacSSheldon HearnThis section holds a symbol hash table.
9354e86fcacSSheldon HearnThis section is of type
936ea14e5c3SBrian Feldman.Sy SHT_HASH .
937ea14e5c3SBrian FeldmanThe attribute used is
938ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
939ea14e5c3SBrian Feldman.It .init
940ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process
9414e86fcacSSheldon Hearninitialization code.
9424e86fcacSSheldon HearnWhen a program starts to run the system arranges to
943ea14e5c3SBrian Feldmanexecute the code in this section before calling the main program entry point.
944ea14e5c3SBrian FeldmanThis section is of type
945ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
946ea14e5c3SBrian FeldmanThe attributes used are
947ea14e5c3SBrian Feldman.Sy SHF_ALLOC
948ea14e5c3SBrian Feldmanand
949ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
950ea14e5c3SBrian Feldman.It .interp
9514e86fcacSSheldon HearnThis section holds the pathname of a program interpreter.
9524e86fcacSSheldon HearnIf the file has
953ea14e5c3SBrian Feldmana loadable segment that includes the section, the section's attributes will
954ea14e5c3SBrian Feldmaninclude the
955ea14e5c3SBrian Feldman.Sy SHF_ALLOC
9564e86fcacSSheldon Hearnbit.
9574e86fcacSSheldon HearnOtherwise, that bit will be off.
9584e86fcacSSheldon HearnThis section is of type
959ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
960ea14e5c3SBrian Feldman.It .line
961ea14e5c3SBrian FeldmanThis section holds line number information for symbolic debugging, which
962ea14e5c3SBrian Feldmandescribes the correspondence between the program source and the machine code.
9634e86fcacSSheldon HearnThe contents are unspecified.
9644e86fcacSSheldon HearnThis section is of type
965ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
966ea14e5c3SBrian FeldmanNo attribute types are used.
967ea14e5c3SBrian Feldman.It .note
968ea14e5c3SBrian FeldmanThis section holds information in the
969ea14e5c3SBrian Feldman.Dq Note Section
9704e86fcacSSheldon Hearnformat described below.
9714e86fcacSSheldon HearnThis section is of type
972ea14e5c3SBrian Feldman.Sy SHT_NOTE .
973ea14e5c3SBrian FeldmanNo attribute types are used.
974ea14e5c3SBrian Feldman.It .plt
9754e86fcacSSheldon HearnThis section holds the procedure linkage table.
9764e86fcacSSheldon HearnThis section is of type
977ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
978ea14e5c3SBrian FeldmanThe attributes are processor-specific.
979ea14e5c3SBrian Feldman.It .relNAME
9804e86fcacSSheldon HearnThis section holds relocation information as described below.
9814e86fcacSSheldon HearnIf the file
982ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes
983ea14e5c3SBrian Feldmanwill include the
984ea14e5c3SBrian Feldman.Sy SHF_ALLOC
9854e86fcacSSheldon Hearnbit.
9864e86fcacSSheldon HearnOtherwise the bit will be off.
9874e86fcacSSheldon HearnBy convention,
988ea14e5c3SBrian Feldman.Dq NAME
9894e86fcacSSheldon Hearnis supplied by the section to which the relocations apply.
9904e86fcacSSheldon HearnThus a relocation
991ea14e5c3SBrian Feldmansection for
992ea14e5c3SBrian Feldman.Sy .text
993ea14e5c3SBrian Feldmannormally would have the name
994ea14e5c3SBrian Feldman.Sy .rel.text .
995ea14e5c3SBrian FeldmanThis section is of type
996ea14e5c3SBrian Feldman.Sy SHT_REL .
997ea14e5c3SBrian Feldman.It .relaNAME
9984e86fcacSSheldon HearnThis section holds relocation information as described below.
9994e86fcacSSheldon HearnIf the file
1000ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes
1001ea14e5c3SBrian Feldmanwill include the
1002ea14e5c3SBrian Feldman.Sy SHF_ALLOC
10034e86fcacSSheldon Hearnbit.
10044e86fcacSSheldon HearnOtherwise the bit will be off.
10054e86fcacSSheldon HearnBy convention,
1006ea14e5c3SBrian Feldman.Dq NAME
10074e86fcacSSheldon Hearnis supplied by the section to which the relocations apply.
10084e86fcacSSheldon HearnThus a relocation
1009ea14e5c3SBrian Feldmansection for
1010ea14e5c3SBrian Feldman.Sy .text
1011ea14e5c3SBrian Feldmannormally would have the name
1012ea14e5c3SBrian Feldman.Sy .rela.text .
1013ea14e5c3SBrian FeldmanThis section is of type
1014ea14e5c3SBrian Feldman.Sy SHT_RELA .
1015ea14e5c3SBrian Feldman.It .rodata
1016f3a2511aSChris CostelloThis section holds read-only data that typically contributes to a
10174e86fcacSSheldon Hearnnon-writable segment in the process image.
10184e86fcacSSheldon HearnThis section is of type
1019ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
1020ea14e5c3SBrian FeldmanThe attribute used is
1021ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
1022ea14e5c3SBrian Feldman.It .rodata1
10236f96b548SZhenlei HuangThis section holds read-only data that typically contributes to a
10244e86fcacSSheldon Hearnnon-writable segment in the process image.
10254e86fcacSSheldon HearnThis section is of type
1026ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
1027ea14e5c3SBrian FeldmanThe attribute used is
1028ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
1029ea14e5c3SBrian Feldman.It .shstrtab
10304e86fcacSSheldon HearnThis section holds section names.
10314e86fcacSSheldon HearnThis section is of type
1032ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
1033ea14e5c3SBrian FeldmanNo attribute types are used.
1034ea14e5c3SBrian Feldman.It .strtab
1035ea14e5c3SBrian FeldmanThis section holds strings, most commonly the strings that represent the
10364e86fcacSSheldon Hearnnames associated with symbol table entries.
10374e86fcacSSheldon HearnIf the file has a loadable
1038ea14e5c3SBrian Feldmansegment that includes the symbol string table, the section's attributes
1039ea14e5c3SBrian Feldmanwill include the
1040ea14e5c3SBrian Feldman.Sy SHF_ALLOC
10414e86fcacSSheldon Hearnbit.
10424e86fcacSSheldon HearnOtherwise the bit will be off.
10434e86fcacSSheldon HearnThis section is of type
1044ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
1045ea14e5c3SBrian Feldman.It .symtab
10464e86fcacSSheldon HearnThis section holds a symbol table.
10474e86fcacSSheldon HearnIf the file has a loadable segment
1048ea14e5c3SBrian Feldmanthat includes the symbol table, the section's attributes will include
1049ea14e5c3SBrian Feldmanthe
1050ea14e5c3SBrian Feldman.Sy SHF_ALLOC
10514e86fcacSSheldon Hearnbit.
10524e86fcacSSheldon HearnOtherwise the bit will be off.
10534e86fcacSSheldon HearnThis section is of type
1054ea14e5c3SBrian Feldman.Sy SHT_SYMTAB .
1055ea14e5c3SBrian Feldman.It .text
1056ea14e5c3SBrian FeldmanThis section holds the
1057ea14e5c3SBrian Feldman.Dq text ,
10584e86fcacSSheldon Hearnor executable instructions, of a program.
10594e86fcacSSheldon HearnThis section is of type
1060ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
1061ea14e5c3SBrian FeldmanThe attributes used are
1062ea14e5c3SBrian Feldman.Sy SHF_ALLOC
1063ea14e5c3SBrian Feldmanand
1064ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
1065dc1cbf89STom Rhodes.It .jcr
1066dc1cbf89STom RhodesThis section holds information about Java classes that must
1067dc1cbf89STom Rhodesbe registered.
1068dc1cbf89STom Rhodes.It .eh_frame
1069dc1cbf89STom RhodesThis section holds information used for C++ exception-handling.
1070ea14e5c3SBrian Feldman.El
1071ea14e5c3SBrian Feldman.Pp
1072e0189cf6SMark JohnstonA section with the
1073e0189cf6SMark Johnston.Dv SHF_COMPRESSED
1074e0189cf6SMark Johnstonflag set contains a compressed copy of the section data.
1075e0189cf6SMark JohnstonCompressed section data begins with an
1076e0189cf6SMark Johnston.Vt Elf64_Chdr
1077e0189cf6SMark Johnstonor
1078e0189cf6SMark Johnston.Vt Elf32_Chdr structure
1079e0189cf6SMark Johnstonwhich encodes the compression algorithm and some characteristics of the
1080e0189cf6SMark Johnstonuncompressed data.
1081e0189cf6SMark Johnston.Bd -literal -offset indent
1082e0189cf6SMark Johnstontypedef struct {
1083e0189cf6SMark Johnston	Elf32_Word    ch_type;
1084e0189cf6SMark Johnston	Elf32_Word    ch_size;
1085e0189cf6SMark Johnston	Elf32_Word    ch_addralign;
1086e0189cf6SMark Johnston} Elf32_Chdr;
1087e0189cf6SMark Johnston.Ed
1088e0189cf6SMark Johnston.Bd -literal -offset indent
1089e0189cf6SMark Johnstontypedef struct {
1090e0189cf6SMark Johnston	Elf64_Word    ch_type;
1091e0189cf6SMark Johnston	Elf64_Word    ch_reserved;
1092e0189cf6SMark Johnston	Elf64_Xword   ch_size;
1093e0189cf6SMark Johnston	Elf64_Xword   ch_addralign;
1094e0189cf6SMark Johnston} Elf64_Chdr;
1095e0189cf6SMark Johnston.Ed
1096e0189cf6SMark Johnston.Pp
1097e0189cf6SMark Johnston.Bl -tag -width "ch_addralign" -compact
1098e0189cf6SMark Johnston.It Dv ch_type
1099e0189cf6SMark JohnstonThe compression algorithm used.
1100e0189cf6SMark JohnstonA value of
1101e0189cf6SMark Johnston.Dv ELFCOMPRESS_ZLIB
1102e0189cf6SMark Johnstonindicates that the data is compressed using
1103e0189cf6SMark Johnston.Xr zlib 3 .
110405b6744cSEd MasteA value of
110505b6744cSEd Maste.Dv ELFCOMPRESS_ZSTD
110605b6744cSEd Masteindicates that the data is compressed using
110705b6744cSEd MasteZstandard.
1108e0189cf6SMark Johnston.It Dv ch_size
1109e0189cf6SMark JohnstonThe size, in bytes, of the uncompressed section data.
1110e0189cf6SMark JohnstonThis corresponds to the
1111e0189cf6SMark Johnston.Sy sh_size
1112e0189cf6SMark Johnstonfield of a section header containing uncompressed data.
1113e0189cf6SMark Johnston.It Dv ch_addralign
1114e0189cf6SMark JohnstonThe address alignment of the uncompressed section data.
1115e0189cf6SMark JohnstonThis corresponds to the
1116e0189cf6SMark Johnston.Sy sh_addralign
1117e0189cf6SMark Johnstonfield of a section header containing uncompressed data.
1118e0189cf6SMark Johnston.El
1119e0189cf6SMark Johnston.Pp
1120ea14e5c3SBrian FeldmanString table sections hold null-terminated character sequences, commonly
11214e86fcacSSheldon Hearncalled strings.
11224e86fcacSSheldon HearnThe object file uses these strings to represent symbol
11234e86fcacSSheldon Hearnand section names.
11244e86fcacSSheldon HearnOne references a string as an index into the string
11254e86fcacSSheldon Hearntable section.
11264e86fcacSSheldon HearnThe first byte, which is index zero, is defined to hold
11274e86fcacSSheldon Hearna null character.
11284e86fcacSSheldon HearnSimilarly, a string table's last byte is defined to
1129ea14e5c3SBrian Feldmanhold a null character, ensuring null termination for all strings.
1130ea14e5c3SBrian Feldman.Pp
1131ea14e5c3SBrian FeldmanAn object file's symbol table holds information needed to locate and
11324e86fcacSSheldon Hearnrelocate a program's symbolic definitions and references.
11334e86fcacSSheldon HearnA symbol table
1134ea14e5c3SBrian Feldmanindex is a subscript into this array.
1135ea14e5c3SBrian Feldman.Bd -literal -offset indent
1136ea14e5c3SBrian Feldmantypedef struct {
1137ea14e5c3SBrian Feldman	Elf32_Word      st_name;
1138ea14e5c3SBrian Feldman	Elf32_Addr      st_value;
1139757686b1SMarcel Moolenaar	Elf32_Word      st_size;
1140ea14e5c3SBrian Feldman	unsigned char   st_info;
1141ea14e5c3SBrian Feldman	unsigned char   st_other;
1142ea14e5c3SBrian Feldman	Elf32_Half      st_shndx;
1143ea14e5c3SBrian Feldman} Elf32_Sym;
1144ea14e5c3SBrian Feldman.Ed
1145ea14e5c3SBrian Feldman.Bd -literal -offset indent
1146ea14e5c3SBrian Feldmantypedef struct {
1147757686b1SMarcel Moolenaar	Elf64_Word      st_name;
1148ea14e5c3SBrian Feldman	unsigned char   st_info;
1149ea14e5c3SBrian Feldman	unsigned char   st_other;
1150757686b1SMarcel Moolenaar	Elf64_Half      st_shndx;
1151ea14e5c3SBrian Feldman	Elf64_Addr      st_value;
1152757686b1SMarcel Moolenaar	Elf64_Xword     st_size;
1153ea14e5c3SBrian Feldman} Elf64_Sym;
1154ea14e5c3SBrian Feldman.Ed
1155ea14e5c3SBrian Feldman.Pp
1156ea14e5c3SBrian Feldman.Bl -tag -width "st_value" -compact
1157ea14e5c3SBrian Feldman.It Dv st_name
1158ea14e5c3SBrian FeldmanThis member holds an index into the object file's symbol string table,
11594e86fcacSSheldon Hearnwhich holds character representations of the symbol names.
11604e86fcacSSheldon HearnIf the value
1161ea14e5c3SBrian Feldmanis non-zero, it represents a string table index that gives the symbol
11624e86fcacSSheldon Hearnname.
11634e86fcacSSheldon HearnOtherwise, the symbol table has no name.
1164ea14e5c3SBrian Feldman.It Dv st_value
1165ea14e5c3SBrian FeldmanThis member gives the value of the associated symbol.
1166ea14e5c3SBrian Feldman.It Dv st_size
11674e86fcacSSheldon HearnMany symbols have associated sizes.
11684e86fcacSSheldon HearnThis member holds zero if the symbol
1169ea14e5c3SBrian Feldmanhas no size or an unknown size.
1170ea14e5c3SBrian Feldman.It Dv st_info
1171ea14e5c3SBrian FeldmanThis member specifies the symbol's type and binding attributes:
1172ea14e5c3SBrian Feldman.Pp
1173ea14e5c3SBrian Feldman.Bl -tag -width "STT_SECTION" -compact
1174ea14e5c3SBrian Feldman.It Dv STT_NOTYPE
1175ea14e5c3SBrian FeldmanThe symbol's type is not defined.
1176ea14e5c3SBrian Feldman.It Dv STT_OBJECT
1177ea14e5c3SBrian FeldmanThe symbol is associated with a data object.
1178ea14e5c3SBrian Feldman.It Dv STT_FUNC
1179ea14e5c3SBrian FeldmanThe symbol is associated with a function or other executable code.
1180ea14e5c3SBrian Feldman.It Dv STT_SECTION
11814e86fcacSSheldon HearnThe symbol is associated with a section.
11824e86fcacSSheldon HearnSymbol table entries of
1183ea14e5c3SBrian Feldmanthis type exist primarily for relocation and normally have
1184ea14e5c3SBrian Feldman.Sy STB_LOCAL
1185ea14e5c3SBrian Feldmanbindings.
1186ea14e5c3SBrian Feldman.It Dv STT_FILE
1187ea14e5c3SBrian FeldmanBy convention the symbol's name gives the name of the source file
11884e86fcacSSheldon Hearnassociated with the object file.
11894e86fcacSSheldon HearnA file symbol has
1190ea14e5c3SBrian Feldman.Sy STB_LOCAL
1191ea14e5c3SBrian Feldmanbindings, its section index is
1192ea14e5c3SBrian Feldman.Sy SHN_ABS ,
1193ea14e5c3SBrian Feldmanand it precedes the other
1194ea14e5c3SBrian Feldman.Sy STB_LOCAL
1195ea14e5c3SBrian Feldmansymbols of the file, if it is present.
1196ea14e5c3SBrian Feldman.It Dv STT_LOPROC
1197ea14e5c3SBrian FeldmanThis value up to and including
1198ea14e5c3SBrian Feldman.Sy STT_HIPROC
1199ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1200ea14e5c3SBrian Feldman.It Dv STT_HIPROC
1201ea14e5c3SBrian FeldmanThis value down to and including
1202ea14e5c3SBrian Feldman.Sy STT_LOPROC
1203ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1204ea14e5c3SBrian Feldman.El
1205ea14e5c3SBrian Feldman.Pp
1206ea14e5c3SBrian Feldman.Bl -tag -width "STB_GLOBAL" -compact
1207ea14e5c3SBrian Feldman.It Dv STB_LOCAL
1208ea14e5c3SBrian FeldmanLocal symbols are not visible outside the object file containing their
12094e86fcacSSheldon Hearndefinition.
12104e86fcacSSheldon HearnLocal symbols of the same name may exist in multiple file
1211ea14e5c3SBrian Feldmanwithout interfering with each other.
1212ea14e5c3SBrian Feldman.It Dv STB_GLOBAL
12134e86fcacSSheldon HearnGlobal symbols are visible to all object files being combined.
12144e86fcacSSheldon HearnOne file's
1215ea14e5c3SBrian Feldmandefinition of a global symbol will satisfy another file's undefined
1216ea14e5c3SBrian Feldmanreference to the same symbol.
1217ea14e5c3SBrian Feldman.It Dv STB_WEAK
1218ea14e5c3SBrian FeldmanWeak symbols resemble global symbols, but their definitions have lower
1219ea14e5c3SBrian Feldmanprecedence.
1220ea14e5c3SBrian Feldman.It Dv STB_LOPROC
1221ea14e5c3SBrian FeldmanThis value up to and including
1222ea14e5c3SBrian Feldman.Sy STB_HIPROC
1223ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1224ea14e5c3SBrian Feldman.It Dv STB_HIPROC
1225ea14e5c3SBrian FeldmanThis value down to and including
1226ea14e5c3SBrian Feldman.Sy STB_LOPROC
1227ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1228ea14e5c3SBrian Feldman.Pp
1229ea14e5c3SBrian FeldmanThere are macros for packing and unpacking the binding and type fields:
1230d0353b83SRuslan Ermilov.Pp
1231ea14e5c3SBrian Feldman.Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact
1232d0353b83SRuslan Ermilov.It Xo
1233d0353b83SRuslan Ermilov.Fn ELF32_ST_BIND info
1234d0353b83SRuslan Ermilov.Xc
1235ea14e5c3SBrian Feldmanor
1236d0353b83SRuslan Ermilov.Fn ELF64_ST_BIND info
1237f3a2511aSChris Costelloextract a binding from an st_info value.
1238d0353b83SRuslan Ermilov.It Xo
1239d0353b83SRuslan Ermilov.Fn ELF64_ST_TYPE info
1240d0353b83SRuslan Ermilov.Xc
1241ea14e5c3SBrian Feldmanor
1242d0353b83SRuslan Ermilov.Fn ELF32_ST_TYPE info
1243f3a2511aSChris Costelloextract a type from an st_info value.
1244d0353b83SRuslan Ermilov.It Xo
1245d0353b83SRuslan Ermilov.Fn ELF32_ST_INFO bind type
1246d0353b83SRuslan Ermilov.Xc
1247ea14e5c3SBrian Feldmanor
1248d0353b83SRuslan Ermilov.Fn ELF64_ST_INFO bind type
1249f3a2511aSChris Costelloconvert a binding and a type into an st_info value.
1250ea14e5c3SBrian Feldman.El
1251ea14e5c3SBrian Feldman.El
1252ea14e5c3SBrian Feldman.Pp
1253ea14e5c3SBrian Feldman.It Dv st_other
1254ea14e5c3SBrian FeldmanThis member currently holds zero and has no defined meaning.
1255ea14e5c3SBrian Feldman.It Dv st_shndx
1256ea14e5c3SBrian FeldmanEvery symbol table entry is
1257ea14e5c3SBrian Feldman.Dq defined
1258210ad6ebSJoseph Koshyin relation to some section.
12594e86fcacSSheldon HearnThis member holds the relevant section
1260ea14e5c3SBrian Feldmanheader table index.
1261ea14e5c3SBrian Feldman.El
1262ea14e5c3SBrian Feldman.Pp
1263ea14e5c3SBrian FeldmanRelocation is the process of connecting symbolic references with
12644e86fcacSSheldon Hearnsymbolic definitions.
12654e86fcacSSheldon HearnRelocatable files must have information that
1266ea14e5c3SBrian Feldmandescribes how to modify their section contents, thus allowing executable
1267ea14e5c3SBrian Feldmanand shared object files to hold the right information for a process'
12684e86fcacSSheldon Hearnprogram image.
12694e86fcacSSheldon HearnRelocation entries are these data.
1270ea14e5c3SBrian Feldman.Pp
1271ea14e5c3SBrian FeldmanRelocation structures that do not need an addend:
1272ea14e5c3SBrian Feldman.Bd -literal -offset indent
1273ea14e5c3SBrian Feldmantypedef struct {
1274ea14e5c3SBrian Feldman	Elf32_Addr      r_offset;
1275ea14e5c3SBrian Feldman	Elf32_Word      r_info;
1276ea14e5c3SBrian Feldman} Elf32_Rel;
1277ea14e5c3SBrian Feldman.Ed
1278ea14e5c3SBrian Feldman.Bd -literal -offset indent
1279ea14e5c3SBrian Feldmantypedef struct {
1280ea14e5c3SBrian Feldman	Elf64_Addr      r_offset;
1281757686b1SMarcel Moolenaar	Elf64_Xword     r_info;
1282ea14e5c3SBrian Feldman} Elf64_Rel;
1283ea14e5c3SBrian Feldman.Ed
1284ea14e5c3SBrian Feldman.Pp
1285ea14e5c3SBrian FeldmanRelocation structures that need an addend:
1286ea14e5c3SBrian Feldman.Bd -literal -offset indent
1287ea14e5c3SBrian Feldmantypedef struct {
1288ea14e5c3SBrian Feldman	Elf32_Addr      r_offset;
1289ea14e5c3SBrian Feldman	Elf32_Word      r_info;
1290ea14e5c3SBrian Feldman	Elf32_Sword     r_addend;
1291ea14e5c3SBrian Feldman} Elf32_Rela;
1292ea14e5c3SBrian Feldman.Ed
1293ea14e5c3SBrian Feldman.Bd -literal -offset indent
1294ea14e5c3SBrian Feldmantypedef struct {
1295ea14e5c3SBrian Feldman	Elf64_Addr      r_offset;
1296757686b1SMarcel Moolenaar	Elf64_Xword     r_info;
1297757686b1SMarcel Moolenaar	Elf64_Sxword    r_addend;
1298ea14e5c3SBrian Feldman} Elf64_Rela;
1299ea14e5c3SBrian Feldman.Ed
1300ea14e5c3SBrian Feldman.Pp
1301ea14e5c3SBrian Feldman.Bl -tag -width "r_offset" -compact
1302ea14e5c3SBrian Feldman.It Dv r_offset
1303ea14e5c3SBrian FeldmanThis member gives the location at which to apply the relocation action.
1304ea14e5c3SBrian FeldmanFor a relocatable file, the value is the byte offset from the beginning
13054e86fcacSSheldon Hearnof the section to the storage unit affected by the relocation.
13064e86fcacSSheldon HearnFor an
1307ea14e5c3SBrian Feldmanexecutable file or shared object, the value is the virtual address of
1308ea14e5c3SBrian Feldmanthe storage unit affected by the relocation.
1309ea14e5c3SBrian Feldman.It Dv r_info
1310ea14e5c3SBrian FeldmanThis member gives both the symbol table index with respect to which the
13114e86fcacSSheldon Hearnrelocation must be made and the type of relocation to apply.
13124e86fcacSSheldon HearnRelocation
13134e86fcacSSheldon Hearntypes are processor-specific.
13144e86fcacSSheldon HearnWhen the text refers to a relocation
1315ea14e5c3SBrian Feldmanentry's relocation type or symbol table index, it means the result of
1316ea14e5c3SBrian Feldmanapplying
1317ea14e5c3SBrian Feldman.Sy ELF_[32|64]_R_TYPE
1318ea14e5c3SBrian Feldmanor
1319ea14e5c3SBrian Feldman.Sy ELF[32|64]_R_SYM ,
1320ea14e5c3SBrian Feldmanrespectively to the entry's
1321ea14e5c3SBrian Feldman.Sy r_info
1322ea14e5c3SBrian Feldmanmember.
1323ea14e5c3SBrian Feldman.It Dv r_addend
1324ea14e5c3SBrian FeldmanThis member specifies a constant addend used to compute the value to be
1325ea14e5c3SBrian Feldmanstored into the relocatable field.
1326ea14e5c3SBrian Feldman.El
1327311223e0SEd Maste.Ss Note Section
1328202f6d83SEd MasteELF note sections consist of entries with the following format:
1329202f6d83SEd Maste.Bl -column -offset indent "namesz" "32 bits" "Null-terminated originator name"
1330202f6d83SEd Maste.Sy Field       Ta Sy Size    Ta Sy Description
1331202f6d83SEd Maste.It Va namesz   Ta 32 bits    Ta Size of "name"
1332202f6d83SEd Maste.It Va descsz   Ta 32 bits    Ta Size of "desc"
1333202f6d83SEd Maste.It Va type     Ta 32 bits    Ta OS-dependent note type
1334202f6d83SEd Maste.It Va name     Ta Va namesz  Ta Null-terminated originator name
1335202f6d83SEd Maste.It Va desc     Ta Va descsz  Ta OS-dependent note data
1336311223e0SEd Maste.El
1337311223e0SEd Maste.Pp
1338311223e0SEd MasteThe
1339202f6d83SEd Maste.Va name
1340311223e0SEd Masteand
1341202f6d83SEd Maste.Va desc
1342*ffc4f93eSBenedict Reuschlingfields are padded to ensure 4-byte alignment.
1343202f6d83SEd Maste.Va namesz
1344311223e0SEd Masteand
1345202f6d83SEd Maste.Va descsz
1346311223e0SEd Mastespecify the unpadded length.
134751ae1284SEd Maste.Pp
134851ae1284SEd Maste.Fx
134951ae1284SEd Mastedefines the following ELF note types
135051ae1284SEd Maste.Po with corresponding interpretation of
135151ae1284SEd Maste.Va desc Pc :
135251ae1284SEd Maste.Bl -tag -width 4n
135351ae1284SEd Maste.It Dv NT_FREEBSD_ABI_TAG Pq Value: 1
135451ae1284SEd MasteIndicates the OS ABI version in a form of a 32-bit integer containing expected
135551ae1284SEd MasteABI version
135651ae1284SEd Maste.Po i.e.,
135751ae1284SEd Maste.Dv __FreeBSD_version Pc .
135851ae1284SEd Maste.It Dv NT_FREEBSD_NOINIT_TAG Pq Value: 2
13592338bd47SEd MasteIndicates that the C startup does not call initialization routines, and thus
13602338bd47SEd Maste.Xr rtld 1
13612338bd47SEd Mastemust do so.
136251ae1284SEd Maste.Va desc
136351ae1284SEd Masteis ignored.
136451ae1284SEd Maste.It Dv NT_FREEBSD_ARCH_TAG Pq Value: 3
1365ae629006SEd MasteContains the MACHINE_ARCH that the executable was built for.
136651ae1284SEd Maste.It Dv NT_FREEBSD_FEATURE_CTL Pq Value: 4
136751ae1284SEd MasteContains a bitmask of mitigations and features to enable:
1368bf384820SEd Maste.Bl -tag -width 4n
1369bf384820SEd Maste.It NT_FREEBSD_FCTL_ASLR_DISABLE Pq Value: 0x01
1370bf384820SEd MasteRequest that address randomization (ASLR) not be performed.
1371bf384820SEd MasteSee
1372bf384820SEd Maste.Xr security 7 .
1373bf384820SEd Maste.It NT_FREEBSD_FCTL_PROTMAX_DISABLE Pq Value: 0x02
1374bf384820SEd MasteRequest that
1375bf384820SEd Maste.Xr mmap 2
1376bf384820SEd Mastecalls not set PROT_MAX to the initial value of the
1377bf384820SEd Maste.Fa prot
1378bf384820SEd Masteargument.
1379bf384820SEd Maste.It NT_FREEBSD_FCTL_STKGAP_DISABLE Pq Value: 0x04
1380bf384820SEd MasteDisable stack gap.
1381bf384820SEd Maste.It NT_FREEBSD_FCTL_WXNEEDED Pq Value: 0x08
1382bf384820SEd MasteIndicate that the binary requires mappings that are simultaneously
1383bf384820SEd Mastewriteable and executable.
138451ae1284SEd Maste.El
138551ae1284SEd Maste.El
1386ea14e5c3SBrian Feldman.Sh SEE ALSO
1387ea14e5c3SBrian Feldman.Xr as 1 ,
13883c405c7eSJens Schweikhardt.Xr gdb 1 Pq Pa ports/devel/gdb ,
1389ea14e5c3SBrian Feldman.Xr ld 1 ,
1390ea14e5c3SBrian Feldman.Xr objdump 1 ,
1391c647e51fSEd Maste.Xr readelf 1 ,
1392ea14e5c3SBrian Feldman.Xr execve 2 ,
1393e0189cf6SMark Johnston.Xr zlib 3 ,
13946a4b42f0SJoseph Koshy.Xr ar 5 ,
1395ea14e5c3SBrian Feldman.Xr core 5
1396ea14e5c3SBrian Feldman.Rs
1397ea14e5c3SBrian Feldman.%A Hewlett Packard
1398ea14e5c3SBrian Feldman.%B Elf-64 Object File Format
1399ea14e5c3SBrian Feldman.Re
1400ea14e5c3SBrian Feldman.Rs
1401ea14e5c3SBrian Feldman.%A Santa Cruz Operation
1402ea14e5c3SBrian Feldman.%B System V Application Binary Interface
1403ea14e5c3SBrian Feldman.Re
1404ea14e5c3SBrian Feldman.Rs
1405ea14e5c3SBrian Feldman.%A Unix System Laboratories
1406ea14e5c3SBrian Feldman.%T Object Files
1407ea14e5c3SBrian Feldman.%B "Executable and Linking Format (ELF)"
1408ea14e5c3SBrian Feldman.Re
1409ea14e5c3SBrian Feldman.Sh HISTORY
1410ea14e5c3SBrian FeldmanThe ELF header files made their appearance in
1411ea14e5c3SBrian Feldman.Fx 2.2.6 .
1412ea14e5c3SBrian FeldmanELF in itself first appeared in
1413ea14e5c3SBrian Feldman.At V .
1414ea14e5c3SBrian FeldmanThe ELF format is an adopted standard.
1415ea14e5c3SBrian Feldman.Sh AUTHORS
1416ea14e5c3SBrian FeldmanThis manual page was written by
1417a63d6c94SBaptiste Daroussin.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org
1418ed2879a5SRuslan Ermilovwith inspiration from BSDi's
1419ed2879a5SRuslan Ermilov.Bsx
142016e36754SEdward Tomasz Napierala.Nm
1421ea14e5c3SBrian Feldmanmanpage.
1422