---
name: "elf"
section: "5"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd", "openbsd"]
url: "https://new.carta.tech/elf/5"
---

# elf(5)

format of ELF executable binary files

## NAME

**elf** – format of ELF executable binary files

## SYNOPSIS

**#include \<elf.h\>**

## DESCRIPTION

The header file ⟨elf.h⟩ defines the format of ELF executable binary files. Amongst these files are normal executable files, relocatable object files, core files and shared libraries.

An executable file using the ELF file format consists of an ELF header, followed by a program header table or a section header table, or both. The ELF header is always at offset zero of the file. The program header table and the section header table's offset in the file are defined in the ELF header. The two tables describe the rest of the particularities of the file.

Applications which wish to process ELF binary files for their native architecture only should include ⟨elf.h⟩ in their source code. These applications should need to refer to all the types and structures by their generic names “Elf\_xxx” and to the macros by “ELF\_xxx”. Applications written this way can be compiled on any architecture, regardless whether the host is 32-bit or 64-bit.

Should an application need to process ELF files of an unknown architecture then the application needs to include both ⟨sys/elf32.h⟩ and ⟨sys/elf64.h⟩ instead of ⟨elf.h⟩. Furthermore, all types and structures need to be identified by either “Elf32\_xxx” or “Elf64\_xxx”. The macros need to be identified by “ELF32\_xxx” or “ELF64\_xxx”.

Whatever the system's architecture is, it will always include ⟨sys/elf\_common.h⟩ as well as ⟨sys/elf\_generic.h⟩.

These header files describe the above mentioned headers as C structures and also include structures for dynamic sections, relocation sections and symbol tables.

The following types are being used for 32-bit architectures:

```
Elf32_Addr	Unsigned 32-bit program address
Elf32_Half	Unsigned 16-bit field
Elf32_Lword	Unsigned 64-bit field
Elf32_Off	Unsigned 32-bit file offset
Elf32_Sword	Signed 32-bit field or integer
Elf32_Word	Unsigned 32-bit field or integer
```

For 64-bit architectures we have the following types:

```
Elf64_Addr	Unsigned 64-bit program address
Elf64_Half	Unsigned 16-bit field
Elf64_Lword	Unsigned 64-bit field
Elf64_Off	Unsigned 64-bit file offset
Elf64_Sword	Signed 32-bit field
Elf64_Sxword	Signed 64-bit field or integer
Elf64_Word	Unsigned 32-bit field
Elf64_Xword	Unsigned 64-bit field or integer
```

All data structures that the file format defines follow the “natural” size and alignment guidelines for the relevant class. If necessary, data structures contain explicit padding to ensure 4-byte alignment for 4-byte objects, to force structure sizes to a multiple of 4, etc.

The ELF header is described by the type Elf32\_Ehdr or Elf64\_Ehdr:

```
typedef struct {
        unsigned char   e_ident[EI_NIDENT];
        Elf32_Half      e_type;
        Elf32_Half      e_machine;
        Elf32_Word      e_version;
        Elf32_Addr      e_entry;
        Elf32_Off       e_phoff;
        Elf32_Off       e_shoff;
        Elf32_Word      e_flags;
        Elf32_Half      e_ehsize;
        Elf32_Half      e_phentsize;
        Elf32_Half      e_phnum;
        Elf32_Half      e_shentsize;
        Elf32_Half      e_shnum;
        Elf32_Half      e_shstrndx;
} Elf32_Ehdr;
```

```
typedef struct {
	unsigned char   e_ident[EI_NIDENT];
	Elf64_Half      e_type;
	Elf64_Half      e_machine;
	Elf64_Word      e_version;
	Elf64_Addr      e_entry;
	Elf64_Off       e_phoff;
	Elf64_Off       e_shoff;
	Elf64_Word      e_flags;
	Elf64_Half      e_ehsize;
	Elf64_Half      e_phentsize;
	Elf64_Half      e_phnum;
	Elf64_Half      e_shentsize;
	Elf64_Half      e_shnum;
	Elf64_Half      e_shstrndx;
} Elf64_Ehdr;
```

The fields have the following meanings:

- e\_ident

  This array of bytes specifies to interpret the file, independent of the processor or the file's remaining contents. Within this array everything is named by macros, which start with the prefix **EI\_** and may contain values which start with the prefix **ELF**. The following macros are defined:

  - EI\_MAG0

    The first byte of the magic number. It must be filled with **ELFMAG0**.

  - EI\_MAG1

    The second byte of the magic number. It must be filled with **ELFMAG1**.

  - EI\_MAG2

    The third byte of the magic number. It must be filled with **ELFMAG2**.

  - EI\_MAG3

    The fourth byte of the magic number. It must be filled with **ELFMAG3**.

  - EI\_CLASS

    The fifth byte identifies the architecture for this binary:

    - ELFCLASSNONE

      This class is invalid.

    - ELFCLASS32

      This defines the 32-bit architecture. It supports machines with files and virtual address spaces up to 4 Gigabytes.

    - ELFCLASS64

      This defines the 64-bit architecture.

  - EI\_DATA

    The sixth byte specifies the data encoding of the processor-specific data in the file. Currently these encodings are supported:

    - ELFDATANONE

      Unknown data format.

    - ELFDATA2LSB

      Two's complement, little-endian.

    - ELFDATA2MSB

      Two's complement, big-endian.

  - EI\_VERSION

    The version number of the ELF specification:

    - EV\_NONE

      Invalid version.

    - EV\_CURRENT

      Current version.

  - EI\_OSABI

    This byte identifies the operating system and ABI to which the object is targeted. Some fields in other ELF structures have flags and values that have platform specific meanings; the interpretation of those fields is determined by the value of this byte. The following values are currently defined:

    - ELFOSABI\_SYSV

      UNIX System V ABI.

    - ELFOSABI\_HPUX

      HP-UX operating system ABI.

    - ELFOSABI\_NETBSD

      NetBSD operating system ABI.

    - ELFOSABI\_LINUX

      GNU/Linux operating system ABI.

    - ELFOSABI\_HURD

      GNU/Hurd operating system ABI.

    - ELFOSABI\_86OPEN

      86Open Common IA32 ABI.

    - ELFOSABI\_SOLARIS

      Solaris operating system ABI.

    - ELFOSABI\_MONTEREY

      Monterey project ABI.

    - ELFOSABI\_IRIX

      IRIX operating system ABI.

    - ELFOSABI\_FREEBSD

      FreeBSD operating system ABI.

    - ELFOSABI\_TRU64

      TRU64 UNIX operating system ABI.

    - ELFOSABI\_ARM

      ARM architecture ABI.

    - ELFOSABI\_STANDALONE

      Standalone (embedded) ABI.

  - EI\_ABIVERSION

    This byte identifies the version of the ABI to which the object is targeted. This field is used to distinguish among incompatible versions of an ABI. The interpretation of this version number is dependent on the ABI identified by the EI\_OSABI field. Applications conforming to this specification use the value 0.

  - EI\_PAD

    Start of padding. These bytes are reserved and set to zero. Programs which read them should ignore them. The value for EI\_PAD will change in the future if currently unused bytes are given meanings.

  - EI\_BRAND

    Start of architecture identification.

  - EI\_NIDENT

    The size of the e\_ident array.

- e\_type

  This member of the structure identifies the object file type:

  - ET\_NONE

    An unknown type.

  - ET\_REL

    A relocatable file.

  - ET\_EXEC

    An executable file.

  - ET\_DYN

    A shared object.

  - ET\_CORE

    A core file.

- e\_machine

  This member specifies the required architecture for an individual file:

  - EM\_NONE

    An unknown machine.

  - EM\_M32

    AT&T WE 32100.

  - EM\_SPARC

    Sun Microsystems SPARC.

  - EM\_386

    Intel 80386.

  - EM\_68K

    Motorola 68000.

  - EM\_88K

    Motorola 88000.

  - EM\_486

    Intel 80486.

  - EM\_860

    Intel 80860.

  - EM\_MIPS

    MIPS RS3000 (big-endian only).

  - EM\_MIPS\_RS4\_BE

    MIPS RS4000 (big-endian only).

  - EM\_SPARC64

    SPARC v9 64-bit unofficial.

  - EM\_PARISC

    HPPA.

  - EM\_PPC

    PowerPC.

  - EM\_ALPHA

    Compaq \[DEC\] Alpha.

- e\_version

  This member identifies the file version:

  - EV\_NONE

    Invalid version

  - EV\_CURRENT

    Current version

- e\_entry

  This member gives the virtual address to which the system first transfers control, thus starting the process. If the file has no associated entry point, this member holds zero.

- e\_phoff

  This member holds the program header table's file offset in bytes. If the file has no program header table, this member holds zero.

- e\_shoff

  This member holds the section header table's file offset in bytes. If the file has no section header table this member holds zero.

- e\_flags

  This member holds processor-specific flags associated with the file. Flag names take the form EF\_\`machine\_flag'. Currently no flags have been defined.

- e\_ehsize

  This member holds the ELF header's size in bytes.

- e\_phentsize

  This member holds the size in bytes of one entry in the file's program header table; all entries are the same size.

- e\_phnum

  This member holds the number of entries in the program header table. If the file is using extended program header numbering, then the **e\_phnum** member will contain the value PN\_XNUM and the actual number of program header table entries will be stored in the **sh\_info** member of the section header at index SHN\_UNDEF. The product of **e\_phentsize** and the number of program header table entries gives the program header table's size in bytes. If a file has no program header, **e\_phnum** holds the value zero.

- e\_shentsize

  This member holds a sections header's size in bytes. A section header is one entry in the section header table; all entries are the same size.

- e\_shnum

  This member holds the number of entries in the section header table. If the file is using extended section numbering, then the **e\_shnum** member will be zero and the actual section number will be stored in the **sh\_size** member of the section header at index SHN\_UNDEF. If a file has no section header table, both the **e\_shnum** and the **e\_shoff** fields of the ELF header will be zero. The product of **e\_shentsize** and the number of sections in the file gives the section header table's size in bytes.

- e\_shstrndx

  This member holds the section header table index of the entry associated with the section name string table. If extended section numbering is being used, this field will hold the value **SHN\_XINDEX**, and the actual section header table index will be present in the **sh\_link** field of the section header entry at index SHN\_UNDEF. If the file has no section name string table, this member holds the value **SHN\_UNDEF**.

An executable or shared object file's program header table is an array of structures, each describing a segment or other information the system needs to prepare the program for execution. An object file *segment* contains one or more *sections*. Program headers are meaningful only for executable and shared object files. A file specifies its own program header size with the ELF header's **e\_phentsize** and **e\_phnum** members. As with the Elf executable header, the program header also has different versions depending on the architecture:

```
typedef struct {
        Elf32_Word      p_type;
        Elf32_Off       p_offset;
        Elf32_Addr      p_vaddr;
        Elf32_Addr      p_paddr;
        Elf32_Word      p_filesz;
        Elf32_Word      p_memsz;
        Elf32_Word      p_flags;
        Elf32_Word      p_align;
} Elf32_Phdr;
```

```
typedef struct {
        Elf64_Word      p_type;
        Elf64_Word      p_flags;
        Elf64_Off       p_offset;
        Elf64_Addr      p_vaddr;
        Elf64_Addr      p_paddr;
        Elf64_Xword     p_filesz;
        Elf64_Xword     p_memsz;
        Elf64_Xword     p_align;
} Elf64_Phdr;
```

The main difference between the 32-bit and the 64-bit program header lies only in the location of a **p\_flags** member in the total struct.

- p\_type

  This member of the Phdr struct tells what kind of segment this array element describes or how to interpret the array element's information.

  - PT\_NULL

    The array element is unused and the other members' values are undefined. This lets the program header have ignored entries.

  - PT\_LOAD

    The array element specifies a loadable segment, described by **p\_filesz** and **p\_memsz**. The bytes from the file are mapped to the beginning of the memory segment. If the segment's memory size (**p\_memsz**) is larger than the file size (**p\_filesz**), the “extra” bytes are defined to hold the value 0 and to follow the segment's initialized area. The file size may not be larger than the memory size. Loadable segment entries in the program header table appear in ascending order, sorted on the **p\_vaddr** member.

  - PT\_DYNAMIC

    The array element specifies dynamic linking information.

  - PT\_INTERP

    The array element specifies the location and size of a null-terminated path name to invoke as an interpreter. This segment type is meaningful only for executable files (though it may occur for shared objects). However it may not occur more than once in a file. If it is present it must precede any loadable segment entry.

  - PT\_NOTE

    The array element specifies the location and size for auxiliary information.

  - PT\_SHLIB

    This segment type is reserved but has unspecified semantics. Programs that contain an array element of this type do not conform to the ABI.

  - PT\_PHDR

    The array element, if present, specifies the location and size of the program header table itself, both in the file and in the memory image of the program. This segment type may not occur more than once in a file. Moreover, it may only occur if the program header table is part of the memory image of the program. If it is present it must precede any loadable segment entry.

  - PT\_LOPROC

    This value up to and including **PT\_HIPROC** are reserved for processor-specific semantics.

  - PT\_HIPROC

    This value down to and including **PT\_LOPROC** are reserved for processor-specific semantics.

- p\_offset

  This member holds the offset from the beginning of the file at which the first byte of the segment resides.

- p\_vaddr

  This member holds the virtual address at which the first byte of the segment resides in memory.

- p\_paddr

  On systems for which physical addressing is relevant, this member is reserved for the segment's physical address. Under BSD this member is not used and must be zero.

- p\_filesz

  This member holds the number of bytes in the file image of the segment. It may be zero.

- p\_memsz

  This member holds the number of bytes in the memory image of the segment. It may be zero.

- p\_flags

  This member holds flags relevant to the segment:

  - PF\_X

    An executable segment.

  - PF\_W

    A writable segment.

  - PF\_R

    A readable segment.

    A text segment commonly has the flags **PF\_X** and **PF\_R**. A data segment commonly has **PF\_X**, **PF\_W** and **PF\_R**.

- p\_align

  This member holds the value to which the segments are aligned in memory and in the file. Loadable process segments must have congruent values for **p\_vaddr** and **p\_offset**, modulo the page size. Values of zero and one mean no alignment is required. Otherwise, **p\_align** should be a positive, integral power of two, and **p\_vaddr** should equal **p\_offset**, modulo **p\_align**.

An file's section header table lets one locate all the file's sections. The section header table is an array of Elf32\_Shdr or Elf64\_Shdr structures. The ELF header's **e\_shoff** member gives the byte offset from the beginning of the file to the section header table. **e\_shnum** holds the number of entries the section header table contains. **e\_shentsize** holds the size in bytes of each entry.

A section header table index is a subscript into this array. Some section header table indices are reserved. An object file does not have sections for these special indices:

- SHN\_UNDEF

  This value marks an undefined, missing, irrelevant, or otherwise meaningless section reference. For example, a symbol “defined” relative to section number **SHN\_UNDEF** is an undefined symbol.

- SHN\_LORESERVE

  This value specifies the lower bound of the range of reserved indices.

- SHN\_LOPROC

  This value up to and including **SHN\_HIPROC** are reserved for processor-specific semantics.

- SHN\_HIPROC

  This value down to and including **SHN\_LOPROC** are reserved for processor-specific semantics.

- SHN\_ABS

  This value specifies absolute values for the corresponding reference. For example, symbols defined relative to section number **SHN\_ABS** have absolute values and are not affected by relocation.

- SHN\_COMMON

  Symbols defined relative to this section are common symbols, such as FORTRAN COMMON or unallocated C external variables.

- SHN\_HIRESERVE

  This value specifies the upper bound of the range of reserved indices. The system reserves indices between **SHN\_LORESERVE** and **SHN\_HIRESERVE**, inclusive. The section header table does not contain entries for the reserved indices.

The section header has the following structure:

```
typedef struct {
	Elf32_Word      sh_name;
	Elf32_Word      sh_type;
	Elf32_Word      sh_flags;
	Elf32_Addr      sh_addr;
	Elf32_Off       sh_offset;
	Elf32_Word      sh_size;
	Elf32_Word      sh_link;
	Elf32_Word      sh_info;
	Elf32_Word      sh_addralign;
	Elf32_Word      sh_entsize;
} Elf32_Shdr;
```

```
typedef struct {
	Elf64_Word      sh_name;
	Elf64_Word      sh_type;
	Elf64_Xword     sh_flags;
	Elf64_Addr      sh_addr;
	Elf64_Off       sh_offset;
	Elf64_Xword     sh_size;
	Elf64_Word      sh_link;
	Elf64_Word      sh_info;
	Elf64_Xword     sh_addralign;
	Elf64_Xword     sh_entsize;
} Elf64_Shdr;
```

- sh\_name

  This member specifies the name of the section. Its value is an index into the section header string table section, giving the location of a null-terminated string.

- sh\_type

  This member categorizes the section's contents and semantics.

  - SHT\_NULL

    This value marks the section header as inactive. It does not have an associated section. Other members of the section header have undefined values.

  - SHT\_PROGBITS

    The section holds information defined by the program, whose format and meaning are determined solely by the program.

  - SHT\_SYMTAB

    This section holds a symbol table. Typically, **SHT\_SYMTAB** provides symbols for link editing, though it may also be used for dynamic linking. As a complete symbol table, it may contain many symbols unnecessary for dynamic linking. An object file can also contain a **SHN\_DYNSYM** section.

  - SHT\_STRTAB

    This section holds a string table. An object file may have multiple string table sections.

  - SHT\_RELA

    This section holds relocation entries with explicit addends, such as type **Elf32\_Rela** for the 32-bit class of object files. An object may have multiple relocation sections.

  - SHT\_HASH

    This section holds a symbol hash table. All object participating in dynamic linking must contain a symbol hash table. An object file may have only one hash table.

  - SHT\_DYNAMIC

    This section holds information for dynamic linking. An object file may have only one dynamic section.

  - SHT\_NOTE

    This section holds information that marks the file in some way.

  - SHT\_NOBITS

    A section of this type occupies no space in the file but otherwise resembles **SHN\_PROGBITS**. Although this section contains no bytes, the **sh\_offset** member contains the conceptual file offset.

  - SHT\_REL

    This section holds relocation offsets without explicit addends, such as type **Elf32\_Rel** for the 32-bit class of object files. An object file may have multiple relocation sections.

  - SHT\_SHLIB

    This section is reserved but has unspecified semantics.

  - SHT\_DYNSYM

    This section holds a minimal set of dynamic linking symbols. An object file can also contain a **SHN\_SYMTAB** section.

  - SHT\_LOPROC

    This value up to and including **SHT\_HIPROC** are reserved for processor-specific semantics.

  - SHT\_HIPROC

    This value down to and including **SHT\_LOPROC** are reserved for processor-specific semantics.

  - SHT\_LOUSER

    This value specifies the lower bound of the range of indices reserved for application programs.

  - SHT\_HIUSER

    This value specifies the upper bound of the range of indices reserved for application programs. Section types between **SHT\_LOUSER** and **SHT\_HIUSER** may be used by the application, without conflicting with current or future system-defined section types.

- sh\_flags

  Sections support one-bit flags that describe miscellaneous attributes. If a flag bit is set in **sh\_flags**, the attribute is “on” for the section. Otherwise, the attribute is “off” or does not apply. Undefined attributes are set to zero.

  - SHF\_WRITE

    This section contains data that should be writable during process execution.

  - SHF\_ALLOC

    The section occupies memory during process execution. Some control sections do not reside in the memory image of an object file. This attribute is off for those sections.

  - SHF\_EXECINSTR

    The section contains executable machine instructions.

  - SHF\_MASKPROC

    All bits included in this mask are reserved for processor-specific semantics.

  - SHF\_COMPRESSED

    The section data is compressed.

- sh\_addr

  If the section will appear in the memory image of a process, this member holds the address at which the section's first byte should reside. Otherwise, the member contains zero.

- sh\_offset

  This member's value holds the byte offset from the beginning of the file to the first byte in the section. One section type, **SHT\_NOBITS**, occupies no space in the file, and its **sh\_offset** member locates the conceptual placement in the file.

- sh\_size

  This member holds the section's size in bytes. Unless the section type is **SHT\_NOBITS**, the section occupies **sh\_size** bytes in the file. A section of type **SHT\_NOBITS** may have a non-zero size, but it occupies no space in the file.

- sh\_link

  This member holds a section header table index link, whose interpretation depends on the section type.

- sh\_info

  This member holds extra information, whose interpretation depends on the section type.

- sh\_addralign

  Some sections have address alignment constraints. If a section holds a doubleword, the system must ensure doubleword alignment for the entire section. That is, the value of **sh\_addr** must be congruent to zero, modulo the value of **sh\_addralign**. Only zero and positive integral powers of two are allowed. Values of zero or one mean the section has no alignment constraints.

- sh\_entsize

  Some sections hold a table of fixed-sized entries, such as a symbol table. For such a section, this member gives the size in bytes for each entry. This member contains zero if the section does not hold a table of fixed-size entries.

Various sections hold program and control information:

- .bss

  (Block Started by Symbol) This section holds uninitialized data that contributes to the program's memory image. By definition, the system initializes the data with zeros when the program begins to run. This section is of type **SHT\_NOBITS**. The attributes types are **SHF\_ALLOC** and **SHF\_WRITE**.

- .comment

  This section holds version control information. This section is of type **SHT\_PROGBITS**. No attribute types are used.

- .ctors

  This legacy section holds pointers to initialization routines, executed before calling the main program entry point. This section is of type **SHT\_PROGBITS**. The attributes used are **SHF\_ALLOC**.

- .data

  This section holds initialized data that contribute to the program's memory image. This section is of type **SHT\_PROGBITS**. The attribute types are **SHF\_ALLOC** and **SHF\_WRITE**.

- .data1

  This section holds initialized data that contribute to the program's memory image. This section is of type **SHT\_PROGBITS**. The attribute types are **SHF\_ALLOC** and **SHF\_WRITE**.

- .debug

  This section holds information for symbolic debugging. The contents are unspecified. This section is of type **SHT\_PROGBITS**. No attribute types are used.

- .dtors

  This legacy section holds pointers to finalization routines, executed when the program exits normally. This section is of type **SHT\_PROGBITS**. The attributes used are **SHF\_ALLOC**.

- .dynamic

  This section holds dynamic linking information. The section's attributes will include the **SHF\_ALLOC** bit. Whether the **SHF\_WRITE** bit is set is processor-specific. This section is of type **SHT\_DYNAMIC**. See the attributes above.

- .dynstr

  This section holds strings needed for dynamic linking, most commonly the strings that represent the names associated with symbol table entries. This section is of type **SHT\_STRTAB**. The attribute type used is **SHF\_ALLOC**.

- .dynsym

  This section holds the dynamic linking symbol table. This section is of type **SHT\_DYNSYM**. The attribute used is **SHF\_ALLOC**.

- .fini

  This legacy section holds executable instructions that contribute to the process termination code. When a program exits normally the system arranges to execute the code in this section. This section is of type **SHT\_PROGBITS**. The attributes used are **SHF\_ALLOC** and **SHF\_EXECINSTR**.

- .fini\_array

  This section holds pointers to finalization routines. When a program exits normally [rtld(1)](/rtld/1.md) executes the code referenced by this section. This section is of type **SHT\_FINI\_ARRAY**. The attributes used are **SHF\_ALLOC**. Refer to NT\_FREEBSD\_NOINIT\_TAG (below) for a description of how initialization and finalization code is invoked.

- .got

  This section holds the global offset table. This section is of type **SHT\_PROGBITS**. The attributes are processor-specific.

- .hash

  This section holds a symbol hash table. This section is of type **SHT\_HASH**. The attribute used is **SHF\_ALLOC**.

- .init

  This legacy section holds executable instructions that contribute to the process initialization code. When a program starts to run the system arranges to execute the code in this section before calling the main program entry point. This section is of type **SHT\_PROGBITS**. The attributes used are **SHF\_ALLOC** and **SHF\_EXECINSTR**.

- .init\_array

  This section holds pointers to initialization routines. When a program starts to run [rtld(1)](/rtld/1.md) executes the code referenced by this section before calling the program entry point. This section is of type **SHT\_INIT\_ARRAY**. The attributes used are **SHF\_ALLOC**. Refer to NT\_FREEBSD\_NOINIT\_TAG (below) for a description of how initialization and finalization code is invoked.

- .interp

  This section holds the pathname of a program interpreter. If the file has a loadable segment that includes the section, the section's attributes will include the **SHF\_ALLOC** bit. Otherwise, that bit will be off. This section is of type **SHT\_PROGBITS**.

- .line

  This section holds line number information for symbolic debugging, which describes the correspondence between the program source and the machine code. The contents are unspecified. This section is of type **SHT\_PROGBITS**. No attribute types are used.

- .note

  This section holds information in the “Note Section” format described below. This section is of type **SHT\_NOTE**. No attribute types are used.

- .plt

  This section holds the procedure linkage table. This section is of type **SHT\_PROGBITS**. The attributes are processor-specific.

- .relNAME

  This section holds relocation information as described below. If the file has a loadable segment that includes relocation, the section's attributes will include the **SHF\_ALLOC** bit. Otherwise the bit will be off. By convention, “NAME” is supplied by the section to which the relocations apply. Thus a relocation section for **.text** normally would have the name **.rel.text**. This section is of type **SHT\_REL**.

- .relaNAME

  This section holds relocation information as described below. If the file has a loadable segment that includes relocation, the section's attributes will include the **SHF\_ALLOC** bit. Otherwise the bit will be off. By convention, “NAME” is supplied by the section to which the relocations apply. Thus a relocation section for **.text** normally would have the name **.rela.text**. This section is of type **SHT\_RELA**.

- .rodata

  This section holds read-only data that typically contributes to a non-writable segment in the process image. This section is of type **SHT\_PROGBITS**. The attribute used is **SHF\_ALLOC**.

- .rodata1

  This section holds read-only data that typically contributes to a non-writable segment in the process image. This section is of type **SHT\_PROGBITS**. The attribute used is **SHF\_ALLOC**.

- .shstrtab

  This section holds section names. This section is of type **SHT\_STRTAB**. No attribute types are used.

- .strtab

  This section holds strings, most commonly the strings that represent the names associated with symbol table entries. If the file has a loadable segment that includes the symbol string table, the section's attributes will include the **SHF\_ALLOC** bit. Otherwise the bit will be off. This section is of type **SHT\_STRTAB**.

- .symtab

  This section holds a symbol table. If the file has a loadable segment that includes the symbol table, the section's attributes will include the **SHF\_ALLOC** bit. Otherwise the bit will be off. This section is of type **SHT\_SYMTAB**.

- .text

  This section holds the “text”, or executable instructions, of a program. This section is of type **SHT\_PROGBITS**. The attributes used are **SHF\_ALLOC** and **SHF\_EXECINSTR**.

- .jcr

  This section holds information about Java classes that must be registered. It is obsolete and binaries created for FreeBSD 15 or later do not process it.

- .eh\_frame

  This section holds information used for C++ exception-handling.

A section with the SHF\_COMPRESSED flag set contains a compressed copy of the section data. Compressed section data begins with an *Elf64\_Chdr* or *Elf32\_Chdr* *structure* which encodes the compression algorithm and some characteristics of the uncompressed data.

```
typedef struct {
	Elf32_Word    ch_type;
	Elf32_Word    ch_size;
	Elf32_Word    ch_addralign;
} Elf32_Chdr;
```

```
typedef struct {
	Elf64_Word    ch_type;
	Elf64_Word    ch_reserved;
	Elf64_Xword   ch_size;
	Elf64_Xword   ch_addralign;
} Elf64_Chdr;
```

- ch\_type

  The compression algorithm used. A value of ELFCOMPRESS\_ZLIB indicates that the data is compressed using [zlib(3)](/zlib/3.md). A value of ELFCOMPRESS\_ZSTD indicates that the data is compressed using Zstandard.

- ch\_size

  The size, in bytes, of the uncompressed section data. This corresponds to the **sh\_size** field of a section header containing uncompressed data.

- ch\_addralign

  The address alignment of the uncompressed section data. This corresponds to the **sh\_addralign** field of a section header containing uncompressed data.

String table sections hold null-terminated character sequences, commonly called strings. The object file uses these strings to represent symbol and section names. One references a string as an index into the string table section. The first byte, which is index zero, is defined to hold a null character. Similarly, a string table's last byte is defined to hold a null character, ensuring null termination for all strings.

An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and references. A symbol table index is a subscript into this array.

```
typedef struct {
	Elf32_Word      st_name;
	Elf32_Addr      st_value;
	Elf32_Word      st_size;
	unsigned char   st_info;
	unsigned char   st_other;
	Elf32_Half      st_shndx;
} Elf32_Sym;
```

```
typedef struct {
	Elf64_Word      st_name;
	unsigned char   st_info;
	unsigned char   st_other;
	Elf64_Half      st_shndx;
	Elf64_Addr      st_value;
	Elf64_Xword     st_size;
} Elf64_Sym;
```

- st\_name

  This member holds an index into the object file's symbol string table, which holds character representations of the symbol names. If the value is non-zero, it represents a string table index that gives the symbol name. Otherwise, the symbol table has no name.

- st\_value

  This member gives the value of the associated symbol.

- st\_size

  Many symbols have associated sizes. This member holds zero if the symbol has no size or an unknown size.

- st\_info

  This member specifies the symbol's type and binding attributes:

  - STT\_NOTYPE

    The symbol's type is not defined.

  - STT\_OBJECT

    The symbol is associated with a data object.

  - STT\_FUNC

    The symbol is associated with a function or other executable code.

  - STT\_SECTION

    The symbol is associated with a section. Symbol table entries of this type exist primarily for relocation and normally have **STB\_LOCAL** bindings.

  - STT\_FILE

    By convention the symbol's name gives the name of the source file associated with the object file. A file symbol has **STB\_LOCAL** bindings, its section index is **SHN\_ABS**, and it precedes the other **STB\_LOCAL** symbols of the file, if it is present.

  - STT\_LOPROC

    This value up to and including **STT\_HIPROC** are reserved for processor-specific semantics.

  - STT\_HIPROC

    This value down to and including **STT\_LOPROC** are reserved for processor-specific semantics.

    - STB\_LOCAL

      Local symbols are not visible outside the object file containing their definition. Local symbols of the same name may exist in multiple file without interfering with each other.

    - STB\_GLOBAL

      Global symbols are visible to all object files being combined. One file's definition of a global symbol will satisfy another file's undefined reference to the same symbol.

    - STB\_WEAK

      Weak symbols resemble global symbols, but their definitions have lower precedence.

    - STB\_LOPROC

      This value up to and including **STB\_HIPROC** are reserved for processor-specific semantics.

    - STB\_HIPROC

      This value down to and including **STB\_LOPROC** are reserved for processor-specific semantics.

      There are macros for packing and unpacking the binding and type fields:

      -

        **ELF32\_ST\_BIND**(*info*) or **ELF64\_ST\_BIND**(*info*) extract a binding from an st\_info value.

      -

        **ELF64\_ST\_TYPE**(*info*) or **ELF32\_ST\_TYPE**(*info*) extract a type from an st\_info value.

      -

        **ELF32\_ST\_INFO**(*bind*, *type*) or **ELF64\_ST\_INFO**(*bind*, *type*) convert a binding and a type into an st\_info value.

- st\_other

  This member currently holds zero and has no defined meaning.

- st\_shndx

  Every symbol table entry is “defined” in relation to some section. This member holds the relevant section header table index.

Relocation is the process of connecting symbolic references with symbolic definitions. Relocatable files must have information that describes how to modify their section contents, thus allowing executable and shared object files to hold the right information for a process' program image. Relocation entries are these data.

Relocation structures that do not need an addend:

```
typedef struct {
	Elf32_Addr      r_offset;
	Elf32_Word      r_info;
} Elf32_Rel;
```

```
typedef struct {
	Elf64_Addr      r_offset;
	Elf64_Xword     r_info;
} Elf64_Rel;
```

Relocation structures that need an addend:

```
typedef struct {
	Elf32_Addr      r_offset;
	Elf32_Word      r_info;
	Elf32_Sword     r_addend;
} Elf32_Rela;
```

```
typedef struct {
	Elf64_Addr      r_offset;
	Elf64_Xword     r_info;
	Elf64_Sxword    r_addend;
} Elf64_Rela;
```

- r\_offset

  This member gives the location at which to apply the relocation action. For a relocatable file, the value is the byte offset from the beginning of the section to the storage unit affected by the relocation. For an executable file or shared object, the value is the virtual address of the storage unit affected by the relocation.

- r\_info

  This member gives both the symbol table index with respect to which the relocation must be made and the type of relocation to apply. Relocation types are processor-specific. When the text refers to a relocation entry's relocation type or symbol table index, it means the result of applying **ELF\_\[32\|64\]\_R\_TYPE** or **ELF\[32\|64\]\_R\_SYM**, respectively to the entry's **r\_info** member.

- r\_addend

  This member specifies a constant addend used to compute the value to be stored into the relocatable field.

### Note Section

ELF note sections consist of entries with the following format:

| | | |
| --- | --- | --- |
| *namesz* | 32 bits | Size of name |
| *descsz* | 32 bits | Size of desc |
| *type* | 32 bits | OS-dependent note type |
| *name* | *namesz* | Null-terminated originator name |
| *desc* | *descsz* | OS-dependent note data |

**Field** 	 **Size** 	 **Description**

The *name* and *desc* fields are padded to ensure 4-byte alignment. *namesz* and *descsz* specify the unpadded length.

FreeBSD defines the following ELF note types (with corresponding interpretation of *desc*):

- NT\_FREEBSD\_ABI\_TAG (Value: 1)

  Indicates the OS ABI version in a form of a 32-bit integer containing expected ABI version (i.e., \_\_FreeBSD\_version).

- NT\_FREEBSD\_NOINIT\_TAG (Value: 2)

  Indicates that the C startup does not call initialization routines, and thus [rtld(1)](/rtld/1.md) must do so. *desc* is ignored.

- NT\_FREEBSD\_ARCH\_TAG (Value: 3)

  Contains the MACHINE\_ARCH that the executable was built for.

- NT\_FREEBSD\_FEATURE\_CTL (Value: 4)

  Contains a bitmask of mitigations and features to enable:

  - NT\_FREEBSD\_FCTL\_ASLR\_DISABLE (Value: 0x01)

    Request that address randomization (ASLR) not be performed. See [security(7)](/security/7.md).

  - NT\_FREEBSD\_FCTL\_PROTMAX\_DISABLE (Value: 0x02)

    Request that [mmap(2)](/mmap/2.md) calls not set PROT\_MAX to the initial value of the *prot* argument.

  - NT\_FREEBSD\_FCTL\_STKGAP\_DISABLE (Value: 0x04)

    Disable stack gap.

  - NT\_FREEBSD\_FCTL\_WXNEEDED (Value: 0x08)

    Indicate that the binary requires mappings that are simultaneously writeable and executable.

  - NT\_FREEBSD\_FCTL\_LA48 (Value: 0x10)

    Request 48-bit linear address space on amd64.

  - NT\_FREEBSD\_FCTL\_LA57 (Value: 0x40)

    Accept 57-bit linear address space on amd64.

## SEE ALSO

[as(1)](/as/1.md), [gdb(1)](/gdb/1.md) (*ports/devel/gdb*), [ld(1)](/ld/1.md), [objdump(1)](/objdump/1.md), [readelf(1)](/readelf/1.md), [execve(2)](/execve/2.md), [zlib(3)](/zlib/3.md), [ar(5)](/ar/5.md), [core(5)](/core/5.md) Hewlett Packard, *Elf-64 Object File Format*. Santa Cruz Operation, *System V Application Binary Interface*. Unix System Laboratories, “Object Files”, *Executable and Linking Format (ELF)*.

## HISTORY

The ELF header files made their appearance in FreeBSD 2.2.6. ELF in itself first appeared in AT&T System V UNIX. The ELF format is an adopted standard.

## AUTHORS

This manual page was written by Jeroen Ruigrok van der Werven ⟨*asmodai@FreeBSD.org*⟩ with inspiration from BSDi's BSD/OS **elf** manpage.
