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