PatchworkOS  da8a090
A non-POSIX operating system.
Loading...
Searching...
No Matches

Executable and linkable format definitions. More...

Collaboration diagram for ELF file:

Detailed Description

Executable and linkable format definitions.

The ELF (Executable and Linkable Format) is a commonly utilized file format for generic binary files, including executables, object code, shared libraries, etc. and we utilize it in various parts of the operating system.

Only 64-bit ELF is implemented/handled in PatchworkOS.

For the sake of alignment with the ELF specification we use the same naming conventions, even if they are different from the usual conventions used in PatchworkOS.

See also
ELF Specification for more information.
[https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf] for the x86_64 ABI specification.

Data Structures

struct  Elf64_Ehdr
 ELF64 Header. More...
 
struct  Elf64_Shdr
 ELF64 Section Header. More...
 
struct  Elf64_Sym
 ELF64 Symbol Table Entry. More...
 
struct  Elf64_Rel
 ELF64 Rel Entry without addend. More...
 
struct  Elf64_Rela
 ELF64 Rela Entry with addend. More...
 
struct  Elf64_Phdr
 ELF64 Program Header. More...
 
struct  Elf64_File
 ELF File Helper structure. More...
 

Macros

#define ELF64_ST_BIND(i)   ((i) >> 4)
 Extract the binding from st_info.
 
#define ELF64_ST_TYPE(i)   ((i) & 0xf)
 Extract the type from st_info.
 
#define ELF64_ST_INFO(b, t)   (((b) << 4) + ((t) & 0xf))
 Create an st_info value from binding and type.
 
#define ELF64_R_SYM(i)   ((i) >> 32)
 Extract the symbol index from r_info.
 
#define ELF64_R_TYPE(i)   ((i) & 0xffffffffL)
 Extract the type from r_info.
 
#define ELF64_R_INFO(s, t)   (((s) << 32) + ((t) & 0xffffffffL))
 Create an r_info value from symbol index and type.
 
#define ELF64_GET_PHDR(elf, index)    ((Elf64_Phdr*)((uint8_t*)(elf)->header + (elf)->header->e_phoff + ((index) * (elf)->header->e_phentsize)))
 Get the program header at the given index from an ELF file.
 
#define ELF64_GET_SHDR(elf, index)    ((Elf64_Shdr*)((uint8_t*)(elf)->header + (elf)->header->e_shoff + ((index) * (elf)->header->e_shentsize)))
 Get the section header at the given index from an ELF file.
 
#define ELF64_AT_OFFSET(elf, offset)   ((void*)((uint8_t*)(elf)->header + (offset)))
 Get a pointer to a location in the ELF file at the given offset.
 

Typedefs

typedef uint64_t Elf64_Addr
 ELF64 Unsigned program address.
 
typedef uint64_t Elf64_Off
 ELF64 Unsigned file offset.
 
typedef uint16_t Elf64_Half
 ELF64 Unsigned medium integer.
 
typedef uint32_t Elf64_Word
 ELF64 Unsigned integer.
 
typedef int32_t Elf64_Sword
 ELF64 Signed integer.
 
typedef uint64_t Elf64_Xword
 ELF64 Unsigned long integer.
 
typedef uint64_t Elf64_Sxword
 ELF64 Signed long integer.
 

Enumerations

enum  Elf64_Ident_Indexes {
  EI_MAG0 = 0 , EI_MAG1 = 1 , EI_MAG2 = 2 , EI_MAG3 = 3 ,
  EI_CLASS = 4 , EI_DATA = 5 , EI_VERSION = 6 , EI_OSABI = 7 ,
  EI_ABIVERSION = 8 , EI_PAD = 9 , EI_NIDENT = 16
}
 Indices for e_ident[]. More...
 
enum  Elf64_Magic { ELFMAG0 = 0x7f , ELFMAG1 = 'E' , ELFMAG2 = 'L' , ELFMAG3 = 'F' }
 Expected magic values in e_ident[EI_MAG0] to e_ident[EI_MAG3]. More...
 
enum  Elf64_Class { ELFCLASSNONE = 0 , ELFCLASS32 = 1 , ELFCLASS64 = 2 }
 File class values for e_ident[EI_CLASS]. More...
 
enum  Elf64_Data { ELFDATANONE = 0 , ELFDATALSB = 1 , ELFDATAMSB = 2 }
 Data encoding values for e_ident[EI_DATA]. More...
 
enum  Elf64_Version { EV_NONE = 0 , EV_CURRENT = 1 }
 Version values for e_ident[EI_VERSION] and e_version. More...
 
enum  Elf64_OsAbi {
  ELFOSABI_NONE = 0 , ELFOSABI_HPUX = 1 , ELFOSABI_NETBSD = 2 , ELFOSABI_GNU = 3 ,
  ELFOSABI_LINUX = 3 , ELFOSABI_SOLARIS = 6 , ELFOSABI_AIX = 7 , ELFOSABI_IRIX = 8 ,
  ELFOSABI_FREEBSD = 9 , ELFOSABI_TRU64 = 10 , ELFOSABI_MODESTO = 11 , ELFOSABI_OPENBSD = 12 ,
  ELFOSABI_OPENVMS = 13 , ELFOSABI_NSK = 14 , ELFOSABI_AROS = 15 , ELFOSABI_FENIXOS = 16 ,
  ELFOSABI_CLOUDABI = 17 , ELFOSABI_OPENVOS = 18
}
 OS/ABI identification values for e_ident[EI_OSABI]. More...
 
enum  Elf64_Type {
  ET_NONE = 0 , ET_REL = 1 , ET_EXEC = 2 , ET_DYN = 3 ,
  ET_CORE = 4
}
 Object file type values for e_type. More...
 
enum  Elf64_Machine {
  EM_NONE = 0 , EM_M32 = 1 , EM_SPARC = 2 , EM_386 = 3 ,
  EM_68K = 4 , EM_88K = 5 , EM_IAMCU = 6 , EM_860 = 7 ,
  EM_MIPS = 8 , EM_S370 = 9 , EM_MIPS_RS3_LE = 10 , EM_PARISC = 15 ,
  EM_VPP500 = 17 , EM_SPARC32PLUS = 18 , EM_960 = 19 , EM_PPC = 20 ,
  EM_PPC64 = 21 , EM_S390 = 22 , EM_SPU = 23 , EM_V800 = 36 ,
  EM_FR20 = 37 , EM_RH32 = 38 , EM_RCE = 39 , EM_ARM = 40 ,
  EM_ALPHA = 41 , EM_SH = 42 , EM_SPARCV9 = 43 , EM_TRICORE = 44 ,
  EM_ARC = 45 , EM_H8_300 = 46 , EM_H8_300H = 47 , EM_H8S = 48 ,
  EM_H8_500 = 49 , EM_IA_64 = 50 , EM_MIPS_X = 51 , EM_COLDFIRE = 52 ,
  EM_68HC12 = 53 , EM_MMA = 54 , EM_PCP = 55 , EM_NCPU = 56 ,
  EM_NDR1 = 57 , EM_STARCORE = 58 , EM_ME16 = 59 , EM_ST100 = 60 ,
  EM_TINYJ = 61 , EM_X86_64 = 62 , EM_PDSP = 63 , EM_PDP10 = 64 ,
  EM_PDP11 = 65 , EM_FX66 = 66 , EM_ST9PLUS = 67 , EM_ST7 = 68 ,
  EM_68HC16 = 69 , EM_68HC11 = 70 , EM_68HC08 = 71 , EM_68HC05 = 72 ,
  EM_SVX = 73 , EM_ST19 = 74 , EM_VAX = 75 , EM_CRIS = 76 ,
  EM_JAVELIN = 77 , EM_FIREPATH = 78 , EM_ZSP = 79 , EM_MMIX = 80 ,
  EM_HUANY = 81 , EM_PRISM = 82 , EM_AVR = 83 , EM_FR30 = 84 ,
  EM_D10V = 85 , EM_D30V = 86 , EM_V850 = 87 , EM_M32R = 88 ,
  EM_MN10300 = 89 , EM_MN10200 = 90 , EM_PJ = 91 , EM_OPENRISC = 92 ,
  EM_ARC_COMPACT = 93 , EM_XTENSA = 94 , EM_VIDEOCORE = 95 , EM_TMM_GPP = 96 ,
  EM_NS32K = 97 , EM_TPC = 98 , EM_SNP1K = 99 , EM_ST200 = 100 ,
  EM_IP2K = 101 , EM_MAX = 102 , EM_CR = 103 , EM_F2MC16 = 104 ,
  EM_MSP430 = 105 , EM_BLACKFIN = 106 , EM_SE_C33 = 107 , EM_SEP = 108 ,
  EM_ARCA = 109 , EM_UNICORE = 110 , EM_EXCESS = 111 , EM_DXP = 112 ,
  EM_ALTERA_NIOS2 = 113 , EM_CRX = 114 , EM_XGATE = 115 , EM_C166 = 116 ,
  EM_M16C = 117 , EM_DSPIC30F = 118 , EM_CE = 119 , EM_M32C = 120 ,
  EM_TSK3000 = 131 , EM_RS08 = 132 , EM_SHARC = 133 , EM_ECOG2 = 134 ,
  EM_SCORE7 = 135 , EM_DSP24 = 136 , EM_VIDEOCORE3 = 137 , EM_LATTICEMICO32 = 138 ,
  EM_SE_C17 = 139 , EM_TI_C6000 = 140 , EM_TI_C2000 = 141 , EM_TI_C5500 = 142 ,
  EM_TI_ARP32 = 143 , EM_TI_PRU = 144 , EM_MMDSP_PLUS = 160 , EM_CYPRESS_M8C = 161 ,
  EM_R32C = 162 , EM_TRIMEDIA = 163 , EM_QDSP6 = 164 , EM_8051 = 165 ,
  EM_STXP7X = 166 , EM_NDS32 = 167 , EM_ECOG1 = 168 , EM_ECOG1X = 168 ,
  EM_MAXQ30 = 169 , EM_XIMO16 = 170 , EM_MANIK = 171 , EM_CRAYNV2 = 172 ,
  EM_RX = 173 , EM_METAG = 174 , EM_MCST_ELBRUS = 175 , EM_ECOG16 = 176 ,
  EM_CR16 = 177 , EM_ETPU = 178 , EM_SLE9X = 179 , EM_L10M = 180 ,
  EM_K10M = 181 , EM_AARCH64 = 183 , EM_AVR32 = 185 , EM_STM8 = 186 ,
  EM_TILE64 = 187 , EM_TILEPRO = 188 , EM_MICROBLAZE = 189 , EM_CUDA = 190 ,
  EM_TILEGX = 191 , EM_CLOUDSHIELD = 192 , EM_COREA_1ST = 193 , EM_COREA_2ND = 194 ,
  EM_ARC_COMPACT2 = 195 , EM_OPEN8 = 196 , EM_RL78 = 197 , EM_VIDEOCORE5 = 198 ,
  EM_78KOR = 199 , EM_56800EX = 200 , EM_BA1 = 201 , EM_BA2 = 202 ,
  EM_XCORE = 203 , EM_MCHP_PIC = 204 , EM_INTEL205 = 205 , EM_INTEL206 = 206 ,
  EM_INTEL207 = 207 , EM_INTEL208 = 208 , EM_INTEL209 = 209 , EM_KM32 = 210 ,
  EM_KMX32 = 211 , EM_KMX16 = 212 , EM_KMX8 = 213 , EM_KVARC = 214 ,
  EM_CDP = 215 , EM_COGE = 216 , EM_COOL = 217 , EM_NORC = 218 ,
  EM_CSR_KALIMBA = 219 , EM_Z80 = 220 , EM_VISIUM = 221 , EM_FT32 = 222 ,
  EM_MOXIE = 223 , EM_AMDGPU = 224 , EM_RISCV = 243 , EM_LANAI = 244 ,
  EM_CEVA = 245 , EM_CEVA_X2 = 246 , EM_BPF = 247 , EM_GRAPHCORE_IPU = 248 ,
  EM_IMG1 = 249 , EM_NFP = 250 , EM_VE = 251 , EM_CSKY = 252 ,
  EM_ARC_COMPACT3_64 = 253 , EM_MCS6502 = 254 , EM_ARC_COMPACT3 = 255 , EM_KVX = 256 ,
  EM_65816 = 257 , EM_LOONGARCH = 258 , EM_KF32 = 259 , EM_U16_U8CORE = 260 ,
  EM_TACHYUM = 261 , EM_56800EF = 262 , EM_SBF = 263 , EM_AIENGINE = 264 ,
  EM_SIMA_MLA = 265 , EM_BANG = 266 , EM_LOONGGPU = 267 , EM_SW64 = 268 ,
  EM_AIECTRLCODE = 269
}
 Machine architecture values for e_machine. More...
 
enum  Elf64_Shn_Indexes {
  SHN_UNDEF = 0 , SHN_LORESERVE = 0xff00 , SHN_LOPROC = 0xff00 , SHN_HIPROC = 0xff1f ,
  SHN_LOOS = 0xff20 , SHN_HIOS = 0xff3f , SHN_ABS = 0xfff1 , SHN_COMMON = 0xfff2 ,
  SHN_XINDEX = 0xffff , SHN_HIRESERVE = 0xffff
}
 Special section indexes. More...
 
enum  Elf64_Section_Types {
  SHT_NULL = 0 , SHT_PROGBITS = 1 , SHT_SYMTAB = 2 , SHT_STRTAB = 3 ,
  SHT_RELA = 4 , SHT_HASH = 5 , SHT_DYNAMIC = 6 , SHT_NOTE = 7 ,
  SHT_NOBITS = 8 , SHT_REL = 9 , SHT_SHLIB = 10 , SHT_DYNSYM = 11 ,
  SHT_INIT_ARRAY = 14 , SHT_FINI_ARRAY = 15 , SHT_PREINIT_ARRAY = 16 , SHT_GROUP = 17 ,
  SHT_SYMTAB_SHNDX = 18 , SHT_RELR = 19 , SHT_LOOS = 0x60000000 , SHT_HIOS = 0x6fffffff ,
  SHT_LOPROC = 0x70000000 , SHT_HIPROC = 0x7fffffff , SHT_LOUSER = 0x80000000 , SHT_HIUSER = 0xffffffff
}
 Section type values for sh_type. More...
 
enum  Elf64_Section_Flags {
  SHF_WRITE = 0x1 , SHF_ALLOC = 0x2 , SHF_EXECINSTR = 0x4 , SHF_MERGE = 0x10 ,
  SHF_STRINGS = 0x20 , SHF_INFO_LINK = 0x40 , SHF_LINK_ORDER = 0x80 , SHF_OS_NONCONFORMING = 0x100 ,
  SHF_GROUP = 0x200 , SHF_TLS = 0x400 , SHF_COMPRESSED = 0x800 , SHF_MASKOS = 0x0ff00000 ,
  SHF_MASKPROC = 0xf0000000
}
 Section flag values for sh_flags. More...
 
enum  Elf64_Symbol_Binding {
  STB_LOCAL = 0 , STB_GLOBAL = 1 , STB_WEAK = 2 , STB_LOOS = 10 ,
  STB_HIOS = 12 , STB_LOPROC = 13 , STB_HIPROC = 15
}
 Symbol binding values stored in st_info. More...
 
enum  Elf64_Symbol_Type {
  STT_NOTYPE = 0 , STT_OBJECT = 1 , STT_FUNC = 2 , STT_SECTION = 3 ,
  STT_FILE = 4 , STT_LOOS = 10 , STT_HIOS = 12 , STT_LOPROC = 13 ,
  STT_HIPROC = 15
}
 Symbol type values stored in st_info. More...
 
enum  Elf64_Relocation_Types_x86_64 {
  R_X86_64_NONE = 0 , R_X86_64_64 = 1 , R_X86_64_PC32 = 2 , R_X86_64_GOT32 = 3 ,
  R_X86_64_PLT32 = 4 , R_X86_64_COPY = 5 , R_X86_64_GLOB_DAT = 6 , R_X86_64_JUMP_SLOT = 7 ,
  R_X86_64_RELATIVE = 8 , R_X86_64_GOTPCREL = 9 , R_X86_64_32 = 10 , R_X86_64_32S = 11 ,
  R_X86_64_16 = 12 , R_X86_64_PC16 = 13 , R_X86_64_8 = 14 , R_X86_64_PC8 = 15 ,
  R_X86_64_DTPMOD64 = 16 , R_X86_64_DTPOFF64 = 17 , R_X86_64_TPOFF64 = 18 , R_X86_64_TLSGD = 19 ,
  R_X86_64_TLSLD = 20 , R_X86_64_DTPOFF32 = 21 , R_X86_64_GOTTPOFF = 22 , R_X86_64_TPOFF32 = 23 ,
  R_X86_64_PC64 = 24 , R_X86_64_GOTOFF64 = 25 , R_X86_64_GOTPC32 = 26 , R_X86_64_SIZE32 = 32 ,
  R_X86_64_SIZE64 = 33 , R_X86_64_GOTPC32_TLSDESC = 34 , R_X86_64_TLSDESC_CALL = 35 , R_X86_64_TLSDESC = 36 ,
  R_X86_64_IRELATIVE = 37
}
 Relocation type values for r_info. More...
 
enum  Elf64_Program_Types {
  PT_NULL = 0 , PT_LOAD = 1 , PT_DYNAMIC = 2 , PT_INTERP = 3 ,
  PT_NOTE = 4 , PT_SHLIB = 5 , PT_PHDR = 6 , PT_TLS = 7 ,
  PT_LOOS = 0x60000000 , PT_HIOS = 0x6fffffff , PT_LOPROC = 0x70000000 , PT_HIPROC = 0x7fffffff
}
 Segment type values for p_type. More...
 
enum  Elf64_Program_Flags {
  PF_X = 0x1 , PF_W = 0x2 , PF_R = 0x4 , PF_MASKOS = 0x0ff00000 ,
  PF_MASKPROC = 0xf0000000
}
 Segment flag values for p_flags. More...
 

Functions

uint64_t elf64_validate (Elf64_File *elf, void *data, uint64_t size)
 Validate a files content and initalize a ELF64_File structure using it.
 
void elf64_get_loadable_bounds (const Elf64_File *elf, Elf64_Addr *minAddr, Elf64_Addr *maxAddr)
 Get the loadable virtual memory bounds of an ELF file.
 
void elf64_load_segments (const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset)
 Load all loadable segments of an ELF file into memory.
 
uint64_t elf64_relocate (const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset, void *(*resolve_symbol)(const char *name, void *private), void *private)
 Perform relocations on an ELF file loaded into memory.
 
const char * elf64_get_string (const Elf64_File *elf, Elf64_Xword strTabIndex, Elf64_Off offset)
 Get a string from the string table section at the given offset.
 
Elf64_Shdrelf64_get_section_by_name (const Elf64_File *elf, const char *name)
 Get a section by its name.
 
const char * elf64_get_section_name (const Elf64_File *elf, const Elf64_Shdr *section)
 Get the name of a section.
 
Elf64_Symelf64_get_symbol_by_index (const Elf64_File *elf, Elf64_Xword symbolIndex)
 Get a symbol by its index from the symbol table.
 
Elf64_Symelf64_get_symbol_by_name (const Elf64_File *elf, const char *name)
 Get a symbol by its name from the symbol table.
 
const char * elf64_get_symbol_name (const Elf64_File *elf, const Elf64_Sym *symbol)
 Get the name of a symbol.
 
Elf64_Symelf64_get_dynamic_symbol_by_index (const Elf64_File *elf, Elf64_Xword symbolIndex)
 Get a dynamic symbol by its index from the dynamic symbol table.
 
const char * elf64_get_dynamic_symbol_name (const Elf64_File *elf, const Elf64_Sym *symbol)
 Get the name of a dynamic symbol.
 

Macro Definition Documentation

◆ ELF64_ST_BIND

#define ELF64_ST_BIND (   i)    ((i) >> 4)

Extract the binding from st_info.

Parameters
iThe st_info value
Returns
The binding value

Definition at line 558 of file elf.h.

◆ ELF64_ST_TYPE

#define ELF64_ST_TYPE (   i)    ((i) & 0xf)

Extract the type from st_info.

Parameters
iThe st_info value
Returns
The type value

Definition at line 581 of file elf.h.

◆ ELF64_ST_INFO

#define ELF64_ST_INFO (   b,
 
)    (((b) << 4) + ((t) & 0xf))

Create an st_info value from binding and type.

See also
https://gabi.xinuos.com/elf/05-symtab.html
Parameters
bThe binding value
tThe type value
Returns
The combined st_info value

Definition at line 609 of file elf.h.

◆ ELF64_R_SYM

#define ELF64_R_SYM (   i)    ((i) >> 32)

Extract the symbol index from r_info.

See also
https://gabi.xinuos.com/elf/06-reloc.html
Parameters
iThe r_info value
Returns
The symbol index

Definition at line 640 of file elf.h.

◆ ELF64_R_TYPE

#define ELF64_R_TYPE (   i)    ((i) & 0xffffffffL)

Extract the type from r_info.

See also
https://gabi.xinuos.com/elf/06-reloc.html
Parameters
iThe r_info value
Returns
The type value

Definition at line 650 of file elf.h.

◆ ELF64_R_INFO

#define ELF64_R_INFO (   s,
 
)    (((s) << 32) + ((t) & 0xffffffffL))

Create an r_info value from symbol index and type.

See also
https://gabi.xinuos.com/elf/06-reloc.html
Parameters
sThe symbol index
tThe type value
Returns
The combined r_info value

Definition at line 717 of file elf.h.

◆ ELF64_GET_PHDR

#define ELF64_GET_PHDR (   elf,
  index 
)     ((Elf64_Phdr*)((uint8_t*)(elf)->header + (elf)->header->e_phoff + ((index) * (elf)->header->e_phentsize)))

Get the program header at the given index from an ELF file.

Parameters
elfThe ELF file
indexThe program header index
Returns
Pointer to the program header

Definition at line 795 of file elf.h.

◆ ELF64_GET_SHDR

#define ELF64_GET_SHDR (   elf,
  index 
)     ((Elf64_Shdr*)((uint8_t*)(elf)->header + (elf)->header->e_shoff + ((index) * (elf)->header->e_shentsize)))

Get the section header at the given index from an ELF file.

Parameters
elfThe ELF file
indexThe section header index
Returns
Pointer to the section header

Definition at line 805 of file elf.h.

◆ ELF64_AT_OFFSET

#define ELF64_AT_OFFSET (   elf,
  offset 
)    ((void*)((uint8_t*)(elf)->header + (offset)))

Get a pointer to a location in the ELF file at the given offset.

Parameters
elfThe ELF file
offsetThe offset in bytes
Returns
Pointer to the location in the ELF file

Definition at line 814 of file elf.h.

Typedef Documentation

◆ Elf64_Addr

ELF64 Unsigned program address.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 30 of file elf.h.

◆ Elf64_Off

ELF64 Unsigned file offset.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 36 of file elf.h.

◆ Elf64_Half

ELF64 Unsigned medium integer.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 42 of file elf.h.

◆ Elf64_Word

ELF64 Unsigned integer.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 48 of file elf.h.

◆ Elf64_Sword

ELF64 Signed integer.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 54 of file elf.h.

◆ Elf64_Xword

ELF64 Unsigned long integer.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 60 of file elf.h.

◆ Elf64_Sxword

ELF64 Signed long integer.

See also
https://gabi.xinuos.com/elf/01-intro.html#file-format

Definition at line 66 of file elf.h.

Enumeration Type Documentation

◆ Elf64_Ident_Indexes

Indices for e_ident[].

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
EI_MAG0 

Index of magic number byte 0.

EI_MAG1 

Index of magic number byte 1.

EI_MAG2 

Index of magic number byte 2.

EI_MAG3 

Index of magic number byte 3.

EI_CLASS 

Index of the file class byte.

EI_DATA 

Index of the data encoding byte.

EI_VERSION 

Index of the file version byte.

EI_OSABI 

Index of the OS/ABI identification byte.

EI_ABIVERSION 

Index of the ABI version byte.

EI_PAD 

Index of the start of padding bytes.

EI_NIDENT 

Total size of e_ident.

Definition at line 72 of file elf.h.

◆ Elf64_Magic

Expected magic values in e_ident[EI_MAG0] to e_ident[EI_MAG3].

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
ELFMAG0 

Expected value for e_ident[EI_MAG0]

ELFMAG1 

Expected value for e_ident[EI_MAG1]

ELFMAG2 

Expected value for e_ident[EI_MAG2]

ELFMAG3 

Expected value for e_ident[EI_MAG3]

Definition at line 130 of file elf.h.

◆ Elf64_Class

File class values for e_ident[EI_CLASS].

Identifies whether the file is 32-bit or 64-bit.

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
ELFCLASSNONE 

Invalid class.

ELFCLASS32 

32-bit objects

ELFCLASS64 

64-bit objects, we always expect this value

Definition at line 145 of file elf.h.

◆ Elf64_Data

enum Elf64_Data

Data encoding values for e_ident[EI_DATA].

Identifies the endianness of the file.

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
ELFDATANONE 

Invalid data encoding.

ELFDATALSB 

Little-endian encoding, we always expect this value.

ELFDATAMSB 

Big-endian encoding.

Definition at line 159 of file elf.h.

◆ Elf64_Version

Version values for e_ident[EI_VERSION] and e_version.

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
EV_NONE 

Invalid version.

EV_CURRENT 

Current version, we always expect this value.

Definition at line 170 of file elf.h.

◆ Elf64_OsAbi

OS/ABI identification values for e_ident[EI_OSABI].

Defines the expected operating system or ABI for the file.

Even if we are in fact not Linux or GNU, we still expect this value or 0 since we for the most part follow the same conventions.

We ignore the "ABI Version" field e_ident[EI_ABIVERSION] entirely.

See also
https://gabi.xinuos.com/elf/b-osabi.html
Enumerator
ELFOSABI_NONE 

No extensions or unspecified.

ELFOSABI_HPUX 

Hewlett-Packard HP-UX.

ELFOSABI_NETBSD 

NetBSD.

ELFOSABI_GNU 

GNU, we always expect this value.

ELFOSABI_LINUX 

Linux, alias for ELFOSABI_GNU.

ELFOSABI_SOLARIS 

Sun Solaris.

ELFOSABI_AIX 

IBM AIX.

ELFOSABI_IRIX 

SGI Irix.

ELFOSABI_FREEBSD 

FreeBSD.

ELFOSABI_TRU64 

Compaq TRU64 UNIX.

ELFOSABI_MODESTO 

Novell Modesto.

ELFOSABI_OPENBSD 

Open BSD.

ELFOSABI_OPENVMS 

Open VMS.

ELFOSABI_NSK 

Hewlett-Packard Non-Stop Kernel.

ELFOSABI_AROS 

Amiga Research OS.

ELFOSABI_FENIXOS 

Fenix OS.

ELFOSABI_CLOUDABI 

Nuxi CloudABI.

ELFOSABI_OPENVOS 

Stratus Technologies OpenVOS.

Definition at line 188 of file elf.h.

◆ Elf64_Type

enum Elf64_Type

Object file type values for e_type.

See also
https://gabi.xinuos.com/elf/02-eheader.html
Enumerator
ET_NONE 

No file type.

ET_REL 

Relocatable file.

ET_EXEC 

Executable file.

ET_DYN 

Shared object file.

ET_CORE 

Core file.

Definition at line 214 of file elf.h.

◆ Elf64_Machine

Machine architecture values for e_machine.

See also
https://gabi.xinuos.com/elf/a-emachine.html
Enumerator
EM_NONE 

No machine.

EM_M32 

AT&T WE 32100.

EM_SPARC 

SPARC.

EM_386 

Intel 80386.

EM_68K 

Motorola 68000.

EM_88K 

Motorola 88000.

EM_IAMCU 

Intel MCU.

EM_860 

Intel 80860.

EM_MIPS 

MIPS I Architecture.

EM_S370 

IBM System/370 Processor.

EM_MIPS_RS3_LE 

MIPS RS3000 Little-endian.

EM_PARISC 

Hewlett-Packard PA-RISC.

EM_VPP500 

Fujitsu VPP500.

EM_SPARC32PLUS 

Enhanced instruction set SPARC.

EM_960 

Intel 80960.

EM_PPC 

PowerPC.

EM_PPC64 

64-bit PowerPC

EM_S390 

IBM System/390 Processor.

EM_SPU 

IBM SPU/SPC.

EM_V800 

NEC V800.

EM_FR20 

Fujitsu FR20.

EM_RH32 

TRW RH-32.

EM_RCE 

Motorola RCE.

EM_ARM 

ARM 32-bit architecture (AARCH32)

EM_ALPHA 

Digital Alpha.

EM_SH 

Hitachi SH.

EM_SPARCV9 

SPARC Version 9.

EM_TRICORE 

Siemens TriCore embedded processor.

EM_ARC 

Argonaut RISC Core, Argonaut Technologies Inc.

EM_H8_300 

Hitachi H8/300.

EM_H8_300H 

Hitachi H8/300H.

EM_H8S 

Hitachi H8S.

EM_H8_500 

Hitachi H8/500.

EM_IA_64 

Intel IA-64 processor architecture.

EM_MIPS_X 

Stanford MIPS-X.

EM_COLDFIRE 

Motorola ColdFire.

EM_68HC12 

Motorola M68HC12.

EM_MMA 

Fujitsu MMA Multimedia Accelerator.

EM_PCP 

Siemens PCP.

EM_NCPU 

Sony nCPU embedded RISC processor.

EM_NDR1 

Denso NDR1 microprocessor.

EM_STARCORE 

Motorola Star*Core processor.

EM_ME16 

Toyota ME16 processor.

EM_ST100 

STMicroelectronics ST100 processor.

EM_TINYJ 

Advanced Logic Corp. TinyJ embedded processor family.

EM_X86_64 

AMD x86-64 architecture, we always expect this value.

EM_PDSP 

Sony DSP Processor.

EM_PDP10 

Digital Equipment Corp. PDP-10.

EM_PDP11 

Digital Equipment Corp. PDP-11.

EM_FX66 

Siemens FX66 microcontroller.

EM_ST9PLUS 

STMicroelectronics ST9+ 8/16 bit microcontroller.

EM_ST7 

STMicroelectronics ST7 8-bit microcontroller.

EM_68HC16 

Motorola MC68HC16 Microcontroller.

EM_68HC11 

Motorola MC68HC11 Microcontroller.

EM_68HC08 

Motorola MC68HC08 Microcontroller.

EM_68HC05 

Motorola MC68HC05 Microcontroller.

EM_SVX 

Silicon Graphics SVx.

EM_ST19 

STMicroelectronics ST19 8-bit microcontroller.

EM_VAX 

Digital VAX.

EM_CRIS 

Axis Communications 32-bit embedded processor.

EM_JAVELIN 

Infineon Technologies 32-bit embedded processor.

EM_FIREPATH 

Element 14 64-bit DSP Processor.

EM_ZSP 

LSI Logic 16-bit DSP Processor.

EM_MMIX 

Donald Knuth’s educational 64-bit processor.

EM_HUANY 

Harvard University machine-independent object files.

EM_PRISM 

SiTera Prism.

EM_AVR 

Atmel AVR 8-bit microcontroller.

EM_FR30 

Fujitsu FR30.

EM_D10V 

Mitsubishi D10V.

EM_D30V 

Mitsubishi D30V.

EM_V850 

NEC v850.

EM_M32R 

Mitsubishi M32R.

EM_MN10300 

Matsushita MN10300.

EM_MN10200 

Matsushita MN10200.

EM_PJ 

picoJava

EM_OPENRISC 

OpenRISC 32-bit embedded processor.

EM_ARC_COMPACT 

ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5)

EM_XTENSA 

Tensilica Xtensa Architecture.

EM_VIDEOCORE 

Alphamosaic VideoCore processor.

EM_TMM_GPP 

Thompson Multimedia General Purpose Processor.

EM_NS32K 

National Semiconductor 32000 series.

EM_TPC 

Tenor Network TPC processor.

EM_SNP1K 

Trebia SNP 1000 processor.

EM_ST200 

STMicroelectronics (www.st.com) ST200 microcontroller.

EM_IP2K 

Ubicom IP2xxx microcontroller family.

EM_MAX 

MAX Processor.

EM_CR 

National Semiconductor CompactRISC microprocessor.

EM_F2MC16 

Fujitsu F2MC16.

EM_MSP430 

Texas Instruments embedded microcontroller msp430.

EM_BLACKFIN 

Analog Devices Blackfin (DSP) processor.

EM_SE_C33 

S1C33 Family of Seiko Epson processors.

EM_SEP 

Sharp embedded microprocessor.

EM_ARCA 

Arca RISC Microprocessor.

EM_UNICORE 

Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University.

EM_EXCESS 

eXcess: 16/32/64-bit configurable embedded CPU

EM_DXP 

Icera Semiconductor Inc. Deep Execution Processor.

EM_ALTERA_NIOS2 

Altera Nios II soft-core processor.

EM_CRX 

National Semiconductor CompactRISC CRX microprocessor.

EM_XGATE 

Motorola XGATE embedded processor.

EM_C166 

Infineon C16x/XC16x processor.

EM_M16C 

Renesas M16C series microprocessors.

EM_DSPIC30F 

Microchip Technology dsPIC30F Digital Signal Controller.

EM_CE 

Freescale Communication Engine RISC core.

EM_M32C 

Renesas M32C series microprocessors.

EM_TSK3000 

Altium TSK3000 core.

EM_RS08 

Freescale RS08 embedded processor.

EM_SHARC 

Analog Devices SHARC family of 32-bit DSP processors.

EM_ECOG2 

Cyan Technology eCOG2 microprocessor.

EM_SCORE7 

Sunplus S+core7 RISC processor.

EM_DSP24 

New Japan Radio (NJR) 24-bit DSP Processor.

EM_VIDEOCORE3 

Broadcom VideoCore III processor.

EM_LATTICEMICO32 

RISC processor for Lattice FPGA architecture.

EM_SE_C17 

Seiko Epson C17 family.

EM_TI_C6000 

The Texas Instruments TMS320C6000 DSP family.

EM_TI_C2000 

The Texas Instruments TMS320C2000 DSP family.

EM_TI_C5500 

The Texas Instruments TMS320C55x DSP family.

EM_TI_ARP32 

Texas Instruments Application Specific RISC Processor, 32bit fetch.

EM_TI_PRU 

Texas Instruments Programmable Realtime Unit.

EM_MMDSP_PLUS 

STMicroelectronics 64bit VLIW Data Signal Processor.

EM_CYPRESS_M8C 

Cypress M8C microprocessor.

EM_R32C 

Renesas R32C series microprocessors.

EM_TRIMEDIA 

NXP Semiconductors TriMedia architecture family.

EM_QDSP6 

QUALCOMM DSP6 Processor.

EM_8051 

Intel 8051 and variants.

EM_STXP7X 

STMicroelectronics STxP7x family of configurable and extensible RISC processors.

EM_NDS32 

Andes Technology compact code size embedded RISC processor family.

EM_ECOG1 

Cyan Technology eCOG1X family.

EM_ECOG1X 

Cyan Technology eCOG1X family.

EM_MAXQ30 

Dallas Semiconductor MAXQ30 Core Micro-controllers.

EM_XIMO16 

New Japan Radio (NJR) 16-bit DSP Processor.

EM_MANIK 

M2000 Reconfigurable RISC Microprocessor.

EM_CRAYNV2 

Cray Inc. NV2 vector architecture.

EM_RX 

Renesas RX family.

EM_METAG 

Imagination Technologies META processor architecture.

EM_MCST_ELBRUS 

MCST Elbrus general purpose hardware architecture.

EM_ECOG16 

Cyan Technology eCOG16 family.

EM_CR16 

National Semiconductor CompactRISC CR16 16-bit microprocessor.

EM_ETPU 

Freescale Extended Time Processing Unit.

EM_SLE9X 

Infineon Technologies SLE9X core.

EM_L10M 

Intel L10M.

EM_K10M 

Intel K10M.

EM_AARCH64 

ARM 64-bit architecture (AARCH64)

EM_AVR32 

Atmel Corporation 32-bit microprocessor family.

EM_STM8 

STMicroeletronics STM8 8-bit microcontroller.

EM_TILE64 

Tilera TILE64 multicore architecture family.

EM_TILEPRO 

Tilera TILEPro multicore architecture family.

EM_MICROBLAZE 

Xilinx MicroBlaze 32-bit RISC soft processor core.

EM_CUDA 

NVIDIA CUDA architecture.

EM_TILEGX 

Tilera TILE-Gx multicore architecture family.

EM_CLOUDSHIELD 

CloudShield architecture family.

EM_COREA_1ST 

KIPO-KAIST Core-A 1st generation processor family.

EM_COREA_2ND 

KIPO-KAIST Core-A 2nd generation processor family.

EM_ARC_COMPACT2 

Synopsys ARCompact V2.

EM_OPEN8 

Open8 8-bit RISC soft processor core.

EM_RL78 

Renesas RL78 family.

EM_VIDEOCORE5 

Broadcom VideoCore V processor.

EM_78KOR 

Renesas 78KOR family.

EM_56800EX 

Freescale 56800EX Digital Signal Controller (DSC)

EM_BA1 

Beyond BA1 CPU architecture.

EM_BA2 

Beyond BA2 CPU architecture.

EM_XCORE 

XMOS xCORE processor family.

EM_MCHP_PIC 

Microchip 8-bit PIC(r) family.

EM_INTEL205 

Reserved by Intel.

EM_INTEL206 

Reserved by Intel.

EM_INTEL207 

Reserved by Intel.

EM_INTEL208 

Reserved by Intel.

EM_INTEL209 

Reserved by Intel.

EM_KM32 

KM211 KM32 32-bit processor.

EM_KMX32 

KM211 KMX32 32-bit processor.

EM_KMX16 

KM211 KMX16 16-bit processor.

EM_KMX8 

KM211 KMX8 8-bit processor.

EM_KVARC 

KM211 KVARC processor.

EM_CDP 

Paneve CDP architecture family.

EM_COGE 

Cognitive Smart Memory Processor.

EM_COOL 

Bluechip Systems CoolEngine.

EM_NORC 

Nanoradio Optimized RISC.

EM_CSR_KALIMBA 

CSR Kalimba architecture family.

EM_Z80 

Zilog Z80.

EM_VISIUM 

Controls and Data Services VISIUMcore processor.

EM_FT32 

FTDI Chip FT32 high performance 32-bit RISC architecture.

EM_MOXIE 

Moxie processor family.

EM_AMDGPU 

AMD GPU architecture.

EM_RISCV 

RISC-V.

EM_LANAI 

Lanai processor.

EM_CEVA 

CEVA Processor Architecture Family.

EM_CEVA_X2 

CEVA X2 Processor Family.

EM_BPF 

Linux BPF – in-kernel virtual machine.

EM_GRAPHCORE_IPU 

Graphcore Intelligent Processing Unit.

EM_IMG1 

Imagination Technologies.

EM_NFP 

Netronome Flow Processor (NFP)

EM_VE 

NEC Vector Engine.

EM_CSKY 

C-SKY processor family.

EM_ARC_COMPACT3_64 

Synopsys ARCv2.3 64-bit.

EM_MCS6502 

MOS Technology MCS 6502 processor.

EM_ARC_COMPACT3 

Synopsys ARCv2.3 32-bit.

EM_KVX 

Kalray VLIW core of the MPPA processor family.

EM_65816 

WDC 65816/65C816.

EM_LOONGARCH 

Loongson Loongarch.

EM_KF32 

ChipON KungFu32.

EM_U16_U8CORE 

LAPIS nX-U16/U8.

EM_TACHYUM 

Reserved for Tachyum processor.

EM_56800EF 

NXP 56800EF Digital Signal Controller (DSC)

EM_SBF 

Solana Bytecode Format.

EM_AIENGINE 

AMD/Xilinx AIEngine architecture.

EM_SIMA_MLA 

SiMa MLA.

EM_BANG 

Cambricon BANG.

EM_LOONGGPU 

Loongson LoongGPU.

EM_SW64 

Wuxi Institute of Advanced Technology SW64.

EM_AIECTRLCODE 

AMD/Xilinx AIEngine ctrlcode.

Definition at line 227 of file elf.h.

◆ Elf64_Shn_Indexes

Special section indexes.

See also
https://gabi.xinuos.com/elf/03-sheader.html
Enumerator
SHN_UNDEF 

Undefined section.

SHN_LORESERVE 

Start of reserved indexes.

SHN_LOPROC 

Start of processor-specific indexes.

SHN_HIPROC 

End of processor-specific indexes.

SHN_LOOS 

Start of OS-specific indexes.

SHN_HIOS 

End of OS-specific indexes.

SHN_ABS 

Specifies absolute values for the corresponding reference.

SHN_COMMON 

Symbols defined relative to this section are common symbols.

SHN_XINDEX 

Indicates that the actual index is too large to fit and is stored elsewhere.

SHN_HIRESERVE 

End of reserved indexes.

Definition at line 444 of file elf.h.

◆ Elf64_Section_Types

Section type values for sh_type.

See also
https://gabi.xinuos.com/elf/03-sheader.html
Enumerator
SHT_NULL 

Does not have an associated section.

SHT_PROGBITS 

Contains information defined by the program.

SHT_SYMTAB 

Contains a symbol table, only 1 per file.

SHT_STRTAB 

Contains a string table.

SHT_RELA 

Contains relocation entries with explicit addends.

SHT_HASH 

Contains a symbol hash table, only 1 per file.

SHT_DYNAMIC 

Contains dynamic linking information, only 1 per file.

SHT_NOTE 

Contains unspecified auxiliary information.

SHT_NOBITS 

Acts like SHT_PROGBITS but does not occupy any space in the file.

SHT_REL 

Contains relocation entries without explicit addends.

SHT_SHLIB 

Reserved, has unspecified semantics.

SHT_DYNSYM 

Acts like SHT_SYMTAB but holds a minimal set of dynamic linking symbols, only 1 per file.

SHT_INIT_ARRAY 

Contains an array of pointers to initialization functions.

SHT_FINI_ARRAY 

Contains an array of pointers to termination functions.

SHT_PREINIT_ARRAY 

Contains an array of pointers to pre-initialization functions.

SHT_GROUP 

Contains a section group, can only appear in relocatable files.

SHT_SYMTAB_SHNDX 

Contains extended section indexes for a symbol table, used with SHN_XINDEX

SHT_RELR 

Contains relocation entries for relative relocations without explicit addends.

SHT_LOOS 

Start of OS-specific section types.

SHT_HIOS 

End of OS-specific section types.

SHT_LOPROC 

Start of processor-specific section types.

SHT_HIPROC 

End of processor-specific section types.

SHT_LOUSER 

Start of application-specific section types.

SHT_HIUSER 

End of application-specific section types.

Definition at line 487 of file elf.h.

◆ Elf64_Section_Flags

Section flag values for sh_flags.

See also
https://gabi.xinuos.com/elf/03-sheader.html
Enumerator
SHF_WRITE 

Section should be writable when loaded to memory.

SHF_ALLOC 

Section should be loaded to memory.

SHF_EXECINSTR 

Section should be executable when loaded to memory.

SHF_MERGE 

Section may be merged to eliminate duplication.

SHF_STRINGS 

Section contains null-terminated strings, sh_entsize contains the char size.

SHF_INFO_LINK 

sh_info contains a section header table index

SHF_LINK_ORDER 

Preserve section ordering when linking.

SHF_OS_NONCONFORMING 

Section requires special OS-specific processing.

SHF_GROUP 

Is part of a section group.

SHF_TLS 

Section holds thread-local storage.

SHF_COMPRESSED 

Section holds compressed data.

SHF_MASKOS 

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

SHF_MASKPROC 

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

Definition at line 519 of file elf.h.

◆ Elf64_Symbol_Binding

Symbol binding values stored in st_info.

See also
https://gabi.xinuos.com/elf/05-symtab.html
Enumerator
STB_LOCAL 

Local symbol, not visible outside the object file.

STB_GLOBAL 

Global symbol, visible to all object files being combined.

STB_WEAK 

Weak symbol, like global but with lower precedence.

STB_LOOS 

Start of OS-specific symbol bindings.

STB_HIOS 

End of OS-specific symbol bindings.

STB_LOPROC 

Start of processor-specific symbol bindings.

STB_HIPROC 

End of processor-specific symbol bindings.

Definition at line 564 of file elf.h.

◆ Elf64_Symbol_Type

Symbol type values stored in st_info.

See also
https://gabi.xinuos.com/elf/05-symtab.html
Enumerator
STT_NOTYPE 

Symbol type is unspecified.

STT_OBJECT 

Symbol is a data object.

STT_FUNC 

Symbol is a code object.

STT_SECTION 

Symbol associated with a section.

STT_FILE 

Symbol's name is the name of a source file.

STT_LOOS 

Start of OS-specific symbol types.

STT_HIOS 

End of OS-specific symbol types.

STT_LOPROC 

Start of processor-specific symbol types.

STT_HIPROC 

End of processor-specific symbol types.

Definition at line 587 of file elf.h.

◆ Elf64_Relocation_Types_x86_64

Relocation type values for r_info.

The associated comments describe the calculation performed for each relocation type where:

  • A = The addend used to compute the value of the relocatable field.
  • B = The base address at which the object is loaded into memory
  • G = The offset into the Global Offset Table
  • GOT = The address of the Global Offset Table
  • L = The address of the procedure linkage table entry for the symbol
  • P = The place (section offset or address) of the storage unit being relocated
  • S = value of the symbol in the relocation entry
  • Z = The size of the symbol

Additionally the size of the relocated field is indicated (word8, word16, word32, word64).

Most of these are not used.

See also
https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf table 4.10
Enumerator
R_X86_64_NONE 

none none

R_X86_64_64 

word64 S + A

R_X86_64_PC32 

word32 S + A - P

R_X86_64_GOT32 

word32 G + A

R_X86_64_PLT32 

word32 L + A - P

R_X86_64_COPY 

none none

R_X86_64_GLOB_DAT 

word64 S

R_X86_64_JUMP_SLOT 

word64 S

R_X86_64_RELATIVE 

word64 B + A

R_X86_64_GOTPCREL 

word32 G + GOT + A - P

R_X86_64_32 

word32 S + A

R_X86_64_32S 

word32 S + A

R_X86_64_16 

word16 S + A

R_X86_64_PC16 

word16 S + A - P

R_X86_64_8 

word8 S + A

R_X86_64_PC8 

word8 S + A - P

R_X86_64_DTPMOD64 

word64

R_X86_64_DTPOFF64 

word64

R_X86_64_TPOFF64 

word64

R_X86_64_TLSGD 

word32

R_X86_64_TLSLD 

word32

R_X86_64_DTPOFF32 

word32

R_X86_64_GOTTPOFF 

word32

R_X86_64_TPOFF32 

word32

R_X86_64_PC64 

word64 S + A - P

R_X86_64_GOTOFF64 

word64 S + A - GOT

R_X86_64_GOTPC32 

word32 GOT + A - P

R_X86_64_SIZE32 

word32 Z + A

R_X86_64_SIZE64 

word64 Z + A

R_X86_64_GOTPC32_TLSDESC 

word32

R_X86_64_TLSDESC_CALL 

none

R_X86_64_TLSDESC 

word64×2

R_X86_64_IRELATIVE 

word64 indirect (B + A)

Definition at line 671 of file elf.h.

◆ Elf64_Program_Types

Segment type values for p_type.

See also
https://gabi.xinuos.com/elf/07-pheader.html
Enumerator
PT_NULL 

Unused segment.

PT_LOAD 

Loadable segment.

PT_DYNAMIC 

Dynamic linking information.

PT_INTERP 

Program interpreter path name.

PT_NOTE 

Auxiliary information.

PT_SHLIB 

Reserved, has unspecified semantics.

PT_PHDR 

Location and size of program header table.

PT_TLS 

Thread-local storage template.

PT_LOOS 

Start of OS-specific segment types.

PT_HIOS 

End of OS-specific segment types.

PT_LOPROC 

Start of processor-specific segment types.

PT_HIPROC 

End of processor-specific segment types.

Definition at line 745 of file elf.h.

◆ Elf64_Program_Flags

Segment flag values for p_flags.

See also
https://gabi.xinuos.com/elf/07-pheader.html

A segment is allowed to be readable even if the PF_R flag is not set.

Enumerator
PF_X 

Executable segment.

PF_W 

Writable segment.

PF_R 

Readable segment.

PF_MASKOS 

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

PF_MASKPROC 

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

Definition at line 767 of file elf.h.

Function Documentation

◆ elf64_validate()

uint64_t elf64_validate ( Elf64_File elf,
void *  data,
uint64_t  size 
)

Validate a files content and initalize a ELF64_File structure using it.

The idea behind this function is to verify every aspect of a ELF file such that other functions acting on the ELF64 file do not need to perform any validation.

The reason this does not read from a file is such that it will be generic and usable in user space, in the kernel and the bootloader.

Having to load the entire file might seem wasteful, but its actually very important in order to avoid a situation where we validate the file, another process modifies it, and then we read actual data later on causing a TOCTOU vulnerability.

Parameters
elfPointer to the structure to initialize
dataPointer to the ELF file data in memory, caller retains ownership
sizeSize of the ELF file data in bytes
Returns
On success, 0. On failure, a non-zero error code. Check the implementation. Does not use ERR or errno.

Definition at line 3 of file elf64_validate.c.

Here is the caller graph for this function:

◆ elf64_get_loadable_bounds()

void elf64_get_loadable_bounds ( const Elf64_File elf,
Elf64_Addr minAddr,
Elf64_Addr maxAddr 
)

Get the loadable virtual memory bounds of an ELF file.

Parameters
elfThe ELF file
minAddrOutput pointer to store the minimum loadable virtual address
maxAddrOutput pointer to store the maximum loadable virtual address

Definition at line 3 of file elf64_get_loadable_bounds.c.

Here is the caller graph for this function:

◆ elf64_load_segments()

void elf64_load_segments ( const Elf64_File elf,
Elf64_Addr  base,
Elf64_Off  offset 
)

Load all loadable segments of an ELF file into memory.

Each segment has virtual addresses specified in p_vaddr which is where the segment is intended to be loaded in memory. But we may not want to load it directly to that address, we might have a buffer where we wish to place the segments instead. Either way, we must still place the segments at the correct offsets relative to each other. Leading to the slightly unintuitive parameters of this function.

The final address where a segment is loaded is calculated as base + (p_vaddr - offset), meaning that if you wish to load a file directly to its intended virtual addresses, you would do:

elf64_load_segments(elf, (void*)0x0, 0x0);
void elf64_load_segments(const Elf64_File *elf, Elf64_Addr base, Elf64_Off offset)
Load all loadable segments of an ELF file into memory.

If you wanted to load the contents to a buffer located at buffer which could later be mapped to the intended virtual addresses or if you wanted to load relocatable code, you would do:

Elf64_Addr minAddr, maxAddr;
elf64_get_loadable_bounds(elf, &minAddr, &maxAddr);
elf64_load_segments(elf, buffer, minAddr);
void elf64_get_loadable_bounds(const Elf64_File *elf, Elf64_Addr *minAddr, Elf64_Addr *maxAddr)
Get the loadable virtual memory bounds of an ELF file.
uint64_t Elf64_Addr
ELF64 Unsigned program address.
Definition elf.h:30
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
Note
This function does not allocate memory, it assumes that the caller has already allocated enough memory at base
  • (p_vaddr - offset) for each segment.
Parameters
elfThe ELF file
baseThe base address to load the segments into
offsetThe offset in bytes to subtract from each segment's virtual address when loading

Definition at line 3 of file elf64_load_segments.c.

Here is the caller graph for this function:

◆ elf64_relocate()

uint64_t elf64_relocate ( const Elf64_File elf,
Elf64_Addr  base,
Elf64_Off  offset,
void *(*)(const char *name, void *private)  resolve_symbol,
void *  private 
)

Perform relocations on an ELF file loaded into memory.

This function will process all relocation sections in the ELF file and apply the relocations to the loaded segments in memory, including resolving symbol addresses using the provided callback as necessary.

Relocations are necessary when a ELF file contains references to symbols whose addresses are not known at compile time, for example the ELF file might be a shared library or kernel module.

Check elf64_load_segments() for an explanation of the base and offset parameters.

The resolve_symbol callback is used to resolve symbol names to addresses, this will be utilized for relocations of undefined symbols. Should return NULL if the symbol could not be resolved.

TOOD: Implement more relocation types as needed.

Parameters
elfThe ELF file
baseThe base address where the segments are loaded in memory
offsetThe offset in bytes that was subtracted from each segment's virtual address when loading
resolve_symbolCallback function to resolve symbol names to addresses
privatePrivate data pointer passed to the resolve_symbol callback
Returns
On success, 0. On failure, ERR.

Definition at line 3 of file elf64_relocate.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ elf64_get_string()

const char * elf64_get_string ( const Elf64_File elf,
Elf64_Xword  strTabIndex,
Elf64_Off  offset 
)

Get a string from the string table section at the given offset.

Parameters
elfThe ELF file
strTabIndexThe index of the string table section to use
offsetThe offset in bytes into the string table
Returns
Pointer to the string in the ELF file or NULL if not found

Definition at line 3 of file elf64_get_string.c.

Here is the caller graph for this function:

◆ elf64_get_section_by_name()

Elf64_Shdr * elf64_get_section_by_name ( const Elf64_File elf,
const char *  name 
)

Get a section by its name.

Parameters
elfThe ELF file
nameThe name of the section to find
Returns
Pointer to the section header or NULL if not found

Definition at line 3 of file elf64_get_section_by_name.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ elf64_get_section_name()

const char * elf64_get_section_name ( const Elf64_File elf,
const Elf64_Shdr section 
)

Get the name of a section.

Parameters
elfThe ELF file
sectionThe section to get the name of
Returns
Pointer to the section name string or NULL if not found

Definition at line 3 of file elf64_get_section_name.c.

Here is the call graph for this function:

◆ elf64_get_symbol_by_index()

Elf64_Sym * elf64_get_symbol_by_index ( const Elf64_File elf,
Elf64_Xword  symbolIndex 
)

Get a symbol by its index from the symbol table.

Parameters
elfThe ELF file
symbolIndexThe index of the symbol to get
Returns
Pointer to the symbol or NULL if not found

Definition at line 3 of file elf64_get_symbol_by_index.c.

Here is the caller graph for this function:

◆ elf64_get_symbol_by_name()

Elf64_Sym * elf64_get_symbol_by_name ( const Elf64_File elf,
const char *  name 
)

Get a symbol by its name from the symbol table.

Parameters
elfThe ELF file
nameThe name of the symbol to find
Returns
Pointer to the symbol or NULL if not found

Definition at line 3 of file elf64_get_symbol_by_name.c.

◆ elf64_get_symbol_name()

const char * elf64_get_symbol_name ( const Elf64_File elf,
const Elf64_Sym symbol 
)

Get the name of a symbol.

Parameters
elfThe ELF file
symbolThe symbol to get the name of
Returns
Pointer to the symbol name string or NULL if not found

Definition at line 3 of file elf64_get_symbol_name.c.

Here is the caller graph for this function:

◆ elf64_get_dynamic_symbol_by_index()

Elf64_Sym * elf64_get_dynamic_symbol_by_index ( const Elf64_File elf,
Elf64_Xword  symbolIndex 
)

Get a dynamic symbol by its index from the dynamic symbol table.

Dynamic symbols are, for example, found in .rela.* sections used for dynamic linking.

Parameters
elfThe ELF file
symbolIndexThe index of the dynamic symbol to get
Returns
Pointer to the dynamic symbol or NULL if not found

Definition at line 3 of file elf64_get_dynamic_symbol_by_index.c.

Here is the caller graph for this function:

◆ elf64_get_dynamic_symbol_name()

const char * elf64_get_dynamic_symbol_name ( const Elf64_File elf,
const Elf64_Sym symbol 
)

Get the name of a dynamic symbol.

Parameters
elfThe ELF file
symbolThe dynamic symbol to get the name of
Returns
Pointer to the dynamic symbol name string or NULL if not found

Definition at line 3 of file elf64_get_dynamic_symbol_name.c.

Here is the caller graph for this function: