xref: /freebsd/share/man/man5/elf.5 (revision f3a2511a25ce33bae3166c730959a167b94fa0eb)
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.\"
25ea14e5c3SBrian Feldman.\"	$FreeBSD$
26ea14e5c3SBrian Feldman.\"
27ea14e5c3SBrian Feldman.Dd July 31, 1999
28ea14e5c3SBrian Feldman.Dt ELF 5
29ea14e5c3SBrian Feldman.Os FreeBSD 3.3
30ea14e5c3SBrian Feldman.Sh NAME
31ea14e5c3SBrian Feldman.Nm elf
32ea14e5c3SBrian Feldman.Nd format of ELF executable binary files
33ea14e5c3SBrian Feldman.Sh SYNOPSIS
34ea14e5c3SBrian Feldman.Fd #include <elf.h>
35ea14e5c3SBrian Feldman.Sh DESCRIPTION
36ea14e5c3SBrian FeldmanThe header file
37ea14e5c3SBrian Feldman.Aq Pa elf.h
38ea14e5c3SBrian Feldmandefines the format of ELF executable binary files. Amongst these files are
39ea14e5c3SBrian Feldmannormal executable files, relocatable object files, core files and shared
40ea14e5c3SBrian Feldmanlibraries.
41ea14e5c3SBrian Feldman.Pp
42ea14e5c3SBrian FeldmanAn executable file using the ELF file format consists of an ELF header,
43ea14e5c3SBrian Feldmanfollowed by a program header table or a section header table, or both.
44ea14e5c3SBrian FeldmanThe ELF header is always at offset zero of the file. The program header
45ea14e5c3SBrian Feldmantable and the section header table's offset in the file are defined in the
46ea14e5c3SBrian FeldmanELF header. The two tables describe the rest of the particularities of
47ea14e5c3SBrian Feldmanthe file.
48ea14e5c3SBrian Feldman.Pp
49ea14e5c3SBrian FeldmanApplications which wish to process ELF binary files for their native
50ea14e5c3SBrian Feldmanarchitecture only should include
51ea14e5c3SBrian Feldman.Pa sys/elf.h
52ea14e5c3SBrian Feldmanin their source code. These applications should need to refer to
53ea14e5c3SBrian Feldmanall the types and structures by their generic names
54ea14e5c3SBrian Feldman.Dq Elf_xxx
55ea14e5c3SBrian Feldmanand to the macros by
56ea14e5c3SBrian Feldman.Dq ELF_xxx .
57ea14e5c3SBrian FeldmanApplications written this way can be compiled on any architecture,
58ea14e5c3SBrian Feldmanregardless whether the host is 32-bit or 64-bit.
59ea14e5c3SBrian Feldman.Pp
60ea14e5c3SBrian FeldmanShould an application need to process ELF files of an unknown
61ea14e5c3SBrian Feldmanarchitecture then the application needs to include both
62ea14e5c3SBrian Feldman.Pa sys/elf32.h
63ea14e5c3SBrian Feldmanand
64ea14e5c3SBrian Feldman.Pa sys/elf64.h
65ea14e5c3SBrian Feldmaninstead of
66ea14e5c3SBrian Feldman.Pa sys/elf.h .
67ea14e5c3SBrian FeldmanFurthermore, all types and structures need to be identified by either
68ea14e5c3SBrian Feldman.Dq Elf32_xxx
69ea14e5c3SBrian Feldmanor
70ea14e5c3SBrian Feldman.Dq Elf64_xxx .
71ea14e5c3SBrian FeldmanThe macros need to be identified by
72ea14e5c3SBrian Feldman.Dq ELF32_xxx
73ea14e5c3SBrian Feldmanor
74ea14e5c3SBrian Feldman.Dq ELF64_xxx .
75ea14e5c3SBrian Feldman.Pp
76ea14e5c3SBrian FeldmanWhatever the system's architecture is, it will always include
77ea14e5c3SBrian Feldman.Pa sys/elf_common.h
78ea14e5c3SBrian Feldmanas well as
79ea14e5c3SBrian Feldman.Pa sys/elf_generic.h .
80ea14e5c3SBrian Feldman.Pp
81ea14e5c3SBrian FeldmanThese header files describe the above mentioned headers as C structures
82ea14e5c3SBrian Feldmanand also include structures for dynamic sections, relocation sections and
83ea14e5c3SBrian Feldmansymbol tables.
84ea14e5c3SBrian Feldman.Pp
85ea14e5c3SBrian FeldmanThe following types are being used for 32-bit architectures:
86ea14e5c3SBrian Feldman.Bd -literal -offset indent
87ea14e5c3SBrian FeldmanElf32_Addr	Unsigned program address
88ea14e5c3SBrian FeldmanElf32_Half	Unsigned halfword field
89ea14e5c3SBrian FeldmanElf32_Off	Unsigned file offset
90ea14e5c3SBrian FeldmanElf32_Sword	Signed large integer
91ea14e5c3SBrian FeldmanElf32_Word	Field or unsigned large integer
92ea14e5c3SBrian FeldmanElf32_Size	Unsigned object size
93ea14e5c3SBrian Feldman.Ed
94ea14e5c3SBrian Feldman.Pp
95ea14e5c3SBrian FeldmanFor 64-bit architectures we have the following types:
96ea14e5c3SBrian Feldman.Bd -literal -offset indent
97ea14e5c3SBrian FeldmanElf64_Addr	Unsigned program address
98ea14e5c3SBrian FeldmanElf64_Half	Unsigned halfword field
99ea14e5c3SBrian FeldmanElf64_Off	Unsigned file offset
100ea14e5c3SBrian FeldmanElf64_Sword	Signed large integer
101ea14e5c3SBrian FeldmanElf64_Word	Field or unsigned large integer
102ea14e5c3SBrian FeldmanElf64_Size	Unsigned object size
103ea14e5c3SBrian FeldmanElf64_Quarter	Unsigned quarterword field
104ea14e5c3SBrian Feldman.Ed
105ea14e5c3SBrian Feldman.Pp
106ea14e5c3SBrian FeldmanAll data structures that the file format defines follow the
107ea14e5c3SBrian Feldman.Dq natural
108ea14e5c3SBrian Feldmansize and alignment guidelines for the relevant class. If necessary,
109ea14e5c3SBrian Feldmandata structures contain explicit padding to ensure 4-byte alignment
110ea14e5c3SBrian Feldmanfor 4-byte objects, to force structure sizes to a multiple of 4, etc.
111ea14e5c3SBrian Feldman.Pp
112ea14e5c3SBrian FeldmanThe ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
113ea14e5c3SBrian Feldman.Bd -literal -offset indent
114ea14e5c3SBrian Feldmantypedef struct {
115ea14e5c3SBrian Feldman        unsigned char   e_ident[EI_NIDENT];
116ea14e5c3SBrian Feldman        Elf32_Half      e_type;
117ea14e5c3SBrian Feldman        Elf32_Half      e_machine;
118ea14e5c3SBrian Feldman        Elf32_Word      e_version;
119ea14e5c3SBrian Feldman        Elf32_Addr      e_entry;
120ea14e5c3SBrian Feldman        Elf32_Off       e_phoff;
121ea14e5c3SBrian Feldman        Elf32_Off       e_shoff;
122ea14e5c3SBrian Feldman        Elf32_Word      e_flags;
123ea14e5c3SBrian Feldman        Elf32_Half      e_ehsize;
124ea14e5c3SBrian Feldman        Elf32_Half      e_phentsize;
125ea14e5c3SBrian Feldman        Elf32_Half      e_phnum;
126ea14e5c3SBrian Feldman        Elf32_Half      e_shentsize;
127ea14e5c3SBrian Feldman        Elf32_Half      e_shnum;
128ea14e5c3SBrian Feldman        Elf32_Half      e_shstrndx;
129ea14e5c3SBrian Feldman} Elf32_Ehdr;
130ea14e5c3SBrian Feldman.Ed
131ea14e5c3SBrian Feldman.Pp
132ea14e5c3SBrian Feldman.Bd -literal -offset indent
133ea14e5c3SBrian Feldmantypedef struct {
134ea14e5c3SBrian Feldman	unsigned char   e_ident[EI_NIDENT];
135ea14e5c3SBrian Feldman	Elf64_Quarter   e_type;
136ea14e5c3SBrian Feldman	Elf64_Quarter   e_machine;
137ea14e5c3SBrian Feldman	Elf64_Half      e_version;
138ea14e5c3SBrian Feldman	Elf64_Addr      e_entry;
139ea14e5c3SBrian Feldman	Elf64_Off       e_phoff;
140ea14e5c3SBrian Feldman	Elf64_Off       e_shoff;
141ea14e5c3SBrian Feldman	Elf64_Half      e_flags;
142ea14e5c3SBrian Feldman	Elf64_Quarter   e_ehsize;
143ea14e5c3SBrian Feldman	Elf64_Quarter   e_phentsize;
144ea14e5c3SBrian Feldman	Elf64_Quarter   e_phnum;
145ea14e5c3SBrian Feldman	Elf64_Quarter   e_shentsize;
146ea14e5c3SBrian Feldman	Elf64_Quarter   e_shnum;
147ea14e5c3SBrian Feldman	Elf64_Quarter   e_shstrndx;
148ea14e5c3SBrian Feldman} Elf64_Ehdr;
149ea14e5c3SBrian Feldman.Ed
150ea14e5c3SBrian Feldman.Pp
151ea14e5c3SBrian FeldmanThe fields have the following meanings:
152ea14e5c3SBrian Feldman.Pp
153ea14e5c3SBrian Feldman.Bl -tag -width "e_phentsize" -compact -offset indent
154ea14e5c3SBrian Feldman.It Dv e_ident
155ea14e5c3SBrian FeldmanThis array of bytes specifies to interpret the file,
156ea14e5c3SBrian Feldmanindependent of the processor or the file's remaining contents.
157ea14e5c3SBrian FeldmanWithin this array everything is named by macros, which start with
158ea14e5c3SBrian Feldmanthe prefix
159ea14e5c3SBrian Feldman.Sy EI_
160ea14e5c3SBrian Feldmanand may contain values which start with the prefix
161ea14e5c3SBrian Feldman.Sy ELF .
162ea14e5c3SBrian FeldmanThe following macros are defined:
163ea14e5c3SBrian Feldman.Pp
164ea14e5c3SBrian Feldman.Bl -tag -width "EI_VERSION" -compact
165ea14e5c3SBrian Feldman.It Dv EI_MAG0
166ea14e5c3SBrian FeldmanThe first byte of the magic number. It must be filled with
167ea14e5c3SBrian Feldman.Sy ELFMAG0 .
168ea14e5c3SBrian Feldman.It Dv EI_MAG1
169ea14e5c3SBrian FeldmanThe second byte of the magic number. It must be filled with
170ea14e5c3SBrian Feldman.Sy ELFMAG1 .
171ea14e5c3SBrian Feldman.It Dv EI_MAG2
172ea14e5c3SBrian FeldmanThe third byte of the magic number. It must be filled with
173ea14e5c3SBrian Feldman.Sy ELFMAG2 .
174ea14e5c3SBrian Feldman.It Dv EI_MAG3
175ea14e5c3SBrian FeldmanThe fourth byte of the magic number. It must be filled with
176ea14e5c3SBrian Feldman.Sy ELFMAG3 .
177ea14e5c3SBrian Feldman.It Dv EI_CLASS
178ea14e5c3SBrian FeldmanThe fifth byte identifies the architecture for this binary:
179ea14e5c3SBrian Feldman.Pp
180ea14e5c3SBrian Feldman.Bl -tag -width "ELFCLASSNONE" -compact
181ea14e5c3SBrian Feldman.It Dv ELFCLASSNONE
182ea14e5c3SBrian FeldmanThis class is invalid.
183ea14e5c3SBrian Feldman.It Dv ELFCLASS32
184ea14e5c3SBrian FeldmanThis defines the 32-bit architecture. It supports machines with files
185ea14e5c3SBrian Feldmanand virtual address spaces up to 4 Gigabytes.
186ea14e5c3SBrian Feldman.It Dv ELFCLASS64
187ea14e5c3SBrian FeldmanThis defines the 64-bit architecture.
188ea14e5c3SBrian Feldman.El
189ea14e5c3SBrian Feldman.It Dv EI_DATA
190ea14e5c3SBrian FeldmanThe sixth byte specifies the data encoding of the processor-specific
191ea14e5c3SBrian Feldmandata in the file. Currently these encodings are supported:
192ea14e5c3SBrian Feldman.Pp
193ea14e5c3SBrian Feldman.Bl -tag -width "ELFDATA2LSB" -compact
194ea14e5c3SBrian Feldman.It Dv ELFDATANONE
195ea14e5c3SBrian FeldmanUnknown data format.
196ea14e5c3SBrian Feldman.It Dv ELFDATA2LSB
197ea14e5c3SBrian FeldmanTwo's complement, little-endian.
198ea14e5c3SBrian Feldman.It Dv ELFDATA2MSB
199ea14e5c3SBrian FeldmanTwo's complement, big-endian.
200ea14e5c3SBrian Feldman.El
201ea14e5c3SBrian Feldman.It Dv EI_VERSION
202ea14e5c3SBrian FeldmanThe version number of the ELF specification:
203ea14e5c3SBrian Feldman.Pp
204ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact
205ea14e5c3SBrian Feldman.It Dv EV_NONE
206ea14e5c3SBrian FeldmanInvalid version.
207ea14e5c3SBrian Feldman.It Dv EV_CURRENT
208ea14e5c3SBrian FeldmanCurrent version.
209ea14e5c3SBrian Feldman.El
210ea14e5c3SBrian Feldman.It Dv EI_PAD
211ea14e5c3SBrian FeldmanStart of padding. These bytes are reserved and set to zero. Programs
212ea14e5c3SBrian Feldmanwhich read them should ignore them. The value for EI_PAD will change in
213ea14e5c3SBrian Feldmanthe future if currently unused bytes are given meanings.
214ea14e5c3SBrian Feldman.It Dv EI_BRAND
215ea14e5c3SBrian FeldmanStart of architecture identification.
216ea14e5c3SBrian Feldman.It Dv EI_NIDENT
217ea14e5c3SBrian FeldmanThe size of the e_ident array.
218ea14e5c3SBrian Feldman.El
219ea14e5c3SBrian Feldman.Pp
220ea14e5c3SBrian Feldman.It Dv e_type
221ea14e5c3SBrian FeldmanThis member of the structure identifies the object file type:
222ea14e5c3SBrian Feldman.Pp
223ea14e5c3SBrian Feldman.Bl -tag -width "ET_NONE" -compact
224ea14e5c3SBrian Feldman.It Dv ET_NONE
225ea14e5c3SBrian FeldmanAn unknown type.
226ea14e5c3SBrian Feldman.It Dv ET_REL
227ea14e5c3SBrian FeldmanA relocatable file.
228ea14e5c3SBrian Feldman.It Dv ET_EXEC
229ea14e5c3SBrian FeldmanAn executable file.
230ea14e5c3SBrian Feldman.It Dv ET_DYN
231ea14e5c3SBrian FeldmanA shared object.
232ea14e5c3SBrian Feldman.It Dv ET_CORE
233ea14e5c3SBrian FeldmanA core file.
234ea14e5c3SBrian Feldman.El
235ea14e5c3SBrian Feldman.Pp
236ea14e5c3SBrian Feldman.It Dv e_machine
237ea14e5c3SBrian FeldmanThis member specifies the required architecture for an individual file:
238ea14e5c3SBrian Feldman.Pp
239ea14e5c3SBrian Feldman.Bl -tag -width "EM_MIPS_RS4_BE" -compact
240ea14e5c3SBrian Feldman.It Dv EM_NONE
241ea14e5c3SBrian FeldmanAn unknown machine.
242ea14e5c3SBrian Feldman.It Dv EM_M32
243ea14e5c3SBrian FeldmanAT&T WE 32100.
244ea14e5c3SBrian Feldman.It Dv EM_SPARC
245ea14e5c3SBrian FeldmanSun Microsystems SPARC.
246ea14e5c3SBrian Feldman.It Dv EM_386
247ea14e5c3SBrian FeldmanIntel 80386.
248ea14e5c3SBrian Feldman.It Dv EM_68K
249ea14e5c3SBrian FeldmanMotorola 68000.
250ea14e5c3SBrian Feldman.It Dv EM_88K
251ea14e5c3SBrian FeldmanMotorola 88000.
252ea14e5c3SBrian Feldman.It Dv EM_486
253ea14e5c3SBrian FeldmanIntel 80486.
254ea14e5c3SBrian Feldman.It Dv EM_860
255ea14e5c3SBrian FeldmanIntel 80860.
256ea14e5c3SBrian Feldman.It Dv EM_MIPS
257ea14e5c3SBrian FeldmanMIPS RS3000 (big-endian only).
258ea14e5c3SBrian Feldman.It Dv EM_MIPS_RS4_BE
259ea14e5c3SBrian FeldmanMIPS RS4000 (big-endian only).
260ea14e5c3SBrian Feldman.It Dv EM_SPARC64
261ea14e5c3SBrian FeldmanSPARC v9 64-bit unofficial.
262ea14e5c3SBrian Feldman.It Dv EM_PARISC
263ea14e5c3SBrian FeldmanHPPA.
264ea14e5c3SBrian Feldman.It Dv EM_PPC
265ea14e5c3SBrian FeldmanPowerPC.
266ea14e5c3SBrian Feldman.It Dv EM_ALPHA
267ea14e5c3SBrian FeldmanCompaq [DEC] Alpha.
268ea14e5c3SBrian Feldman.El
269ea14e5c3SBrian Feldman.Pp
270ea14e5c3SBrian Feldman.It Dv e_version
271ea14e5c3SBrian FeldmanThis member identifies the file version:
272ea14e5c3SBrian Feldman.Pp
273ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact
274ea14e5c3SBrian Feldman.It Dv EV_NONE
275ea14e5c3SBrian FeldmanInvalid version
276ea14e5c3SBrian Feldman.It Dv EV_CURRENT
277ea14e5c3SBrian FeldmanCurrent version
278ea14e5c3SBrian Feldman.El
279ea14e5c3SBrian Feldman.It Dv e_entry
280ea14e5c3SBrian FeldmanThis member gives the virtual address to which the system first transfers
281ea14e5c3SBrian Feldmancontrol, thus starting the process. If the file has no associated entry
282ea14e5c3SBrian Feldmanpoint, this member holds zero.
283ea14e5c3SBrian Feldman.It Dv e_phoff
284ea14e5c3SBrian FeldmanThis member holds the program header table's file offset in bytes. If
285ea14e5c3SBrian Feldmanthe file has no program header table, this member holds zero.
286ea14e5c3SBrian Feldman.It Dv e_shoff
287ea14e5c3SBrian FeldmanThis member holds the section header table's file offset in bytes. If the
288ea14e5c3SBrian Feldmanfile has no section header table this member holds zero.
289ea14e5c3SBrian Feldman.It Dv e_flags
290ea14e5c3SBrian FeldmanThis member holds processor-specific flags associated with the file. Flag
291ea14e5c3SBrian Feldmannames take the form EF_`machine_flag'. Currently no flags have been defined.
292ea14e5c3SBrian Feldman.It Dv e_ehsize
293ea14e5c3SBrian FeldmanThis member holds the ELF header's size in bytes.
294ea14e5c3SBrian Feldman.It Dv e_phentsize
295ea14e5c3SBrian FeldmanThis member holds the size in bytes of one entry in the file's program header
296ea14e5c3SBrian Feldmantable; all entries are the same size.
297ea14e5c3SBrian Feldman.It Dv e_phnum
298f3a2511aSChris CostelloThis member holds the number of entries in the program header
299ea14e5c3SBrian Feldmantable. Thus the product of
300ea14e5c3SBrian Feldman.Sy e_phentsize
301ea14e5c3SBrian Feldmanand
302ea14e5c3SBrian Feldman.Sy e_phnum
303ea14e5c3SBrian Feldmangives the table's size
304ea14e5c3SBrian Feldmanin bytes. If a file has no program header,
305ea14e5c3SBrian Feldman.Sy e_phnum
306ea14e5c3SBrian Feldmanholds the value zero.
307ea14e5c3SBrian Feldman.It Dv e_shentsize
308ea14e5c3SBrian FeldmanThis member holds a sections header's size in bytes. A section header is one
309ea14e5c3SBrian Feldmanentry in the section header table; all entries are the same size.
310ea14e5c3SBrian Feldman.It Dv e_shnum
311ea14e5c3SBrian FeldmanThis member holds the number of entries in the section header table. Thus
312ea14e5c3SBrian Feldmanthe product of
313ea14e5c3SBrian Feldman.Sy e_shentsize
314ea14e5c3SBrian Feldmanand
315ea14e5c3SBrian Feldman.Sy e_shnum
316ea14e5c3SBrian Feldmangives the section header table's size in bytes. If a file has no section
317ea14e5c3SBrian Feldmanheader table,
318ea14e5c3SBrian Feldman.Sy e_shnum
319ea14e5c3SBrian Feldmanholds the value of zero.
320ea14e5c3SBrian Feldman.It Dv e_shstrndx
321ea14e5c3SBrian FeldmanThis member holds the section header table index of the entry associated
322ea14e5c3SBrian Feldmanwith the section name string table. If the file has no section name string
323ea14e5c3SBrian Feldmantable, this member holds the value
324ea14e5c3SBrian Feldman.Sy SHN_UNDEF .
325ea14e5c3SBrian Feldman.Pp
326ea14e5c3SBrian Feldman.Bl -tag -width "SHN_LORESERVE" -compact
327ea14e5c3SBrian Feldman.It Dv SHN_UNDEF
328ea14e5c3SBrian FeldmanThis value marks an undefined, missing, irrelevant, or otherwise meaningless
329ea14e5c3SBrian Feldmansection reference. For example, a symbol
330ea14e5c3SBrian Feldman.Dq defined
331ea14e5c3SBrian Feldmanrelative to section number
332ea14e5c3SBrian Feldman.Sy SHN_UNDEF
333ea14e5c3SBrian Feldmanis an undefined symbol.
334ea14e5c3SBrian Feldman.It Dv SHN_LORESERVE
335ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of reserved indexes.
336ea14e5c3SBrian Feldman.It Dv SHN_LOPROC
337ea14e5c3SBrian FeldmanThis value up to and including
338ea14e5c3SBrian Feldman.Sy SHN_HIPROC
339ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
340ea14e5c3SBrian Feldman.It Dv SHN_HIPROC
341ea14e5c3SBrian FeldmanThis value down to and including
342ea14e5c3SBrian Feldman.Sy SHN_LOPROC
343ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
344ea14e5c3SBrian Feldman.It Dv SHN_ABS
345ea14e5c3SBrian FeldmanThis value specifies absolute values for the corresponding reference. For
346ea14e5c3SBrian Feldmanexample, symbols defined relative to section number
347ea14e5c3SBrian Feldman.Sy SHN_ABS
348ea14e5c3SBrian Feldmanhave absolute values and are not affected by relocation.
349ea14e5c3SBrian Feldman.It Dv SHN_COMMON
350ea14e5c3SBrian FeldmanSymbols defined relative to this section are common symbols, such as Fortran
351ea14e5c3SBrian FeldmanCOMMON or unallocated C external variables.
352ea14e5c3SBrian Feldman.It Dv SHN_HIRESERVE
353ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of the range of reserved
354ea14e5c3SBrian Feldmanindices between
355ea14e5c3SBrian Feldman.Sy SHN_LORESERVE
356ea14e5c3SBrian Feldmanand
357ea14e5c3SBrian Feldman.Sy SHN_HIRESERVE ,
358ea14e5c3SBrian Feldmaninclusive; the values do
359ea14e5c3SBrian Feldmannot reference the section header table. That is, the section header table
360ea14e5c3SBrian Feldmandoes
361ea14e5c3SBrian Feldman.Em not
362ea14e5c3SBrian Feldmancontain entries for the reserved indices.
363ea14e5c3SBrian Feldman.El
364ea14e5c3SBrian Feldman.El
365ea14e5c3SBrian Feldman.Pp
366ea14e5c3SBrian FeldmanAn executable or shared object file's program header table is an array of
367ea14e5c3SBrian Feldmanstructures, each describing a segment or other information the system needs
368ea14e5c3SBrian Feldmanto prepare the program for execution. An object file
369ea14e5c3SBrian Feldman.Em segment
370ea14e5c3SBrian Feldmancontains one or more
371ea14e5c3SBrian Feldman.Em sections .
372ea14e5c3SBrian FeldmanProgram headers are meaningful only for executable and shared object files.
373ea14e5c3SBrian FeldmanA file specifies its own program header size with the ELF header's
374ea14e5c3SBrian Feldman.Sy e_phentsize
375ea14e5c3SBrian Feldmanand
376ea14e5c3SBrian Feldman.Sy e_phnum
377ea14e5c3SBrian Feldmanmembers. As with the Elf executable header, the program header
378ea14e5c3SBrian Feldmanalso has different versions depending on the architecture:
379ea14e5c3SBrian Feldman.Pp
380ea14e5c3SBrian Feldman.Bd -literal -offset indent
381ea14e5c3SBrian Feldmantypedef struct {
382ea14e5c3SBrian Feldman        Elf32_Word      p_type;
383ea14e5c3SBrian Feldman        Elf32_Off       p_offset;
384ea14e5c3SBrian Feldman        Elf32_Addr      p_vaddr;
385ea14e5c3SBrian Feldman        Elf32_Addr      p_paddr;
386ea14e5c3SBrian Feldman        Elf32_Size      p_filesz;
387ea14e5c3SBrian Feldman        Elf32_Size      p_memsz;
388ea14e5c3SBrian Feldman        Elf32_Word      p_flags;
389ea14e5c3SBrian Feldman        Elf32_Size      p_align;
390ea14e5c3SBrian Feldman} Elf32_Phdr;
391ea14e5c3SBrian Feldman.Ed
392ea14e5c3SBrian Feldman.Pp
393ea14e5c3SBrian Feldman.Bd -literal -offset indent
394ea14e5c3SBrian Feldmantypedef struct {
395ea14e5c3SBrian Feldman        Elf64_Half      p_type;
396ea14e5c3SBrian Feldman        Elf64_Half      p_flags;
397ea14e5c3SBrian Feldman        Elf64_Off       p_offset;
398ea14e5c3SBrian Feldman        Elf64_Addr      p_vaddr;
399ea14e5c3SBrian Feldman        Elf64_Addr      p_paddr;
400ea14e5c3SBrian Feldman        Elf64_Size      p_filesz;
401ea14e5c3SBrian Feldman        Elf64_Size      p_memsz;
402ea14e5c3SBrian Feldman        Elf64_Size      p_align;
403ea14e5c3SBrian Feldman} Elf64_Phdr;
404ea14e5c3SBrian Feldman.Ed
405ea14e5c3SBrian Feldman.Pp
406ea14e5c3SBrian FeldmanThe main difference between the 32-bit and the 64-bit program header lies
407ea14e5c3SBrian Feldmanonly in the location of a
408ea14e5c3SBrian Feldman.Sy p_flags
409ea14e5c3SBrian Feldmanmember in the total struct.
410ea14e5c3SBrian Feldman.Pp
411ea14e5c3SBrian Feldman.Bl -tag -width "p_offset" -compact -offset indent
412ea14e5c3SBrian Feldman.It Dv p_type
413ea14e5c3SBrian FeldmanThis member of the Phdr struct tells what kind of segment this array
414ea14e5c3SBrian Feldmanelement describes or how to interpret the array element's information.
415ea14e5c3SBrian Feldman.Bl -tag -width "PT_DYNAMIC" -compact
416ea14e5c3SBrian Feldman.Pp
417ea14e5c3SBrian Feldman.It Dv PT_NULL
418ea14e5c3SBrian FeldmanThe array element is unused and the other members' values are undefined.
419ea14e5c3SBrian FeldmanThis lets the program header have ignored entries.
420ea14e5c3SBrian Feldman.It Dv PT_LOAD
421ea14e5c3SBrian FeldmanThe array element specifies a loadable segment, described by
422ea14e5c3SBrian Feldman.Sy p_filesz
423ea14e5c3SBrian Feldmanand
424ea14e5c3SBrian Feldman.Sy p_memsz .
425ea14e5c3SBrian FeldmanThe bytes from the file are mapped to the beginning of the memory
426ea14e5c3SBrian Feldmansegment. If the segment's memory size (
427ea14e5c3SBrian Feldman.Sy p_memsz
428ea14e5c3SBrian Feldman) is larger than the file
429ea14e5c3SBrian Feldmansize (
430ea14e5c3SBrian Feldman.Sy p_filesz
431ea14e5c3SBrian Feldman), the
432ea14e5c3SBrian Feldman.Dq extra
433ea14e5c3SBrian Feldmanbytes are defined to hold the value 0 and to follow the segment's
4340757c960SBrian Feldmaninitialized area. The file size may not be larger than the memory size.
435ea14e5c3SBrian FeldmanLoadable segment entries in the program header table appear in ascending
436ea14e5c3SBrian Feldmanorder, sorted on the
437ea14e5c3SBrian Feldman.Sy p_vaddr
438ea14e5c3SBrian Feldmanmember.
439ea14e5c3SBrian Feldman.It Dv PT_DYNAMIC
440ea14e5c3SBrian FeldmanThe array element specifies dynamic linking information.
441ea14e5c3SBrian Feldman.It Dv PT_INTERP
442ea14e5c3SBrian FeldmanThe array element specifies the location and size of a null-terminated
443ea14e5c3SBrian Feldmanpath name to invoke as an interpreter. This segment type is meaningful
444ea14e5c3SBrian Feldmanonly for executable files (though it may occur for shared objects). However
445ea14e5c3SBrian Feldmanit may not occur more than once in a file. If it is present it must precede
446ea14e5c3SBrian Feldmanany loadable segment entry.
447ea14e5c3SBrian Feldman.It Dv PT_NOTE
448ea14e5c3SBrian FeldmanThe array element specifies the location and size for auxiliary information.
449ea14e5c3SBrian Feldman.It Dv PT_SHLIB
450ea14e5c3SBrian FeldmanThis segment type is reserved but has unspecified semantics. Programs that
451ea14e5c3SBrian Feldmancontain an array element of this type do not conform to the ABI.
452ea14e5c3SBrian Feldman.It Dv PT_PHDR
453ea14e5c3SBrian FeldmanThe array element, if present, specifies the location and size of the program
454ea14e5c3SBrian Feldmanheader table itself, both in the file and in the memory image of the program.
455ea14e5c3SBrian FeldmanThis segment type may not occur more than once in a file. Moreover, it may
456ea14e5c3SBrian Feldmanonly occur if the program header table is part of the memory image of the
457ea14e5c3SBrian Feldmanprogram. If it is present it must precede any loadable segment entry.
458ea14e5c3SBrian Feldman.It Dv PT_LOPROC
459ea14e5c3SBrian FeldmanThis value up to and including
460ea14e5c3SBrian Feldman.Sy PT_HIPROC
461ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
462ea14e5c3SBrian Feldman.It Dv PT_HIPROC
463ea14e5c3SBrian FeldmanThis value down to and including
464ea14e5c3SBrian Feldman.Sy PT_LOPROC
465ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
466ea14e5c3SBrian Feldman.El
467ea14e5c3SBrian Feldman.Pp
468ea14e5c3SBrian Feldman.It Dv p_offset
469ea14e5c3SBrian FeldmanThis member holds the offset from the beginning of the file at which
470ea14e5c3SBrian Feldmanthe first byte of the of the segment resides.
471ea14e5c3SBrian Feldman.It Dv p_vaddr
472ea14e5c3SBrian FeldmanThis member holds the virtual address at which the first byte of the
473ea14e5c3SBrian Feldmansegment resides in memory.
474ea14e5c3SBrian Feldman.It Dv p_paddr
475ea14e5c3SBrian FeldmanOn systems for which physical addressing is relevant, this member is
476ea14e5c3SBrian Feldmanreserved for the segment's physical address. Under BSD this member is
477ea14e5c3SBrian Feldmannot used and must be zero.
478ea14e5c3SBrian Feldman.It Dv p_filesz
479ea14e5c3SBrian FeldmanThis member holds the number of bytes in the file image of the segment.
480ea14e5c3SBrian FeldmanIt may be zero.
481ea14e5c3SBrian Feldman.It Dv p_memsz
482ea14e5c3SBrian FeldmanThis member holds the number of bytes in the memory image of the segment.
483ea14e5c3SBrian FeldmanIt may be zero.
484ea14e5c3SBrian Feldman.It Dv p_flags
485ea14e5c3SBrian FeldmanThis member holds flags relevant to the segment:
486ea14e5c3SBrian Feldman.Pp
487ea14e5c3SBrian Feldman.Bl -tag -width "PF_X" -compact
488ea14e5c3SBrian Feldman.It Dv PF_X
489ea14e5c3SBrian FeldmanAn executable segment.
490ea14e5c3SBrian Feldman.It Dv PF_W
491ea14e5c3SBrian FeldmanA writable segment.
492ea14e5c3SBrian Feldman.It Dv PF_R
493ea14e5c3SBrian FeldmanA readable segment.
494ea14e5c3SBrian Feldman.El
495ea14e5c3SBrian Feldman.Pp
496ea14e5c3SBrian FeldmanA text segment commonly has the flags
497ea14e5c3SBrian Feldman.Sy PF_X
498ea14e5c3SBrian Feldmanand
499ea14e5c3SBrian Feldman.SY PF_R .
500ea14e5c3SBrian FeldmanA data segment commonly has
501ea14e5c3SBrian Feldman.Sy PF_X ,
502ea14e5c3SBrian Feldman.Sy PF_W
503ea14e5c3SBrian Feldmanand
504ea14e5c3SBrian Feldman.Sy PF_R .
505ea14e5c3SBrian Feldman.It Dv p_align
506ea14e5c3SBrian FeldmanThis member holds the value to which the segments are aligned in memory
507ea14e5c3SBrian Feldmanand in the file. Loadable process segments must have congruent values for
508ea14e5c3SBrian Feldman.Sy p_vaddr
509ea14e5c3SBrian Feldmanand
510ea14e5c3SBrian Feldman.Sy p_offset ,
511ea14e5c3SBrian Feldmanmodulo the page size. Values of zero and one mean no alignment is required.
512ea14e5c3SBrian FeldmanOtherwise,
513ea14e5c3SBrian Feldman.Sy p_align
514ea14e5c3SBrian Feldmanshould be a positive, integral power of two, and
515ea14e5c3SBrian Feldman.Sy p_vaddr
516ea14e5c3SBrian Feldmanshould equal
517ea14e5c3SBrian Feldman.Sy p_offset ,
518ea14e5c3SBrian Feldmanmodulo
519ea14e5c3SBrian Feldman.Sy p_align .
520ea14e5c3SBrian Feldman.El
521ea14e5c3SBrian Feldman.Pp
522ea14e5c3SBrian FeldmanAn file's section header table lets one locate all the file's sections. The
523ea14e5c3SBrian Feldmansection header table is an array of Elf32_Shdr or Elf64_Shdr structures. The
524ea14e5c3SBrian FeldmanELF header's
525ea14e5c3SBrian Feldman.Sy e_shoff
526ea14e5c3SBrian Feldmanmember gives the byte offset from the beginning of the file to the section
527ea14e5c3SBrian Feldmanheader table.
528ea14e5c3SBrian Feldman.Sy e_shnum
529ea14e5c3SBrian Feldmanholds the number of entries the section header table contains.
530ea14e5c3SBrian Feldman.Sy e_shentsize
531ea14e5c3SBrian Feldmanholds the size in bytes of each entry.
532ea14e5c3SBrian Feldman.Pp
533ea14e5c3SBrian FeldmanA section header table index is a subscript into this array. Some section
534ea14e5c3SBrian Feldmanheader table indices are reserved. An object file does not have sections for
535ea14e5c3SBrian Feldmanthese special indices:
536ea14e5c3SBrian Feldman.Pp
537ea14e5c3SBrian Feldman.Bl -tag -width "SHN_LORESERVE" -compact
538ea14e5c3SBrian Feldman.It Dv SHN_UNDEF
539ea14e5c3SBrian FeldmanThis value marks an undefined, missing, irrelevant or otherwise meaningless
540ea14e5c3SBrian Feldmansection reference.
541ea14e5c3SBrian Feldman.It Dv SHN_LORESERVE
542ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of reserved indices.
543ea14e5c3SBrian Feldman.It Dv SHN_LOPROC
544ea14e5c3SBrian FeldmanThis value up to and including
545ea14e5c3SBrian Feldman.Sy SHN_HIPROC
546ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
547ea14e5c3SBrian Feldman.It Dv SHN_HIPROC
548ea14e5c3SBrian FeldmanThis value down to and including
549ea14e5c3SBrian Feldman.Sy SHN_LOPROC
550ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
551ea14e5c3SBrian Feldman.It Dv SHN_ABS
552ea14e5c3SBrian FeldmanThis value specifies absolute values for the corresponding reference. For
553ea14e5c3SBrian Feldmanexample, symbols defined relative to section number
554ea14e5c3SBrian Feldman.Sy SHN_ABS
555ea14e5c3SBrian Feldmanhave absolute values and are not affected by relocation.
556ea14e5c3SBrian Feldman.It Dv SHN_COMMON
557ea14e5c3SBrian FeldmanSymbols defined relative to this section are common symbols, such as FORTRAN
558ea14e5c3SBrian FeldmanCOMMON or unallocated C external variables.
559ea14e5c3SBrian Feldman.It Dv SHN_HIRESERVE
560ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of reserved indices. The
561ea14e5c3SBrian Feldmansystem reserves indices between
562ea14e5c3SBrian Feldman.Sy SHN_LORESERVE
563ea14e5c3SBrian Feldmanand
564ea14e5c3SBrian Feldman.Sy SHN_HIRESERVE,
565ea14e5c3SBrian Feldmaninclusive. The section header table does not contain entries for the
566ea14e5c3SBrian Feldmanreserved indices.
567ea14e5c3SBrian Feldman.El
568ea14e5c3SBrian Feldman.Pp
569ea14e5c3SBrian FeldmanThe section header has the following structure:
570ea14e5c3SBrian Feldman.Bd -literal -offset indent
571ea14e5c3SBrian Feldmantypedef struct {
572ea14e5c3SBrian Feldman	Elf32_Word      sh_name;
573ea14e5c3SBrian Feldman	Elf32_Word      sh_type;
574ea14e5c3SBrian Feldman	Elf32_Word      sh_flags;
575ea14e5c3SBrian Feldman	Elf32_Addr      sh_addr;
576ea14e5c3SBrian Feldman	Elf32_Off       sh_offset;
577ea14e5c3SBrian Feldman	Elf32_Size      sh_size;
578ea14e5c3SBrian Feldman	Elf32_Word      sh_link;
579ea14e5c3SBrian Feldman	Elf32_Word      sh_info;
580ea14e5c3SBrian Feldman	Elf32_Size      sh_addralign;
581ea14e5c3SBrian Feldman	Elf32_Size      sh_entsize;
582ea14e5c3SBrian Feldman} Elf32_Shdr;
583ea14e5c3SBrian Feldman.Ed
584ea14e5c3SBrian Feldman.Pp
585ea14e5c3SBrian Feldman.Bd -literal -offset indent
586ea14e5c3SBrian Feldmantypedef struct {
587ea14e5c3SBrian Feldman	Elf64_Half      sh_name;
588ea14e5c3SBrian Feldman	Elf64_Half      sh_type;
589ea14e5c3SBrian Feldman	Elf64_Size      sh_flags;
590ea14e5c3SBrian Feldman	Elf64_Addr      sh_addr;
591ea14e5c3SBrian Feldman	Elf64_Off       sh_offset;
592ea14e5c3SBrian Feldman	Elf64_Size      sh_size;
593ea14e5c3SBrian Feldman	Elf64_Half      sh_link;
594ea14e5c3SBrian Feldman	Elf64_Half      sh_info;
595ea14e5c3SBrian Feldman	Elf64_Size      sh_addralign;
596ea14e5c3SBrian Feldman	Elf64_Size      sh_entsize;
597ea14e5c3SBrian Feldman} Elf64_Shdr;
598ea14e5c3SBrian Feldman.Ed
599ea14e5c3SBrian Feldman.Pp
600ea14e5c3SBrian Feldman.Bl -tag -width "sh_addralign" -compact
601ea14e5c3SBrian Feldman.It Dv sh_name
602ea14e5c3SBrian FeldmanThis member specifies the name of the section. Its value is an index
603ea14e5c3SBrian Feldmaninto the section header string table section, giving the location of
604ea14e5c3SBrian Feldmana null-terminated string.
605ea14e5c3SBrian Feldman.It Dv sh_type
6060757c960SBrian FeldmanThis member categorizes the section's contents and semantics.
607ea14e5c3SBrian Feldman.Pp
608ea14e5c3SBrian Feldman.Bl -tag -width "SHT_PROGBITS" -compact
609ea14e5c3SBrian Feldman.It Dv SHT_NULL
610ea14e5c3SBrian FeldmanThis value marks the section header as inactive. It does not
611ea14e5c3SBrian Feldmanhave an associated section. Other members of the section header
612ea14e5c3SBrian Feldmanhave undefined values.
613ea14e5c3SBrian Feldman.It Dv SHT_PROGBITS
614ea14e5c3SBrian FeldmanThe section holds information defined by the program, whose
615ea14e5c3SBrian Feldmanformat and meaning are determined solely by the program.
616ea14e5c3SBrian Feldman.It Dv SHT_SYMTAB
617ea14e5c3SBrian FeldmanThis section holds a symbol table. Typically,
618ea14e5c3SBrian Feldman.Sy SHT_SYMTAB
619ea14e5c3SBrian Feldmanprovides symbols for link editing, though it may also be used
620ea14e5c3SBrian Feldmanfor dynamic linking. As a complete symbol table, it may contain
621ea14e5c3SBrian Feldmanmany symbols unnecessary for dynamic linking. An object file can
622ea14e5c3SBrian Feldmanalso contain a
623ea14e5c3SBrian Feldman.Sy SHN_DYNSYM
624ea14e5c3SBrian Feldmansection.
625ea14e5c3SBrian Feldman.It Dv SHT_STRTAB
626ea14e5c3SBrian FeldmanThis section holds a string table. An object file may have multiple
627ea14e5c3SBrian Feldmanstring table sections.
628ea14e5c3SBrian Feldman.It Dv SHT_RELA
629ea14e5c3SBrian FeldmanThis section holds relocation entries with explicit addends, such
630ea14e5c3SBrian Feldmanas type
631ea14e5c3SBrian Feldman.Sy Elf32_Rela
632ea14e5c3SBrian Feldmanfor the 32-bit class of object files. An object may have multiple
633ea14e5c3SBrian Feldmanrelocation sections.
634ea14e5c3SBrian Feldman.It Dv SHT_HASH
635ea14e5c3SBrian FeldmanThis section holds a symbol hash table. All object participating in
636ea14e5c3SBrian Feldmandynamic linking must contain a symbol hash table. An object file may
637ea14e5c3SBrian Feldmanhave only one hash table.
638ea14e5c3SBrian Feldman.It Dv SHT_DYNAMIC
639ea14e5c3SBrian FeldmanThis section holds information for dynamic linking. An object file may
640ea14e5c3SBrian Feldmanhave only one dynamic section.
641ea14e5c3SBrian Feldman.It Dv SHT_NOTE
642ea14e5c3SBrian FeldmanThis section holds information that marks the file in some way.
643ea14e5c3SBrian Feldman.It Dv SHT_NOBITS
644ea14e5c3SBrian FeldmanA section of this type occupies no space in the file but otherwise
645ea14e5c3SBrian Feldmanresembles
646ea14e5c3SBrian Feldman.Sy SHN_PROGBITS .
647ea14e5c3SBrian FeldmanAlthough this section contains no bytes, the
648ea14e5c3SBrian Feldman.Sy sh_offset
649ea14e5c3SBrian Feldmanmember contains the conceptual file offset.
650ea14e5c3SBrian Feldman.It Dv SHT_REL
651ea14e5c3SBrian FeldmanThis section holds relocation offsets without explicit addends, such
652ea14e5c3SBrian Feldmanas type
653ea14e5c3SBrian Feldman.Sy Elf32_Rel
654ea14e5c3SBrian Feldmanfor the 32-bit class of object files. An object file may have multiple
655ea14e5c3SBrian Feldmanrelocation sections.
656ea14e5c3SBrian Feldman.It Dv SHT_SHLIB
657ea14e5c3SBrian FeldmanThis section is reserved but has unspecified semantics.
658ea14e5c3SBrian Feldman.It Dv SHT_DYNSYM
659ea14e5c3SBrian FeldmanThis section holds a minimal set of dynamic linking symbols. An
660ea14e5c3SBrian Feldmanobject file can also contain a
661ea14e5c3SBrian Feldman.Sy SHN_SYMTAB
662ea14e5c3SBrian Feldmansection.
663ea14e5c3SBrian Feldman.It Dv SHT_LOPROC
664ea14e5c3SBrian FeldmanThis value up to and including
665ea14e5c3SBrian Feldman.Sy SHT_HIPROC
666ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
667ea14e5c3SBrian Feldman.It Dv SHT_HIPROC
668ea14e5c3SBrian FeldmanThis value down to and including
669ea14e5c3SBrian Feldman.Sy SHT_LOPROC
670ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
671ea14e5c3SBrian Feldman.It Dv SHT_LOUSER
672ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of indices reserved for
673ea14e5c3SBrian Feldmanapplication programs.
674ea14e5c3SBrian Feldman.It Dv SHT_HIUSER
675ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of indices reserved for
676ea14e5c3SBrian Feldmanapplication programs. Section types between
677ea14e5c3SBrian Feldman.Sy SHT_LOUSER
678ea14e5c3SBrian Feldmanand
679ea14e5c3SBrian Feldman.Sy SHT_HIUSER
680ea14e5c3SBrian Feldmanmay be used by the application, without conflicting with current or future
681ea14e5c3SBrian Feldmansystem-defined section types.
682ea14e5c3SBrian Feldman.El
683ea14e5c3SBrian Feldman.Pp
684ea14e5c3SBrian Feldman.It Dv sh_flags
685ea14e5c3SBrian FeldmanSections support one-bit flags that describe miscellaneous attributes.
686ea14e5c3SBrian FeldmanIf a flag bit is set in
687ea14e5c3SBrian Feldman.Sy sh_flags ,
688ea14e5c3SBrian Feldmanthe attribute is
689ea14e5c3SBrian Feldman.Dq on
690ea14e5c3SBrian Feldmanfor the section. Otherwise, the attribute is
691ea14e5c3SBrian Feldman.Dq off
692ea14e5c3SBrian Feldmanor does not apply. Undefined attributes are set to zero.
693ea14e5c3SBrian Feldman.Pp
694ea14e5c3SBrian Feldman.Bl -tag -width "SHF_EXECINSTR" -compact
695ea14e5c3SBrian Feldman.It Dv SHF_WRITE
696ea14e5c3SBrian FeldmanThis section contains data that should be writable during process
697ea14e5c3SBrian Feldmanexecution.
698ea14e5c3SBrian Feldman.It Dv SHF_ALLOC
699ea14e5c3SBrian FeldmanThe section occupies memory during process execution. Some control
700ea14e5c3SBrian Feldmansections do not reside in the memory image of an object file. This
701ea14e5c3SBrian Feldmanattribute is off for those sections.
702ea14e5c3SBrian Feldman.It Dv SHF_EXECINSTR
703ea14e5c3SBrian FeldmanThe section contains executable machine instructions.
704ea14e5c3SBrian Feldman.It Dv SHF_MASKPROC
705ea14e5c3SBrian FeldmanAll bits included in this mask are reserved for processor-specific
706ea14e5c3SBrian Feldmansemantics.
707ea14e5c3SBrian Feldman.El
708ea14e5c3SBrian Feldman.Pp
709ea14e5c3SBrian Feldman.It Dv sh_addr
710ea14e5c3SBrian FeldmanIf the section will appear in the memory image of a process, this member
711ea14e5c3SBrian Feldmanholds the address at which the section's first byte should reside.
712ea14e5c3SBrian FeldmanOtherwise, the member contains zero.
713ea14e5c3SBrian Feldman.It Dv sh_offset
714ea14e5c3SBrian FeldmanThis member's value holds the byte offset from the beginning of the file
715ea14e5c3SBrian Feldmanto the first byte in the section. One section type,
716ea14e5c3SBrian Feldman.Sy SHT_NOBITS ,
717ea14e5c3SBrian Feldmanoccupies no space in the file, and its
718ea14e5c3SBrian Feldman.Sy sh_offset
719ea14e5c3SBrian Feldmanmember locates the conceptual placement in the file.
720ea14e5c3SBrian Feldman.It Dv sh_size
721ea14e5c3SBrian FeldmanThis member holds the section's size in bytes. Unless the section type
722ea14e5c3SBrian Feldmanis
723ea14e5c3SBrian Feldman.Sy SHT_NOBITS ,
724ea14e5c3SBrian Feldmanthe section occupies
725ea14e5c3SBrian Feldman.Sy sh_size
726ea14e5c3SBrian Feldmanbytes in the file. A section of type
727ea14e5c3SBrian Feldman.Sy SHT_NOBITS
728ea14e5c3SBrian Feldmanmay have a non-zero size, but it occupies no space in the file.
729ea14e5c3SBrian Feldman.It Dv sh_link
730ea14e5c3SBrian FeldmanThis member holds a section header table index link, whose interpretation
731ea14e5c3SBrian Feldmandepends on the section type.
732ea14e5c3SBrian Feldman.It Dv sh_info
733ea14e5c3SBrian FeldmanThis member holds extra information, whose interpretation depends on the
734ea14e5c3SBrian Feldmansection type.
735ea14e5c3SBrian Feldman.It Dv sh_addralign
736ea14e5c3SBrian FeldmanSome sections have address alignment constraints. If a section holds a
737ea14e5c3SBrian Feldmandoubleword, the system must ensure doubleword alignment for the entire
738ea14e5c3SBrian Feldmansection. That is, the value of
739ea14e5c3SBrian Feldman.Sy sh_addr
740ea14e5c3SBrian Feldmanmust be congruent to zero, modulo the value of
741ea14e5c3SBrian Feldman.Sy sh_addralign .
742ea14e5c3SBrian FeldmanOnly zero and positive integral powers of two are allowed. Values of zero
743ea14e5c3SBrian Feldmanor one mean the section has no alignment constraints.
744ea14e5c3SBrian Feldman.It Dv sh_entsize
745ea14e5c3SBrian FeldmanSome sections hold a table of fixed-sized entries, such as a symbol table.
746ea14e5c3SBrian FeldmanFor such a section, this member gives the size in bytes for each entry.
747ea14e5c3SBrian FeldmanThis member contains zero if the section does not hold a table of
748ea14e5c3SBrian Feldmanfixed-size entries.
749ea14e5c3SBrian Feldman.El
750ea14e5c3SBrian Feldman.Pp
751ea14e5c3SBrian FeldmanVarious sections hold program and control information:
752ea14e5c3SBrian Feldman.Bl -tag -width ".shstrtab" -compact
753ea14e5c3SBrian Feldman.It .bss
7540757c960SBrian FeldmanThis section holds uninitialized data that contributes to the program's
7550757c960SBrian Feldmanmemory image. By definition, the system initializes the data with zeros
756ea14e5c3SBrian Feldmanwhen the program begins to run. This section is of type
757ea14e5c3SBrian Feldman.Sy SHT_NOBITS .
758ea14e5c3SBrian FeldmanThe attributes types are
759ea14e5c3SBrian Feldman.Sy SHF_ALLOC
760ea14e5c3SBrian Feldmanand
761ea14e5c3SBrian Feldman.Sy SHF_WRITE .
762ea14e5c3SBrian Feldman.It .comment
763ea14e5c3SBrian FeldmanThis section holds version control information. This section is of type
764ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
765ea14e5c3SBrian FeldmanNo attribute types are used.
766ea14e5c3SBrian Feldman.It .data
7670757c960SBrian FeldmanThis section holds initialized data that contribute to the program's
768ea14e5c3SBrian Feldmanmemory image. This section is of type
769ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
770ea14e5c3SBrian FeldmanThe attribute types are
771ea14e5c3SBrian Feldman.Sy SHF_ALLOC
772ea14e5c3SBrian Feldmanand
773ea14e5c3SBrian Feldman.Sy SHF_WRITE .
774ea14e5c3SBrian Feldman.It .data1
7750757c960SBrian FeldmanThis section holds initialized data that contribute to the program's
776ea14e5c3SBrian Feldmanmemory image. This section is of type
777ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
778ea14e5c3SBrian FeldmanThe attribute types are
779ea14e5c3SBrian Feldman.Sy SHF_ALLOC
780ea14e5c3SBrian Feldmanand
781ea14e5c3SBrian Feldman.Sy SHF_WRITE .
782ea14e5c3SBrian Feldman.It .debug
783ea14e5c3SBrian FeldmanThis section holds information for symbolic debugging. The contents
784ea14e5c3SBrian Feldmanare unspecified. This section is of type
785ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
786ea14e5c3SBrian FeldmanNo attribute types are used.
787ea14e5c3SBrian Feldman.It .dynamic
788ea14e5c3SBrian FeldmanThis section holds dynamic linking information. The section's attributes
789ea14e5c3SBrian Feldmanwill include the
790ea14e5c3SBrian Feldman.Sy SHF_ALLOC
791ea14e5c3SBrian Feldmanbit. Whether the
792ea14e5c3SBrian Feldman.Sy SHF_WRITE
793ea14e5c3SBrian Feldmanbit is set is processor-specific. This section is of type
794ea14e5c3SBrian Feldman.Sy SHT_DYNAMIC .
795ea14e5c3SBrian FeldmanSee the attributes above.
796ea14e5c3SBrian Feldman.It .dynstr
797ea14e5c3SBrian FeldmanThis section holds strings needed for dynamic linking, most commonly
798ea14e5c3SBrian Feldmanthe strings that represent the names associated with symbol table entries.
799ea14e5c3SBrian FeldmanThis section is of type
800ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
801ea14e5c3SBrian FeldmanThe attribute type used is
802ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
803ea14e5c3SBrian Feldman.It .dynsym
804ea14e5c3SBrian FeldmanThis section holds the dynamic linking symbol table. This section is of type
805ea14e5c3SBrian Feldman.Sy SHT_DYNSYM .
806ea14e5c3SBrian FeldmanThe attribute used is
807ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
808ea14e5c3SBrian Feldman.It .fini
809ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process
810f3a2511aSChris Costellotermination code. When a program exits normally the system arranges to
811ea14e5c3SBrian Feldmanexecute the code in this section. This section is of type
812ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
813ea14e5c3SBrian FeldmanThe attributes used are
814ea14e5c3SBrian Feldman.Sy SHF_ALLOC
815ea14e5c3SBrian Feldmanand
816ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
817ea14e5c3SBrian Feldman.It .got
818ea14e5c3SBrian FeldmanThis section holds the global offset table. This section is of type
819ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
820ea14e5c3SBrian FeldmanThe attributes are processor-specific.
821ea14e5c3SBrian Feldman.It .hash
822ea14e5c3SBrian FeldmanThis section holds a symbol hash table. This section is of type
823ea14e5c3SBrian Feldman.Sy SHT_HASH .
824ea14e5c3SBrian FeldmanThe attribute used is
825ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
826ea14e5c3SBrian Feldman.It .init
827ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process
8280757c960SBrian Feldmaninitialization code. When a program starts to run the system arranges to
829ea14e5c3SBrian Feldmanexecute the code in this section before calling the main program entry point.
830ea14e5c3SBrian FeldmanThis section is of type
831ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
832ea14e5c3SBrian FeldmanThe attributes used are
833ea14e5c3SBrian Feldman.Sy SHF_ALLOC
834ea14e5c3SBrian Feldmanand
835ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
836ea14e5c3SBrian Feldman.It .interp
837ea14e5c3SBrian FeldmanThis section holds the pathname of a program interpreter. If the file has
838ea14e5c3SBrian Feldmana loadable segment that includes the section, the section's attributes will
839ea14e5c3SBrian Feldmaninclude the
840ea14e5c3SBrian Feldman.Sy SHF_ALLOC
841ea14e5c3SBrian Feldmanbit. Otherwise, that bit will be off. This section is of type
842ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
843ea14e5c3SBrian Feldman.It .line
844ea14e5c3SBrian FeldmanThis section holds line number information for symbolic debugging, which
845ea14e5c3SBrian Feldmandescribes the correspondence between the program source and the machine code.
846ea14e5c3SBrian FeldmanThe contents are unspecified. This section is of type
847ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
848ea14e5c3SBrian FeldmanNo attribute types are used.
849ea14e5c3SBrian Feldman.It .note
850ea14e5c3SBrian FeldmanThis section holds information in the
851ea14e5c3SBrian Feldman.Dq Note Section
852ea14e5c3SBrian Feldmanformat described below. This section is of type
853ea14e5c3SBrian Feldman.Sy SHT_NOTE .
854ea14e5c3SBrian FeldmanNo attribute types are used.
855ea14e5c3SBrian Feldman.It .plt
856ea14e5c3SBrian FeldmanThis section holds the procedure linkage table. This section is of type
857ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
858ea14e5c3SBrian FeldmanThe attributes are processor-specific.
859ea14e5c3SBrian Feldman.It .relNAME
860ea14e5c3SBrian FeldmanThis section holds relocation information as described below. If the file
861ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes
862ea14e5c3SBrian Feldmanwill include the
863ea14e5c3SBrian Feldman.Sy SHF_ALLOC
864ea14e5c3SBrian Feldmanbit. Otherwise the bit will be off. By convention,
865ea14e5c3SBrian Feldman.Dq NAME
866ea14e5c3SBrian Feldmanis supplied by the section to which the relocations apply. Thus a relocation
867ea14e5c3SBrian Feldmansection for
868ea14e5c3SBrian Feldman.Sy .text
869ea14e5c3SBrian Feldmannormally would have the name
870ea14e5c3SBrian Feldman.Sy .rel.text .
871ea14e5c3SBrian FeldmanThis section is of type
872ea14e5c3SBrian Feldman.Sy SHT_REL .
873ea14e5c3SBrian Feldman.It .relaNAME
874ea14e5c3SBrian FeldmanThis section holds relocation information as described below. If the file
875ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes
876ea14e5c3SBrian Feldmanwill include the
877ea14e5c3SBrian Feldman.Sy SHF_ALLOC
878ea14e5c3SBrian Feldmanbit. Otherwise the bit will be off. By convention,
879ea14e5c3SBrian Feldman.Dq NAME
880ea14e5c3SBrian Feldmanis supplied by the section to which the relocations apply. Thus a relocation
881ea14e5c3SBrian Feldmansection for
882ea14e5c3SBrian Feldman.Sy .text
883ea14e5c3SBrian Feldmannormally would have the name
884ea14e5c3SBrian Feldman.Sy .rela.text .
885ea14e5c3SBrian FeldmanThis section is of type
886ea14e5c3SBrian Feldman.Sy SHT_RELA .
887ea14e5c3SBrian Feldman.It .rodata
888f3a2511aSChris CostelloThis section holds read-only data that typically contributes to a
889ea14e5c3SBrian Feldmannon-writable segment in the process image. This section is of type
890ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
891ea14e5c3SBrian FeldmanThe attribute used is
892ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
893ea14e5c3SBrian Feldman.It .rodata1
894ea14e5c3SBrian FeldmanThis section hold read-only data that typically contributes to a
895ea14e5c3SBrian Feldmannon-writable segment in the process image. This section is of type
896ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
897ea14e5c3SBrian FeldmanThe attribute used is
898ea14e5c3SBrian Feldman.Sy SHF_ALLOC .
899ea14e5c3SBrian Feldman.It .shstrtab
900ea14e5c3SBrian FeldmanThis section holds section names. This section is of type
901ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
902ea14e5c3SBrian FeldmanNo attribute types are used.
903ea14e5c3SBrian Feldman.It .strtab
904ea14e5c3SBrian FeldmanThis section holds strings, most commonly the strings that represent the
905ea14e5c3SBrian Feldmannames associated with symbol table entries. If the file has a loadable
906ea14e5c3SBrian Feldmansegment that includes the symbol string table, the section's attributes
907ea14e5c3SBrian Feldmanwill include the
908ea14e5c3SBrian Feldman.Sy SHF_ALLOC
909ea14e5c3SBrian Feldmanbit. Otherwise the bit will be off. This section is of type
910ea14e5c3SBrian Feldman.Sy SHT_STRTAB .
911ea14e5c3SBrian Feldman.It .symtab
912ea14e5c3SBrian FeldmanThis section holds a symbol table. If the file has a loadable segment
913ea14e5c3SBrian Feldmanthat includes the symbol table, the section's attributes will include
914ea14e5c3SBrian Feldmanthe
915ea14e5c3SBrian Feldman.Sy SHF_ALLOC
916ea14e5c3SBrian Feldmanbit. Otherwise the bit will be off. This section is of type
917ea14e5c3SBrian Feldman.Sy SHT_SYMTAB .
918ea14e5c3SBrian Feldman.It .text
919ea14e5c3SBrian FeldmanThis section holds the
920ea14e5c3SBrian Feldman.Dq text ,
921ea14e5c3SBrian Feldmanor executable instructions, of a program. This section is of type
922ea14e5c3SBrian Feldman.Sy SHT_PROGBITS .
923ea14e5c3SBrian FeldmanThe attributes used are
924ea14e5c3SBrian Feldman.Sy SHF_ALLOC
925ea14e5c3SBrian Feldmanand
926ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR .
927ea14e5c3SBrian Feldman.El
928ea14e5c3SBrian Feldman.Pp
929ea14e5c3SBrian FeldmanString table sections hold null-terminated character sequences, commonly
930ea14e5c3SBrian Feldmancalled strings. The object file uses these strings to represent symbol
931ea14e5c3SBrian Feldmanand section names. One references a string as an index into the string
932ea14e5c3SBrian Feldmantable section. The first byte, which is index zero, is defined to hold
933ea14e5c3SBrian Feldmana null character. Similarly, a string table's last byte is defined to
934ea14e5c3SBrian Feldmanhold a null character, ensuring null termination for all strings.
935ea14e5c3SBrian Feldman.Pp
936ea14e5c3SBrian FeldmanAn object file's symbol table holds information needed to locate and
937ea14e5c3SBrian Feldmanrelocate a program's symbolic definitions and references. A symbol table
938ea14e5c3SBrian Feldmanindex is a subscript into this array.
939ea14e5c3SBrian Feldman.Pp
940ea14e5c3SBrian Feldman.Bd -literal -offset indent
941ea14e5c3SBrian Feldmantypedef struct {
942ea14e5c3SBrian Feldman	Elf32_Word      st_name;
943ea14e5c3SBrian Feldman	Elf32_Addr      st_value;
944ea14e5c3SBrian Feldman	Elf32_Size      st_size;
945ea14e5c3SBrian Feldman	unsigned char   st_info;
946ea14e5c3SBrian Feldman	unsigned char   st_other;
947ea14e5c3SBrian Feldman	Elf32_Half      st_shndx;
948ea14e5c3SBrian Feldman} Elf32_Sym;
949ea14e5c3SBrian Feldman.Ed
950ea14e5c3SBrian Feldman.Pp
951ea14e5c3SBrian Feldman.Bd -literal -offset indent
952ea14e5c3SBrian Feldmantypedef struct {
953ea14e5c3SBrian Feldman	Elf64_Half      st_name;
954ea14e5c3SBrian Feldman	unsigned char   st_info;
955ea14e5c3SBrian Feldman	unsigned char   st_other;
956ea14e5c3SBrian Feldman	Elf64_Quarter   st_shndx;
957ea14e5c3SBrian Feldman	Elf64_Addr      st_value;
958ea14e5c3SBrian Feldman	Elf64_Size      st_size;
959ea14e5c3SBrian Feldman} Elf64_Sym;
960ea14e5c3SBrian Feldman.Ed
961ea14e5c3SBrian Feldman.Pp
962ea14e5c3SBrian Feldman.Bl -tag -width "st_value" -compact
963ea14e5c3SBrian Feldman.It Dv st_name
964ea14e5c3SBrian FeldmanThis member holds an index into the object file's symbol string table,
965ea14e5c3SBrian Feldmanwhich holds character representations of the symbol names. If the value
966ea14e5c3SBrian Feldmanis non-zero, it represents a string table index that gives the symbol
967ea14e5c3SBrian Feldmanname. Otherwise, the symbol table has no name.
968ea14e5c3SBrian Feldman.It Dv st_value
969ea14e5c3SBrian FeldmanThis member gives the value of the associated symbol.
970ea14e5c3SBrian Feldman.It Dv st_size
971ea14e5c3SBrian FeldmanMany symbols have associated sizes. This member holds zero if the symbol
972ea14e5c3SBrian Feldmanhas no size or an unknown size.
973ea14e5c3SBrian Feldman.It Dv st_info
974ea14e5c3SBrian FeldmanThis member specifies the symbol's type and binding attributes:
975ea14e5c3SBrian Feldman.Pp
976ea14e5c3SBrian Feldman.Bl -tag -width "STT_SECTION" -compact
977ea14e5c3SBrian Feldman.It Dv STT_NOTYPE
978ea14e5c3SBrian FeldmanThe symbol's type is not defined.
979ea14e5c3SBrian Feldman.It Dv STT_OBJECT
980ea14e5c3SBrian FeldmanThe symbol is associated with a data object.
981ea14e5c3SBrian Feldman.It Dv STT_FUNC
982ea14e5c3SBrian FeldmanThe symbol is associated with a function or other executable code.
983ea14e5c3SBrian Feldman.It Dv STT_SECTION
984ea14e5c3SBrian FeldmanThe symbol is associated with a section. Symbol table entries of
985ea14e5c3SBrian Feldmanthis type exist primarily for relocation and normally have
986ea14e5c3SBrian Feldman.Sy STB_LOCAL
987ea14e5c3SBrian Feldmanbindings.
988ea14e5c3SBrian Feldman.It Dv STT_FILE
989ea14e5c3SBrian FeldmanBy convention the symbol's name gives the name of the source file
990ea14e5c3SBrian Feldmanassociated with the object file. A file symbol has
991ea14e5c3SBrian Feldman.Sy STB_LOCAL
992ea14e5c3SBrian Feldmanbindings, its section index is
993ea14e5c3SBrian Feldman.Sy SHN_ABS ,
994ea14e5c3SBrian Feldmanand it precedes the other
995ea14e5c3SBrian Feldman.Sy STB_LOCAL
996ea14e5c3SBrian Feldmansymbols of the file, if it is present.
997ea14e5c3SBrian Feldman.It Dv STT_LOPROC
998ea14e5c3SBrian FeldmanThis value up to and including
999ea14e5c3SBrian Feldman.Sy STT_HIPROC
1000ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1001ea14e5c3SBrian Feldman.It Dv STT_HIPROC
1002ea14e5c3SBrian FeldmanThis value down to and including
1003ea14e5c3SBrian Feldman.Sy STT_LOPROC
1004ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1005ea14e5c3SBrian Feldman.El
1006ea14e5c3SBrian Feldman.Pp
1007ea14e5c3SBrian Feldman.Bl -tag -width "STB_GLOBAL" -compact
1008ea14e5c3SBrian Feldman.It Dv STB_LOCAL
1009ea14e5c3SBrian FeldmanLocal symbols are not visible outside the object file containing their
1010ea14e5c3SBrian Feldmandefinition. Local symbols of the same name may exist in multiple file
1011ea14e5c3SBrian Feldmanwithout interfering with each other.
1012ea14e5c3SBrian Feldman.It Dv STB_GLOBAL
1013ea14e5c3SBrian FeldmanGlobal symbols are visible to all object files being combined. One file's
1014ea14e5c3SBrian Feldmandefinition of a global symbol will satisfy another file's undefined
1015ea14e5c3SBrian Feldmanreference to the same symbol.
1016ea14e5c3SBrian Feldman.It Dv STB_WEAK
1017ea14e5c3SBrian FeldmanWeak symbols resemble global symbols, but their definitions have lower
1018ea14e5c3SBrian Feldmanprecedence.
1019ea14e5c3SBrian Feldman.It Dv STB_LOPROC
1020ea14e5c3SBrian FeldmanThis value up to and including
1021ea14e5c3SBrian Feldman.Sy STB_HIPROC
1022ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1023ea14e5c3SBrian Feldman.It Dv STB_HIPROC
1024ea14e5c3SBrian FeldmanThis value down to and including
1025ea14e5c3SBrian Feldman.Sy STB_LOPROC
1026ea14e5c3SBrian Feldmanare reserved for processor-specific semantics.
1027ea14e5c3SBrian Feldman.Pp
1028ea14e5c3SBrian FeldmanThere are macros for packing and unpacking the binding and type fields:
1029ea14e5c3SBrian Feldman.Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact
1030ea14e5c3SBrian Feldman.It Dv ELF32_ST_BIND(info)
1031ea14e5c3SBrian Feldmanor
1032ea14e5c3SBrian Feldman.Sy ELF64_ST_BIND(info)
1033f3a2511aSChris Costelloextract a binding from an st_info value.
1034ea14e5c3SBrian Feldman.It Dv ELF64_ST_TYPE(info)
1035ea14e5c3SBrian Feldmanor
1036ea14e5c3SBrian Feldman.Sy ELF32_ST_TYPE(info)
1037f3a2511aSChris Costelloextract a type from an st_info value.
1038ea14e5c3SBrian Feldman.It Dv ELF32_ST_INFO(bind, type)
1039ea14e5c3SBrian Feldmanor
1040ea14e5c3SBrian Feldman.Sy ELF64_ST_INFO(bind, type)
1041f3a2511aSChris Costelloconvert a binding and a type into an st_info value.
1042ea14e5c3SBrian Feldman.El
1043ea14e5c3SBrian Feldman.El
1044ea14e5c3SBrian Feldman.Pp
1045ea14e5c3SBrian Feldman.It Dv st_other
1046ea14e5c3SBrian FeldmanThis member currently holds zero and has no defined meaning.
1047ea14e5c3SBrian Feldman.It Dv st_shndx
1048ea14e5c3SBrian FeldmanEvery symbol table entry is
1049ea14e5c3SBrian Feldman.Dq defined
1050ea14e5c3SBrian Feldmanin relation to some action. This member holds the relevant section
1051ea14e5c3SBrian Feldmanheader table index.
1052ea14e5c3SBrian Feldman.El
1053ea14e5c3SBrian Feldman.Pp
1054ea14e5c3SBrian FeldmanRelocation is the process of connecting symbolic references with
1055ea14e5c3SBrian Feldmansymbolic definitions. Relocatable files must have information that
1056ea14e5c3SBrian Feldmandescribes how to modify their section contents, thus allowing executable
1057ea14e5c3SBrian Feldmanand shared object files to hold the right information for a process'
1058ea14e5c3SBrian Feldmanprogram image. Relocation entries are these data.
1059ea14e5c3SBrian Feldman.Pp
1060ea14e5c3SBrian FeldmanRelocation structures that do not need an addend:
1061ea14e5c3SBrian Feldman.Pp
1062ea14e5c3SBrian Feldman.Bd -literal -offset indent
1063ea14e5c3SBrian Feldmantypedef struct {
1064ea14e5c3SBrian Feldman	Elf32_Addr      r_offset;
1065ea14e5c3SBrian Feldman	Elf32_Word      r_info;
1066ea14e5c3SBrian Feldman} Elf32_Rel;
1067ea14e5c3SBrian Feldman.Ed
1068ea14e5c3SBrian Feldman.Bd -literal -offset indent
1069ea14e5c3SBrian Feldmantypedef struct {
1070ea14e5c3SBrian Feldman	Elf64_Addr      r_offset;
1071ea14e5c3SBrian Feldman	Elf64_Size      r_info;
1072ea14e5c3SBrian Feldman} Elf64_Rel;
1073ea14e5c3SBrian Feldman.Ed
1074ea14e5c3SBrian Feldman.Pp
1075ea14e5c3SBrian FeldmanRelocation structures that need an addend:
1076ea14e5c3SBrian Feldman.Pp
1077ea14e5c3SBrian Feldman.Bd -literal -offset indent
1078ea14e5c3SBrian Feldmantypedef struct {
1079ea14e5c3SBrian Feldman	Elf32_Addr      r_offset;
1080ea14e5c3SBrian Feldman	Elf32_Word      r_info;
1081ea14e5c3SBrian Feldman	Elf32_Sword     r_addend;
1082ea14e5c3SBrian Feldman} Elf32_Rela;
1083ea14e5c3SBrian Feldman.Ed
1084ea14e5c3SBrian Feldman.Bd -literal -offset indent
1085ea14e5c3SBrian Feldmantypedef struct {
1086ea14e5c3SBrian Feldman	Elf64_Addr      r_offset;
1087ea14e5c3SBrian Feldman	Elf64_Size      r_info;
1088ea14e5c3SBrian Feldman	Elf64_Off       r_addend;
1089ea14e5c3SBrian Feldman} Elf64_Rela;
1090ea14e5c3SBrian Feldman.Ed
1091ea14e5c3SBrian Feldman.Pp
1092ea14e5c3SBrian Feldman.Bl -tag -width "r_offset" -compact
1093ea14e5c3SBrian Feldman.It Dv r_offset
1094ea14e5c3SBrian FeldmanThis member gives the location at which to apply the relocation action.
1095ea14e5c3SBrian FeldmanFor a relocatable file, the value is the byte offset from the beginning
1096ea14e5c3SBrian Feldmanof the section to the storage unit affected by the relocation. For an
1097ea14e5c3SBrian Feldmanexecutable file or shared object, the value is the virtual address of
1098ea14e5c3SBrian Feldmanthe storage unit affected by the relocation.
1099ea14e5c3SBrian Feldman.It Dv r_info
1100ea14e5c3SBrian FeldmanThis member gives both the symbol table index with respect to which the
1101ea14e5c3SBrian Feldmanrelocation must be made and the type of relocation to apply. Relocation
1102ea14e5c3SBrian Feldmantypes are processor-specific. When the text refers to a relocation
1103ea14e5c3SBrian Feldmanentry's relocation type or symbol table index, it means the result of
1104ea14e5c3SBrian Feldmanapplying
1105ea14e5c3SBrian Feldman.Sy ELF_[32|64]_R_TYPE
1106ea14e5c3SBrian Feldmanor
1107ea14e5c3SBrian Feldman.Sy ELF[32|64]_R_SYM ,
1108ea14e5c3SBrian Feldmanrespectively to the entry's
1109ea14e5c3SBrian Feldman.Sy r_info
1110ea14e5c3SBrian Feldmanmember.
1111ea14e5c3SBrian Feldman.It Dv r_addend
1112ea14e5c3SBrian FeldmanThis member specifies a constant addend used to compute the value to be
1113ea14e5c3SBrian Feldmanstored into the relocatable field.
1114ea14e5c3SBrian Feldman.El
1115ea14e5c3SBrian Feldman.Sh SEE ALSO
1116ea14e5c3SBrian Feldman.Xr as 1 ,
1117ea14e5c3SBrian Feldman.Xr gdb 1 ,
1118ea14e5c3SBrian Feldman.Xr ld 1 ,
1119ea14e5c3SBrian Feldman.Xr objdump 1 ,
1120ea14e5c3SBrian Feldman.Xr execve 2 ,
1121ea14e5c3SBrian Feldman.Xr core 5
1122ea14e5c3SBrian Feldman.Rs
1123ea14e5c3SBrian Feldman.%A Hewlett Packard
1124ea14e5c3SBrian Feldman.%B Elf-64 Object File Format
1125ea14e5c3SBrian Feldman.Re
1126ea14e5c3SBrian Feldman.Rs
1127ea14e5c3SBrian Feldman.%A Santa Cruz Operation
1128ea14e5c3SBrian Feldman.%B System V Application Binary Interface
1129ea14e5c3SBrian Feldman.Re
1130ea14e5c3SBrian Feldman.Rs
1131ea14e5c3SBrian Feldman.%A Unix System Laboratories
1132ea14e5c3SBrian Feldman.%T Object Files
1133ea14e5c3SBrian Feldman.%B "Executable and Linking Format (ELF)"
1134ea14e5c3SBrian Feldman.Re
1135ea14e5c3SBrian Feldman.Sh HISTORY
1136ea14e5c3SBrian FeldmanThe ELF header files made their appearance in
1137ea14e5c3SBrian Feldman.Fx 2.2.6 .
1138ea14e5c3SBrian FeldmanELF in itself first appeared in
1139ea14e5c3SBrian Feldman.At V .
1140ea14e5c3SBrian FeldmanThe ELF format is an adopted standard.
1141ea14e5c3SBrian Feldman.Sh AUTHORS
1142ea14e5c3SBrian FeldmanThis manual page was written by
1143ea14e5c3SBrian Feldman.An Jeroen Ruigrok van der Werven
1144ea14e5c3SBrian Feldman.Aq asmodai@wxs.nl
1145ea14e5c3SBrian Feldmanwith inspiration from BSDi's BSD/OS
1146ea14e5c3SBrian Feldman.Xr elf 5
1147ea14e5c3SBrian Feldmanmanpage.
1148