xref: /openbsd-src/share/man/man5/elf.5 (revision 41ce3b17e73f6b7d2d9e1a3d961e4bab2d895cb5)
1*41ce3b17Snaddy.\"	$OpenBSD: elf.5,v 1.42 2022/03/31 17:27:22 naddy Exp $
26df95ca2Smiod.\"Copyright (c) 1999 Jeroen Ruigrok van der Werven
36df95ca2Smiod.\"All rights reserved.
46df95ca2Smiod.\"
56df95ca2Smiod.\"Redistribution and use in source and binary forms, with or without
66df95ca2Smiod.\"modification, are permitted provided that the following conditions
76df95ca2Smiod.\"are met:
86df95ca2Smiod.\"1. Redistributions of source code must retain the above copyright
96df95ca2Smiod.\"   notice, this list of conditions and the following disclaimer.
106df95ca2Smiod.\"2. Redistributions in binary form must reproduce the above copyright
116df95ca2Smiod.\"   notice, this list of conditions and the following disclaimer in the
126df95ca2Smiod.\"   documentation and/or other materials provided with the distribution.
136df95ca2Smiod.\"
146df95ca2Smiod.\"THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156df95ca2Smiod.\"ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166df95ca2Smiod.\"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176df95ca2Smiod.\"ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186df95ca2Smiod.\"FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196df95ca2Smiod.\"DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206df95ca2Smiod.\"OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216df95ca2Smiod.\"HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226df95ca2Smiod.\"LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236df95ca2Smiod.\"OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246df95ca2Smiod.\"SUCH DAMAGE.
256df95ca2Smiod.\"
266df95ca2Smiod.\"	$FreeBSD: src/share/man/man5/elf.5,v 1.21 2001/10/01 16:09:23 ru Exp $
276df95ca2Smiod.\"
28*41ce3b17Snaddy.Dd $Mdocdate: March 31 2022 $
296df95ca2Smiod.Dt ELF 5
306df95ca2Smiod.Os
316df95ca2Smiod.Sh NAME
326df95ca2Smiod.Nm elf
336df95ca2Smiod.Nd format of ELF executable binary files
346df95ca2Smiod.Sh SYNOPSIS
3585343d16Smpi.In elf.h
366df95ca2Smiod.Sh DESCRIPTION
376df95ca2SmiodThe header file
3885343d16Smpi.In elf.h
396df95ca2Smioddefines the format of ELF executable binary files.
406df95ca2SmiodAmongst these files are
416df95ca2Smiodnormal executable files, relocatable object files, core files and shared
426df95ca2Smiodlibraries.
436df95ca2Smiod.Pp
446df95ca2SmiodAn executable file using the ELF file format consists of an ELF header,
456df95ca2Smiodfollowed by a program header table or a section header table, or both.
466df95ca2SmiodThe ELF header is always at offset zero of the file.
476df95ca2SmiodThe program header
486df95ca2Smiodtable and the section header table's offset in the file are defined in the
496df95ca2SmiodELF header.
506df95ca2SmiodThe two tables describe the rest of the particularities of
516df95ca2Smiodthe file.
526df95ca2Smiod.Pp
536df95ca2SmiodApplications which wish to process ELF binary files for their native
546df95ca2Smiodarchitecture only should include
5585343d16Smpi.In elf.h
566df95ca2Smiodin their source code.
576df95ca2SmiodThese applications should need to refer to
586df95ca2Smiodall the types and structures by their generic names
596df95ca2Smiod.Dq Elf_xxx
606df95ca2Smiodand to the macros by
616df95ca2Smiod.Dq ELF_xxx .
626df95ca2SmiodApplications written this way can be compiled on any architecture,
638637447dSderaadtregardless of whether the host is 32-bit or 64-bit.
646df95ca2Smiod.Pp
656df95ca2SmiodShould an application need to process ELF files of an unknown
668637447dSderaadtarchitecture, then the application needs to explicitly use either
676df95ca2Smiod.Dq Elf32_xxx
686df95ca2Smiodor
696df95ca2Smiod.Dq Elf64_xxx
706df95ca2Smiodtype and structure names.
716df95ca2SmiodLikewise, the macros need to be identified by
726df95ca2Smiod.Dq ELF32_xxx
736df95ca2Smiodor
746df95ca2Smiod.Dq ELF64_xxx .
756df95ca2Smiod.Pp
766df95ca2SmiodThis header file describes the above mentioned headers as C structures
778637447dSderaadtand also includes structures for dynamic sections, relocation sections and
786df95ca2Smiodsymbol tables.
796df95ca2Smiod.Pp
808637447dSderaadtThe following types are used for 32-bit architectures:
816df95ca2Smiod.Bd -literal -offset indent
8229a5018dSjsgElf32_Addr	Unsigned 32-bit program address
8329a5018dSjsgElf32_Half	Unsigned 16-bit field
8429a5018dSjsgElf32_Lword	Unsigned 64-bit field
8529a5018dSjsgElf32_Off	Unsigned 32-bit file offset
8629a5018dSjsgElf32_Sword	Signed 32-bit field or integer
8729a5018dSjsgElf32_Word	Unsigned 32-bit field or integer
886df95ca2Smiod.Ed
896df95ca2Smiod.Pp
908637447dSderaadtAnd the following types are used for 64-bit architectures:
916df95ca2Smiod.Bd -literal -offset indent
9229a5018dSjsgElf64_Addr	Unsigned 64-bit program address
9329a5018dSjsgElf64_Half	Unsigned 16-bit field
9429a5018dSjsgElf64_Lword	Unsigned 64-bit field
9529a5018dSjsgElf64_Off	Unsigned 64-bit file offset
9629a5018dSjsgElf64_Sword	Signed 32-bit field
9729a5018dSjsgElf64_Sxword	Signed 64-bit field or integer
9829a5018dSjsgElf64_Word	Unsigned 32-bit field
9929a5018dSjsgElf64_Xword	Unsigned 64-bit field or integer
1006df95ca2Smiod.Ed
1016df95ca2Smiod.Pp
1026df95ca2SmiodAll data structures that the file format defines follow the
1036df95ca2Smiod.Dq natural
1046df95ca2Smiodsize and alignment guidelines for the relevant class.
1056df95ca2SmiodIf necessary,
1066df95ca2Smioddata structures contain explicit padding to ensure 4-byte alignment
1076df95ca2Smiodfor 4-byte objects, to force structure sizes to a multiple of 4, etc.
1086df95ca2Smiod.Pp
1096df95ca2SmiodThe ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr:
1106df95ca2Smiod.Bd -literal -offset indent
1116df95ca2Smiodtypedef struct {
1126df95ca2Smiod        unsigned char   e_ident[EI_NIDENT];
1136df95ca2Smiod        Elf32_Half      e_type;
1146df95ca2Smiod        Elf32_Half      e_machine;
1156df95ca2Smiod        Elf32_Word      e_version;
1166df95ca2Smiod        Elf32_Addr      e_entry;
1176df95ca2Smiod        Elf32_Off       e_phoff;
1186df95ca2Smiod        Elf32_Off       e_shoff;
1196df95ca2Smiod        Elf32_Word      e_flags;
1206df95ca2Smiod        Elf32_Half      e_ehsize;
1216df95ca2Smiod        Elf32_Half      e_phentsize;
1226df95ca2Smiod        Elf32_Half      e_phnum;
1236df95ca2Smiod        Elf32_Half      e_shentsize;
1246df95ca2Smiod        Elf32_Half      e_shnum;
1256df95ca2Smiod        Elf32_Half      e_shstrndx;
1266df95ca2Smiod} Elf32_Ehdr;
1276df95ca2Smiod.Ed
1286df95ca2Smiod.Bd -literal -offset indent
1296df95ca2Smiodtypedef struct {
1306df95ca2Smiod	unsigned char   e_ident[EI_NIDENT];
13129a5018dSjsg	Elf64_Half      e_type;
13229a5018dSjsg	Elf64_Half      e_machine;
13329a5018dSjsg	Elf64_Word      e_version;
1346df95ca2Smiod	Elf64_Addr      e_entry;
1356df95ca2Smiod	Elf64_Off       e_phoff;
1366df95ca2Smiod	Elf64_Off       e_shoff;
13729a5018dSjsg	Elf64_Word      e_flags;
13829a5018dSjsg	Elf64_Half      e_ehsize;
13929a5018dSjsg	Elf64_Half      e_phentsize;
14029a5018dSjsg	Elf64_Half      e_phnum;
14129a5018dSjsg	Elf64_Half      e_shentsize;
14229a5018dSjsg	Elf64_Half      e_shnum;
14329a5018dSjsg	Elf64_Half      e_shstrndx;
1446df95ca2Smiod} Elf64_Ehdr;
1456df95ca2Smiod.Ed
1466df95ca2Smiod.Pp
1476df95ca2SmiodThe fields have the following meanings:
14846de36c5Sjmc.Bl -tag -width "e_phentsize" -offset indent
1496df95ca2Smiod.It Dv e_ident
1505f5d0b2cSguentherThis array of bytes specifies how to interpret the file,
1516df95ca2Smiodindependent of the processor or the file's remaining contents.
1526df95ca2SmiodWithin this array everything is named by macros, which start with
1536df95ca2Smiodthe prefix
1546df95ca2Smiod.Sy EI_
1556df95ca2Smiodand may contain values which start with the prefix
1566df95ca2Smiod.Sy ELF .
1576df95ca2SmiodThe following macros are defined:
1581b69268cSjmc.Bl -tag -width "EI_VERSION"
1596df95ca2Smiod.It Dv EI_MAG0
1606df95ca2SmiodThe first byte of the magic number.
1616df95ca2SmiodIt must be filled with
1629d0398b3Sschwarze.Dv ELFMAG0 .
1636df95ca2Smiod.It Dv EI_MAG1
1646df95ca2SmiodThe second byte of the magic number.
1656df95ca2SmiodIt must be filled with
1669d0398b3Sschwarze.Dv ELFMAG1 .
1676df95ca2Smiod.It Dv EI_MAG2
1686df95ca2SmiodThe third byte of the magic number.
1696df95ca2SmiodIt must be filled with
1709d0398b3Sschwarze.Dv ELFMAG2 .
1716df95ca2Smiod.It Dv EI_MAG3
1726df95ca2SmiodThe fourth byte of the magic number.
1736df95ca2SmiodIt must be filled with
1749d0398b3Sschwarze.Dv ELFMAG3 .
1756df95ca2Smiod.It Dv EI_CLASS
1766df95ca2SmiodThe fifth byte identifies the architecture for this binary:
1776df95ca2Smiod.Pp
1786df95ca2Smiod.Bl -tag -width "ELFCLASSNONE" -compact
1796df95ca2Smiod.It Dv ELFCLASSNONE
1806df95ca2SmiodThis class is invalid.
1816df95ca2Smiod.It Dv ELFCLASS32
1826df95ca2SmiodThis defines the 32-bit architecture.
1836df95ca2SmiodIt supports machines with files
1846df95ca2Smiodand virtual address spaces up to 4 Gigabytes.
1856df95ca2Smiod.It Dv ELFCLASS64
1866df95ca2SmiodThis defines the 64-bit architecture.
1876df95ca2Smiod.El
1886df95ca2Smiod.It Dv EI_DATA
1896df95ca2SmiodThe sixth byte specifies the data encoding of the processor-specific
1906df95ca2Smioddata in the file.
1916df95ca2SmiodCurrently these encodings are supported:
1926df95ca2Smiod.Pp
1936df95ca2Smiod.Bl -tag -width "ELFDATA2LSB" -compact
1946df95ca2Smiod.It Dv ELFDATANONE
1956df95ca2SmiodUnknown data format.
1966df95ca2Smiod.It Dv ELFDATA2LSB
1976df95ca2SmiodTwo's complement, little-endian.
1986df95ca2Smiod.It Dv ELFDATA2MSB
1996df95ca2SmiodTwo's complement, big-endian.
2006df95ca2Smiod.El
2016df95ca2Smiod.It Dv EI_VERSION
2026df95ca2SmiodThe version number of the ELF specification:
2036df95ca2Smiod.Pp
2046df95ca2Smiod.Bl -tag -width "EV_CURRENT" -compact
2056df95ca2Smiod.It Dv EV_NONE
2066df95ca2SmiodInvalid version.
2076df95ca2Smiod.It Dv EV_CURRENT
2086df95ca2SmiodCurrent version.
2096df95ca2Smiod.El
210bedba225Skettenis.It Dv EI_OSABI
211bedba225SkettenisThis byte identifies the OS- or ABI-specific ELF extensions used by
212bedba225Skettenisthis object.
213bedba225SkettenisSome fields in other ELF structures have flags and values that have
214bedba225Skettenisplatform specific meanings; the interpretation of those fields is
215bedba225Skettenisdetermined by the value of this byte.
216bedba225SkettenisThe following values are currently defined:
217bedba225Skettenis.Pp
218bedba225Skettenis.Bl -tag -width "ELFOSABI_STANDALONE" -compact
219bedba225Skettenis.It Dv ELFOSABI_SYSV
220bedba225SkettenisUNIX System V ABI.
221bedba225Skettenis.It Dv ELFOSABI_HPUX
222bedba225SkettenisHP-UX operating system ABI.
223bedba225Skettenis.It Dv ELFOSABI_NETBSD
224bedba225Skettenis.Nx
225bedba225Skettenisoperating system ABI.
226bedba225Skettenis.It Dv ELFOSABI_LINUX
227bedba225SkettenisGNU/Linux operating system ABI.
228bedba225Skettenis.It Dv ELFOSABI_HURD
229bedba225SkettenisGNU/Hurd operating system ABI.
230bedba225Skettenis.It Dv ELFOSABI_86OPEN
231bedba225Skettenis86Open Common IA32 ABI.
232bedba225Skettenis.It Dv ELFOSABI_SOLARIS
233bedba225SkettenisSolaris operating system ABI.
234bedba225Skettenis.It Dv ELFOSABI_MONTEREY
235bedba225SkettenisMonterey project ABI.
236bedba225Skettenis.It Dv ELFOSABI_IRIX
237bedba225SkettenisIRIX operating system ABI.
238bedba225Skettenis.It Dv ELFOSABI_FREEBSD
239bedba225Skettenis.Fx
240bedba225Skettenisoperating system ABI.
241bedba225Skettenis.It Dv ELFOSABI_TRU64
242bedba225SkettenisTRU64 UNIX operating system ABI.
243bedba225Skettenis.It Dv ELFOSABI_MODESTO
244bedba225SkettenisNovell Modesto operating system ABI.
245bedba225Skettenis.It Dv ELFOSABI_OPENBSD
246bedba225Skettenis.Ox
247bedba225Skettenisoperating system ABI.
248bedba225Skettenis.It Dv ELFOSABI_ARM
249bedba225SkettenisARM architecture ABI.
250bedba225Skettenis.It Dv ELFOSABI_STANDALONE
251bedba225SkettenisStand-alone (embedded) ABI.
252bedba225Skettenis.El
253bedba225Skettenis.It Dv EI_ABIVERSION
254bedba225SkettenisThis byte identifies the version of the ABI
255bedba225Skettenisto which the object is targeted.
256bedba225SkettenisThis field is used to distinguish among incompatible versions of an ABI.
257bedba225SkettenisThe interpretation of this version number
258bedba225Skettenisis dependent on the ABI identified by the EI_OSABI field.
2596df95ca2Smiod.It Dv EI_PAD
2606df95ca2SmiodStart of padding.
2616df95ca2SmiodThese bytes are reserved and set to zero.
262bedba225SkettenisPrograms which read them should ignore them.
2636df95ca2SmiodThe value for EI_PAD will change in
2646df95ca2Smiodthe future if currently unused bytes are given meanings.
2656df95ca2Smiod.It Dv EI_NIDENT
2666df95ca2SmiodThe size of the e_ident array.
2676df95ca2Smiod.El
2686df95ca2Smiod.It Dv e_type
2696df95ca2SmiodThis member of the structure identifies the object file type:
2706df95ca2Smiod.Pp
2716df95ca2Smiod.Bl -tag -width "ET_NONE" -compact
2726df95ca2Smiod.It Dv ET_NONE
2736df95ca2SmiodAn unknown type.
2746df95ca2Smiod.It Dv ET_REL
2756df95ca2SmiodA relocatable file.
2766df95ca2Smiod.It Dv ET_EXEC
2776df95ca2SmiodAn executable file.
2786df95ca2Smiod.It Dv ET_DYN
2796df95ca2SmiodA shared object.
2806df95ca2Smiod.It Dv ET_CORE
2816df95ca2SmiodA core file.
2826df95ca2Smiod.El
2836df95ca2Smiod.It Dv e_machine
2846df95ca2SmiodThis member specifies the required architecture for an individual file:
2856df95ca2Smiod.Pp
2866df95ca2Smiod.Bl -tag -width "EM_MIPS_RS4_BE" -compact
2876df95ca2Smiod.It Dv EM_NONE
2886df95ca2SmiodAn unknown machine.
2896df95ca2Smiod.It Dv EM_M32
2906df95ca2SmiodAT&T WE 32100.
2916df95ca2Smiod.It Dv EM_SPARC
2926df95ca2SmiodSun Microsystems SPARC.
2936df95ca2Smiod.It Dv EM_386
2946df95ca2SmiodIntel 80386.
2956df95ca2Smiod.It Dv EM_68K
2966df95ca2SmiodMotorola 68000.
2976df95ca2Smiod.It Dv EM_88K
2986df95ca2SmiodMotorola 88000.
2996df95ca2Smiod.It Dv EM_486
3006df95ca2SmiodIntel 80486.
3016df95ca2Smiod.It Dv EM_860
3026df95ca2SmiodIntel 80860.
3036df95ca2Smiod.It Dv EM_MIPS
3046df95ca2SmiodMIPS RS3000 (big-endian only).
3056df95ca2Smiod.It Dv EM_MIPS_RS4_BE
3066df95ca2SmiodMIPS RS4000 (big-endian only).
3076df95ca2Smiod.It Dv EM_SPARC64
3086df95ca2SmiodSPARC v9 64-bit (unofficial).
3096df95ca2Smiod.It Dv EM_PARISC
3106df95ca2SmiodHPPA.
3116df95ca2Smiod.It Dv EM_SPARC32PLUS
3126df95ca2SmiodSPARC with enhanced instruction set.
3136df95ca2Smiod.It Dv EM_PPC
3146df95ca2SmiodPowerPC.
3159a2e4399Skevlo.It Dv EM_PPC64
3169a2e4399SkevloPowerPC 64-bit.
317e0744942Smiod.It Dv EM_ARM
318e0744942SmiodAdvanced RISC Machines ARM.
3196df95ca2Smiod.It Dv EM_ALPHA
3206df95ca2SmiodCompaq [DEC] Alpha.
321e0744942Smiod.It Dv EM_SH
322e0744942SmiodHitachi/Renesas Super-H.
3236df95ca2Smiod.It Dv EM_SPARCV9
3246df95ca2SmiodSPARC v9 64-bit.
325e0744942Smiod.It Dv EM_IA_64
326e0744942SmiodIntel IA-64.
327e0744942Smiod.It Dv EM_AMD64
328e0744942SmiodAMD64.
3296df95ca2Smiod.It Dv EM_VAX
3306df95ca2SmiodDEC Vax.
331b9535a92Skevlo.It Dv EM_AARCH64
332b9535a92SkevloARM 64-bit.
3336e7d9244Skevlo.It Dv EM_RISCV
3346e7d9244SkevloRISC-V.
335e0744942Smiod.It Dv EM_ALPHA_EXP
336e0744942SmiodCompaq [DEC] Alpha with enhanced instruction set.
3376df95ca2Smiod.El
3386df95ca2Smiod.It Dv e_version
3396df95ca2SmiodThis member identifies the file version:
3406df95ca2Smiod.Pp
3416df95ca2Smiod.Bl -tag -width "EV_CURRENT" -compact
3426df95ca2Smiod.It Dv EV_NONE
34346de36c5SjmcInvalid version.
3446df95ca2Smiod.It Dv EV_CURRENT
34546de36c5SjmcCurrent version.
3466df95ca2Smiod.El
3476df95ca2Smiod.It Dv e_entry
3486df95ca2SmiodThis member gives the virtual address to which the system first transfers
3496df95ca2Smiodcontrol, thus starting the process.
3506df95ca2SmiodIf the file has no associated entry
3516df95ca2Smiodpoint, this member holds zero.
3526df95ca2Smiod.It Dv e_phoff
3536df95ca2SmiodThis member holds the program header table's file offset in bytes.
3546df95ca2SmiodIf
3556df95ca2Smiodthe file has no program header table, this member holds zero.
3566df95ca2Smiod.It Dv e_shoff
3576df95ca2SmiodThis member holds the section header table's file offset in bytes.
3586df95ca2SmiodIf the
359*41ce3b17Snaddyfile has no section header table, this member holds zero.
3606df95ca2Smiod.It Dv e_flags
3616df95ca2SmiodThis member holds processor-specific flags associated with the file.
362fa986dacSdavidFlag names take the form EF_`machine_flag'.
363fa986dacSdavidCurrently no flags have been defined.
3646df95ca2Smiod.It Dv e_ehsize
3656df95ca2SmiodThis member holds the ELF header's size in bytes.
3666df95ca2Smiod.It Dv e_phentsize
3676df95ca2SmiodThis member holds the size in bytes of one entry in the file's program header
3686df95ca2Smiodtable; all entries are the same size.
3696df95ca2Smiod.It Dv e_phnum
3706df95ca2SmiodThis member holds the number of entries in the program header
3716df95ca2Smiodtable.
3726df95ca2SmiodThus the product of
3736df95ca2Smiod.Sy e_phentsize
3746df95ca2Smiodand
3756df95ca2Smiod.Sy e_phnum
3766df95ca2Smiodgives the table's size
3776df95ca2Smiodin bytes.
3786df95ca2SmiodIf a file has no program header,
3796df95ca2Smiod.Sy e_phnum
3806df95ca2Smiodholds the value zero.
3816df95ca2Smiod.It Dv e_shentsize
3826df95ca2SmiodThis member holds a sections header's size in bytes.
3836df95ca2SmiodA section header is one
3846df95ca2Smiodentry in the section header table; all entries are the same size.
3856df95ca2Smiod.It Dv e_shnum
3866df95ca2SmiodThis member holds the number of entries in the section header table.
3876df95ca2SmiodThus
3886df95ca2Smiodthe product of
3896df95ca2Smiod.Sy e_shentsize
3906df95ca2Smiodand
3916df95ca2Smiod.Sy e_shnum
3926df95ca2Smiodgives the section header table's size in bytes.
3936df95ca2SmiodIf a file has no section
3946df95ca2Smiodheader table,
3956df95ca2Smiod.Sy e_shnum
3966df95ca2Smiodholds the value of zero.
3976df95ca2Smiod.It Dv e_shstrndx
3986df95ca2SmiodThis member holds the section header table index of the entry associated
3996df95ca2Smiodwith the section name string table.
4006df95ca2SmiodIf the file has no section name string
4016df95ca2Smiodtable, this member holds the value
4029d0398b3Sschwarze.Dv SHN_UNDEF .
4036df95ca2Smiod.El
4046df95ca2Smiod.Pp
4056df95ca2SmiodAn executable or shared object file's program header table is an array of
4066df95ca2Smiodstructures, each describing a segment or other information the system needs
4076df95ca2Smiodto prepare the program for execution.
4086df95ca2SmiodAn object file
4096df95ca2Smiod.Em segment
4106df95ca2Smiodcontains one or more
4116df95ca2Smiod.Em sections .
4126df95ca2SmiodProgram headers are meaningful only for executable and shared object files.
4136df95ca2SmiodA file specifies its own program header size with the ELF header's
4146df95ca2Smiod.Sy e_phentsize
4156df95ca2Smiodand
4166df95ca2Smiod.Sy e_phnum
4176df95ca2Smiodmembers.
41876764b9bSjmcAs with the ELF executable header, the program header
4196df95ca2Smiodalso has different versions depending on the architecture:
4206df95ca2Smiod.Bd -literal -offset indent
4216df95ca2Smiodtypedef struct {
4226df95ca2Smiod        Elf32_Word      p_type;
4236df95ca2Smiod        Elf32_Off       p_offset;
4246df95ca2Smiod        Elf32_Addr      p_vaddr;
4256df95ca2Smiod        Elf32_Addr      p_paddr;
4266df95ca2Smiod        Elf32_Word      p_filesz;
4276df95ca2Smiod        Elf32_Word      p_memsz;
4286df95ca2Smiod        Elf32_Word      p_flags;
4296df95ca2Smiod        Elf32_Word      p_align;
4306df95ca2Smiod} Elf32_Phdr;
4316df95ca2Smiod.Ed
4326df95ca2Smiod.Bd -literal -offset indent
4336df95ca2Smiodtypedef struct {
43429a5018dSjsg        Elf64_Word      p_type;
43529a5018dSjsg        Elf64_Word      p_flags;
4366df95ca2Smiod        Elf64_Off       p_offset;
4376df95ca2Smiod        Elf64_Addr      p_vaddr;
4386df95ca2Smiod        Elf64_Addr      p_paddr;
4396df95ca2Smiod        Elf64_Xword     p_filesz;
4406df95ca2Smiod        Elf64_Xword     p_memsz;
4416df95ca2Smiod        Elf64_Xword     p_align;
4426df95ca2Smiod} Elf64_Phdr;
4436df95ca2Smiod.Ed
4446df95ca2Smiod.Pp
4456df95ca2SmiodThe main difference between the 32-bit and the 64-bit program header lies
4466df95ca2Smiodonly in the location of a
4476df95ca2Smiod.Sy p_flags
4486df95ca2Smiodmember in the total struct.
44946de36c5Sjmc.Bl -tag -width "p_offset" -offset indent
4506df95ca2Smiod.It Dv p_type
4516df95ca2SmiodThis member of the Phdr struct tells what kind of segment this array
4526df95ca2Smiodelement describes or how to interpret the array element's information.
45346de36c5Sjmc.Bl -tag -width "PT_DYNAMIC"
4546df95ca2Smiod.It Dv PT_NULL
4556df95ca2SmiodThe array element is unused and the other members' values are undefined.
4566df95ca2SmiodThis lets the program header have ignored entries.
4576df95ca2Smiod.It Dv PT_LOAD
4586df95ca2SmiodThe array element specifies a loadable segment, described by
4596df95ca2Smiod.Sy p_filesz
4606df95ca2Smiodand
4616df95ca2Smiod.Sy p_memsz .
4626df95ca2SmiodThe bytes from the file are mapped to the beginning of the memory
4636df95ca2Smiodsegment.
4646df95ca2SmiodIf the segment's memory size
4656df95ca2Smiod.Pq Sy p_memsz
4666df95ca2Smiodis larger than the file size
4676df95ca2Smiod.Pq Sy p_filesz ,
4686df95ca2Smiodthe
4696df95ca2Smiod.Dq extra
4706df95ca2Smiodbytes are defined to hold the value 0 and to follow the segment's
4716df95ca2Smiodinitialized area.
4726df95ca2SmiodThe file size may not be larger than the memory size.
4736df95ca2SmiodLoadable segment entries in the program header table appear in ascending
4746df95ca2Smiodorder, sorted on the
4756df95ca2Smiod.Sy p_vaddr
4766df95ca2Smiodmember.
4776df95ca2Smiod.It Dv PT_DYNAMIC
478db6b419eSguentherThe array element specifies the location and size of the dynamic section,
479db6b419eSguentherboth in the file and in the memory image of the program.
480db6b419eSguentherThis segment type may not occur more than once in a file and may
481db6b419eSguentheronly occur if the dynamic section is part of the memory image of
482db6b419eSguentherthe program.
4836df95ca2Smiod.It Dv PT_INTERP
4846df95ca2SmiodThe array element specifies the location and size of a null-terminated
4856df95ca2Smiodpath name to invoke as an interpreter.
4866df95ca2SmiodThis segment type is meaningful
487fa986dacSdavidonly for executable files (though it may occur for shared objects).
488fa986dacSdavidHowever it may not occur more than once in a file.
48946de36c5SjmcIf it is present, it must precede any loadable segment entry.
4906df95ca2Smiod.It Dv PT_NOTE
4916df95ca2SmiodThe array element specifies the location and size for auxiliary information.
4926df95ca2Smiod.It Dv PT_SHLIB
4936df95ca2SmiodThis segment type is reserved but has unspecified semantics.
4946df95ca2SmiodPrograms that
4956df95ca2Smiodcontain an array element of this type do not conform to the ABI.
4966df95ca2Smiod.It Dv PT_PHDR
497db6b419eSguentherThe array element specifies the location and size of the program
4986df95ca2Smiodheader table itself, both in the file and in the memory image of the program.
499db6b419eSguentherThis segment type may not occur more than once in a file and may
500db6b419eSguentheronly occur if the program header table is part of the memory image
501db6b419eSguentherof the program.
50246de36c5SjmcIf it is present, it must precede any loadable segment entry.
50313553819Sguenther.It Dv PT_TLS
504db6b419eSguentherThe array element specifies the location and size of the
50513553819Sguentherthread-local storage for this file.
50613553819SguentherEach thread in a process loading this file will have the segment's
50713553819Sguenthermemory size
50813553819Sguenther.Pq Sy p_memsz
50913553819Sguentherallocated for it, where the bytes up to the segment's file size
51013553819Sguenther.Pq Sy p_filesz
51113553819Sguentherwill be initialized with the data in this segment and the remaining
51213553819Sguenther.Dq extra
51313553819Sguentherbytes will be set to zero.
514db6b419eSguentherThis segment type may not occur more than once in a file and may
515db6b419eSguentheronly occur if the thread-local storage is part of the memory image
516db6b419eSguentherof the program.
517db6b419eSguenther.It Dv PT_GNU_EH_FRAME
518db6b419eSguentherThe array element specifies the location and size of the GNU exception
519db6b419eSguentherframe header, both in the file and in the memory image of the program.
520db6b419eSguentherThis segment type may not occur more than once in a file and may
521db6b419eSguentheronly occur if the GNU exception frame header is part of the memory
522db6b419eSguentherimage of the program.
523db6b419eSguenther.It Dv PT_GNU_RELRO
524db6b419eSguentherThe array element specifies the location and size of a part of the
525db6b419eSguenthermemory image of the program that should be made read-only once all
526db6b419eSguentherimmediate relocation processing for the file has been performed.
527db6b419eSguentherThis segment type may not occur more than once in a file.
528db6b419eSguenther.It Dv PT_OPENBSD_RANDOMIZE
529db6b419eSguentherThe array element specifies the location and size of a part of the
530db6b419eSguenthermemory image of the program that must be filled with random data
531db6b419eSguentherbefore any code in the object is executed.
532363dd772SguentherThe memory region specified by a segment of this type may overlap
533363dd772Sguentherthe region specified by a
534363dd772Sguenther.Dv PT_GNU_RELRO
5358a37d0a9Sguenthersegment, in which case the intersection will be filled with random
5368a37d0a9Sguentherdata before being marked read-only.
537db6b419eSguentherThis segment type may occur more than once in a file, but a limit
538db6b419eSguentheron the total number of bytes in the segments for an object of no
539db6b419eSguentherless than 65536 bytes may be imposed.
540db6b419eSguenther.It Dv PT_OPENBSD_WXNEEDED
541db6b419eSguentherThe array element specifies that a process executing this file may
542db6b419eSguentherneed to be able to map or protect memory regions as simultaneously
543db6b419eSguentherexecutable and writable.
5443464b97eSjmcIf the system is unable or unwilling to permit that for this executable
545db6b419eSguentherthen it may fail immediately.
546db6b419eSguentherThis segment type is meaningful only for executable files and is
547db6b419eSguentherignored in other objects.
548428d4e86Skettenis.It Dv PT_LOOS
549428d4e86SkettenisThis value up to and including
5509d0398b3Sschwarze.Dv PT_HIOS
551ec774d31Sjcais reserved for operating system-specific semantics.
552428d4e86Skettenis.It Dv PT_HIOS
553428d4e86SkettenisThis value down to and including
5549d0398b3Sschwarze.Dv PT_LOOS
555428d4e86Skettenisis reserved for operating system-specific semantics.
5566df95ca2Smiod.It Dv PT_LOPROC
55781bc2514SkettenisThis value up to and including
5589d0398b3Sschwarze.Dv PT_HIPROC
55981bc2514Skettenisis reserved for processor-specific semantics.
5606df95ca2Smiod.It Dv PT_HIPROC
56181bc2514SkettenisThis value down to and including
5629d0398b3Sschwarze.Dv PT_LOPROC
56381bc2514Skettenisis reserved for processor-specific semantics.
5646df95ca2Smiod.El
5656df95ca2Smiod.It Dv p_offset
5666df95ca2SmiodThis member holds the offset from the beginning of the file at which
5678637447dSderaadtthe first byte of the segment resides.
5686df95ca2Smiod.It Dv p_vaddr
5696df95ca2SmiodThis member holds the virtual address at which the first byte of the
5706df95ca2Smiodsegment resides in memory.
5716df95ca2Smiod.It Dv p_paddr
5726df95ca2SmiodOn systems for which physical addressing is relevant, this member is
5736df95ca2Smiodreserved for the segment's physical address.
5746df95ca2SmiodUnder
5756df95ca2Smiod.Bx
5766df95ca2Smiodthis member is
5776df95ca2Smiodnot used and must be zero.
5786df95ca2Smiod.It Dv p_filesz
5796df95ca2SmiodThis member holds the number of bytes in the file image of the segment.
5806df95ca2SmiodIt may be zero.
5816df95ca2Smiod.It Dv p_memsz
5826df95ca2SmiodThis member holds the number of bytes in the memory image of the segment.
5836df95ca2SmiodIt may be zero.
5846df95ca2Smiod.It Dv p_flags
5856df95ca2SmiodThis member holds flags relevant to the segment:
5866df95ca2Smiod.Pp
5876df95ca2Smiod.Bl -tag -width "PF_X" -compact
5886df95ca2Smiod.It Dv PF_X
5896df95ca2SmiodAn executable segment.
5906df95ca2Smiod.It Dv PF_W
5916df95ca2SmiodA writable segment.
5926df95ca2Smiod.It Dv PF_R
5936df95ca2SmiodA readable segment.
5946df95ca2Smiod.El
5956df95ca2Smiod.Pp
5966df95ca2SmiodA text segment commonly has the flags
5979d0398b3Sschwarze.Dv PF_X
5986df95ca2Smiodand
5999d0398b3Sschwarze.Dv PF_R .
6006df95ca2SmiodA data segment commonly has
6019d0398b3Sschwarze.Dv PF_X ,
6029d0398b3Sschwarze.Dv PF_W
6036df95ca2Smiodand
6049d0398b3Sschwarze.Dv PF_R .
6056df95ca2Smiod.It Dv p_align
6066df95ca2SmiodThis member holds the value to which the segments are aligned in memory
6076df95ca2Smiodand in the file.
6086df95ca2SmiodLoadable process segments must have congruent values for
6096df95ca2Smiod.Sy p_vaddr
6106df95ca2Smiodand
6116df95ca2Smiod.Sy p_offset ,
6126df95ca2Smiodmodulo the page size.
6136df95ca2SmiodValues of zero and one mean no alignment is required.
6146df95ca2SmiodOtherwise,
6156df95ca2Smiod.Sy p_align
6166df95ca2Smiodshould be a positive, integral power of two, and
6176df95ca2Smiod.Sy p_vaddr
6186df95ca2Smiodshould equal
6196df95ca2Smiod.Sy p_offset ,
6206df95ca2Smiodmodulo
6216df95ca2Smiod.Sy p_align .
6226df95ca2Smiod.El
6236df95ca2Smiod.Pp
6248637447dSderaadtA file's section header table lets one locate all the file's sections.
6256df95ca2SmiodThe
6266df95ca2Smiodsection header table is an array of Elf32_Shdr or Elf64_Shdr structures.
6276df95ca2SmiodThe
6286df95ca2SmiodELF header's
6296df95ca2Smiod.Sy e_shoff
6306df95ca2Smiodmember gives the byte offset from the beginning of the file to the section
6316df95ca2Smiodheader table.
6326df95ca2Smiod.Sy e_shnum
6336df95ca2Smiodholds the number of entries the section header table contains.
6346df95ca2Smiod.Sy e_shentsize
6356df95ca2Smiodholds the size in bytes of each entry.
6366df95ca2Smiod.Pp
6376df95ca2SmiodA section header table index is a subscript into this array.
6386df95ca2SmiodSome section
6396df95ca2Smiodheader table indices are reserved.
6406df95ca2SmiodAn object file does not have sections for
6416df95ca2Smiodthese special indices:
64246de36c5Sjmc.Bl -tag -width "SHN_LORESERVE"
6436df95ca2Smiod.It Dv SHN_UNDEF
6446df95ca2SmiodThis value marks an undefined, missing, irrelevant or otherwise meaningless
6456df95ca2Smiodsection reference.
64681bc2514SkettenisFor example, a symbol
64781bc2514Skettenis.Dq defined
64881bc2514Skettenisrelative to section number
6499d0398b3Sschwarze.Dv SHN_UNDEF
65081bc2514Skettenisis an undefined symbol.
6516df95ca2Smiod.It Dv SHN_LORESERVE
6526df95ca2SmiodThis value specifies the lower bound of the range of reserved indices.
6536df95ca2Smiod.It Dv SHN_LOPROC
65481bc2514SkettenisThis value up to and including
6559d0398b3Sschwarze.Dv SHN_HIPROC
65681bc2514Skettenisis reserved for processor-specific semantics.
6576df95ca2Smiod.It Dv SHN_HIPROC
65881bc2514SkettenisThis value down to and including
6599d0398b3Sschwarze.Dv SHN_LOPROC
66081bc2514Skettenisis reserved for processor-specific semantics.
6616df95ca2Smiod.It Dv SHN_ABS
66205c18f6fSmillertThis value specifies the absolute value for the corresponding reference.
6636df95ca2SmiodFor
66405c18f6fSmillertexample, a symbol defined relative to section number
6659d0398b3Sschwarze.Dv SHN_ABS
66605c18f6fSmillerthas an absolute value and is not affected by relocation.
6676df95ca2Smiod.It Dv SHN_COMMON
6686df95ca2SmiodSymbols defined relative to this section are common symbols, such as FORTRAN
6696df95ca2SmiodCOMMON or unallocated C external variables.
6706df95ca2Smiod.It Dv SHN_HIRESERVE
6716df95ca2SmiodThis value specifies the upper bound of the range of reserved indices.
6726df95ca2SmiodThe
6736df95ca2Smiodsystem reserves indices between
6749d0398b3Sschwarze.Dv SHN_LORESERVE
6756df95ca2Smiodand
6769d0398b3Sschwarze.Dv SHN_HIRESERVE ,
6776df95ca2Smiodinclusive.
6786df95ca2SmiodThe section header table does not contain entries for the
6796df95ca2Smiodreserved indices.
6806df95ca2Smiod.El
6816df95ca2Smiod.Pp
6826df95ca2SmiodThe section header has the following structure:
6836df95ca2Smiod.Bd -literal -offset indent
6846df95ca2Smiodtypedef struct {
6856df95ca2Smiod	Elf32_Word      sh_name;
6866df95ca2Smiod	Elf32_Word      sh_type;
6876df95ca2Smiod	Elf32_Word      sh_flags;
6886df95ca2Smiod	Elf32_Addr      sh_addr;
6896df95ca2Smiod	Elf32_Off       sh_offset;
6906df95ca2Smiod	Elf32_Word      sh_size;
6916df95ca2Smiod	Elf32_Word      sh_link;
6926df95ca2Smiod	Elf32_Word      sh_info;
6936df95ca2Smiod	Elf32_Word      sh_addralign;
6946df95ca2Smiod	Elf32_Word      sh_entsize;
6956df95ca2Smiod} Elf32_Shdr;
6966df95ca2Smiod.Ed
6976df95ca2Smiod.Bd -literal -offset indent
6986df95ca2Smiodtypedef struct {
69929a5018dSjsg	Elf64_Word      sh_name;
70029a5018dSjsg	Elf64_Word      sh_type;
7016df95ca2Smiod	Elf64_Xword     sh_flags;
7026df95ca2Smiod	Elf64_Addr      sh_addr;
7036df95ca2Smiod	Elf64_Off       sh_offset;
7046df95ca2Smiod	Elf64_Xword     sh_size;
70529a5018dSjsg	Elf64_Word      sh_link;
70629a5018dSjsg	Elf64_Word      sh_info;
7076df95ca2Smiod	Elf64_Xword     sh_addralign;
7086df95ca2Smiod	Elf64_Xword     sh_entsize;
7096df95ca2Smiod} Elf64_Shdr;
7106df95ca2Smiod.Ed
71146de36c5Sjmc.Bl -tag -width "sh_addralign"
7126df95ca2Smiod.It Dv sh_name
7136df95ca2SmiodThis member specifies the name of the section.
7146df95ca2SmiodIts value is an index
7156df95ca2Smiodinto the section header string table section, giving the location of
7166df95ca2Smioda null-terminated string.
7176df95ca2Smiod.It Dv sh_type
7186df95ca2SmiodThis member categorizes the section's contents and semantics.
71946de36c5Sjmc.Bl -tag -width "SHT_PROGBITS"
7206df95ca2Smiod.It Dv SHT_NULL
7216df95ca2SmiodThis value marks the section header as inactive.
7226df95ca2SmiodIt does not
7236df95ca2Smiodhave an associated section.
7246df95ca2SmiodOther members of the section header
7256df95ca2Smiodhave undefined values.
7266df95ca2Smiod.It Dv SHT_PROGBITS
72746de36c5SjmcThis section holds information defined by the program, whose
7286df95ca2Smiodformat and meaning are determined solely by the program.
7296df95ca2Smiod.It Dv SHT_SYMTAB
7306df95ca2SmiodThis section holds a symbol table.
7316df95ca2SmiodTypically,
7329d0398b3Sschwarze.Dv SHT_SYMTAB
7336df95ca2Smiodprovides symbols for link editing, though it may also be used
7346df95ca2Smiodfor dynamic linking.
7356df95ca2SmiodAs a complete symbol table, it may contain
7366df95ca2Smiodmany symbols unnecessary for dynamic linking.
7376df95ca2SmiodAn object file can
7386df95ca2Smiodalso contain a
7399d0398b3Sschwarze.Dv SHT_DYNSYM
7406df95ca2Smiodsection.
7416df95ca2Smiod.It Dv SHT_STRTAB
7426df95ca2SmiodThis section holds a string table.
7436df95ca2SmiodAn object file may have multiple
7446df95ca2Smiodstring table sections.
7456df95ca2Smiod.It Dv SHT_RELA
7466df95ca2SmiodThis section holds relocation entries with explicit addends, such
7476df95ca2Smiodas type
7486df95ca2Smiod.Sy Elf32_Rela
7496df95ca2Smiodfor the 32-bit class of object files.
7506df95ca2SmiodAn object may have multiple
7516df95ca2Smiodrelocation sections.
7526df95ca2Smiod.It Dv SHT_HASH
7536df95ca2SmiodThis section holds a symbol hash table.
7548637447dSderaadtAn object participating in
7556df95ca2Smioddynamic linking must contain a symbol hash table.
7566df95ca2SmiodAn object file may
7576df95ca2Smiodhave only one hash table.
7586df95ca2Smiod.It Dv SHT_DYNAMIC
7596df95ca2SmiodThis section holds information for dynamic linking.
7606df95ca2SmiodAn object file may
7616df95ca2Smiodhave only one dynamic section.
7626df95ca2Smiod.It Dv SHT_NOTE
7636df95ca2SmiodThis section holds information that marks the file in some way.
7646df95ca2Smiod.It Dv SHT_NOBITS
7656df95ca2SmiodA section of this type occupies no space in the file but otherwise
7666df95ca2Smiodresembles
7679d0398b3Sschwarze.Dv SHT_PROGBITS .
7686df95ca2SmiodAlthough this section contains no bytes, the
7696df95ca2Smiod.Sy sh_offset
7706df95ca2Smiodmember contains the conceptual file offset.
7716df95ca2Smiod.It Dv SHT_REL
7726df95ca2SmiodThis section holds relocation offsets without explicit addends, such
7736df95ca2Smiodas type
7746df95ca2Smiod.Sy Elf32_Rel
7756df95ca2Smiodfor the 32-bit class of object files.
7766df95ca2SmiodAn object file may have multiple
7776df95ca2Smiodrelocation sections.
7786df95ca2Smiod.It Dv SHT_SHLIB
7796df95ca2SmiodThis section is reserved but has unspecified semantics.
7806df95ca2Smiod.It Dv SHT_DYNSYM
7816df95ca2SmiodThis section holds a minimal set of dynamic linking symbols.
7826df95ca2SmiodAn
7836df95ca2Smiodobject file can also contain a
7849d0398b3Sschwarze.Dv SHT_SYMTAB
7856df95ca2Smiodsection.
7866df95ca2Smiod.It Dv SHT_LOPROC
7876df95ca2SmiodThis value up to and including
7889d0398b3Sschwarze.Dv SHT_HIPROC
7898637447dSderaadtis reserved for processor-specific semantics.
7906df95ca2Smiod.It Dv SHT_HIPROC
7916df95ca2SmiodThis value down to and including
7929d0398b3Sschwarze.Dv SHT_LOPROC
7938637447dSderaadtis reserved for processor-specific semantics.
7946df95ca2Smiod.It Dv SHT_LOUSER
7956df95ca2SmiodThis value specifies the lower bound of the range of indices reserved for
7966df95ca2Smiodapplication programs.
7976df95ca2Smiod.It Dv SHT_HIUSER
7986df95ca2SmiodThis value specifies the upper bound of the range of indices reserved for
7996df95ca2Smiodapplication programs.
8006df95ca2SmiodSection types between
8019d0398b3Sschwarze.Dv SHT_LOUSER
8026df95ca2Smiodand
8039d0398b3Sschwarze.Dv SHT_HIUSER
8046df95ca2Smiodmay be used by the application, without conflicting with current or future
8056df95ca2Smiodsystem-defined section types.
8066df95ca2Smiod.El
8076df95ca2Smiod.It Dv sh_flags
8086df95ca2SmiodSections support one-bit flags that describe miscellaneous attributes.
8096df95ca2SmiodIf a flag bit is set in
8106df95ca2Smiod.Sy sh_flags ,
8116df95ca2Smiodthe attribute is
8126df95ca2Smiod.Dq on
8136df95ca2Smiodfor the section.
8146df95ca2SmiodOtherwise, the attribute is
8156df95ca2Smiod.Dq off
8166df95ca2Smiodor does not apply.
8176df95ca2SmiodUndefined attributes are set to zero.
8186df95ca2Smiod.Pp
8196df95ca2Smiod.Bl -tag -width "SHF_EXECINSTR" -compact
8206df95ca2Smiod.It Dv SHF_WRITE
8216df95ca2SmiodThis section contains data that should be writable during process
8226df95ca2Smiodexecution.
8236df95ca2Smiod.It Dv SHF_ALLOC
8248637447dSderaadtThis section occupies memory during process execution.
8256df95ca2SmiodSome control
8266df95ca2Smiodsections do not reside in the memory image of an object file.
8276df95ca2SmiodThis
8286df95ca2Smiodattribute is off for those sections.
8296df95ca2Smiod.It Dv SHF_EXECINSTR
8308637447dSderaadtThis section contains executable machine instructions.
83113553819Sguenther.It Dv SHF_TLS
83213553819SguentherThis section is for thread-local storage.
8336df95ca2Smiod.It Dv SHF_MASKPROC
8346df95ca2SmiodAll bits included in this mask are reserved for processor-specific
8356df95ca2Smiodsemantics.
8366df95ca2Smiod.El
8376df95ca2Smiod.It Dv sh_addr
8388637447dSderaadtIf this section appears in the memory image of a process, this member
8396df95ca2Smiodholds the address at which the section's first byte should reside.
8406df95ca2SmiodOtherwise, the member contains zero.
8416df95ca2Smiod.It Dv sh_offset
8426df95ca2SmiodThis member's value holds the byte offset from the beginning of the file
8436df95ca2Smiodto the first byte in the section.
8446df95ca2SmiodOne section type,
8459d0398b3Sschwarze.Dv SHT_NOBITS ,
8466df95ca2Smiodoccupies no space in the file, and its
8476df95ca2Smiod.Sy sh_offset
8486df95ca2Smiodmember locates the conceptual placement in the file.
8496df95ca2Smiod.It Dv sh_size
8506df95ca2SmiodThis member holds the section's size in bytes.
8516df95ca2SmiodUnless the section type
8526df95ca2Smiodis
8539d0398b3Sschwarze.Dv SHT_NOBITS ,
8546df95ca2Smiodthe section occupies
8556df95ca2Smiod.Sy sh_size
8566df95ca2Smiodbytes in the file.
8576df95ca2SmiodA section of type
8589d0398b3Sschwarze.Dv SHT_NOBITS
8596df95ca2Smiodmay have a non-zero size, but it occupies no space in the file.
8606df95ca2Smiod.It Dv sh_link
8616df95ca2SmiodThis member holds a section header table index link, whose interpretation
8626df95ca2Smioddepends on the section type.
8636df95ca2Smiod.It Dv sh_info
8646df95ca2SmiodThis member holds extra information, whose interpretation depends on the
8656df95ca2Smiodsection type.
8666df95ca2Smiod.It Dv sh_addralign
8676df95ca2SmiodSome sections have address alignment constraints.
8686df95ca2SmiodIf a section holds a
8696df95ca2Smioddoubleword, the system must ensure doubleword alignment for the entire
8706df95ca2Smiodsection.
8716df95ca2SmiodThat is, the value of
8726df95ca2Smiod.Sy sh_addr
8736df95ca2Smiodmust be congruent to zero, modulo the value of
8746df95ca2Smiod.Sy sh_addralign .
8756df95ca2SmiodOnly zero and positive integral powers of two are allowed.
8766df95ca2SmiodValues of zero
8776df95ca2Smiodor one mean the section has no alignment constraints.
8786df95ca2Smiod.It Dv sh_entsize
8796df95ca2SmiodSome sections hold a table of fixed-sized entries, such as a symbol table.
8806df95ca2SmiodFor such a section, this member gives the size in bytes for each entry.
8816df95ca2SmiodThis member contains zero if the section does not hold a table of
8826df95ca2Smiodfixed-size entries.
8836df95ca2Smiod.El
8846df95ca2Smiod.Pp
8856df95ca2SmiodVarious sections hold program and control information:
88646de36c5Sjmc.Bl -tag -width ".shstrtab"
88772123b7dSjasper.It .SUNW_ctf
88872123b7dSjasperThis section contains the (un)compressed Compact C-Type Format data
88972123b7dSjasperdescribing the object's types and symbols.
89072123b7dSjasperThis section is of type
89172123b7dSjasper.Dv SHT_PROGBITS .
8926df95ca2Smiod.It .bss
89313553819SguentherThis section holds uninitialized data that contribute to the program's
8946df95ca2Smiodmemory image.
8956df95ca2SmiodBy definition, the system initializes the data with zeros
8966df95ca2Smiodwhen the program begins to run.
8976df95ca2SmiodThis section is of type
8989d0398b3Sschwarze.Dv SHT_NOBITS .
89946de36c5SjmcThe attribute types are
9009d0398b3Sschwarze.Dv SHF_ALLOC
9016df95ca2Smiodand
9029d0398b3Sschwarze.Dv SHF_WRITE .
9036df95ca2Smiod.It .comment
9046df95ca2SmiodThis section holds version control information.
9056df95ca2SmiodThis section is of type
9069d0398b3Sschwarze.Dv SHT_PROGBITS .
9076df95ca2SmiodNo attribute types are used.
9086df95ca2Smiod.It .ctors
9096df95ca2SmiodThis section holds initialized pointers to the C++ constructor functions.
9106df95ca2SmiodThis section is of type
9119d0398b3Sschwarze.Dv SHT_PROGBITS .
9126df95ca2SmiodThe attribute types are
9139d0398b3Sschwarze.Dv SHF_ALLOC
9146df95ca2Smiodand
9159d0398b3Sschwarze.Dv SHF_WRITE .
9166df95ca2Smiod.It .data
9176df95ca2SmiodThis section holds initialized data that contribute to the program's
9186df95ca2Smiodmemory image.
9196df95ca2SmiodThis section is of type
9209d0398b3Sschwarze.Dv SHT_PROGBITS .
9216df95ca2SmiodThe attribute types are
9229d0398b3Sschwarze.Dv SHF_ALLOC
9236df95ca2Smiodand
9249d0398b3Sschwarze.Dv SHF_WRITE .
9256df95ca2Smiod.It .data1
9266df95ca2SmiodThis section holds initialized data that contribute to the program's
9276df95ca2Smiodmemory image.
9286df95ca2SmiodThis section is of type
9299d0398b3Sschwarze.Dv SHT_PROGBITS .
9306df95ca2SmiodThe attribute types are
9319d0398b3Sschwarze.Dv SHF_ALLOC
9326df95ca2Smiodand
9339d0398b3Sschwarze.Dv SHF_WRITE .
9346df95ca2Smiod.It .debug
9356df95ca2SmiodThis section holds information for symbolic debugging.
9366df95ca2SmiodThe contents
9376df95ca2Smiodare unspecified.
9386df95ca2SmiodThis section is of type
9399d0398b3Sschwarze.Dv SHT_PROGBITS .
9406df95ca2SmiodNo attribute types are used.
9416df95ca2Smiod.It .dtors
9426df95ca2SmiodThis section holds initialized pointers to the C++ destructor functions.
9436df95ca2SmiodThis section is of type
9449d0398b3Sschwarze.Dv SHT_PROGBITS .
9456df95ca2SmiodThe attribute types are
9469d0398b3Sschwarze.Dv SHF_ALLOC
9476df95ca2Smiodand
9489d0398b3Sschwarze.Dv SHF_WRITE .
9496df95ca2Smiod.It .dynamic
9506df95ca2SmiodThis section holds dynamic linking information.
9516df95ca2SmiodThe section's attributes
9526df95ca2Smiodwill include the
9539d0398b3Sschwarze.Dv SHF_ALLOC
9546df95ca2Smiodbit.
9556df95ca2SmiodWhether the
9569d0398b3Sschwarze.Dv SHF_WRITE
9576df95ca2Smiodbit is set is processor-specific.
9586df95ca2SmiodThis section is of type
9599d0398b3Sschwarze.Dv SHT_DYNAMIC .
9606df95ca2SmiodSee the attributes above.
9616df95ca2Smiod.It .dynstr
9626df95ca2SmiodThis section holds strings needed for dynamic linking, most commonly
9636df95ca2Smiodthe strings that represent the names associated with symbol table entries.
9646df95ca2SmiodThis section is of type
9659d0398b3Sschwarze.Dv SHT_STRTAB .
9666df95ca2SmiodThe attribute type used is
9679d0398b3Sschwarze.Dv SHF_ALLOC .
9686df95ca2Smiod.It .dynsym
9696df95ca2SmiodThis section holds the dynamic linking symbol table.
9706df95ca2SmiodThis section is of type
9719d0398b3Sschwarze.Dv SHT_DYNSYM .
9726df95ca2SmiodThe attribute used is
9739d0398b3Sschwarze.Dv SHF_ALLOC .
9746df95ca2Smiod.It .fini
9756df95ca2SmiodThis section holds executable instructions that contribute to the process
9766df95ca2Smiodtermination code.
977*41ce3b17SnaddyWhen a program exits normally, the system arranges to
9786df95ca2Smiodexecute the code in this section.
9796df95ca2SmiodThis section is of type
9809d0398b3Sschwarze.Dv SHT_PROGBITS .
9816df95ca2SmiodThe attributes used are
9829d0398b3Sschwarze.Dv SHF_ALLOC
9836df95ca2Smiodand
9849d0398b3Sschwarze.Dv SHF_EXECINSTR .
9856df95ca2Smiod.It .got
9866df95ca2SmiodThis section holds the global offset table.
9876df95ca2SmiodThis section is of type
9889d0398b3Sschwarze.Dv SHT_PROGBITS .
9896df95ca2SmiodThe attributes are processor-specific.
9906df95ca2Smiod.It .hash
9916df95ca2SmiodThis section holds a symbol hash table.
9926df95ca2SmiodThis section is of type
9939d0398b3Sschwarze.Dv SHT_HASH .
9946df95ca2SmiodThe attribute used is
9959d0398b3Sschwarze.Dv SHF_ALLOC .
9966df95ca2Smiod.It .init
9976df95ca2SmiodThis section holds executable instructions that contribute to the process
9986df95ca2Smiodinitialization code.
999*41ce3b17SnaddyWhen a program starts to run, the system arranges to
10006df95ca2Smiodexecute the code in this section before calling the main program entry point.
10016df95ca2SmiodThis section is of type
10029d0398b3Sschwarze.Dv SHT_PROGBITS .
10036df95ca2SmiodThe attributes used are
10049d0398b3Sschwarze.Dv SHF_ALLOC
10056df95ca2Smiodand
10069d0398b3Sschwarze.Dv SHF_EXECINSTR .
10076df95ca2Smiod.It .interp
10086df95ca2SmiodThis section holds the pathname of a program interpreter.
10096df95ca2SmiodIf the file has
10106df95ca2Smioda loadable segment that includes the section, the section's attributes will
10116df95ca2Smiodinclude the
10129d0398b3Sschwarze.Dv SHF_ALLOC
10136df95ca2Smiodbit.
10146df95ca2SmiodOtherwise, that bit will be off.
10156df95ca2SmiodThis section is of type
10169d0398b3Sschwarze.Dv SHT_PROGBITS .
10176df95ca2Smiod.It .line
10186df95ca2SmiodThis section holds line number information for symbolic debugging, which
10196df95ca2Smioddescribes the correspondence between the program source and the machine code.
10206df95ca2SmiodThe contents are unspecified.
10216df95ca2SmiodThis section is of type
10229d0398b3Sschwarze.Dv SHT_PROGBITS .
10236df95ca2SmiodNo attribute types are used.
10246df95ca2Smiod.It .note
10256df95ca2SmiodThis section holds information in the
10261aadfae2Sjmcnote section
10276df95ca2Smiodformat described below.
10286df95ca2SmiodThis section is of type
10299d0398b3Sschwarze.Dv SHT_NOTE .
10306df95ca2SmiodNo attribute types are used.
10316df95ca2Smiod.Ox
10323ae2476eSjmcnative executables contain a
10336df95ca2Smiod.Sy .note.openbsd.ident
1034a7516626Sjmcsection to identify themselves.
10356df95ca2Smiod.It .plt
10366df95ca2SmiodThis section holds the procedure linkage table.
10376df95ca2SmiodThis section is of type
10389d0398b3Sschwarze.Dv SHT_PROGBITS .
10396df95ca2SmiodThe attributes are processor-specific.
10406df95ca2Smiod.It .relNAME
10416df95ca2SmiodThis section holds relocation information as described below.
10426df95ca2SmiodIf the file
10436df95ca2Smiodhas a loadable segment that includes relocation, the section's attributes
10446df95ca2Smiodwill include the
10459d0398b3Sschwarze.Dv SHF_ALLOC
10466df95ca2Smiodbit.
10476df95ca2SmiodOtherwise the bit will be off.
10486df95ca2SmiodBy convention,
10496df95ca2Smiod.Dq NAME
10506df95ca2Smiodis supplied by the section to which the relocations apply.
10516df95ca2SmiodThus a relocation
10526df95ca2Smiodsection for
10536df95ca2Smiod.Sy .text
10546df95ca2Smiodnormally would have the name
10556df95ca2Smiod.Sy .rel.text .
10566df95ca2SmiodThis section is of type
10579d0398b3Sschwarze.Dv SHT_REL .
10586df95ca2Smiod.It .relaNAME
10596df95ca2SmiodThis section holds relocation information as described below.
10606df95ca2SmiodIf the file
10616df95ca2Smiodhas a loadable segment that includes relocation, the section's attributes
10626df95ca2Smiodwill include the
10639d0398b3Sschwarze.Dv SHF_ALLOC
10646df95ca2Smiodbit.
10656df95ca2SmiodOtherwise the bit will be off.
10666df95ca2SmiodBy convention,
10676df95ca2Smiod.Dq NAME
10686df95ca2Smiodis supplied by the section to which the relocations apply.
10696df95ca2SmiodThus a relocation
10706df95ca2Smiodsection for
10716df95ca2Smiod.Sy .text
10726df95ca2Smiodnormally would have the name
10736df95ca2Smiod.Sy .rela.text .
10746df95ca2SmiodThis section is of type
10759d0398b3Sschwarze.Dv SHT_RELA .
10766df95ca2Smiod.It .rodata
107713553819SguentherThis section holds read-only data that typically contribute to a
10786df95ca2Smiodnon-writable segment in the process image.
10796df95ca2SmiodThis section is of type
10809d0398b3Sschwarze.Dv SHT_PROGBITS .
10816df95ca2SmiodThe attribute used is
10829d0398b3Sschwarze.Dv SHF_ALLOC .
10836df95ca2Smiod.It .rodata1
108413553819SguentherThis section holds read-only data that typically contribute to a
10856df95ca2Smiodnon-writable segment in the process image.
10866df95ca2SmiodThis section is of type
10879d0398b3Sschwarze.Dv SHT_PROGBITS .
10886df95ca2SmiodThe attribute used is
10899d0398b3Sschwarze.Dv SHF_ALLOC .
10906df95ca2Smiod.It .shstrtab
10916df95ca2SmiodThis section holds section names.
10926df95ca2SmiodThis section is of type
10939d0398b3Sschwarze.Dv SHT_STRTAB .
10946df95ca2SmiodNo attribute types are used.
10956df95ca2Smiod.It .strtab
10966df95ca2SmiodThis section holds strings, most commonly the strings that represent the
10976df95ca2Smiodnames associated with symbol table entries.
10986df95ca2SmiodIf the file has a loadable
10996df95ca2Smiodsegment that includes the symbol string table, the section's attributes
11006df95ca2Smiodwill include the
11019d0398b3Sschwarze.Dv SHF_ALLOC
11026df95ca2Smiodbit.
11036df95ca2SmiodOtherwise the bit will be off.
11046df95ca2SmiodThis section is of type
11059d0398b3Sschwarze.Dv SHT_STRTAB .
11066df95ca2Smiod.It .symtab
11076df95ca2SmiodThis section holds a symbol table.
11086df95ca2SmiodIf the file has a loadable segment
11096df95ca2Smiodthat includes the symbol table, the section's attributes will include
11106df95ca2Smiodthe
11119d0398b3Sschwarze.Dv SHF_ALLOC
11126df95ca2Smiodbit.
11136df95ca2SmiodOtherwise the bit will be off.
11146df95ca2SmiodThis section is of type
11159d0398b3Sschwarze.Dv SHT_SYMTAB .
111613553819Sguenther.It .tbss
111713553819SguentherThis section is the thread-local storage version of
111813553819Sguenther.Sy .bss ,
111913553819Sguentherholding uninitialized data that contribute to the program's memory
112013553819Sguentherimage on a per-thread basis.
112113553819SguentherBy definition, the system allocates and initializes the data with
112213553819Sguentherzeros for each thread before it first accesses it.
112313553819SguentherThis section is of type
11249d0398b3Sschwarze.Dv SHT_NOBITS .
112513553819SguentherThe attribute types are
11269d0398b3Sschwarze.Dv SHF_ALLOC ,
11279d0398b3Sschwarze.Dv SHF_WRITE ,
112813553819Sguentherand
11299d0398b3Sschwarze.Dv SHF_TLS .
113013553819Sguenther.It .tdata
113113553819SguentherThis section is the thread-local storage version of
113213553819Sguenther.Sy .data ,
113313553819Sguentherholding initialized data that contribute to the program's memory
113413553819Sguentherimage on a per-thread basis.
113513553819SguentherThe system allocates and initializes the data for each thread before
113613553819Sguentherit first accesses it.
113713553819SguentherThis section is of type
11389d0398b3Sschwarze.Dv SHT_PROGBITS .
113913553819SguentherThe attribute types are
11409d0398b3Sschwarze.Dv SHF_ALLOC ,
11419d0398b3Sschwarze.Dv SHF_WRITE ,
114213553819Sguentherand
11439d0398b3Sschwarze.Dv SHF_TLS .
11446df95ca2Smiod.It .text
11456df95ca2SmiodThis section holds the
11466df95ca2Smiod.Dq text ,
11476df95ca2Smiodor executable instructions, of a program.
11486df95ca2SmiodThis section is of type
11499d0398b3Sschwarze.Dv SHT_PROGBITS .
11506df95ca2SmiodThe attributes used are
11519d0398b3Sschwarze.Dv SHF_ALLOC
11526df95ca2Smiodand
11539d0398b3Sschwarze.Dv SHF_EXECINSTR .
11546df95ca2Smiod.El
11556df95ca2Smiod.Pp
11566df95ca2SmiodString table sections hold null-terminated character sequences, commonly
11576df95ca2Smiodcalled strings.
11586df95ca2SmiodThe object file uses these strings to represent symbol
11596df95ca2Smiodand section names.
11606df95ca2SmiodOne references a string as an index into the string
11616df95ca2Smiodtable section.
11626df95ca2SmiodThe first byte, which is index zero, is defined to hold
11636df95ca2Smioda null character.
11646df95ca2SmiodSimilarly, a string table's last byte is defined to
11656df95ca2Smiodhold a null character, ensuring null termination for all strings.
11666df95ca2Smiod.Pp
11676df95ca2SmiodAn object file's symbol table holds information needed to locate and
11686df95ca2Smiodrelocate a program's symbolic definitions and references.
11696df95ca2SmiodA symbol table
11706df95ca2Smiodindex is a subscript into this array.
11716df95ca2Smiod.Bd -literal -offset indent
11726df95ca2Smiodtypedef struct {
11736df95ca2Smiod	Elf32_Word      st_name;
11746df95ca2Smiod	Elf32_Addr      st_value;
11756df95ca2Smiod	Elf32_Word      st_size;
11766df95ca2Smiod	unsigned char   st_info;
11776df95ca2Smiod	unsigned char   st_other;
11786df95ca2Smiod	Elf32_Half      st_shndx;
11796df95ca2Smiod} Elf32_Sym;
11806df95ca2Smiod.Ed
11816df95ca2Smiod.Bd -literal -offset indent
11826df95ca2Smiodtypedef struct {
118329a5018dSjsg	Elf64_Word      st_name;
118429a5018dSjsg	unsigned char	st_info;
118529a5018dSjsg	unsigned char	st_other;
118629a5018dSjsg	Elf64_Half   	st_shndx;
118729a5018dSjsg	Elf64_Addr	st_value;
11886df95ca2Smiod	Elf64_Xword     st_size;
11896df95ca2Smiod} Elf64_Sym;
11906df95ca2Smiod.Ed
119146de36c5Sjmc.Bl -tag -width "st_value"
11926df95ca2Smiod.It Dv st_name
11936df95ca2SmiodThis member holds an index into the object file's symbol string table,
11946df95ca2Smiodwhich holds character representations of the symbol names.
11956df95ca2SmiodIf the value
11966df95ca2Smiodis non-zero, it represents a string table index that gives the symbol
11976df95ca2Smiodname.
11986df95ca2SmiodOtherwise, the symbol table has no name.
11996df95ca2Smiod.It Dv st_value
12006df95ca2SmiodThis member gives the value of the associated symbol.
12016df95ca2Smiod.It Dv st_size
12026df95ca2SmiodMany symbols have associated sizes.
12036df95ca2SmiodThis member holds zero if the symbol
12046df95ca2Smiodhas no size or an unknown size.
12056df95ca2Smiod.It Dv st_info
12066df95ca2SmiodThis member specifies the symbol's type and binding attributes:
120746de36c5Sjmc.Bl -tag -width "STT_SECTION"
12086df95ca2Smiod.It Dv STT_NOTYPE
12096df95ca2SmiodThe symbol's type is not defined.
12106df95ca2Smiod.It Dv STT_OBJECT
12116df95ca2SmiodThe symbol is associated with a data object.
12126df95ca2Smiod.It Dv STT_FUNC
12136df95ca2SmiodThe symbol is associated with a function or other executable code.
12146df95ca2Smiod.It Dv STT_SECTION
12156df95ca2SmiodThe symbol is associated with a section.
12166df95ca2SmiodSymbol table entries of
12176df95ca2Smiodthis type exist primarily for relocation and normally have
12189d0398b3Sschwarze.Dv STB_LOCAL
12196df95ca2Smiodbindings.
12206df95ca2Smiod.It Dv STT_FILE
122146de36c5SjmcBy convention, the symbol's name gives the name of the source file
12226df95ca2Smiodassociated with the object file.
12236df95ca2SmiodA file symbol has
12249d0398b3Sschwarze.Dv STB_LOCAL
12256df95ca2Smiodbindings, its section index is
12269d0398b3Sschwarze.Dv SHN_ABS ,
12276df95ca2Smiodand it precedes the other
12289d0398b3Sschwarze.Dv STB_LOCAL
12296df95ca2Smiodsymbols of the file, if it is present.
123013553819Sguenther.It Dv STT_TLS
123113553819SguentherThe symbol is associated with an object in thread-local storage.
123213553819SguentherThe symbol's value is its offset in the TLS storage for this file.
12336df95ca2Smiod.It Dv STT_LOPROC
12346df95ca2SmiodThis value up to and including
12359d0398b3Sschwarze.Dv STT_HIPROC
12368637447dSderaadtis reserved for processor-specific semantics.
12376df95ca2Smiod.It Dv STT_HIPROC
12386df95ca2SmiodThis value down to and including
12399d0398b3Sschwarze.Dv STT_LOPROC
12408637447dSderaadtis reserved for processor-specific semantics.
12416df95ca2Smiod.El
124246de36c5Sjmc.Bl -tag -width "STB_GLOBAL"
12436df95ca2Smiod.It Dv STB_LOCAL
12446df95ca2SmiodLocal symbols are not visible outside the object file containing their
12456df95ca2Smioddefinition.
12468637447dSderaadtLocal symbols of the same name may exist in multiple files
12476df95ca2Smiodwithout interfering with each other.
12486df95ca2Smiod.It Dv STB_GLOBAL
12496df95ca2SmiodGlobal symbols are visible to all object files being combined.
12506df95ca2SmiodOne file's
12516df95ca2Smioddefinition of a global symbol will satisfy another file's undefined
12526df95ca2Smiodreference to the same symbol.
12536df95ca2Smiod.It Dv STB_WEAK
12546df95ca2SmiodWeak symbols resemble global symbols, but their definitions have lower
12556df95ca2Smiodprecedence.
12566df95ca2Smiod.It Dv STB_LOPROC
12576df95ca2SmiodThis value up to and including
12589d0398b3Sschwarze.Dv STB_HIPROC
12598637447dSderaadtis reserved for processor-specific semantics.
12606df95ca2Smiod.It Dv STB_HIPROC
12616df95ca2SmiodThis value down to and including
12629d0398b3Sschwarze.Dv STB_LOPROC
12638637447dSderaadtis reserved for processor-specific semantics.
12646df95ca2Smiod.Pp
12656df95ca2SmiodThere are macros for packing and unpacking the binding and type fields:
12666df95ca2Smiod.Pp
12676df95ca2Smiod.Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact
12686df95ca2Smiod.It Xo
12696df95ca2Smiod.Fn ELF32_ST_BIND info
12706df95ca2Smiod.Xc
12716df95ca2Smiodor
12726df95ca2Smiod.Fn ELF64_ST_BIND info
12736df95ca2Smiodextract a binding from an st_info value.
12746df95ca2Smiod.It Xo
12756df95ca2Smiod.Fn ELF64_ST_TYPE info
12766df95ca2Smiod.Xc
12776df95ca2Smiodor
12786df95ca2Smiod.Fn ELF32_ST_TYPE info
12796df95ca2Smiodextract a type from an st_info value.
12806df95ca2Smiod.It Xo
12816df95ca2Smiod.Fn ELF32_ST_INFO bind type
12826df95ca2Smiod.Xc
12836df95ca2Smiodor
12846df95ca2Smiod.Fn ELF64_ST_INFO bind type
12856df95ca2Smiodconvert a binding and a type into an st_info value.
12866df95ca2Smiod.El
12876df95ca2Smiod.El
12886df95ca2Smiod.It Dv st_other
12896df95ca2SmiodThis member currently holds zero and has no defined meaning.
12906df95ca2Smiod.It Dv st_shndx
12916df95ca2SmiodEvery symbol table entry is
12926df95ca2Smiod.Dq defined
129397b5ea19Sjmcin relation to some section.
12946df95ca2SmiodThis member holds the relevant section
12956df95ca2Smiodheader table index.
12966df95ca2Smiod.El
12976df95ca2Smiod.Pp
12986df95ca2SmiodRelocation is the process of connecting symbolic references with
12996df95ca2Smiodsymbolic definitions.
13006df95ca2SmiodRelocatable files must have information that
13016df95ca2Smioddescribes how to modify their section contents, thus allowing executable
13026df95ca2Smiodand shared object files to hold the right information for a process'
13036df95ca2Smiodprogram image.
13046df95ca2SmiodRelocation entries are these data.
13056df95ca2Smiod.Pp
13066df95ca2SmiodRelocation structures that do not need an addend:
13076df95ca2Smiod.Bd -literal -offset indent
13086df95ca2Smiodtypedef struct {
13096df95ca2Smiod	Elf32_Addr      r_offset;
13106df95ca2Smiod	Elf32_Word      r_info;
13116df95ca2Smiod} Elf32_Rel;
13126df95ca2Smiod.Ed
13136df95ca2Smiod.Bd -literal -offset indent
13146df95ca2Smiodtypedef struct {
131529a5018dSjsg	Elf64_Addr      r_offset;
13166df95ca2Smiod	Elf64_Xword     r_info;
13176df95ca2Smiod} Elf64_Rel;
13186df95ca2Smiod.Ed
13196df95ca2Smiod.Pp
13206df95ca2SmiodRelocation structures that need an addend:
13216df95ca2Smiod.Bd -literal -offset indent
13226df95ca2Smiodtypedef struct {
13236df95ca2Smiod	Elf32_Addr      r_offset;
13246df95ca2Smiod	Elf32_Word      r_info;
13256df95ca2Smiod	Elf32_Sword     r_addend;
13266df95ca2Smiod} Elf32_Rela;
13276df95ca2Smiod.Ed
13286df95ca2Smiod.Bd -literal -offset indent
13296df95ca2Smiodtypedef struct {
133029a5018dSjsg	Elf64_Addr      r_offset;
13316df95ca2Smiod	Elf64_Xword     r_info;
13326df95ca2Smiod	Elf64_Sxword    r_addend;
13336df95ca2Smiod} Elf64_Rela;
13346df95ca2Smiod.Ed
133546de36c5Sjmc.Bl -tag -width "r_offset"
13366df95ca2Smiod.It Dv r_offset
13376df95ca2SmiodThis member gives the location at which to apply the relocation action.
13386df95ca2SmiodFor a relocatable file, the value is the byte offset from the beginning
13396df95ca2Smiodof the section to the storage unit affected by the relocation.
13406df95ca2SmiodFor an
13416df95ca2Smiodexecutable file or shared object, the value is the virtual address of
13426df95ca2Smiodthe storage unit affected by the relocation.
13436df95ca2Smiod.It Dv r_info
13446df95ca2SmiodThis member gives both the symbol table index with respect to which the
13456df95ca2Smiodrelocation must be made and the type of relocation to apply.
13466df95ca2SmiodRelocation
13476df95ca2Smiodtypes are processor-specific.
13486df95ca2SmiodWhen the text refers to a relocation
13496df95ca2Smiodentry's relocation type or symbol table index, it means the result of
13506df95ca2Smiodapplying
13519d0398b3Sschwarze.Dv ELF[32|64]_R_TYPE
13526df95ca2Smiodor
13539d0398b3Sschwarze.Dv ELF[32|64]_R_SYM ,
13548637447dSderaadtrespectively, to the entry's
13556df95ca2Smiod.Sy r_info
13566df95ca2Smiodmember.
13576df95ca2Smiod.It Dv r_addend
13586df95ca2SmiodThis member specifies a constant addend used to compute the value to be
13596df95ca2Smiodstored into the relocatable field.
13606df95ca2Smiod.El
13611aadfae2Sjmc.Pp
13621aadfae2SjmcThe note section is used to hold vendor-specific information that
13631aadfae2Sjmcmay be used to help identify a binary's ABI.
13641aadfae2SjmcIt should start with an Elf_Note struct,
13651aadfae2Sjmcfollowed by the section name and the section description.
13661aadfae2SjmcThe actual note contents follow thereafter.
13671aadfae2Sjmc.Bd -literal -offset indent
13681aadfae2Sjmctypedef struct {
13691aadfae2Sjmc	Elf32_Word namesz;
13701aadfae2Sjmc	Elf32_Word descsz;
13711aadfae2Sjmc	Elf32_Word type;
13721aadfae2Sjmc} Elf32_Note;
13731aadfae2Sjmc
13741aadfae2Sjmctypedef struct {
137529a5018dSjsg	Elf64_Word namesz;
137629a5018dSjsg	Elf64_Word descsz;
137729a5018dSjsg	Elf64_Word type;
13781aadfae2Sjmc} Elf64_Note;
13791aadfae2Sjmc.Ed
13801aadfae2Sjmc.Bl -tag -width "r_offset"
13811aadfae2Sjmc.It Dv namesz
13821aadfae2SjmcLength of the note name, rounded up to a 4-byte boundary.
13831aadfae2Sjmc.It Dv descsz
13841aadfae2SjmcLength of the note description, rounded up to a 4-byte boundary.
13851aadfae2Sjmc.It Dv type
13861aadfae2SjmcA vendor-specific note type.
13871aadfae2Sjmc.El
13881aadfae2Sjmc.Pp
13891aadfae2SjmcThe name and description strings follow the note structure.
13901aadfae2SjmcEach string is aligned on a 4-byte boundary.
13916df95ca2Smiod.Sh SEE ALSO
13926df95ca2Smiod.Xr as 1 ,
13936df95ca2Smiod.Xr gdb 1 ,
13946df95ca2Smiod.Xr ld 1 ,
13956df95ca2Smiod.Xr objdump 1 ,
13966df95ca2Smiod.Xr execve 2 ,
13976df95ca2Smiod.Xr core 5
13986df95ca2Smiod.Rs
13997518e2abSjmc.%A Hewlett-Packard
14006df95ca2Smiod.%B Elf-64 Object File Format
14016df95ca2Smiod.Re
14026df95ca2Smiod.Rs
14036df95ca2Smiod.%A Santa Cruz Operation
14046df95ca2Smiod.%B System V Application Binary Interface
14056df95ca2Smiod.Re
14066df95ca2Smiod.Rs
14076df95ca2Smiod.%A Unix System Laboratories
14086df95ca2Smiod.%T Object Files
14096df95ca2Smiod.%B "Executable and Linking Format (ELF)"
14106df95ca2Smiod.Re
14116df95ca2Smiod.Sh HISTORY
14126df95ca2Smiod.Ox
14136df95ca2SmiodELF support first appeared in
141487a312ddSmatthew.Ox 1.2 .
141587a312ddSmatthewStarting with
141687a312ddSmatthew.Ox 5.4 ,
141787a312ddSmatthewall supported platforms use it as the native binary file format.
14186df95ca2SmiodELF in itself first appeared in
14196df95ca2Smiod.At V .
14206df95ca2SmiodThe ELF format is an adopted standard.
14216df95ca2Smiod.Sh AUTHORS
14226df95ca2SmiodThis manual page was written by
14237cd6ad0cSschwarze.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org
14246df95ca2Smiodwith inspiration from BSDi's
14256df95ca2Smiod.Bsx
14263b1d4ce7Sjmc.Nm elf
14276df95ca2Smiodmanpage.
1428