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