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