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 384e86fcacSSheldon Hearndefines the format of ELF executable binary files. 394e86fcacSSheldon HearnAmongst these files are 40ea14e5c3SBrian Feldmannormal executable files, relocatable object files, core files and shared 41ea14e5c3SBrian Feldmanlibraries. 42ea14e5c3SBrian Feldman.Pp 43ea14e5c3SBrian FeldmanAn executable file using the ELF file format consists of an ELF header, 44ea14e5c3SBrian Feldmanfollowed by a program header table or a section header table, or both. 454e86fcacSSheldon HearnThe ELF header is always at offset zero of the file. 464e86fcacSSheldon HearnThe program header 47ea14e5c3SBrian Feldmantable and the section header table's offset in the file are defined in the 484e86fcacSSheldon HearnELF header. 494e86fcacSSheldon HearnThe two tables describe the rest of the particularities of 50ea14e5c3SBrian Feldmanthe file. 51ea14e5c3SBrian Feldman.Pp 52ea14e5c3SBrian FeldmanApplications which wish to process ELF binary files for their native 53ea14e5c3SBrian Feldmanarchitecture only should include 54ea14e5c3SBrian Feldman.Pa sys/elf.h 554e86fcacSSheldon Hearnin their source code. 564e86fcacSSheldon HearnThese applications should need to refer to 57ea14e5c3SBrian Feldmanall the types and structures by their generic names 58ea14e5c3SBrian Feldman.Dq Elf_xxx 59ea14e5c3SBrian Feldmanand to the macros by 60ea14e5c3SBrian Feldman.Dq ELF_xxx . 61ea14e5c3SBrian FeldmanApplications written this way can be compiled on any architecture, 62ea14e5c3SBrian Feldmanregardless whether the host is 32-bit or 64-bit. 63ea14e5c3SBrian Feldman.Pp 64ea14e5c3SBrian FeldmanShould an application need to process ELF files of an unknown 65ea14e5c3SBrian Feldmanarchitecture then the application needs to include both 66ea14e5c3SBrian Feldman.Pa sys/elf32.h 67ea14e5c3SBrian Feldmanand 68ea14e5c3SBrian Feldman.Pa sys/elf64.h 69ea14e5c3SBrian Feldmaninstead of 70ea14e5c3SBrian Feldman.Pa sys/elf.h . 71ea14e5c3SBrian FeldmanFurthermore, all types and structures need to be identified by either 72ea14e5c3SBrian Feldman.Dq Elf32_xxx 73ea14e5c3SBrian Feldmanor 74ea14e5c3SBrian Feldman.Dq Elf64_xxx . 75ea14e5c3SBrian FeldmanThe macros need to be identified by 76ea14e5c3SBrian Feldman.Dq ELF32_xxx 77ea14e5c3SBrian Feldmanor 78ea14e5c3SBrian Feldman.Dq ELF64_xxx . 79ea14e5c3SBrian Feldman.Pp 80ea14e5c3SBrian FeldmanWhatever the system's architecture is, it will always include 81ea14e5c3SBrian Feldman.Pa sys/elf_common.h 82ea14e5c3SBrian Feldmanas well as 83ea14e5c3SBrian Feldman.Pa sys/elf_generic.h . 84ea14e5c3SBrian Feldman.Pp 85ea14e5c3SBrian FeldmanThese header files describe the above mentioned headers as C structures 86ea14e5c3SBrian Feldmanand also include structures for dynamic sections, relocation sections and 87ea14e5c3SBrian Feldmansymbol tables. 88ea14e5c3SBrian Feldman.Pp 89ea14e5c3SBrian FeldmanThe following types are being used for 32-bit architectures: 90ea14e5c3SBrian Feldman.Bd -literal -offset indent 91ea14e5c3SBrian FeldmanElf32_Addr Unsigned program address 92ea14e5c3SBrian FeldmanElf32_Half Unsigned halfword field 93ea14e5c3SBrian FeldmanElf32_Off Unsigned file offset 94ea14e5c3SBrian FeldmanElf32_Sword Signed large integer 95ea14e5c3SBrian FeldmanElf32_Word Field or unsigned large integer 96ea14e5c3SBrian FeldmanElf32_Size Unsigned object size 97ea14e5c3SBrian Feldman.Ed 98ea14e5c3SBrian Feldman.Pp 99ea14e5c3SBrian FeldmanFor 64-bit architectures we have the following types: 100ea14e5c3SBrian Feldman.Bd -literal -offset indent 101ea14e5c3SBrian FeldmanElf64_Addr Unsigned program address 102ea14e5c3SBrian FeldmanElf64_Half Unsigned halfword field 103ea14e5c3SBrian FeldmanElf64_Off Unsigned file offset 104ea14e5c3SBrian FeldmanElf64_Sword Signed large integer 105ea14e5c3SBrian FeldmanElf64_Word Field or unsigned large integer 106ea14e5c3SBrian FeldmanElf64_Size Unsigned object size 107ea14e5c3SBrian FeldmanElf64_Quarter Unsigned quarterword field 108ea14e5c3SBrian Feldman.Ed 109ea14e5c3SBrian Feldman.Pp 110ea14e5c3SBrian FeldmanAll data structures that the file format defines follow the 111ea14e5c3SBrian Feldman.Dq natural 1124e86fcacSSheldon Hearnsize and alignment guidelines for the relevant class. 1134e86fcacSSheldon HearnIf necessary, 114ea14e5c3SBrian Feldmandata structures contain explicit padding to ensure 4-byte alignment 115ea14e5c3SBrian Feldmanfor 4-byte objects, to force structure sizes to a multiple of 4, etc. 116ea14e5c3SBrian Feldman.Pp 117ea14e5c3SBrian FeldmanThe ELF header is described by the type Elf32_Ehdr or Elf64_Ehdr: 118ea14e5c3SBrian Feldman.Bd -literal -offset indent 119ea14e5c3SBrian Feldmantypedef struct { 120ea14e5c3SBrian Feldman unsigned char e_ident[EI_NIDENT]; 121ea14e5c3SBrian Feldman Elf32_Half e_type; 122ea14e5c3SBrian Feldman Elf32_Half e_machine; 123ea14e5c3SBrian Feldman Elf32_Word e_version; 124ea14e5c3SBrian Feldman Elf32_Addr e_entry; 125ea14e5c3SBrian Feldman Elf32_Off e_phoff; 126ea14e5c3SBrian Feldman Elf32_Off e_shoff; 127ea14e5c3SBrian Feldman Elf32_Word e_flags; 128ea14e5c3SBrian Feldman Elf32_Half e_ehsize; 129ea14e5c3SBrian Feldman Elf32_Half e_phentsize; 130ea14e5c3SBrian Feldman Elf32_Half e_phnum; 131ea14e5c3SBrian Feldman Elf32_Half e_shentsize; 132ea14e5c3SBrian Feldman Elf32_Half e_shnum; 133ea14e5c3SBrian Feldman Elf32_Half e_shstrndx; 134ea14e5c3SBrian Feldman} Elf32_Ehdr; 135ea14e5c3SBrian Feldman.Ed 136ea14e5c3SBrian Feldman.Pp 137ea14e5c3SBrian Feldman.Bd -literal -offset indent 138ea14e5c3SBrian Feldmantypedef struct { 139ea14e5c3SBrian Feldman unsigned char e_ident[EI_NIDENT]; 140ea14e5c3SBrian Feldman Elf64_Quarter e_type; 141ea14e5c3SBrian Feldman Elf64_Quarter e_machine; 142ea14e5c3SBrian Feldman Elf64_Half e_version; 143ea14e5c3SBrian Feldman Elf64_Addr e_entry; 144ea14e5c3SBrian Feldman Elf64_Off e_phoff; 145ea14e5c3SBrian Feldman Elf64_Off e_shoff; 146ea14e5c3SBrian Feldman Elf64_Half e_flags; 147ea14e5c3SBrian Feldman Elf64_Quarter e_ehsize; 148ea14e5c3SBrian Feldman Elf64_Quarter e_phentsize; 149ea14e5c3SBrian Feldman Elf64_Quarter e_phnum; 150ea14e5c3SBrian Feldman Elf64_Quarter e_shentsize; 151ea14e5c3SBrian Feldman Elf64_Quarter e_shnum; 152ea14e5c3SBrian Feldman Elf64_Quarter e_shstrndx; 153ea14e5c3SBrian Feldman} Elf64_Ehdr; 154ea14e5c3SBrian Feldman.Ed 155ea14e5c3SBrian Feldman.Pp 156ea14e5c3SBrian FeldmanThe fields have the following meanings: 157ea14e5c3SBrian Feldman.Pp 158ea14e5c3SBrian Feldman.Bl -tag -width "e_phentsize" -compact -offset indent 159ea14e5c3SBrian Feldman.It Dv e_ident 160ea14e5c3SBrian FeldmanThis array of bytes specifies to interpret the file, 161ea14e5c3SBrian Feldmanindependent of the processor or the file's remaining contents. 162ea14e5c3SBrian FeldmanWithin this array everything is named by macros, which start with 163ea14e5c3SBrian Feldmanthe prefix 164ea14e5c3SBrian Feldman.Sy EI_ 165ea14e5c3SBrian Feldmanand may contain values which start with the prefix 166ea14e5c3SBrian Feldman.Sy ELF . 167ea14e5c3SBrian FeldmanThe following macros are defined: 168ea14e5c3SBrian Feldman.Pp 169ea14e5c3SBrian Feldman.Bl -tag -width "EI_VERSION" -compact 170ea14e5c3SBrian Feldman.It Dv EI_MAG0 1714e86fcacSSheldon HearnThe first byte of the magic number. 1724e86fcacSSheldon HearnIt must be filled with 173ea14e5c3SBrian Feldman.Sy ELFMAG0 . 174ea14e5c3SBrian Feldman.It Dv EI_MAG1 1754e86fcacSSheldon HearnThe second byte of the magic number. 1764e86fcacSSheldon HearnIt must be filled with 177ea14e5c3SBrian Feldman.Sy ELFMAG1 . 178ea14e5c3SBrian Feldman.It Dv EI_MAG2 1794e86fcacSSheldon HearnThe third byte of the magic number. 1804e86fcacSSheldon HearnIt must be filled with 181ea14e5c3SBrian Feldman.Sy ELFMAG2 . 182ea14e5c3SBrian Feldman.It Dv EI_MAG3 1834e86fcacSSheldon HearnThe fourth byte of the magic number. 1844e86fcacSSheldon HearnIt must be filled with 185ea14e5c3SBrian Feldman.Sy ELFMAG3 . 186ea14e5c3SBrian Feldman.It Dv EI_CLASS 187ea14e5c3SBrian FeldmanThe fifth byte identifies the architecture for this binary: 188ea14e5c3SBrian Feldman.Pp 189ea14e5c3SBrian Feldman.Bl -tag -width "ELFCLASSNONE" -compact 190ea14e5c3SBrian Feldman.It Dv ELFCLASSNONE 191ea14e5c3SBrian FeldmanThis class is invalid. 192ea14e5c3SBrian Feldman.It Dv ELFCLASS32 1934e86fcacSSheldon HearnThis defines the 32-bit architecture. 1944e86fcacSSheldon HearnIt supports machines with files 195ea14e5c3SBrian Feldmanand virtual address spaces up to 4 Gigabytes. 196ea14e5c3SBrian Feldman.It Dv ELFCLASS64 197ea14e5c3SBrian FeldmanThis defines the 64-bit architecture. 198ea14e5c3SBrian Feldman.El 199ea14e5c3SBrian Feldman.It Dv EI_DATA 200ea14e5c3SBrian FeldmanThe sixth byte specifies the data encoding of the processor-specific 2014e86fcacSSheldon Hearndata in the file. 2024e86fcacSSheldon HearnCurrently these encodings are supported: 203ea14e5c3SBrian Feldman.Pp 204ea14e5c3SBrian Feldman.Bl -tag -width "ELFDATA2LSB" -compact 205ea14e5c3SBrian Feldman.It Dv ELFDATANONE 206ea14e5c3SBrian FeldmanUnknown data format. 207ea14e5c3SBrian Feldman.It Dv ELFDATA2LSB 208ea14e5c3SBrian FeldmanTwo's complement, little-endian. 209ea14e5c3SBrian Feldman.It Dv ELFDATA2MSB 210ea14e5c3SBrian FeldmanTwo's complement, big-endian. 211ea14e5c3SBrian Feldman.El 212ea14e5c3SBrian Feldman.It Dv EI_VERSION 213ea14e5c3SBrian FeldmanThe version number of the ELF specification: 214ea14e5c3SBrian Feldman.Pp 215ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact 216ea14e5c3SBrian Feldman.It Dv EV_NONE 217ea14e5c3SBrian FeldmanInvalid version. 218ea14e5c3SBrian Feldman.It Dv EV_CURRENT 219ea14e5c3SBrian FeldmanCurrent version. 220ea14e5c3SBrian Feldman.El 221ea14e5c3SBrian Feldman.It Dv EI_PAD 2224e86fcacSSheldon HearnStart of padding. 2234e86fcacSSheldon HearnThese bytes are reserved and set to zero. 2244e86fcacSSheldon HearnPrograms 2254e86fcacSSheldon Hearnwhich read them should ignore them. 2264e86fcacSSheldon HearnThe value for EI_PAD will change in 227ea14e5c3SBrian Feldmanthe future if currently unused bytes are given meanings. 228ea14e5c3SBrian Feldman.It Dv EI_BRAND 229ea14e5c3SBrian FeldmanStart of architecture identification. 230ea14e5c3SBrian Feldman.It Dv EI_NIDENT 231ea14e5c3SBrian FeldmanThe size of the e_ident array. 232ea14e5c3SBrian Feldman.El 233ea14e5c3SBrian Feldman.Pp 234ea14e5c3SBrian Feldman.It Dv e_type 235ea14e5c3SBrian FeldmanThis member of the structure identifies the object file type: 236ea14e5c3SBrian Feldman.Pp 237ea14e5c3SBrian Feldman.Bl -tag -width "ET_NONE" -compact 238ea14e5c3SBrian Feldman.It Dv ET_NONE 239ea14e5c3SBrian FeldmanAn unknown type. 240ea14e5c3SBrian Feldman.It Dv ET_REL 241ea14e5c3SBrian FeldmanA relocatable file. 242ea14e5c3SBrian Feldman.It Dv ET_EXEC 243ea14e5c3SBrian FeldmanAn executable file. 244ea14e5c3SBrian Feldman.It Dv ET_DYN 245ea14e5c3SBrian FeldmanA shared object. 246ea14e5c3SBrian Feldman.It Dv ET_CORE 247ea14e5c3SBrian FeldmanA core file. 248ea14e5c3SBrian Feldman.El 249ea14e5c3SBrian Feldman.Pp 250ea14e5c3SBrian Feldman.It Dv e_machine 251ea14e5c3SBrian FeldmanThis member specifies the required architecture for an individual file: 252ea14e5c3SBrian Feldman.Pp 253ea14e5c3SBrian Feldman.Bl -tag -width "EM_MIPS_RS4_BE" -compact 254ea14e5c3SBrian Feldman.It Dv EM_NONE 255ea14e5c3SBrian FeldmanAn unknown machine. 256ea14e5c3SBrian Feldman.It Dv EM_M32 257ea14e5c3SBrian FeldmanAT&T WE 32100. 258ea14e5c3SBrian Feldman.It Dv EM_SPARC 259ea14e5c3SBrian FeldmanSun Microsystems SPARC. 260ea14e5c3SBrian Feldman.It Dv EM_386 261ea14e5c3SBrian FeldmanIntel 80386. 262ea14e5c3SBrian Feldman.It Dv EM_68K 263ea14e5c3SBrian FeldmanMotorola 68000. 264ea14e5c3SBrian Feldman.It Dv EM_88K 265ea14e5c3SBrian FeldmanMotorola 88000. 266ea14e5c3SBrian Feldman.It Dv EM_486 267ea14e5c3SBrian FeldmanIntel 80486. 268ea14e5c3SBrian Feldman.It Dv EM_860 269ea14e5c3SBrian FeldmanIntel 80860. 270ea14e5c3SBrian Feldman.It Dv EM_MIPS 271ea14e5c3SBrian FeldmanMIPS RS3000 (big-endian only). 272ea14e5c3SBrian Feldman.It Dv EM_MIPS_RS4_BE 273ea14e5c3SBrian FeldmanMIPS RS4000 (big-endian only). 274ea14e5c3SBrian Feldman.It Dv EM_SPARC64 275ea14e5c3SBrian FeldmanSPARC v9 64-bit unofficial. 276ea14e5c3SBrian Feldman.It Dv EM_PARISC 277ea14e5c3SBrian FeldmanHPPA. 278ea14e5c3SBrian Feldman.It Dv EM_PPC 279ea14e5c3SBrian FeldmanPowerPC. 280ea14e5c3SBrian Feldman.It Dv EM_ALPHA 281ea14e5c3SBrian FeldmanCompaq [DEC] Alpha. 282ea14e5c3SBrian Feldman.El 283ea14e5c3SBrian Feldman.Pp 284ea14e5c3SBrian Feldman.It Dv e_version 285ea14e5c3SBrian FeldmanThis member identifies the file version: 286ea14e5c3SBrian Feldman.Pp 287ea14e5c3SBrian Feldman.Bl -tag -width "EV_CURRENT" -compact 288ea14e5c3SBrian Feldman.It Dv EV_NONE 289ea14e5c3SBrian FeldmanInvalid version 290ea14e5c3SBrian Feldman.It Dv EV_CURRENT 291ea14e5c3SBrian FeldmanCurrent version 292ea14e5c3SBrian Feldman.El 293ea14e5c3SBrian Feldman.It Dv e_entry 294ea14e5c3SBrian FeldmanThis member gives the virtual address to which the system first transfers 2954e86fcacSSheldon Hearncontrol, thus starting the process. 2964e86fcacSSheldon HearnIf the file has no associated entry 297ea14e5c3SBrian Feldmanpoint, this member holds zero. 298ea14e5c3SBrian Feldman.It Dv e_phoff 2994e86fcacSSheldon HearnThis member holds the program header table's file offset in bytes. 3004e86fcacSSheldon HearnIf 301ea14e5c3SBrian Feldmanthe file has no program header table, this member holds zero. 302ea14e5c3SBrian Feldman.It Dv e_shoff 3034e86fcacSSheldon HearnThis member holds the section header table's file offset in bytes. 3044e86fcacSSheldon HearnIf the 305ea14e5c3SBrian Feldmanfile has no section header table this member holds zero. 306ea14e5c3SBrian Feldman.It Dv e_flags 3074e86fcacSSheldon HearnThis member holds processor-specific flags associated with the file. 3084e86fcacSSheldon HearnFlag 309ea14e5c3SBrian Feldmannames take the form EF_`machine_flag'. Currently no flags have been defined. 310ea14e5c3SBrian Feldman.It Dv e_ehsize 311ea14e5c3SBrian FeldmanThis member holds the ELF header's size in bytes. 312ea14e5c3SBrian Feldman.It Dv e_phentsize 313ea14e5c3SBrian FeldmanThis member holds the size in bytes of one entry in the file's program header 314ea14e5c3SBrian Feldmantable; all entries are the same size. 315ea14e5c3SBrian Feldman.It Dv e_phnum 316f3a2511aSChris CostelloThis member holds the number of entries in the program header 3174e86fcacSSheldon Hearntable. 3184e86fcacSSheldon HearnThus the product of 319ea14e5c3SBrian Feldman.Sy e_phentsize 320ea14e5c3SBrian Feldmanand 321ea14e5c3SBrian Feldman.Sy e_phnum 322ea14e5c3SBrian Feldmangives the table's size 3234e86fcacSSheldon Hearnin bytes. 3244e86fcacSSheldon HearnIf a file has no program header, 325ea14e5c3SBrian Feldman.Sy e_phnum 326ea14e5c3SBrian Feldmanholds the value zero. 327ea14e5c3SBrian Feldman.It Dv e_shentsize 3284e86fcacSSheldon HearnThis member holds a sections header's size in bytes. 3294e86fcacSSheldon HearnA section header is one 330ea14e5c3SBrian Feldmanentry in the section header table; all entries are the same size. 331ea14e5c3SBrian Feldman.It Dv e_shnum 3324e86fcacSSheldon HearnThis member holds the number of entries in the section header table. 3334e86fcacSSheldon HearnThus 334ea14e5c3SBrian Feldmanthe product of 335ea14e5c3SBrian Feldman.Sy e_shentsize 336ea14e5c3SBrian Feldmanand 337ea14e5c3SBrian Feldman.Sy e_shnum 3384e86fcacSSheldon Hearngives the section header table's size in bytes. 3394e86fcacSSheldon HearnIf a file has no section 340ea14e5c3SBrian Feldmanheader table, 341ea14e5c3SBrian Feldman.Sy e_shnum 342ea14e5c3SBrian Feldmanholds the value of zero. 343ea14e5c3SBrian Feldman.It Dv e_shstrndx 344ea14e5c3SBrian FeldmanThis member holds the section header table index of the entry associated 3454e86fcacSSheldon Hearnwith the section name string table. 3464e86fcacSSheldon HearnIf the file has no section name string 347ea14e5c3SBrian Feldmantable, this member holds the value 348ea14e5c3SBrian Feldman.Sy SHN_UNDEF . 349ea14e5c3SBrian Feldman.Pp 350ea14e5c3SBrian Feldman.Bl -tag -width "SHN_LORESERVE" -compact 351ea14e5c3SBrian Feldman.It Dv SHN_UNDEF 352ea14e5c3SBrian FeldmanThis value marks an undefined, missing, irrelevant, or otherwise meaningless 3534e86fcacSSheldon Hearnsection reference. 3544e86fcacSSheldon HearnFor example, a symbol 355ea14e5c3SBrian Feldman.Dq defined 356ea14e5c3SBrian Feldmanrelative to section number 357ea14e5c3SBrian Feldman.Sy SHN_UNDEF 358ea14e5c3SBrian Feldmanis an undefined symbol. 359ea14e5c3SBrian Feldman.It Dv SHN_LORESERVE 360ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of reserved indexes. 361ea14e5c3SBrian Feldman.It Dv SHN_LOPROC 362ea14e5c3SBrian FeldmanThis value up to and including 363ea14e5c3SBrian Feldman.Sy SHN_HIPROC 364ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 365ea14e5c3SBrian Feldman.It Dv SHN_HIPROC 366ea14e5c3SBrian FeldmanThis value down to and including 367ea14e5c3SBrian Feldman.Sy SHN_LOPROC 368ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 369ea14e5c3SBrian Feldman.It Dv SHN_ABS 3704e86fcacSSheldon HearnThis value specifies absolute values for the corresponding reference. 3714e86fcacSSheldon HearnFor 372ea14e5c3SBrian Feldmanexample, symbols defined relative to section number 373ea14e5c3SBrian Feldman.Sy SHN_ABS 374ea14e5c3SBrian Feldmanhave absolute values and are not affected by relocation. 375ea14e5c3SBrian Feldman.It Dv SHN_COMMON 376ea14e5c3SBrian FeldmanSymbols defined relative to this section are common symbols, such as Fortran 377ea14e5c3SBrian FeldmanCOMMON or unallocated C external variables. 378ea14e5c3SBrian Feldman.It Dv SHN_HIRESERVE 379ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of the range of reserved 380ea14e5c3SBrian Feldmanindices between 381ea14e5c3SBrian Feldman.Sy SHN_LORESERVE 382ea14e5c3SBrian Feldmanand 383ea14e5c3SBrian Feldman.Sy SHN_HIRESERVE , 384ea14e5c3SBrian Feldmaninclusive; the values do 3854e86fcacSSheldon Hearnnot reference the section header table. 3864e86fcacSSheldon HearnThat is, the section header table 387ea14e5c3SBrian Feldmandoes 388ea14e5c3SBrian Feldman.Em not 389ea14e5c3SBrian Feldmancontain entries for the reserved indices. 390ea14e5c3SBrian Feldman.El 391ea14e5c3SBrian Feldman.El 392ea14e5c3SBrian Feldman.Pp 393ea14e5c3SBrian FeldmanAn executable or shared object file's program header table is an array of 394ea14e5c3SBrian Feldmanstructures, each describing a segment or other information the system needs 3954e86fcacSSheldon Hearnto prepare the program for execution. 3964e86fcacSSheldon HearnAn object file 397ea14e5c3SBrian Feldman.Em segment 398ea14e5c3SBrian Feldmancontains one or more 399ea14e5c3SBrian Feldman.Em sections . 400ea14e5c3SBrian FeldmanProgram headers are meaningful only for executable and shared object files. 401ea14e5c3SBrian FeldmanA file specifies its own program header size with the ELF header's 402ea14e5c3SBrian Feldman.Sy e_phentsize 403ea14e5c3SBrian Feldmanand 404ea14e5c3SBrian Feldman.Sy e_phnum 4054e86fcacSSheldon Hearnmembers. 4064e86fcacSSheldon HearnAs with the Elf executable header, the program header 407ea14e5c3SBrian Feldmanalso has different versions depending on the architecture: 408ea14e5c3SBrian Feldman.Pp 409ea14e5c3SBrian Feldman.Bd -literal -offset indent 410ea14e5c3SBrian Feldmantypedef struct { 411ea14e5c3SBrian Feldman Elf32_Word p_type; 412ea14e5c3SBrian Feldman Elf32_Off p_offset; 413ea14e5c3SBrian Feldman Elf32_Addr p_vaddr; 414ea14e5c3SBrian Feldman Elf32_Addr p_paddr; 415ea14e5c3SBrian Feldman Elf32_Size p_filesz; 416ea14e5c3SBrian Feldman Elf32_Size p_memsz; 417ea14e5c3SBrian Feldman Elf32_Word p_flags; 418ea14e5c3SBrian Feldman Elf32_Size p_align; 419ea14e5c3SBrian Feldman} Elf32_Phdr; 420ea14e5c3SBrian Feldman.Ed 421ea14e5c3SBrian Feldman.Pp 422ea14e5c3SBrian Feldman.Bd -literal -offset indent 423ea14e5c3SBrian Feldmantypedef struct { 424ea14e5c3SBrian Feldman Elf64_Half p_type; 425ea14e5c3SBrian Feldman Elf64_Half p_flags; 426ea14e5c3SBrian Feldman Elf64_Off p_offset; 427ea14e5c3SBrian Feldman Elf64_Addr p_vaddr; 428ea14e5c3SBrian Feldman Elf64_Addr p_paddr; 429ea14e5c3SBrian Feldman Elf64_Size p_filesz; 430ea14e5c3SBrian Feldman Elf64_Size p_memsz; 431ea14e5c3SBrian Feldman Elf64_Size p_align; 432ea14e5c3SBrian Feldman} Elf64_Phdr; 433ea14e5c3SBrian Feldman.Ed 434ea14e5c3SBrian Feldman.Pp 435ea14e5c3SBrian FeldmanThe main difference between the 32-bit and the 64-bit program header lies 436ea14e5c3SBrian Feldmanonly in the location of a 437ea14e5c3SBrian Feldman.Sy p_flags 438ea14e5c3SBrian Feldmanmember in the total struct. 439ea14e5c3SBrian Feldman.Pp 440ea14e5c3SBrian Feldman.Bl -tag -width "p_offset" -compact -offset indent 441ea14e5c3SBrian Feldman.It Dv p_type 442ea14e5c3SBrian FeldmanThis member of the Phdr struct tells what kind of segment this array 443ea14e5c3SBrian Feldmanelement describes or how to interpret the array element's information. 444ea14e5c3SBrian Feldman.Bl -tag -width "PT_DYNAMIC" -compact 445ea14e5c3SBrian Feldman.Pp 446ea14e5c3SBrian Feldman.It Dv PT_NULL 447ea14e5c3SBrian FeldmanThe array element is unused and the other members' values are undefined. 448ea14e5c3SBrian FeldmanThis lets the program header have ignored entries. 449ea14e5c3SBrian Feldman.It Dv PT_LOAD 450ea14e5c3SBrian FeldmanThe array element specifies a loadable segment, described by 451ea14e5c3SBrian Feldman.Sy p_filesz 452ea14e5c3SBrian Feldmanand 453ea14e5c3SBrian Feldman.Sy p_memsz . 454ea14e5c3SBrian FeldmanThe bytes from the file are mapped to the beginning of the memory 4554e86fcacSSheldon Hearnsegment. 4564e86fcacSSheldon HearnIf the segment's memory size ( 457ea14e5c3SBrian Feldman.Sy p_memsz 458ea14e5c3SBrian Feldman) is larger than the file 459ea14e5c3SBrian Feldmansize ( 460ea14e5c3SBrian Feldman.Sy p_filesz 461ea14e5c3SBrian Feldman), the 462ea14e5c3SBrian Feldman.Dq extra 463ea14e5c3SBrian Feldmanbytes are defined to hold the value 0 and to follow the segment's 4644e86fcacSSheldon Hearninitialized area. 4654e86fcacSSheldon HearnThe file size may not be larger than the memory size. 466ea14e5c3SBrian FeldmanLoadable segment entries in the program header table appear in ascending 467ea14e5c3SBrian Feldmanorder, sorted on the 468ea14e5c3SBrian Feldman.Sy p_vaddr 469ea14e5c3SBrian Feldmanmember. 470ea14e5c3SBrian Feldman.It Dv PT_DYNAMIC 471ea14e5c3SBrian FeldmanThe array element specifies dynamic linking information. 472ea14e5c3SBrian Feldman.It Dv PT_INTERP 473ea14e5c3SBrian FeldmanThe array element specifies the location and size of a null-terminated 4744e86fcacSSheldon Hearnpath name to invoke as an interpreter. 4754e86fcacSSheldon HearnThis segment type is meaningful 476ea14e5c3SBrian Feldmanonly for executable files (though it may occur for shared objects). However 4774e86fcacSSheldon Hearnit may not occur more than once in a file. 4784e86fcacSSheldon HearnIf it is present it must precede 479ea14e5c3SBrian Feldmanany loadable segment entry. 480ea14e5c3SBrian Feldman.It Dv PT_NOTE 481ea14e5c3SBrian FeldmanThe array element specifies the location and size for auxiliary information. 482ea14e5c3SBrian Feldman.It Dv PT_SHLIB 4834e86fcacSSheldon HearnThis segment type is reserved but has unspecified semantics. 4844e86fcacSSheldon HearnPrograms that 485ea14e5c3SBrian Feldmancontain an array element of this type do not conform to the ABI. 486ea14e5c3SBrian Feldman.It Dv PT_PHDR 487ea14e5c3SBrian FeldmanThe array element, if present, specifies the location and size of the program 488ea14e5c3SBrian Feldmanheader table itself, both in the file and in the memory image of the program. 4894e86fcacSSheldon HearnThis segment type may not occur more than once in a file. 4904e86fcacSSheldon HearnMoreover, it may 491ea14e5c3SBrian Feldmanonly occur if the program header table is part of the memory image of the 4924e86fcacSSheldon Hearnprogram. 4934e86fcacSSheldon HearnIf it is present it must precede any loadable segment entry. 494ea14e5c3SBrian Feldman.It Dv PT_LOPROC 495ea14e5c3SBrian FeldmanThis value up to and including 496ea14e5c3SBrian Feldman.Sy PT_HIPROC 497ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 498ea14e5c3SBrian Feldman.It Dv PT_HIPROC 499ea14e5c3SBrian FeldmanThis value down to and including 500ea14e5c3SBrian Feldman.Sy PT_LOPROC 501ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 502ea14e5c3SBrian Feldman.El 503ea14e5c3SBrian Feldman.Pp 504ea14e5c3SBrian Feldman.It Dv p_offset 505ea14e5c3SBrian FeldmanThis member holds the offset from the beginning of the file at which 506ea14e5c3SBrian Feldmanthe first byte of the of the segment resides. 507ea14e5c3SBrian Feldman.It Dv p_vaddr 508ea14e5c3SBrian FeldmanThis member holds the virtual address at which the first byte of the 509ea14e5c3SBrian Feldmansegment resides in memory. 510ea14e5c3SBrian Feldman.It Dv p_paddr 511ea14e5c3SBrian FeldmanOn systems for which physical addressing is relevant, this member is 5124e86fcacSSheldon Hearnreserved for the segment's physical address. 5134e86fcacSSheldon HearnUnder BSD this member is 514ea14e5c3SBrian Feldmannot used and must be zero. 515ea14e5c3SBrian Feldman.It Dv p_filesz 516ea14e5c3SBrian FeldmanThis member holds the number of bytes in the file image of the segment. 517ea14e5c3SBrian FeldmanIt may be zero. 518ea14e5c3SBrian Feldman.It Dv p_memsz 519ea14e5c3SBrian FeldmanThis member holds the number of bytes in the memory image of the segment. 520ea14e5c3SBrian FeldmanIt may be zero. 521ea14e5c3SBrian Feldman.It Dv p_flags 522ea14e5c3SBrian FeldmanThis member holds flags relevant to the segment: 523ea14e5c3SBrian Feldman.Pp 524ea14e5c3SBrian Feldman.Bl -tag -width "PF_X" -compact 525ea14e5c3SBrian Feldman.It Dv PF_X 526ea14e5c3SBrian FeldmanAn executable segment. 527ea14e5c3SBrian Feldman.It Dv PF_W 528ea14e5c3SBrian FeldmanA writable segment. 529ea14e5c3SBrian Feldman.It Dv PF_R 530ea14e5c3SBrian FeldmanA readable segment. 531ea14e5c3SBrian Feldman.El 532ea14e5c3SBrian Feldman.Pp 533ea14e5c3SBrian FeldmanA text segment commonly has the flags 534ea14e5c3SBrian Feldman.Sy PF_X 535ea14e5c3SBrian Feldmanand 536ea14e5c3SBrian Feldman.SY PF_R . 537ea14e5c3SBrian FeldmanA data segment commonly has 538ea14e5c3SBrian Feldman.Sy PF_X , 539ea14e5c3SBrian Feldman.Sy PF_W 540ea14e5c3SBrian Feldmanand 541ea14e5c3SBrian Feldman.Sy PF_R . 542ea14e5c3SBrian Feldman.It Dv p_align 543ea14e5c3SBrian FeldmanThis member holds the value to which the segments are aligned in memory 5444e86fcacSSheldon Hearnand in the file. 5454e86fcacSSheldon HearnLoadable process segments must have congruent values for 546ea14e5c3SBrian Feldman.Sy p_vaddr 547ea14e5c3SBrian Feldmanand 548ea14e5c3SBrian Feldman.Sy p_offset , 5494e86fcacSSheldon Hearnmodulo the page size. 5504e86fcacSSheldon HearnValues of zero and one mean no alignment is required. 551ea14e5c3SBrian FeldmanOtherwise, 552ea14e5c3SBrian Feldman.Sy p_align 553ea14e5c3SBrian Feldmanshould be a positive, integral power of two, and 554ea14e5c3SBrian Feldman.Sy p_vaddr 555ea14e5c3SBrian Feldmanshould equal 556ea14e5c3SBrian Feldman.Sy p_offset , 557ea14e5c3SBrian Feldmanmodulo 558ea14e5c3SBrian Feldman.Sy p_align . 559ea14e5c3SBrian Feldman.El 560ea14e5c3SBrian Feldman.Pp 5614e86fcacSSheldon HearnAn file's section header table lets one locate all the file's sections. 5624e86fcacSSheldon HearnThe 5634e86fcacSSheldon Hearnsection header table is an array of Elf32_Shdr or Elf64_Shdr structures. 5644e86fcacSSheldon HearnThe 565ea14e5c3SBrian FeldmanELF header's 566ea14e5c3SBrian Feldman.Sy e_shoff 567ea14e5c3SBrian Feldmanmember gives the byte offset from the beginning of the file to the section 568ea14e5c3SBrian Feldmanheader table. 569ea14e5c3SBrian Feldman.Sy e_shnum 570ea14e5c3SBrian Feldmanholds the number of entries the section header table contains. 571ea14e5c3SBrian Feldman.Sy e_shentsize 572ea14e5c3SBrian Feldmanholds the size in bytes of each entry. 573ea14e5c3SBrian Feldman.Pp 5744e86fcacSSheldon HearnA section header table index is a subscript into this array. 5754e86fcacSSheldon HearnSome section 5764e86fcacSSheldon Hearnheader table indices are reserved. 5774e86fcacSSheldon HearnAn object file does not have sections for 578ea14e5c3SBrian Feldmanthese special indices: 579ea14e5c3SBrian Feldman.Pp 580ea14e5c3SBrian Feldman.Bl -tag -width "SHN_LORESERVE" -compact 581ea14e5c3SBrian Feldman.It Dv SHN_UNDEF 582ea14e5c3SBrian FeldmanThis value marks an undefined, missing, irrelevant or otherwise meaningless 583ea14e5c3SBrian Feldmansection reference. 584ea14e5c3SBrian Feldman.It Dv SHN_LORESERVE 585ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of reserved indices. 586ea14e5c3SBrian Feldman.It Dv SHN_LOPROC 587ea14e5c3SBrian FeldmanThis value up to and including 588ea14e5c3SBrian Feldman.Sy SHN_HIPROC 589ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 590ea14e5c3SBrian Feldman.It Dv SHN_HIPROC 591ea14e5c3SBrian FeldmanThis value down to and including 592ea14e5c3SBrian Feldman.Sy SHN_LOPROC 593ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 594ea14e5c3SBrian Feldman.It Dv SHN_ABS 5954e86fcacSSheldon HearnThis value specifies absolute values for the corresponding reference. 5964e86fcacSSheldon HearnFor 597ea14e5c3SBrian Feldmanexample, symbols defined relative to section number 598ea14e5c3SBrian Feldman.Sy SHN_ABS 599ea14e5c3SBrian Feldmanhave absolute values and are not affected by relocation. 600ea14e5c3SBrian Feldman.It Dv SHN_COMMON 601ea14e5c3SBrian FeldmanSymbols defined relative to this section are common symbols, such as FORTRAN 602ea14e5c3SBrian FeldmanCOMMON or unallocated C external variables. 603ea14e5c3SBrian Feldman.It Dv SHN_HIRESERVE 6044e86fcacSSheldon HearnThis value specifies the upper bound of the range of reserved indices. 6054e86fcacSSheldon HearnThe 606ea14e5c3SBrian Feldmansystem reserves indices between 607ea14e5c3SBrian Feldman.Sy SHN_LORESERVE 608ea14e5c3SBrian Feldmanand 609ea14e5c3SBrian Feldman.Sy SHN_HIRESERVE, 6104e86fcacSSheldon Hearninclusive. 6114e86fcacSSheldon HearnThe section header table does not contain entries for the 612ea14e5c3SBrian Feldmanreserved indices. 613ea14e5c3SBrian Feldman.El 614ea14e5c3SBrian Feldman.Pp 615ea14e5c3SBrian FeldmanThe section header has the following structure: 616ea14e5c3SBrian Feldman.Bd -literal -offset indent 617ea14e5c3SBrian Feldmantypedef struct { 618ea14e5c3SBrian Feldman Elf32_Word sh_name; 619ea14e5c3SBrian Feldman Elf32_Word sh_type; 620ea14e5c3SBrian Feldman Elf32_Word sh_flags; 621ea14e5c3SBrian Feldman Elf32_Addr sh_addr; 622ea14e5c3SBrian Feldman Elf32_Off sh_offset; 623ea14e5c3SBrian Feldman Elf32_Size sh_size; 624ea14e5c3SBrian Feldman Elf32_Word sh_link; 625ea14e5c3SBrian Feldman Elf32_Word sh_info; 626ea14e5c3SBrian Feldman Elf32_Size sh_addralign; 627ea14e5c3SBrian Feldman Elf32_Size sh_entsize; 628ea14e5c3SBrian Feldman} Elf32_Shdr; 629ea14e5c3SBrian Feldman.Ed 630ea14e5c3SBrian Feldman.Pp 631ea14e5c3SBrian Feldman.Bd -literal -offset indent 632ea14e5c3SBrian Feldmantypedef struct { 633ea14e5c3SBrian Feldman Elf64_Half sh_name; 634ea14e5c3SBrian Feldman Elf64_Half sh_type; 635ea14e5c3SBrian Feldman Elf64_Size sh_flags; 636ea14e5c3SBrian Feldman Elf64_Addr sh_addr; 637ea14e5c3SBrian Feldman Elf64_Off sh_offset; 638ea14e5c3SBrian Feldman Elf64_Size sh_size; 639ea14e5c3SBrian Feldman Elf64_Half sh_link; 640ea14e5c3SBrian Feldman Elf64_Half sh_info; 641ea14e5c3SBrian Feldman Elf64_Size sh_addralign; 642ea14e5c3SBrian Feldman Elf64_Size sh_entsize; 643ea14e5c3SBrian Feldman} Elf64_Shdr; 644ea14e5c3SBrian Feldman.Ed 645ea14e5c3SBrian Feldman.Pp 646ea14e5c3SBrian Feldman.Bl -tag -width "sh_addralign" -compact 647ea14e5c3SBrian Feldman.It Dv sh_name 6484e86fcacSSheldon HearnThis member specifies the name of the section. 6494e86fcacSSheldon HearnIts value is an index 650ea14e5c3SBrian Feldmaninto the section header string table section, giving the location of 651ea14e5c3SBrian Feldmana null-terminated string. 652ea14e5c3SBrian Feldman.It Dv sh_type 6530757c960SBrian FeldmanThis member categorizes the section's contents and semantics. 654ea14e5c3SBrian Feldman.Pp 655ea14e5c3SBrian Feldman.Bl -tag -width "SHT_PROGBITS" -compact 656ea14e5c3SBrian Feldman.It Dv SHT_NULL 6574e86fcacSSheldon HearnThis value marks the section header as inactive. 6584e86fcacSSheldon HearnIt does not 6594e86fcacSSheldon Hearnhave an associated section. 6604e86fcacSSheldon HearnOther members of the section header 661ea14e5c3SBrian Feldmanhave undefined values. 662ea14e5c3SBrian Feldman.It Dv SHT_PROGBITS 663ea14e5c3SBrian FeldmanThe section holds information defined by the program, whose 664ea14e5c3SBrian Feldmanformat and meaning are determined solely by the program. 665ea14e5c3SBrian Feldman.It Dv SHT_SYMTAB 6664e86fcacSSheldon HearnThis section holds a symbol table. 6674e86fcacSSheldon HearnTypically, 668ea14e5c3SBrian Feldman.Sy SHT_SYMTAB 669ea14e5c3SBrian Feldmanprovides symbols for link editing, though it may also be used 6704e86fcacSSheldon Hearnfor dynamic linking. 6714e86fcacSSheldon HearnAs a complete symbol table, it may contain 6724e86fcacSSheldon Hearnmany symbols unnecessary for dynamic linking. 6734e86fcacSSheldon HearnAn object file can 674ea14e5c3SBrian Feldmanalso contain a 675ea14e5c3SBrian Feldman.Sy SHN_DYNSYM 676ea14e5c3SBrian Feldmansection. 677ea14e5c3SBrian Feldman.It Dv SHT_STRTAB 6784e86fcacSSheldon HearnThis section holds a string table. 6794e86fcacSSheldon HearnAn object file may have multiple 680ea14e5c3SBrian Feldmanstring table sections. 681ea14e5c3SBrian Feldman.It Dv SHT_RELA 682ea14e5c3SBrian FeldmanThis section holds relocation entries with explicit addends, such 683ea14e5c3SBrian Feldmanas type 684ea14e5c3SBrian Feldman.Sy Elf32_Rela 6854e86fcacSSheldon Hearnfor the 32-bit class of object files. 6864e86fcacSSheldon HearnAn object may have multiple 687ea14e5c3SBrian Feldmanrelocation sections. 688ea14e5c3SBrian Feldman.It Dv SHT_HASH 6894e86fcacSSheldon HearnThis section holds a symbol hash table. 6904e86fcacSSheldon HearnAll object participating in 6914e86fcacSSheldon Hearndynamic linking must contain a symbol hash table. 6924e86fcacSSheldon HearnAn object file may 693ea14e5c3SBrian Feldmanhave only one hash table. 694ea14e5c3SBrian Feldman.It Dv SHT_DYNAMIC 6954e86fcacSSheldon HearnThis section holds information for dynamic linking. 6964e86fcacSSheldon HearnAn object file may 697ea14e5c3SBrian Feldmanhave only one dynamic section. 698ea14e5c3SBrian Feldman.It Dv SHT_NOTE 699ea14e5c3SBrian FeldmanThis section holds information that marks the file in some way. 700ea14e5c3SBrian Feldman.It Dv SHT_NOBITS 701ea14e5c3SBrian FeldmanA section of this type occupies no space in the file but otherwise 702ea14e5c3SBrian Feldmanresembles 703ea14e5c3SBrian Feldman.Sy SHN_PROGBITS . 704ea14e5c3SBrian FeldmanAlthough this section contains no bytes, the 705ea14e5c3SBrian Feldman.Sy sh_offset 706ea14e5c3SBrian Feldmanmember contains the conceptual file offset. 707ea14e5c3SBrian Feldman.It Dv SHT_REL 708ea14e5c3SBrian FeldmanThis section holds relocation offsets without explicit addends, such 709ea14e5c3SBrian Feldmanas type 710ea14e5c3SBrian Feldman.Sy Elf32_Rel 7114e86fcacSSheldon Hearnfor the 32-bit class of object files. 7124e86fcacSSheldon HearnAn object file may have multiple 713ea14e5c3SBrian Feldmanrelocation sections. 714ea14e5c3SBrian Feldman.It Dv SHT_SHLIB 715ea14e5c3SBrian FeldmanThis section is reserved but has unspecified semantics. 716ea14e5c3SBrian Feldman.It Dv SHT_DYNSYM 7174e86fcacSSheldon HearnThis section holds a minimal set of dynamic linking symbols. 7184e86fcacSSheldon HearnAn 719ea14e5c3SBrian Feldmanobject file can also contain a 720ea14e5c3SBrian Feldman.Sy SHN_SYMTAB 721ea14e5c3SBrian Feldmansection. 722ea14e5c3SBrian Feldman.It Dv SHT_LOPROC 723ea14e5c3SBrian FeldmanThis value up to and including 724ea14e5c3SBrian Feldman.Sy SHT_HIPROC 725ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 726ea14e5c3SBrian Feldman.It Dv SHT_HIPROC 727ea14e5c3SBrian FeldmanThis value down to and including 728ea14e5c3SBrian Feldman.Sy SHT_LOPROC 729ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 730ea14e5c3SBrian Feldman.It Dv SHT_LOUSER 731ea14e5c3SBrian FeldmanThis value specifies the lower bound of the range of indices reserved for 732ea14e5c3SBrian Feldmanapplication programs. 733ea14e5c3SBrian Feldman.It Dv SHT_HIUSER 734ea14e5c3SBrian FeldmanThis value specifies the upper bound of the range of indices reserved for 7354e86fcacSSheldon Hearnapplication programs. 7364e86fcacSSheldon HearnSection types between 737ea14e5c3SBrian Feldman.Sy SHT_LOUSER 738ea14e5c3SBrian Feldmanand 739ea14e5c3SBrian Feldman.Sy SHT_HIUSER 740ea14e5c3SBrian Feldmanmay be used by the application, without conflicting with current or future 741ea14e5c3SBrian Feldmansystem-defined section types. 742ea14e5c3SBrian Feldman.El 743ea14e5c3SBrian Feldman.Pp 744ea14e5c3SBrian Feldman.It Dv sh_flags 745ea14e5c3SBrian FeldmanSections support one-bit flags that describe miscellaneous attributes. 746ea14e5c3SBrian FeldmanIf a flag bit is set in 747ea14e5c3SBrian Feldman.Sy sh_flags , 748ea14e5c3SBrian Feldmanthe attribute is 749ea14e5c3SBrian Feldman.Dq on 7504e86fcacSSheldon Hearnfor the section. 7514e86fcacSSheldon HearnOtherwise, the attribute is 752ea14e5c3SBrian Feldman.Dq off 7534e86fcacSSheldon Hearnor does not apply. 7544e86fcacSSheldon HearnUndefined attributes are set to zero. 755ea14e5c3SBrian Feldman.Pp 756ea14e5c3SBrian Feldman.Bl -tag -width "SHF_EXECINSTR" -compact 757ea14e5c3SBrian Feldman.It Dv SHF_WRITE 758ea14e5c3SBrian FeldmanThis section contains data that should be writable during process 759ea14e5c3SBrian Feldmanexecution. 760ea14e5c3SBrian Feldman.It Dv SHF_ALLOC 7614e86fcacSSheldon HearnThe section occupies memory during process execution. 7624e86fcacSSheldon HearnSome control 7634e86fcacSSheldon Hearnsections do not reside in the memory image of an object file. 7644e86fcacSSheldon HearnThis 765ea14e5c3SBrian Feldmanattribute is off for those sections. 766ea14e5c3SBrian Feldman.It Dv SHF_EXECINSTR 767ea14e5c3SBrian FeldmanThe section contains executable machine instructions. 768ea14e5c3SBrian Feldman.It Dv SHF_MASKPROC 769ea14e5c3SBrian FeldmanAll bits included in this mask are reserved for processor-specific 770ea14e5c3SBrian Feldmansemantics. 771ea14e5c3SBrian Feldman.El 772ea14e5c3SBrian Feldman.Pp 773ea14e5c3SBrian Feldman.It Dv sh_addr 774ea14e5c3SBrian FeldmanIf the section will appear in the memory image of a process, this member 775ea14e5c3SBrian Feldmanholds the address at which the section's first byte should reside. 776ea14e5c3SBrian FeldmanOtherwise, the member contains zero. 777ea14e5c3SBrian Feldman.It Dv sh_offset 778ea14e5c3SBrian FeldmanThis member's value holds the byte offset from the beginning of the file 7794e86fcacSSheldon Hearnto the first byte in the section. 7804e86fcacSSheldon HearnOne section type, 781ea14e5c3SBrian Feldman.Sy SHT_NOBITS , 782ea14e5c3SBrian Feldmanoccupies no space in the file, and its 783ea14e5c3SBrian Feldman.Sy sh_offset 784ea14e5c3SBrian Feldmanmember locates the conceptual placement in the file. 785ea14e5c3SBrian Feldman.It Dv sh_size 7864e86fcacSSheldon HearnThis member holds the section's size in bytes. 7874e86fcacSSheldon HearnUnless the section type 788ea14e5c3SBrian Feldmanis 789ea14e5c3SBrian Feldman.Sy SHT_NOBITS , 790ea14e5c3SBrian Feldmanthe section occupies 791ea14e5c3SBrian Feldman.Sy sh_size 7924e86fcacSSheldon Hearnbytes in the file. 7934e86fcacSSheldon HearnA section of type 794ea14e5c3SBrian Feldman.Sy SHT_NOBITS 795ea14e5c3SBrian Feldmanmay have a non-zero size, but it occupies no space in the file. 796ea14e5c3SBrian Feldman.It Dv sh_link 797ea14e5c3SBrian FeldmanThis member holds a section header table index link, whose interpretation 798ea14e5c3SBrian Feldmandepends on the section type. 799ea14e5c3SBrian Feldman.It Dv sh_info 800ea14e5c3SBrian FeldmanThis member holds extra information, whose interpretation depends on the 801ea14e5c3SBrian Feldmansection type. 802ea14e5c3SBrian Feldman.It Dv sh_addralign 8034e86fcacSSheldon HearnSome sections have address alignment constraints. 8044e86fcacSSheldon HearnIf a section holds a 805ea14e5c3SBrian Feldmandoubleword, the system must ensure doubleword alignment for the entire 8064e86fcacSSheldon Hearnsection. 8074e86fcacSSheldon HearnThat is, the value of 808ea14e5c3SBrian Feldman.Sy sh_addr 809ea14e5c3SBrian Feldmanmust be congruent to zero, modulo the value of 810ea14e5c3SBrian Feldman.Sy sh_addralign . 8114e86fcacSSheldon HearnOnly zero and positive integral powers of two are allowed. 8124e86fcacSSheldon HearnValues of zero 813ea14e5c3SBrian Feldmanor one mean the section has no alignment constraints. 814ea14e5c3SBrian Feldman.It Dv sh_entsize 815ea14e5c3SBrian FeldmanSome sections hold a table of fixed-sized entries, such as a symbol table. 816ea14e5c3SBrian FeldmanFor such a section, this member gives the size in bytes for each entry. 817ea14e5c3SBrian FeldmanThis member contains zero if the section does not hold a table of 818ea14e5c3SBrian Feldmanfixed-size entries. 819ea14e5c3SBrian Feldman.El 820ea14e5c3SBrian Feldman.Pp 821ea14e5c3SBrian FeldmanVarious sections hold program and control information: 822ea14e5c3SBrian Feldman.Bl -tag -width ".shstrtab" -compact 823ea14e5c3SBrian Feldman.It .bss 8240757c960SBrian FeldmanThis section holds uninitialized data that contributes to the program's 8254e86fcacSSheldon Hearnmemory image. 8264e86fcacSSheldon HearnBy definition, the system initializes the data with zeros 8274e86fcacSSheldon Hearnwhen the program begins to run. 8284e86fcacSSheldon HearnThis section is of type 829ea14e5c3SBrian Feldman.Sy SHT_NOBITS . 830ea14e5c3SBrian FeldmanThe attributes types are 831ea14e5c3SBrian Feldman.Sy SHF_ALLOC 832ea14e5c3SBrian Feldmanand 833ea14e5c3SBrian Feldman.Sy SHF_WRITE . 834ea14e5c3SBrian Feldman.It .comment 8354e86fcacSSheldon HearnThis section holds version control information. 8364e86fcacSSheldon HearnThis section is of type 837ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 838ea14e5c3SBrian FeldmanNo attribute types are used. 839ea14e5c3SBrian Feldman.It .data 8400757c960SBrian FeldmanThis section holds initialized data that contribute to the program's 8414e86fcacSSheldon Hearnmemory image. 8424e86fcacSSheldon HearnThis section is of type 843ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 844ea14e5c3SBrian FeldmanThe attribute types are 845ea14e5c3SBrian Feldman.Sy SHF_ALLOC 846ea14e5c3SBrian Feldmanand 847ea14e5c3SBrian Feldman.Sy SHF_WRITE . 848ea14e5c3SBrian Feldman.It .data1 8490757c960SBrian FeldmanThis section holds initialized data that contribute to the program's 8504e86fcacSSheldon Hearnmemory image. 8514e86fcacSSheldon HearnThis section is of type 852ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 853ea14e5c3SBrian FeldmanThe attribute types are 854ea14e5c3SBrian Feldman.Sy SHF_ALLOC 855ea14e5c3SBrian Feldmanand 856ea14e5c3SBrian Feldman.Sy SHF_WRITE . 857ea14e5c3SBrian Feldman.It .debug 8584e86fcacSSheldon HearnThis section holds information for symbolic debugging. 8594e86fcacSSheldon HearnThe contents 8604e86fcacSSheldon Hearnare unspecified. 8614e86fcacSSheldon HearnThis section is of type 862ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 863ea14e5c3SBrian FeldmanNo attribute types are used. 864ea14e5c3SBrian Feldman.It .dynamic 8654e86fcacSSheldon HearnThis section holds dynamic linking information. 8664e86fcacSSheldon HearnThe section's attributes 867ea14e5c3SBrian Feldmanwill include the 868ea14e5c3SBrian Feldman.Sy SHF_ALLOC 8694e86fcacSSheldon Hearnbit. 8704e86fcacSSheldon HearnWhether the 871ea14e5c3SBrian Feldman.Sy SHF_WRITE 8724e86fcacSSheldon Hearnbit is set is processor-specific. 8734e86fcacSSheldon HearnThis section is of type 874ea14e5c3SBrian Feldman.Sy SHT_DYNAMIC . 875ea14e5c3SBrian FeldmanSee the attributes above. 876ea14e5c3SBrian Feldman.It .dynstr 877ea14e5c3SBrian FeldmanThis section holds strings needed for dynamic linking, most commonly 878ea14e5c3SBrian Feldmanthe strings that represent the names associated with symbol table entries. 879ea14e5c3SBrian FeldmanThis section is of type 880ea14e5c3SBrian Feldman.Sy SHT_STRTAB . 881ea14e5c3SBrian FeldmanThe attribute type used is 882ea14e5c3SBrian Feldman.Sy SHF_ALLOC . 883ea14e5c3SBrian Feldman.It .dynsym 8844e86fcacSSheldon HearnThis section holds the dynamic linking symbol table. 8854e86fcacSSheldon HearnThis section is of type 886ea14e5c3SBrian Feldman.Sy SHT_DYNSYM . 887ea14e5c3SBrian FeldmanThe attribute used is 888ea14e5c3SBrian Feldman.Sy SHF_ALLOC . 889ea14e5c3SBrian Feldman.It .fini 890ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process 8914e86fcacSSheldon Hearntermination code. 8924e86fcacSSheldon HearnWhen a program exits normally the system arranges to 8934e86fcacSSheldon Hearnexecute the code in this section. 8944e86fcacSSheldon HearnThis section is of type 895ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 896ea14e5c3SBrian FeldmanThe attributes used are 897ea14e5c3SBrian Feldman.Sy SHF_ALLOC 898ea14e5c3SBrian Feldmanand 899ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR . 900ea14e5c3SBrian Feldman.It .got 9014e86fcacSSheldon HearnThis section holds the global offset table. 9024e86fcacSSheldon HearnThis section is of type 903ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 904ea14e5c3SBrian FeldmanThe attributes are processor-specific. 905ea14e5c3SBrian Feldman.It .hash 9064e86fcacSSheldon HearnThis section holds a symbol hash table. 9074e86fcacSSheldon HearnThis section is of type 908ea14e5c3SBrian Feldman.Sy SHT_HASH . 909ea14e5c3SBrian FeldmanThe attribute used is 910ea14e5c3SBrian Feldman.Sy SHF_ALLOC . 911ea14e5c3SBrian Feldman.It .init 912ea14e5c3SBrian FeldmanThis section holds executable instructions that contribute to the process 9134e86fcacSSheldon Hearninitialization code. 9144e86fcacSSheldon HearnWhen a program starts to run the system arranges to 915ea14e5c3SBrian Feldmanexecute the code in this section before calling the main program entry point. 916ea14e5c3SBrian FeldmanThis section is of type 917ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 918ea14e5c3SBrian FeldmanThe attributes used are 919ea14e5c3SBrian Feldman.Sy SHF_ALLOC 920ea14e5c3SBrian Feldmanand 921ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR . 922ea14e5c3SBrian Feldman.It .interp 9234e86fcacSSheldon HearnThis section holds the pathname of a program interpreter. 9244e86fcacSSheldon HearnIf the file has 925ea14e5c3SBrian Feldmana loadable segment that includes the section, the section's attributes will 926ea14e5c3SBrian Feldmaninclude the 927ea14e5c3SBrian Feldman.Sy SHF_ALLOC 9284e86fcacSSheldon Hearnbit. 9294e86fcacSSheldon HearnOtherwise, that bit will be off. 9304e86fcacSSheldon HearnThis section is of type 931ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 932ea14e5c3SBrian Feldman.It .line 933ea14e5c3SBrian FeldmanThis section holds line number information for symbolic debugging, which 934ea14e5c3SBrian Feldmandescribes the correspondence between the program source and the machine code. 9354e86fcacSSheldon HearnThe contents are unspecified. 9364e86fcacSSheldon HearnThis section is of type 937ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 938ea14e5c3SBrian FeldmanNo attribute types are used. 939ea14e5c3SBrian Feldman.It .note 940ea14e5c3SBrian FeldmanThis section holds information in the 941ea14e5c3SBrian Feldman.Dq Note Section 9424e86fcacSSheldon Hearnformat described below. 9434e86fcacSSheldon HearnThis section is of type 944ea14e5c3SBrian Feldman.Sy SHT_NOTE . 945ea14e5c3SBrian FeldmanNo attribute types are used. 946ea14e5c3SBrian Feldman.It .plt 9474e86fcacSSheldon HearnThis section holds the procedure linkage table. 9484e86fcacSSheldon HearnThis section is of type 949ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 950ea14e5c3SBrian FeldmanThe attributes are processor-specific. 951ea14e5c3SBrian Feldman.It .relNAME 9524e86fcacSSheldon HearnThis section holds relocation information as described below. 9534e86fcacSSheldon HearnIf the file 954ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes 955ea14e5c3SBrian Feldmanwill include the 956ea14e5c3SBrian Feldman.Sy SHF_ALLOC 9574e86fcacSSheldon Hearnbit. 9584e86fcacSSheldon HearnOtherwise the bit will be off. 9594e86fcacSSheldon HearnBy convention, 960ea14e5c3SBrian Feldman.Dq NAME 9614e86fcacSSheldon Hearnis supplied by the section to which the relocations apply. 9624e86fcacSSheldon HearnThus a relocation 963ea14e5c3SBrian Feldmansection for 964ea14e5c3SBrian Feldman.Sy .text 965ea14e5c3SBrian Feldmannormally would have the name 966ea14e5c3SBrian Feldman.Sy .rel.text . 967ea14e5c3SBrian FeldmanThis section is of type 968ea14e5c3SBrian Feldman.Sy SHT_REL . 969ea14e5c3SBrian Feldman.It .relaNAME 9704e86fcacSSheldon HearnThis section holds relocation information as described below. 9714e86fcacSSheldon HearnIf the file 972ea14e5c3SBrian Feldmanhas a loadable segment that includes relocation, the section's attributes 973ea14e5c3SBrian Feldmanwill include the 974ea14e5c3SBrian Feldman.Sy SHF_ALLOC 9754e86fcacSSheldon Hearnbit. 9764e86fcacSSheldon HearnOtherwise the bit will be off. 9774e86fcacSSheldon HearnBy convention, 978ea14e5c3SBrian Feldman.Dq NAME 9794e86fcacSSheldon Hearnis supplied by the section to which the relocations apply. 9804e86fcacSSheldon HearnThus a relocation 981ea14e5c3SBrian Feldmansection for 982ea14e5c3SBrian Feldman.Sy .text 983ea14e5c3SBrian Feldmannormally would have the name 984ea14e5c3SBrian Feldman.Sy .rela.text . 985ea14e5c3SBrian FeldmanThis section is of type 986ea14e5c3SBrian Feldman.Sy SHT_RELA . 987ea14e5c3SBrian Feldman.It .rodata 988f3a2511aSChris CostelloThis section holds read-only data that typically contributes to a 9894e86fcacSSheldon Hearnnon-writable segment in the process image. 9904e86fcacSSheldon HearnThis section is of type 991ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 992ea14e5c3SBrian FeldmanThe attribute used is 993ea14e5c3SBrian Feldman.Sy SHF_ALLOC . 994ea14e5c3SBrian Feldman.It .rodata1 995ea14e5c3SBrian FeldmanThis section hold read-only data that typically contributes to a 9964e86fcacSSheldon Hearnnon-writable segment in the process image. 9974e86fcacSSheldon HearnThis section is of type 998ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 999ea14e5c3SBrian FeldmanThe attribute used is 1000ea14e5c3SBrian Feldman.Sy SHF_ALLOC . 1001ea14e5c3SBrian Feldman.It .shstrtab 10024e86fcacSSheldon HearnThis section holds section names. 10034e86fcacSSheldon HearnThis section is of type 1004ea14e5c3SBrian Feldman.Sy SHT_STRTAB . 1005ea14e5c3SBrian FeldmanNo attribute types are used. 1006ea14e5c3SBrian Feldman.It .strtab 1007ea14e5c3SBrian FeldmanThis section holds strings, most commonly the strings that represent the 10084e86fcacSSheldon Hearnnames associated with symbol table entries. 10094e86fcacSSheldon HearnIf the file has a loadable 1010ea14e5c3SBrian Feldmansegment that includes the symbol string table, the section's attributes 1011ea14e5c3SBrian Feldmanwill include the 1012ea14e5c3SBrian Feldman.Sy SHF_ALLOC 10134e86fcacSSheldon Hearnbit. 10144e86fcacSSheldon HearnOtherwise the bit will be off. 10154e86fcacSSheldon HearnThis section is of type 1016ea14e5c3SBrian Feldman.Sy SHT_STRTAB . 1017ea14e5c3SBrian Feldman.It .symtab 10184e86fcacSSheldon HearnThis section holds a symbol table. 10194e86fcacSSheldon HearnIf the file has a loadable segment 1020ea14e5c3SBrian Feldmanthat includes the symbol table, the section's attributes will include 1021ea14e5c3SBrian Feldmanthe 1022ea14e5c3SBrian Feldman.Sy SHF_ALLOC 10234e86fcacSSheldon Hearnbit. 10244e86fcacSSheldon HearnOtherwise the bit will be off. 10254e86fcacSSheldon HearnThis section is of type 1026ea14e5c3SBrian Feldman.Sy SHT_SYMTAB . 1027ea14e5c3SBrian Feldman.It .text 1028ea14e5c3SBrian FeldmanThis section holds the 1029ea14e5c3SBrian Feldman.Dq text , 10304e86fcacSSheldon Hearnor executable instructions, of a program. 10314e86fcacSSheldon HearnThis section is of type 1032ea14e5c3SBrian Feldman.Sy SHT_PROGBITS . 1033ea14e5c3SBrian FeldmanThe attributes used are 1034ea14e5c3SBrian Feldman.Sy SHF_ALLOC 1035ea14e5c3SBrian Feldmanand 1036ea14e5c3SBrian Feldman.Sy SHF_EXECINSTR . 1037ea14e5c3SBrian Feldman.El 1038ea14e5c3SBrian Feldman.Pp 1039ea14e5c3SBrian FeldmanString table sections hold null-terminated character sequences, commonly 10404e86fcacSSheldon Hearncalled strings. 10414e86fcacSSheldon HearnThe object file uses these strings to represent symbol 10424e86fcacSSheldon Hearnand section names. 10434e86fcacSSheldon HearnOne references a string as an index into the string 10444e86fcacSSheldon Hearntable section. 10454e86fcacSSheldon HearnThe first byte, which is index zero, is defined to hold 10464e86fcacSSheldon Hearna null character. 10474e86fcacSSheldon HearnSimilarly, a string table's last byte is defined to 1048ea14e5c3SBrian Feldmanhold a null character, ensuring null termination for all strings. 1049ea14e5c3SBrian Feldman.Pp 1050ea14e5c3SBrian FeldmanAn object file's symbol table holds information needed to locate and 10514e86fcacSSheldon Hearnrelocate a program's symbolic definitions and references. 10524e86fcacSSheldon HearnA symbol table 1053ea14e5c3SBrian Feldmanindex is a subscript into this array. 1054ea14e5c3SBrian Feldman.Pp 1055ea14e5c3SBrian Feldman.Bd -literal -offset indent 1056ea14e5c3SBrian Feldmantypedef struct { 1057ea14e5c3SBrian Feldman Elf32_Word st_name; 1058ea14e5c3SBrian Feldman Elf32_Addr st_value; 1059ea14e5c3SBrian Feldman Elf32_Size st_size; 1060ea14e5c3SBrian Feldman unsigned char st_info; 1061ea14e5c3SBrian Feldman unsigned char st_other; 1062ea14e5c3SBrian Feldman Elf32_Half st_shndx; 1063ea14e5c3SBrian Feldman} Elf32_Sym; 1064ea14e5c3SBrian Feldman.Ed 1065ea14e5c3SBrian Feldman.Pp 1066ea14e5c3SBrian Feldman.Bd -literal -offset indent 1067ea14e5c3SBrian Feldmantypedef struct { 1068ea14e5c3SBrian Feldman Elf64_Half st_name; 1069ea14e5c3SBrian Feldman unsigned char st_info; 1070ea14e5c3SBrian Feldman unsigned char st_other; 1071ea14e5c3SBrian Feldman Elf64_Quarter st_shndx; 1072ea14e5c3SBrian Feldman Elf64_Addr st_value; 1073ea14e5c3SBrian Feldman Elf64_Size st_size; 1074ea14e5c3SBrian Feldman} Elf64_Sym; 1075ea14e5c3SBrian Feldman.Ed 1076ea14e5c3SBrian Feldman.Pp 1077ea14e5c3SBrian Feldman.Bl -tag -width "st_value" -compact 1078ea14e5c3SBrian Feldman.It Dv st_name 1079ea14e5c3SBrian FeldmanThis member holds an index into the object file's symbol string table, 10804e86fcacSSheldon Hearnwhich holds character representations of the symbol names. 10814e86fcacSSheldon HearnIf the value 1082ea14e5c3SBrian Feldmanis non-zero, it represents a string table index that gives the symbol 10834e86fcacSSheldon Hearnname. 10844e86fcacSSheldon HearnOtherwise, the symbol table has no name. 1085ea14e5c3SBrian Feldman.It Dv st_value 1086ea14e5c3SBrian FeldmanThis member gives the value of the associated symbol. 1087ea14e5c3SBrian Feldman.It Dv st_size 10884e86fcacSSheldon HearnMany symbols have associated sizes. 10894e86fcacSSheldon HearnThis member holds zero if the symbol 1090ea14e5c3SBrian Feldmanhas no size or an unknown size. 1091ea14e5c3SBrian Feldman.It Dv st_info 1092ea14e5c3SBrian FeldmanThis member specifies the symbol's type and binding attributes: 1093ea14e5c3SBrian Feldman.Pp 1094ea14e5c3SBrian Feldman.Bl -tag -width "STT_SECTION" -compact 1095ea14e5c3SBrian Feldman.It Dv STT_NOTYPE 1096ea14e5c3SBrian FeldmanThe symbol's type is not defined. 1097ea14e5c3SBrian Feldman.It Dv STT_OBJECT 1098ea14e5c3SBrian FeldmanThe symbol is associated with a data object. 1099ea14e5c3SBrian Feldman.It Dv STT_FUNC 1100ea14e5c3SBrian FeldmanThe symbol is associated with a function or other executable code. 1101ea14e5c3SBrian Feldman.It Dv STT_SECTION 11024e86fcacSSheldon HearnThe symbol is associated with a section. 11034e86fcacSSheldon HearnSymbol table entries of 1104ea14e5c3SBrian Feldmanthis type exist primarily for relocation and normally have 1105ea14e5c3SBrian Feldman.Sy STB_LOCAL 1106ea14e5c3SBrian Feldmanbindings. 1107ea14e5c3SBrian Feldman.It Dv STT_FILE 1108ea14e5c3SBrian FeldmanBy convention the symbol's name gives the name of the source file 11094e86fcacSSheldon Hearnassociated with the object file. 11104e86fcacSSheldon HearnA file symbol has 1111ea14e5c3SBrian Feldman.Sy STB_LOCAL 1112ea14e5c3SBrian Feldmanbindings, its section index is 1113ea14e5c3SBrian Feldman.Sy SHN_ABS , 1114ea14e5c3SBrian Feldmanand it precedes the other 1115ea14e5c3SBrian Feldman.Sy STB_LOCAL 1116ea14e5c3SBrian Feldmansymbols of the file, if it is present. 1117ea14e5c3SBrian Feldman.It Dv STT_LOPROC 1118ea14e5c3SBrian FeldmanThis value up to and including 1119ea14e5c3SBrian Feldman.Sy STT_HIPROC 1120ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 1121ea14e5c3SBrian Feldman.It Dv STT_HIPROC 1122ea14e5c3SBrian FeldmanThis value down to and including 1123ea14e5c3SBrian Feldman.Sy STT_LOPROC 1124ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 1125ea14e5c3SBrian Feldman.El 1126ea14e5c3SBrian Feldman.Pp 1127ea14e5c3SBrian Feldman.Bl -tag -width "STB_GLOBAL" -compact 1128ea14e5c3SBrian Feldman.It Dv STB_LOCAL 1129ea14e5c3SBrian FeldmanLocal symbols are not visible outside the object file containing their 11304e86fcacSSheldon Hearndefinition. 11314e86fcacSSheldon HearnLocal symbols of the same name may exist in multiple file 1132ea14e5c3SBrian Feldmanwithout interfering with each other. 1133ea14e5c3SBrian Feldman.It Dv STB_GLOBAL 11344e86fcacSSheldon HearnGlobal symbols are visible to all object files being combined. 11354e86fcacSSheldon HearnOne file's 1136ea14e5c3SBrian Feldmandefinition of a global symbol will satisfy another file's undefined 1137ea14e5c3SBrian Feldmanreference to the same symbol. 1138ea14e5c3SBrian Feldman.It Dv STB_WEAK 1139ea14e5c3SBrian FeldmanWeak symbols resemble global symbols, but their definitions have lower 1140ea14e5c3SBrian Feldmanprecedence. 1141ea14e5c3SBrian Feldman.It Dv STB_LOPROC 1142ea14e5c3SBrian FeldmanThis value up to and including 1143ea14e5c3SBrian Feldman.Sy STB_HIPROC 1144ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 1145ea14e5c3SBrian Feldman.It Dv STB_HIPROC 1146ea14e5c3SBrian FeldmanThis value down to and including 1147ea14e5c3SBrian Feldman.Sy STB_LOPROC 1148ea14e5c3SBrian Feldmanare reserved for processor-specific semantics. 1149ea14e5c3SBrian Feldman.Pp 1150ea14e5c3SBrian FeldmanThere are macros for packing and unpacking the binding and type fields: 1151ea14e5c3SBrian Feldman.Bl -tag -width "ELF32_ST_INFO(bind, type)" -compact 1152ea14e5c3SBrian Feldman.It Dv ELF32_ST_BIND(info) 1153ea14e5c3SBrian Feldmanor 1154ea14e5c3SBrian Feldman.Sy ELF64_ST_BIND(info) 1155f3a2511aSChris Costelloextract a binding from an st_info value. 1156ea14e5c3SBrian Feldman.It Dv ELF64_ST_TYPE(info) 1157ea14e5c3SBrian Feldmanor 1158ea14e5c3SBrian Feldman.Sy ELF32_ST_TYPE(info) 1159f3a2511aSChris Costelloextract a type from an st_info value. 1160ea14e5c3SBrian Feldman.It Dv ELF32_ST_INFO(bind, type) 1161ea14e5c3SBrian Feldmanor 1162ea14e5c3SBrian Feldman.Sy ELF64_ST_INFO(bind, type) 1163f3a2511aSChris Costelloconvert a binding and a type into an st_info value. 1164ea14e5c3SBrian Feldman.El 1165ea14e5c3SBrian Feldman.El 1166ea14e5c3SBrian Feldman.Pp 1167ea14e5c3SBrian Feldman.It Dv st_other 1168ea14e5c3SBrian FeldmanThis member currently holds zero and has no defined meaning. 1169ea14e5c3SBrian Feldman.It Dv st_shndx 1170ea14e5c3SBrian FeldmanEvery symbol table entry is 1171ea14e5c3SBrian Feldman.Dq defined 11724e86fcacSSheldon Hearnin relation to some action. 11734e86fcacSSheldon HearnThis member holds the relevant section 1174ea14e5c3SBrian Feldmanheader table index. 1175ea14e5c3SBrian Feldman.El 1176ea14e5c3SBrian Feldman.Pp 1177ea14e5c3SBrian FeldmanRelocation is the process of connecting symbolic references with 11784e86fcacSSheldon Hearnsymbolic definitions. 11794e86fcacSSheldon HearnRelocatable files must have information that 1180ea14e5c3SBrian Feldmandescribes how to modify their section contents, thus allowing executable 1181ea14e5c3SBrian Feldmanand shared object files to hold the right information for a process' 11824e86fcacSSheldon Hearnprogram image. 11834e86fcacSSheldon HearnRelocation entries are these data. 1184ea14e5c3SBrian Feldman.Pp 1185ea14e5c3SBrian FeldmanRelocation structures that do not need an addend: 1186ea14e5c3SBrian Feldman.Pp 1187ea14e5c3SBrian Feldman.Bd -literal -offset indent 1188ea14e5c3SBrian Feldmantypedef struct { 1189ea14e5c3SBrian Feldman Elf32_Addr r_offset; 1190ea14e5c3SBrian Feldman Elf32_Word r_info; 1191ea14e5c3SBrian Feldman} Elf32_Rel; 1192ea14e5c3SBrian Feldman.Ed 1193ea14e5c3SBrian Feldman.Bd -literal -offset indent 1194ea14e5c3SBrian Feldmantypedef struct { 1195ea14e5c3SBrian Feldman Elf64_Addr r_offset; 1196ea14e5c3SBrian Feldman Elf64_Size r_info; 1197ea14e5c3SBrian Feldman} Elf64_Rel; 1198ea14e5c3SBrian Feldman.Ed 1199ea14e5c3SBrian Feldman.Pp 1200ea14e5c3SBrian FeldmanRelocation structures that need an addend: 1201ea14e5c3SBrian Feldman.Pp 1202ea14e5c3SBrian Feldman.Bd -literal -offset indent 1203ea14e5c3SBrian Feldmantypedef struct { 1204ea14e5c3SBrian Feldman Elf32_Addr r_offset; 1205ea14e5c3SBrian Feldman Elf32_Word r_info; 1206ea14e5c3SBrian Feldman Elf32_Sword r_addend; 1207ea14e5c3SBrian Feldman} Elf32_Rela; 1208ea14e5c3SBrian Feldman.Ed 1209ea14e5c3SBrian Feldman.Bd -literal -offset indent 1210ea14e5c3SBrian Feldmantypedef struct { 1211ea14e5c3SBrian Feldman Elf64_Addr r_offset; 1212ea14e5c3SBrian Feldman Elf64_Size r_info; 1213ea14e5c3SBrian Feldman Elf64_Off r_addend; 1214ea14e5c3SBrian Feldman} Elf64_Rela; 1215ea14e5c3SBrian Feldman.Ed 1216ea14e5c3SBrian Feldman.Pp 1217ea14e5c3SBrian Feldman.Bl -tag -width "r_offset" -compact 1218ea14e5c3SBrian Feldman.It Dv r_offset 1219ea14e5c3SBrian FeldmanThis member gives the location at which to apply the relocation action. 1220ea14e5c3SBrian FeldmanFor a relocatable file, the value is the byte offset from the beginning 12214e86fcacSSheldon Hearnof the section to the storage unit affected by the relocation. 12224e86fcacSSheldon HearnFor an 1223ea14e5c3SBrian Feldmanexecutable file or shared object, the value is the virtual address of 1224ea14e5c3SBrian Feldmanthe storage unit affected by the relocation. 1225ea14e5c3SBrian Feldman.It Dv r_info 1226ea14e5c3SBrian FeldmanThis member gives both the symbol table index with respect to which the 12274e86fcacSSheldon Hearnrelocation must be made and the type of relocation to apply. 12284e86fcacSSheldon HearnRelocation 12294e86fcacSSheldon Hearntypes are processor-specific. 12304e86fcacSSheldon HearnWhen the text refers to a relocation 1231ea14e5c3SBrian Feldmanentry's relocation type or symbol table index, it means the result of 1232ea14e5c3SBrian Feldmanapplying 1233ea14e5c3SBrian Feldman.Sy ELF_[32|64]_R_TYPE 1234ea14e5c3SBrian Feldmanor 1235ea14e5c3SBrian Feldman.Sy ELF[32|64]_R_SYM , 1236ea14e5c3SBrian Feldmanrespectively to the entry's 1237ea14e5c3SBrian Feldman.Sy r_info 1238ea14e5c3SBrian Feldmanmember. 1239ea14e5c3SBrian Feldman.It Dv r_addend 1240ea14e5c3SBrian FeldmanThis member specifies a constant addend used to compute the value to be 1241ea14e5c3SBrian Feldmanstored into the relocatable field. 1242ea14e5c3SBrian Feldman.El 1243ea14e5c3SBrian Feldman.Sh SEE ALSO 1244ea14e5c3SBrian Feldman.Xr as 1 , 1245ea14e5c3SBrian Feldman.Xr gdb 1 , 1246ea14e5c3SBrian Feldman.Xr ld 1 , 1247ea14e5c3SBrian Feldman.Xr objdump 1 , 1248ea14e5c3SBrian Feldman.Xr execve 2 , 1249ea14e5c3SBrian Feldman.Xr core 5 1250ea14e5c3SBrian Feldman.Rs 1251ea14e5c3SBrian Feldman.%A Hewlett Packard 1252ea14e5c3SBrian Feldman.%B Elf-64 Object File Format 1253ea14e5c3SBrian Feldman.Re 1254ea14e5c3SBrian Feldman.Rs 1255ea14e5c3SBrian Feldman.%A Santa Cruz Operation 1256ea14e5c3SBrian Feldman.%B System V Application Binary Interface 1257ea14e5c3SBrian Feldman.Re 1258ea14e5c3SBrian Feldman.Rs 1259ea14e5c3SBrian Feldman.%A Unix System Laboratories 1260ea14e5c3SBrian Feldman.%T Object Files 1261ea14e5c3SBrian Feldman.%B "Executable and Linking Format (ELF)" 1262ea14e5c3SBrian Feldman.Re 1263ea14e5c3SBrian Feldman.Sh HISTORY 1264ea14e5c3SBrian FeldmanThe ELF header files made their appearance in 1265ea14e5c3SBrian Feldman.Fx 2.2.6 . 1266ea14e5c3SBrian FeldmanELF in itself first appeared in 1267ea14e5c3SBrian Feldman.At V . 1268ea14e5c3SBrian FeldmanThe ELF format is an adopted standard. 1269ea14e5c3SBrian Feldman.Sh AUTHORS 1270ea14e5c3SBrian FeldmanThis manual page was written by 1271ea14e5c3SBrian Feldman.An Jeroen Ruigrok van der Werven 1272f63bcb27SJeroen Ruigrok van der Werven.Aq asmodai@freebsd.org 1273ea14e5c3SBrian Feldmanwith inspiration from BSDi's BSD/OS 1274ea14e5c3SBrian Feldman.Xr elf 5 1275ea14e5c3SBrian Feldmanmanpage. 1276