format::elf
An implementation of the ELF64 file format. Best accompanied with a reading of
the ELF-64 Object Format (Version 1.5).
Index
Types
type at;
type auxv64;
type dt;
type dyn64;
type elf_machine;
type elf_type;
type hashhdr;
type header64;
type ident_abi;
type ident_class;
type ident_data;
type pf;
type phdr64;
type pt;
type rel64;
type rela64;
type section64;
type shf;
type shn;
type sht;
type stb;
type stt;
type sym64;
type ver_def;
type ver_flg;
type ver_ndx;
type verdaux64;
type verdef64;
Constants
const TARGET_ABI: ident_abi;
const TARGET_MACHINE: elf_machine;
const EI_ABIVERSION: uint;
const EI_CLASS: uint;
const EI_DATA: uint;
const EI_MAG0: uint;
const EI_MAG1: uint;
const EI_MAG2: uint;
const EI_MAG3: uint;
const EI_NIDENT: uint;
const EI_OSABI: uint;
const EI_PAD: uint;
const EI_VERSION: uint;
const EV_CURRENT: u32;
const MAGIC: str;
Functions
fn r64_info(u64, u64) u64;
fn r64_sym(u64) u64;
fn r64_type(u64) u64;
fn st_bind(u8) stb;
fn st_info(stb, stt) u8;
fn st_type(u8) stt;
Types
type at
type at = enum u64 {
NULL = 0,
IGNORE = 1,
EXECFD = 2,
PHDR = 3,
PHENT = 4,
PHNUM = 5,
PAGESZ = 6,
BASE = 7,
FLAGS = 8,
ENTRY = 9,
NOTELF = 10,
UID = 11,
EUID = 12,
GID = 13,
EGID = 14,
CLKTCK = 17,
PLATFORM = 15,
HWCAP = 16,
FPUCW = 18,
DCACHEBSIZE = 19,
ICACHEBSIZE = 20,
UCACHEBSIZE = 21,
IGNOREPPC = 22,
SECURE = 23,
BASE_PLATFORM = 24,
RANDOM = 25,
HWCAP2 = 26,
EXECFN = 31,
SYSINFO = 32,
SYSINFO_EHDR = 33,
L1I_CACHESHAPE = 34,
L1D_CACHESHAPE = 35,
L2_CACHESHAPE = 36,
L3_CACHESHAPE = 37,
L1I_CACHESIZE = 40,
L1I_CACHEGEOMETRY = 41,
L1D_CACHESIZE = 42,
L1D_CACHEGEOMETRY = 43,
L2_CACHESIZE = 44,
L2_CACHEGEOMETRY = 45,
L3_CACHESIZE = 46,
L3_CACHEGEOMETRY = 47,
MINSIGSTKSZ = 51,
};
Legal auxiliary vector entry types
type auxv64
type auxv64 = struct {
a_type: at,
union {
a_val: u64,
a_ptr: *void,
a_fnc: *fn() void,
},
};
Auxiliary vector
type dt
type dt = enum i64 {
NULL = 0,
NEEDED = 1,
PLTRELSZ = 2,
PLTGOT = 3,
HASH = 4,
STRTAB = 5,
SYMTAB = 6,
RELA = 7,
RELASZ = 8,
RELAENT = 9,
STRSZ = 10,
SYMENT = 11,
INIT = 12,
FINI = 13,
SONAME = 14,
RPATH = 15,
SYMBOLIC = 16,
REL = 17,
RELSZ = 18,
RELENT = 19,
PLTREL = 20,
DEBUG = 21,
TEXTREL = 22,
JMPREL = 23,
BIND_NOW = 24,
INIT_ARRAY = 25,
FINI_ARRAY = 26,
INIT_ARRAYSZ = 27,
FINI_ARRAYSZ = 28,
LOOS = 1610612736,
VERSYM = 1879048176,
VERDEF = 1879048188,
VERDEFNUM = 1879048189,
VERNEED = 1879048190,
VERNEEDNUM = 1879048191,
HIOS = 1879048191,
LOPROC = 1879048192,
HIPROC = 2147483647,
};
Dynamic table entry type
type dyn64
type dyn64 = struct {
d_tag: dt,
union {
d_val: u64,
d_ptr: u64,
},
};
Dynamic table entry
type elf_machine
type elf_machine = enum u16 {
NONE = 0,
M32 = 1,
SPARC = 2,
I386 = 3,
M68K = 4,
M88K = 5,
M860 = 7,
MIPS = 8,
S370 = 9,
MIPS_RS3_LE = 10,
PARISC = 15,
VPP500 = 17,
SPARC32PLUS = 18,
I960 = 19,
PPC = 20,
PPC64 = 21,
S390 = 22,
V800 = 36,
FR20 = 37,
RH32 = 38,
RCE = 39,
ARM = 40,
SH = 42,
SPARCV9 = 43,
TRICORE = 44,
ARC = 45,
H8_300 = 46,
H8_300H = 47,
H8S = 48,
H8_500 = 49,
IA_64 = 50,
MIPS_X = 51,
COLDFIRE = 52,
M68HC12 = 53,
MMA = 54,
PCP = 55,
NCPU = 56,
NDR1 = 57,
STARCORE = 58,
ME16 = 59,
ST100 = 60,
TINYJ = 61,
X86_64 = 62,
PDSP = 63,
PDP10 = 64,
PDP11 = 65,
FX66 = 66,
ST9PLUS = 67,
ST7 = 68,
M68HC16 = 69,
M68HC11 = 70,
M68HC08 = 71,
M68HC05 = 72,
SVX = 73,
ST19 = 74,
VAX = 75,
CRIS = 76,
JAVELIN = 77,
FIREPATH = 78,
ZSP = 79,
MMIX = 80,
HUANY = 81,
PRISM = 82,
AVR = 83,
FR30 = 84,
D10V = 85,
D30V = 86,
V850 = 87,
M32R = 88,
MN10300 = 89,
MN10200 = 90,
PJ = 91,
OPENRISC = 92,
ARC_COMPACT = 93,
XTENSA = 94,
VIDEOCORE = 95,
TMM_GPP = 96,
NS32K = 97,
TPC = 98,
SNP1K = 99,
ST200 = 100,
IP2K = 101,
MAX = 102,
CR = 103,
F2MC16 = 104,
MSP430 = 105,
BLACKFIN = 106,
SE_C33 = 107,
SEP = 108,
ARCA = 109,
UNICORE = 110,
EXCESS = 111,
DXP = 112,
ALTERA_NIOS2 = 113,
CRX = 114,
XGATE = 115,
C166 = 116,
M16C = 117,
DSPIC30F = 118,
CE = 119,
M32C = 120,
TSK3000 = 131,
RS08 = 132,
SHARC = 133,
ECOG2 = 134,
SCORE7 = 135,
DSP24 = 136,
VIDEOCORE3 = 137,
LATTICEMICO32 = 138,
SE_C17 = 139,
TI_C6000 = 140,
TI_C2000 = 141,
TI_C5500 = 142,
TI_ARP32 = 143,
TI_PRU = 144,
MMDSP_PLUS = 160,
CYPRESS_M8C = 161,
R32C = 162,
TRIMEDIA = 163,
QDSP6 = 164,
I8051 = 165,
STXP7X = 166,
NDS32 = 167,
ECOG1 = 168,
ECOG1X = 168,
MAXQ30 = 169,
XIMO16 = 170,
MANIK = 171,
CRAYNV2 = 172,
RX = 173,
METAG = 174,
MCST_ELBRUS = 175,
ECOG16 = 176,
CR16 = 177,
ETPU = 178,
SLE9X = 179,
L10M = 180,
K10M = 181,
AARCH64 = 183,
AVR32 = 185,
STM8 = 186,
TILE64 = 187,
TILEPRO = 188,
MICROBLAZE = 189,
CUDA = 190,
TILEGX = 191,
CLOUDSHIELD = 192,
COREA_1ST = 193,
COREA_2ND = 194,
ARC_COMPACT2 = 195,
OPEN8 = 196,
RL78 = 197,
VIDEOCORE5 = 198,
R78KOR = 199,
F56800EX = 200,
BA1 = 201,
BA2 = 202,
XCORE = 203,
MCHP_PIC = 204,
INTEL205 = 205,
INTEL206 = 206,
INTEL207 = 207,
INTEL208 = 208,
INTEL209 = 209,
KM32 = 210,
KMX32 = 211,
KMX16 = 212,
KMX8 = 213,
KVARC = 214,
CDP = 215,
COGE = 216,
COOL = 217,
NORC = 218,
CSR_KALIMBA = 219,
Z80 = 220,
VISIUM = 221,
FT32 = 222,
MOXIE = 223,
AMDGPU = 224,
RISCV = 243,
LANAI = 244,
BPF = 247,
I486 = 6,
MIPS_RS4_BE = 10,
ALPHA_STD = 41,
ALPHA = 36902,
};
Machine architecture
type elf_type
type elf_type = enum u16 {
NONE = 0,
REL = 1,
EXEC = 2,
DYN = 3,
CORE = 4,
LOOS = 65024,
HIOS = 65279,
LOPROC = 65280,
HIPROC = 65535,
};
ELF file type
type hashhdr
type hashhdr = struct {
nbucket: u32,
nchain: u32,
};
DT_HASH section header
type header64 = struct {
e_ident: [EI_NIDENT]u8,
e_type: elf_type,
e_machine: elf_machine,
e_version: u32,
e_entry: u64,
e_phoff: u64,
e_shoff: u64,
e_flags: u32,
e_ehsize: u16,
e_phentsize: u16,
e_phnum: u16,
e_shentsize: u16,
e_shnum: u16,
e_shstrndx: u16,
};
ELF header for ELF64
type ident_abi
type ident_abi = enum u8 {
SYSV = 0,
HPUX = 1,
STANDALONE = 255,
};
Application binary interface
type ident_class
type ident_class = enum u8 {
ELF32 = 1,
ELF64 = 2,
};
ELF file class
type ident_data
type ident_data = enum u8 {
LSB = 1,
MSB = 2,
};
Byte ordering
type pf
type pf = enum u32 {
NONE = 0,
X = 1,
W = 2,
R = 4,
MASKOS = 16711680,
MASKPROC = 4278190080,
};
Segment attributes
type phdr64
type phdr64 = struct {
p_type: pt,
p_flags: u32,
p_offset: u64,
p_vaddr: u64,
p_paddr: u64,
p_filesz: u64,
p_memsz: u64,
p_align: u64,
};
Program header table entry (segment)
type pt
type pt = enum u32 {
NULL = 0,
LOAD = 1,
DYNAMIC = 2,
INTERP = 3,
NOTE = 4,
SHLIB = 5,
PHDR = 6,
LOOS = 1610612736,
HIOS = 1879048191,
LOPROC = 1879048192,
HIPROC = 2147483647,
};
Segment types
type rel64
type rel64 = struct {
r_offset: u64,
r_info: u64,
};
Relocation entry
type rela64
type rela64 = struct {
r_offset: u64,
r_info: u64,
r_addend: i64,
};
Relocation entry with explicit addend
type section64
type section64 = struct {
sh_name: u32,
sh_type: u32,
sh_flags: u64,
sh_addr: u64,
sh_offset: u64,
sh_size: u64,
sh_link: u32,
sh_info: u32,
sh_addralign: u64,
sh_entsize: u64,
};
Section header for ELF64
type shf
type shf = enum u32 {
NONE = 0,
WRITE = 1,
ALLOC = 2,
EXECINSTR = 4,
MASKOS = 251658240,
MASKPROC = 4026531840,
};
Section flags
type shn
type shn = enum u16 {
UNDEF = 0,
LOPROC = 65280,
HIPROC = 65311,
LOOS = 65312,
HIOS = 65343,
ABS = 65521,
COMMON = 65522,
};
Special section indicies
type sht
type sht = enum u32 {
NULL = 0,
PROGBITS = 1,
SYMTAB = 2,
STRTAB = 3,
RELA = 4,
HASH = 5,
DYNAMIC = 6,
NOTE = 7,
NOBITS = 8,
REL = 9,
SHLIB = 10,
DYNSYM = 11,
LOOS = 1610612736,
HIOS = 1879048191,
LOPROC = 1879048192,
HIPROC = 2147483647,
};
Section type
type stb
type stb = enum u8 {
LOCAL = 0,
GLOBAL = 1,
WEAK = 2,
LOOS = 10,
HIOS = 12,
LOPROC = 13,
HIPROC = 15,
};
Symbol bindings
type stt
type stt = enum u8 {
NOTYPE = 0,
OBJECT = 1,
FUNC = 2,
SECTION = 3,
FILE = 4,
COMMON = 5,
LOOS = 10,
HIOS = 12,
LOPROC = 13,
HIPROC = 15,
};
Symbol types
type sym64
type sym64 = struct {
st_name: u32,
st_info: u8,
st_other: u8,
st_shndx: u16,
st_value: u64,
st_size: u64,
};
Symbol table entry
type ver_def
type ver_def = enum u16 {
NONE = 0,
CURRENT = 1,
NUM = 2,
};
Version revision values
type ver_flg
type ver_flg = enum u16 {
BASE = 1,
WEAK = 2,
};
Version information flags
type ver_ndx
type ver_ndx = enum u16 {
LOCAL = 0,
GLOBAL = 1,
LORESERVE = 65280,
ELIMINATE = 65281,
};
Versym index values
type verdaux64
type verdaux64 = struct {
vda_name: u32,
vda_next: u32,
};
Auxiliary version information
type verdef64
type verdef64 = struct {
vd_version: u16,
vd_flags: u16,
vd_ndx: u16,
vd_cnt: u16,
vd_hash: u32,
vd_aux: u32,
vd_next: u32,
};
Version definition section
Constants
def TARGET_ABI
def TARGET_ABI: ident_abi;
The ABI of the target.
def TARGET_MACHINE
def TARGET_MACHINE: elf_machine;
The machine (architecture) of the target.
def EI_ABIVERSION
Show undocumented member
def EI_ABIVERSION: uint;
def EI_CLASS
Show undocumented member
def EI_CLASS: uint;
def EI_DATA
Show undocumented member
def EI_DATA: uint;
def EI_MAG0
Show undocumented member
def EI_MAG0: uint;
def EI_MAG1
Show undocumented member
def EI_MAG1: uint;
def EI_MAG2
Show undocumented member
def EI_MAG2: uint;
def EI_MAG3
Show undocumented member
def EI_MAG3: uint;
def EI_NIDENT
Show undocumented member
def EI_NIDENT: uint;
def EI_OSABI
Show undocumented member
def EI_OSABI: uint;
def EI_PAD
Show undocumented member
def EI_PAD: uint;
def EI_VERSION
Show undocumented member
def EI_VERSION: uint;
def EV_CURRENT
Show undocumented member
def EV_CURRENT: u32;
def MAGIC
Show undocumented member
def MAGIC: str;
Functions
fn r64_info
fn r64_info(sym: u64, stype: u64) u64;
Converts symbol table index and a relocation type into [rel64.r_info].
Equivalent to the ELF64_R_INFO macro.
fn r64_sym
fn r64_sym(info: u64) u64;
Obtains the symbol table index part of [rel64.r_info].
Equivalent to the ELF64_R_SYM macro.
fn r64_type
fn r64_type(info: u64) u64;
Obtains the relocation type part of [rel64.r_info].
Equivalent to the ELF64_R_TYPE macro.
fn st_bind
fn st_bind(i: u8) stb;
Obtains the binding part of [sym64.st_info].
Equivalent to the ELF64_ST_BIND macro.
fn st_info
fn st_info(b: stb, t: stt) u8;
Converts symbol bindings and type into [sym64.st_info].
Equivalent to the ELF64_ST_INFO macro.
fn st_type
fn st_type(i: u8) stt;
Obtains the type part of [sym64.st_info].
Equivalent to the ELF64_ST_TYPE macro.