zig/lib/std / elf.zig

const std = @import("std.zig");
const math = std.math;
const mem = std.mem;
const assert = std.debug.assert;
const native_endian = @import("builtin").target.cpu.arch.endian();

AT_NULL

pub const AT_NULL = 0;

AT_IGNORE

pub const AT_IGNORE = 1;

AT_EXECFD

pub const AT_EXECFD = 2;

AT_PHDR

pub const AT_PHDR = 3;

AT_PHENT

pub const AT_PHENT = 4;

AT_PHNUM

pub const AT_PHNUM = 5;

AT_PAGESZ

pub const AT_PAGESZ = 6;

AT_BASE

pub const AT_BASE = 7;

AT_FLAGS

pub const AT_FLAGS = 8;

AT_ENTRY

pub const AT_ENTRY = 9;

AT_NOTELF

pub const AT_NOTELF = 10;

AT_UID

pub const AT_UID = 11;

AT_EUID

pub const AT_EUID = 12;

AT_GID

pub const AT_GID = 13;

AT_EGID

pub const AT_EGID = 14;

AT_CLKTCK

pub const AT_CLKTCK = 17;

AT_PLATFORM

pub const AT_PLATFORM = 15;

AT_HWCAP

pub const AT_HWCAP = 16;

AT_FPUCW

pub const AT_FPUCW = 18;

AT_DCACHEBSIZE

pub const AT_DCACHEBSIZE = 19;

AT_ICACHEBSIZE

pub const AT_ICACHEBSIZE = 20;

AT_UCACHEBSIZE

pub const AT_UCACHEBSIZE = 21;

AT_IGNOREPPC

pub const AT_IGNOREPPC = 22;

AT_SECURE

pub const AT_SECURE = 23;

AT_BASE_PLATFORM

pub const AT_BASE_PLATFORM = 24;

AT_RANDOM

pub const AT_RANDOM = 25;

AT_HWCAP2

pub const AT_HWCAP2 = 26;

AT_EXECFN

pub const AT_EXECFN = 31;

AT_SYSINFO

pub const AT_SYSINFO = 32;

AT_SYSINFO_EHDR

pub const AT_SYSINFO_EHDR = 33;

AT_L1I_CACHESHAPE

pub const AT_L1I_CACHESHAPE = 34;

AT_L1D_CACHESHAPE

pub const AT_L1D_CACHESHAPE = 35;

AT_L2_CACHESHAPE

pub const AT_L2_CACHESHAPE = 36;

AT_L3_CACHESHAPE

pub const AT_L3_CACHESHAPE = 37;

AT_L1I_CACHESIZE

pub const AT_L1I_CACHESIZE = 40;

AT_L1I_CACHEGEOMETRY

pub const AT_L1I_CACHEGEOMETRY = 41;

AT_L1D_CACHESIZE

pub const AT_L1D_CACHESIZE = 42;

AT_L1D_CACHEGEOMETRY

pub const AT_L1D_CACHEGEOMETRY = 43;

AT_L2_CACHESIZE

pub const AT_L2_CACHESIZE = 44;

AT_L2_CACHEGEOMETRY

pub const AT_L2_CACHEGEOMETRY = 45;

AT_L3_CACHESIZE

pub const AT_L3_CACHESIZE = 46;

AT_L3_CACHEGEOMETRY

pub const AT_L3_CACHEGEOMETRY = 47;

DT_NULL

pub const DT_NULL = 0;

DT_NEEDED

pub const DT_NEEDED = 1;

DT_PLTRELSZ

pub const DT_PLTRELSZ = 2;

DT_PLTGOT

pub const DT_PLTGOT = 3;

DT_HASH

pub const DT_HASH = 4;

DT_STRTAB

pub const DT_STRTAB = 5;

DT_SYMTAB

pub const DT_SYMTAB = 6;

DT_RELA

pub const DT_RELA = 7;

DT_RELASZ

pub const DT_RELASZ = 8;

DT_RELAENT

pub const DT_RELAENT = 9;

DT_STRSZ

pub const DT_STRSZ = 10;

DT_SYMENT

pub const DT_SYMENT = 11;

DT_INIT

pub const DT_INIT = 12;

DT_FINI

pub const DT_FINI = 13;

DT_SONAME

pub const DT_SONAME = 14;

DT_RPATH

pub const DT_RPATH = 15;

DT_SYMBOLIC

pub const DT_SYMBOLIC = 16;

DT_REL

pub const DT_REL = 17;

DT_RELSZ

pub const DT_RELSZ = 18;

DT_RELENT

pub const DT_RELENT = 19;

DT_PLTREL

pub const DT_PLTREL = 20;

DT_DEBUG

pub const DT_DEBUG = 21;

DT_TEXTREL

pub const DT_TEXTREL = 22;

DT_JMPREL

pub const DT_JMPREL = 23;

DT_BIND_NOW

pub const DT_BIND_NOW = 24;

DT_INIT_ARRAY

pub const DT_INIT_ARRAY = 25;

DT_FINI_ARRAY

pub const DT_FINI_ARRAY = 26;

DT_INIT_ARRAYSZ

pub const DT_INIT_ARRAYSZ = 27;

DT_FINI_ARRAYSZ

pub const DT_FINI_ARRAYSZ = 28;

DT_RUNPATH

pub const DT_RUNPATH = 29;

DT_FLAGS

pub const DT_FLAGS = 30;

DT_ENCODING

pub const DT_ENCODING = 32;

DT_PREINIT_ARRAY

pub const DT_PREINIT_ARRAY = 32;

DT_PREINIT_ARRAYSZ

pub const DT_PREINIT_ARRAYSZ = 33;

DT_SYMTAB_SHNDX

pub const DT_SYMTAB_SHNDX = 34;

DT_NUM

pub const DT_NUM = 35;

DT_LOOS

pub const DT_LOOS = 0x6000000d;

DT_HIOS

pub const DT_HIOS = 0x6ffff000;

DT_LOPROC

pub const DT_LOPROC = 0x70000000;

DT_HIPROC

pub const DT_HIPROC = 0x7fffffff;

DT_PROCNUM

pub const DT_PROCNUM = DT_MIPS_NUM;

DT_VALRNGLO

pub const DT_VALRNGLO = 0x6ffffd00;

DT_GNU_PRELINKED

pub const DT_GNU_PRELINKED = 0x6ffffdf5;

DT_GNU_CONFLICTSZ

pub const DT_GNU_CONFLICTSZ = 0x6ffffdf6;

DT_GNU_LIBLISTSZ

pub const DT_GNU_LIBLISTSZ = 0x6ffffdf7;

DT_CHECKSUM

pub const DT_CHECKSUM = 0x6ffffdf8;

DT_PLTPADSZ

pub const DT_PLTPADSZ = 0x6ffffdf9;

DT_MOVEENT

pub const DT_MOVEENT = 0x6ffffdfa;

DT_MOVESZ

pub const DT_MOVESZ = 0x6ffffdfb;

DT_FEATURE_1

pub const DT_FEATURE_1 = 0x6ffffdfc;

DT_POSFLAG_1

pub const DT_POSFLAG_1 = 0x6ffffdfd;

DT_SYMINSZ

pub const DT_SYMINSZ = 0x6ffffdfe;

DT_SYMINENT

pub const DT_SYMINENT = 0x6ffffdff;

DT_VALRNGHI

pub const DT_VALRNGHI = 0x6ffffdff;

DT_VALNUM

pub const DT_VALNUM = 12;

DT_ADDRRNGLO

pub const DT_ADDRRNGLO = 0x6ffffe00;

DT_GNU_HASH

pub const DT_GNU_HASH = 0x6ffffef5;

DT_TLSDESC_PLT

pub const DT_TLSDESC_PLT = 0x6ffffef6;

DT_TLSDESC_GOT

pub const DT_TLSDESC_GOT = 0x6ffffef7;

DT_GNU_CONFLICT

pub const DT_GNU_CONFLICT = 0x6ffffef8;

DT_GNU_LIBLIST

pub const DT_GNU_LIBLIST = 0x6ffffef9;

DT_CONFIG

pub const DT_CONFIG = 0x6ffffefa;

DT_DEPAUDIT

pub const DT_DEPAUDIT = 0x6ffffefb;

DT_AUDIT

pub const DT_AUDIT = 0x6ffffefc;

DT_PLTPAD

pub const DT_PLTPAD = 0x6ffffefd;

DT_MOVETAB

pub const DT_MOVETAB = 0x6ffffefe;

DT_SYMINFO

pub const DT_SYMINFO = 0x6ffffeff;

DT_ADDRRNGHI

pub const DT_ADDRRNGHI = 0x6ffffeff;

DT_ADDRNUM

pub const DT_ADDRNUM = 11;

DT_VERSYM

pub const DT_VERSYM = 0x6ffffff0;

DT_RELACOUNT

pub const DT_RELACOUNT = 0x6ffffff9;

DT_RELCOUNT

pub const DT_RELCOUNT = 0x6ffffffa;

DT_FLAGS_1

pub const DT_FLAGS_1 = 0x6ffffffb;

DT_VERDEF

pub const DT_VERDEF = 0x6ffffffc;

DT_VERDEFNUM

pub const DT_VERDEFNUM = 0x6ffffffd;

DT_VERNEED

pub const DT_VERNEED = 0x6ffffffe;

DT_VERNEEDNUM

pub const DT_VERNEEDNUM = 0x6fffffff;

DT_VERSIONTAGNUM

pub const DT_VERSIONTAGNUM = 16;

DT_AUXILIARY

pub const DT_AUXILIARY = 0x7ffffffd;

DT_FILTER

pub const DT_FILTER = 0x7fffffff;

DT_EXTRANUM

pub const DT_EXTRANUM = 3;

DT_SPARC_REGISTER

pub const DT_SPARC_REGISTER = 0x70000001;

DT_SPARC_NUM

pub const DT_SPARC_NUM = 2;

DT_MIPS_RLD_VERSION

pub const DT_MIPS_RLD_VERSION = 0x70000001;

DT_MIPS_TIME_STAMP

pub const DT_MIPS_TIME_STAMP = 0x70000002;

DT_MIPS_ICHECKSUM

pub const DT_MIPS_ICHECKSUM = 0x70000003;

DT_MIPS_IVERSION

pub const DT_MIPS_IVERSION = 0x70000004;

DT_MIPS_FLAGS

pub const DT_MIPS_FLAGS = 0x70000005;

DT_MIPS_BASE_ADDRESS

pub const DT_MIPS_BASE_ADDRESS = 0x70000006;

DT_MIPS_MSYM

pub const DT_MIPS_MSYM = 0x70000007;

DT_MIPS_CONFLICT

pub const DT_MIPS_CONFLICT = 0x70000008;

DT_MIPS_LIBLIST

pub const DT_MIPS_LIBLIST = 0x70000009;

DT_MIPS_LOCAL_GOTNO

pub const DT_MIPS_LOCAL_GOTNO = 0x7000000a;

DT_MIPS_CONFLICTNO

pub const DT_MIPS_CONFLICTNO = 0x7000000b;

DT_MIPS_LIBLISTNO

pub const DT_MIPS_LIBLISTNO = 0x70000010;

DT_MIPS_SYMTABNO

pub const DT_MIPS_SYMTABNO = 0x70000011;

DT_MIPS_UNREFEXTNO

pub const DT_MIPS_UNREFEXTNO = 0x70000012;

DT_MIPS_GOTSYM

pub const DT_MIPS_GOTSYM = 0x70000013;

DT_MIPS_HIPAGENO

pub const DT_MIPS_HIPAGENO = 0x70000014;

DT_MIPS_RLD_MAP

pub const DT_MIPS_RLD_MAP = 0x70000016;

DT_MIPS_DELTA_CLASS

pub const DT_MIPS_DELTA_CLASS = 0x70000017;

DT_MIPS_DELTA_CLASS_NO

pub const DT_MIPS_DELTA_CLASS_NO = 0x70000018;

DT_MIPS_DELTA_INSTANCE

pub const DT_MIPS_DELTA_INSTANCE = 0x70000019;

DT_MIPS_DELTA_INSTANCE_NO

pub const DT_MIPS_DELTA_INSTANCE_NO = 0x7000001a;

DT_MIPS_DELTA_RELOC

pub const DT_MIPS_DELTA_RELOC = 0x7000001b;

DT_MIPS_DELTA_RELOC_NO

pub const DT_MIPS_DELTA_RELOC_NO = 0x7000001c;

DT_MIPS_DELTA_SYM

pub const DT_MIPS_DELTA_SYM = 0x7000001d;

DT_MIPS_DELTA_SYM_NO

pub const DT_MIPS_DELTA_SYM_NO = 0x7000001e;

DT_MIPS_DELTA_CLASSSYM

pub const DT_MIPS_DELTA_CLASSSYM = 0x70000020;

DT_MIPS_DELTA_CLASSSYM_NO

pub const DT_MIPS_DELTA_CLASSSYM_NO = 0x70000021;

DT_MIPS_CXX_FLAGS

pub const DT_MIPS_CXX_FLAGS = 0x70000022;

DT_MIPS_PIXIE_INIT

pub const DT_MIPS_PIXIE_INIT = 0x70000023;

DT_MIPS_SYMBOL_LIB

pub const DT_MIPS_SYMBOL_LIB = 0x70000024;

DT_MIPS_LOCALPAGE_GOTIDX

pub const DT_MIPS_LOCALPAGE_GOTIDX = 0x70000025;

DT_MIPS_LOCAL_GOTIDX

pub const DT_MIPS_LOCAL_GOTIDX = 0x70000026;

DT_MIPS_HIDDEN_GOTIDX

pub const DT_MIPS_HIDDEN_GOTIDX = 0x70000027;

DT_MIPS_PROTECTED_GOTIDX

pub const DT_MIPS_PROTECTED_GOTIDX = 0x70000028;

DT_MIPS_OPTIONS

pub const DT_MIPS_OPTIONS = 0x70000029;

DT_MIPS_INTERFACE

pub const DT_MIPS_INTERFACE = 0x7000002a;

DT_MIPS_DYNSTR_ALIGN

pub const DT_MIPS_DYNSTR_ALIGN = 0x7000002b;

DT_MIPS_INTERFACE_SIZE

pub const DT_MIPS_INTERFACE_SIZE = 0x7000002c;

DT_MIPS_RLD_TEXT_RESOLVE_ADDR

pub const DT_MIPS_RLD_TEXT_RESOLVE_ADDR = 0x7000002d;

DT_MIPS_PERF_SUFFIX

pub const DT_MIPS_PERF_SUFFIX = 0x7000002e;

DT_MIPS_COMPACT_SIZE

pub const DT_MIPS_COMPACT_SIZE = 0x7000002f;

DT_MIPS_GP_VALUE

pub const DT_MIPS_GP_VALUE = 0x70000030;

DT_MIPS_AUX_DYNAMIC

pub const DT_MIPS_AUX_DYNAMIC = 0x70000031;

DT_MIPS_PLTGOT

pub const DT_MIPS_PLTGOT = 0x70000032;

DT_MIPS_RWPLT

pub const DT_MIPS_RWPLT = 0x70000034;

DT_MIPS_RLD_MAP_REL

pub const DT_MIPS_RLD_MAP_REL = 0x70000035;

DT_MIPS_NUM

pub const DT_MIPS_NUM = 0x36;

DT_ALPHA_PLTRO

pub const DT_ALPHA_PLTRO = (DT_LOPROC + 0);

DT_ALPHA_NUM

pub const DT_ALPHA_NUM = 1;

DT_PPC_GOT

pub const DT_PPC_GOT = (DT_LOPROC + 0);

DT_PPC_OPT

pub const DT_PPC_OPT = (DT_LOPROC + 1);

DT_PPC_NUM

pub const DT_PPC_NUM = 2;

DT_PPC64_GLINK

pub const DT_PPC64_GLINK = (DT_LOPROC + 0);

DT_PPC64_OPD

pub const DT_PPC64_OPD = (DT_LOPROC + 1);

DT_PPC64_OPDSZ

pub const DT_PPC64_OPDSZ = (DT_LOPROC + 2);

DT_PPC64_OPT

pub const DT_PPC64_OPT = (DT_LOPROC + 3);

DT_PPC64_NUM

pub const DT_PPC64_NUM = 4;

DT_IA_64_PLT_RESERVE

pub const DT_IA_64_PLT_RESERVE = (DT_LOPROC + 0);

DT_IA_64_NUM

pub const DT_IA_64_NUM = 1;

DT_NIOS2_GP

pub const DT_NIOS2_GP = 0x70000002;

DF_ORIGIN

pub const DF_ORIGIN = 0x00000001;

DF_SYMBOLIC

pub const DF_SYMBOLIC = 0x00000002;

DF_TEXTREL

pub const DF_TEXTREL = 0x00000004;

DF_BIND_NOW

pub const DF_BIND_NOW = 0x00000008;

DF_STATIC_TLS

pub const DF_STATIC_TLS = 0x00000010;

DF_1_NOW

pub const DF_1_NOW = 0x00000001;

DF_1_GLOBAL

pub const DF_1_GLOBAL = 0x00000002;

DF_1_GROUP

pub const DF_1_GROUP = 0x00000004;

DF_1_NODELETE

pub const DF_1_NODELETE = 0x00000008;

DF_1_LOADFLTR

pub const DF_1_LOADFLTR = 0x00000010;

DF_1_INITFIRST

pub const DF_1_INITFIRST = 0x00000020;

DF_1_NOOPEN

pub const DF_1_NOOPEN = 0x00000040;

DF_1_ORIGIN

pub const DF_1_ORIGIN = 0x00000080;

DF_1_DIRECT

pub const DF_1_DIRECT = 0x00000100;

DF_1_TRANS

pub const DF_1_TRANS = 0x00000200;

DF_1_INTERPOSE

pub const DF_1_INTERPOSE = 0x00000400;

DF_1_NODEFLIB

pub const DF_1_NODEFLIB = 0x00000800;

DF_1_NODUMP

pub const DF_1_NODUMP = 0x00001000;

DF_1_CONFALT

pub const DF_1_CONFALT = 0x00002000;

DF_1_ENDFILTEE

pub const DF_1_ENDFILTEE = 0x00004000;

DF_1_DISPRELDNE

pub const DF_1_DISPRELDNE = 0x00008000;

DF_1_DISPRELPND

pub const DF_1_DISPRELPND = 0x00010000;

DF_1_NODIRECT

pub const DF_1_NODIRECT = 0x00020000;

DF_1_IGNMULDEF

pub const DF_1_IGNMULDEF = 0x00040000;

DF_1_NOKSYMS

pub const DF_1_NOKSYMS = 0x00080000;

DF_1_NOHDR

pub const DF_1_NOHDR = 0x00100000;

DF_1_EDITED

pub const DF_1_EDITED = 0x00200000;

DF_1_NORELOC

pub const DF_1_NORELOC = 0x00400000;

DF_1_SYMINTPOSE

pub const DF_1_SYMINTPOSE = 0x00800000;

DF_1_GLOBAUDIT

pub const DF_1_GLOBAUDIT = 0x01000000;

DF_1_SINGLETON

pub const DF_1_SINGLETON = 0x02000000;

DF_1_STUB

pub const DF_1_STUB = 0x04000000;

DF_1_PIE

pub const DF_1_PIE = 0x08000000;

VERSYM_HIDDEN

pub const VERSYM_HIDDEN = 0x8000;

VERSYM_VERSION

pub const VERSYM_VERSION = 0x7fff;

VER_NDX_LOCAL

Symbol is local

pub const VER_NDX_LOCAL = 0;

VER_NDX_GLOBAL

Symbol is global

pub const VER_NDX_GLOBAL = 1;

VER_NDX_LORESERVE

Beginning of reserved entries

pub const VER_NDX_LORESERVE = 0xff00;

VER_NDX_ELIMINATE

Symbol is to be eliminated

pub const VER_NDX_ELIMINATE = 0xff01;

VER_FLG_BASE

Version definition of the file itself

pub const VER_FLG_BASE = 1;

VER_FLG_WEAK

Weak version identifier

pub const VER_FLG_WEAK = 2;

PT_NULL

Program header table entry unused

pub const PT_NULL = 0;

PT_LOAD

Loadable program segment

pub const PT_LOAD = 1;

PT_DYNAMIC

Dynamic linking information

pub const PT_DYNAMIC = 2;

PT_INTERP

Program interpreter

pub const PT_INTERP = 3;

PT_NOTE

Auxiliary information

pub const PT_NOTE = 4;

PT_SHLIB

Reserved

pub const PT_SHLIB = 5;

PT_PHDR

Entry for header table itself

pub const PT_PHDR = 6;

PT_TLS

Thread-local storage segment

pub const PT_TLS = 7;

PT_NUM

Number of defined types

pub const PT_NUM = 8;

PT_LOOS

Start of OS-specific

pub const PT_LOOS = 0x60000000;

PT_GNU_EH_FRAME

GCC .eh_frame_hdr segment

pub const PT_GNU_EH_FRAME = 0x6474e550;

PT_GNU_STACK

Indicates stack executability

pub const PT_GNU_STACK = 0x6474e551;

PT_GNU_RELRO

Read-only after relocation

pub const PT_GNU_RELRO = 0x6474e552;

PT_LOSUNW

pub const PT_LOSUNW = 0x6ffffffa;

PT_SUNWBSS

Sun specific segment

pub const PT_SUNWBSS = 0x6ffffffa;

PT_SUNWSTACK

Stack segment

pub const PT_SUNWSTACK = 0x6ffffffb;

PT_HISUNW

pub const PT_HISUNW = 0x6fffffff;

PT_HIOS

End of OS-specific

pub const PT_HIOS = 0x6fffffff;

PT_LOPROC

Start of processor-specific

pub const PT_LOPROC = 0x70000000;

PT_HIPROC

End of processor-specific

pub const PT_HIPROC = 0x7fffffff;

SHT_NULL

Section header table entry unused

pub const SHT_NULL = 0;

SHT_PROGBITS

Program data

pub const SHT_PROGBITS = 1;

SHT_SYMTAB

Symbol table

pub const SHT_SYMTAB = 2;

SHT_STRTAB

String table

pub const SHT_STRTAB = 3;

SHT_RELA

Relocation entries with addends

pub const SHT_RELA = 4;

SHT_HASH

Symbol hash table

pub const SHT_HASH = 5;

SHT_DYNAMIC

Dynamic linking information

pub const SHT_DYNAMIC = 6;

SHT_NOTE

Notes

pub const SHT_NOTE = 7;

SHT_NOBITS

Program space with no data (bss)

pub const SHT_NOBITS = 8;

SHT_REL

Relocation entries, no addends

pub const SHT_REL = 9;

SHT_SHLIB

Reserved

pub const SHT_SHLIB = 10;

SHT_DYNSYM

Dynamic linker symbol table

pub const SHT_DYNSYM = 11;

SHT_INIT_ARRAY

Array of constructors

pub const SHT_INIT_ARRAY = 14;

SHT_FINI_ARRAY

Array of destructors

pub const SHT_FINI_ARRAY = 15;

SHT_PREINIT_ARRAY

Array of pre-constructors

pub const SHT_PREINIT_ARRAY = 16;

SHT_GROUP

Section group

pub const SHT_GROUP = 17;

SHT_SYMTAB_SHNDX

Extended section indices

pub const SHT_SYMTAB_SHNDX = 18;

SHT_LOOS

Start of OS-specific

pub const SHT_LOOS = 0x60000000;

SHT_LLVM_ADDRSIG

LLVM address-significance table

pub const SHT_LLVM_ADDRSIG = 0x6fff4c03;

SHT_GNU_HASH

GNU hash table

pub const SHT_GNU_HASH = 0x6ffffff6;

SHT_GNU_VERDEF

GNU version definition table

pub const SHT_GNU_VERDEF = 0x6ffffffd;

SHT_GNU_VERNEED

GNU needed versions table

pub const SHT_GNU_VERNEED = 0x6ffffffe;

SHT_GNU_VERSYM

GNU symbol version table

pub const SHT_GNU_VERSYM = 0x6fffffff;

SHT_HIOS

End of OS-specific

pub const SHT_HIOS = 0x6fffffff;

SHT_LOPROC

Start of processor-specific

pub const SHT_LOPROC = 0x70000000;

SHT_X86_64_UNWIND

Unwind information

pub const SHT_X86_64_UNWIND = 0x70000001;

SHT_HIPROC

End of processor-specific

pub const SHT_HIPROC = 0x7fffffff;

SHT_LOUSER

Start of application-specific

pub const SHT_LOUSER = 0x80000000;

SHT_HIUSER

End of application-specific

pub const SHT_HIUSER = 0xffffffff;

// Note type for .note.gnu.build_id

NT_GNU_BUILD_ID

pub const NT_GNU_BUILD_ID = 3;

STB_LOCAL

Local symbol

pub const STB_LOCAL = 0;

STB_GLOBAL

Global symbol

pub const STB_GLOBAL = 1;

STB_WEAK

Weak symbol

pub const STB_WEAK = 2;

STB_NUM

Number of defined types

pub const STB_NUM = 3;

STB_LOOS

Start of OS-specific

pub const STB_LOOS = 10;

STB_GNU_UNIQUE

Unique symbol

pub const STB_GNU_UNIQUE = 10;

STB_HIOS

End of OS-specific

pub const STB_HIOS = 12;

STB_LOPROC

Start of processor-specific

pub const STB_LOPROC = 13;

STB_HIPROC

End of processor-specific

pub const STB_HIPROC = 15;

STB_MIPS_SPLIT_COMMON

pub const STB_MIPS_SPLIT_COMMON = 13;

STT_NOTYPE

Symbol type is unspecified

pub const STT_NOTYPE = 0;

STT_OBJECT

Symbol is a data object

pub const STT_OBJECT = 1;

STT_FUNC

Symbol is a code object

pub const STT_FUNC = 2;

STT_SECTION

Symbol associated with a section

pub const STT_SECTION = 3;

STT_FILE

Symbol's name is file name

pub const STT_FILE = 4;

STT_COMMON

Symbol is a common data object

pub const STT_COMMON = 5;

STT_TLS

Symbol is thread-local data object

pub const STT_TLS = 6;

STT_NUM

Number of defined types

pub const STT_NUM = 7;

STT_LOOS

Start of OS-specific

pub const STT_LOOS = 10;

STT_GNU_IFUNC

Symbol is indirect code object

pub const STT_GNU_IFUNC = 10;

STT_HIOS

End of OS-specific

pub const STT_HIOS = 12;

STT_LOPROC

Start of processor-specific

pub const STT_LOPROC = 13;

STT_HIPROC

End of processor-specific

pub const STT_HIPROC = 15;

STT_SPARC_REGISTER

pub const STT_SPARC_REGISTER = 13;

STT_PARISC_MILLICODE

pub const STT_PARISC_MILLICODE = 13;

STT_HP_OPAQUE

pub const STT_HP_OPAQUE = (STT_LOOS + 0x1);

STT_HP_STUB

pub const STT_HP_STUB = (STT_LOOS + 0x2);

STT_ARM_TFUNC

pub const STT_ARM_TFUNC = STT_LOPROC;

STT_ARM_16BIT

pub const STT_ARM_16BIT = STT_HIPROC;

MAGIC

pub const MAGIC = "\x7fELF";

ET

File types

pub const ET = enum(u16) {
    NONE = 0,

    REL = 1,

    EXEC = 2,

    DYN = 3,

    CORE = 4,

    pub const LOPROC = 0xff00;

    pub const HIPROC = 0xffff;
};

Header

No file type Relocatable file Executable file Shared object file Core file Beginning of processor-specific codes Processor-specific All integers are native endian.

pub const Header = struct {
    endian: std.builtin.Endian,
    machine: EM,
    is_64: bool,
    entry: u64,
    phoff: u64,
    shoff: u64,
    phentsize: u16,
    phnum: u16,
    shentsize: u16,
    shnum: u16,
    shstrndx: u16,

program_header_iterator()

    pub fn program_header_iterator(self: Header, parse_source: anytype) ProgramHeaderIterator(@TypeOf(parse_source)) {
        return ProgramHeaderIterator(@TypeOf(parse_source)){
            .elf_header = self,
            .parse_source = parse_source,
        };
    }

section_header_iterator()

    pub fn section_header_iterator(self: Header, parse_source: anytype) SectionHeaderIterator(@TypeOf(parse_source)) {
        return SectionHeaderIterator(@TypeOf(parse_source)){
            .elf_header = self,
            .parse_source = parse_source,
        };
    }

read()

    pub fn read(parse_source: anytype) !Header {
        var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined;
        try parse_source.seekableStream().seekTo(0);
        try parse_source.reader().readNoEof(&hdr_buf);
        return Header.parse(&hdr_buf);
    }

parse()

    pub fn parse(hdr_buf: *align(@alignOf(Elf64_Ehdr)) const [@sizeOf(Elf64_Ehdr)]u8) !Header {
        const hdr32 = @as(*const Elf32_Ehdr, @ptrCast(hdr_buf));
        const hdr64 = @as(*const Elf64_Ehdr, @ptrCast(hdr_buf));
        if (!mem.eql(u8, hdr32.e_ident[0..4], MAGIC)) return error.InvalidElfMagic;
        if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion;

        const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) {
            ELFDATA2LSB => .little,
            ELFDATA2MSB => .big,
            else => return error.InvalidElfEndian,
        };
        const need_bswap = endian != native_endian;

        const is_64 = switch (hdr32.e_ident[EI_CLASS]) {
            ELFCLASS32 => false,
            ELFCLASS64 => true,
            else => return error.InvalidElfClass,
        };

        const machine = if (need_bswap) blk: {
            const value = @intFromEnum(hdr32.e_machine);
            break :blk @as(EM, @enumFromInt(@byteSwap(value)));
        } else hdr32.e_machine;

        return @as(Header, .{
            .endian = endian,
            .machine = machine,
            .is_64 = is_64,
            .entry = int(is_64, need_bswap, hdr32.e_entry, hdr64.e_entry),
            .phoff = int(is_64, need_bswap, hdr32.e_phoff, hdr64.e_phoff),
            .shoff = int(is_64, need_bswap, hdr32.e_shoff, hdr64.e_shoff),
            .phentsize = int(is_64, need_bswap, hdr32.e_phentsize, hdr64.e_phentsize),
            .phnum = int(is_64, need_bswap, hdr32.e_phnum, hdr64.e_phnum),
            .shentsize = int(is_64, need_bswap, hdr32.e_shentsize, hdr64.e_shentsize),
            .shnum = int(is_64, need_bswap, hdr32.e_shnum, hdr64.e_shnum),
            .shstrndx = int(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx),
        });
    }
};

ProgramHeaderIterator()

pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {
    return struct {
        elf_header: Header,
        parse_source: ParseSource,
        index: usize = 0,

next()

        pub fn next(self: *@This()) !?Elf64_Phdr {
            if (self.index >= self.elf_header.phnum) return null;
            defer self.index += 1;

            if (self.elf_header.is_64) {
                var phdr: Elf64_Phdr = undefined;
                const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
                try self.parse_source.seekableStream().seekTo(offset);
                try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));

                // ELF endianness matches native endianness.
                if (self.elf_header.endian == native_endian) return phdr;

                // Convert fields to native endianness.
                mem.byteSwapAllFields(Elf64_Phdr, &phdr);
                return phdr;
            }

            var phdr: Elf32_Phdr = undefined;
            const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
            try self.parse_source.seekableStream().seekTo(offset);
            try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));

            // ELF endianness does NOT match native endianness.
            if (self.elf_header.endian != native_endian) {
                // Convert fields to native endianness.
                mem.byteSwapAllFields(Elf32_Phdr, &phdr);
            }

            // Convert 32-bit header to 64-bit.
            return Elf64_Phdr{
                .p_type = phdr.p_type,
                .p_offset = phdr.p_offset,
                .p_vaddr = phdr.p_vaddr,
                .p_paddr = phdr.p_paddr,
                .p_filesz = phdr.p_filesz,
                .p_memsz = phdr.p_memsz,
                .p_flags = phdr.p_flags,
                .p_align = phdr.p_align,
            };
        }
    };
}

SectionHeaderIterator()

pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {
    return struct {
        elf_header: Header,
        parse_source: ParseSource,
        index: usize = 0,

next()

        pub fn next(self: *@This()) !?Elf64_Shdr {
            if (self.index >= self.elf_header.shnum) return null;
            defer self.index += 1;

            if (self.elf_header.is_64) {
                var shdr: Elf64_Shdr = undefined;
                const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
                try self.parse_source.seekableStream().seekTo(offset);
                try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));

                // ELF endianness matches native endianness.
                if (self.elf_header.endian == native_endian) return shdr;

                // Convert fields to native endianness.
                mem.byteSwapAllFields(Elf64_Shdr, &shdr);
                return shdr;
            }

            var shdr: Elf32_Shdr = undefined;
            const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
            try self.parse_source.seekableStream().seekTo(offset);
            try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));

            // ELF endianness does NOT match native endianness.
            if (self.elf_header.endian != native_endian) {
                // Convert fields to native endianness.
                mem.byteSwapAllFields(Elf32_Shdr, &shdr);
            }

            // Convert 32-bit header to 64-bit.
            return Elf64_Shdr{
                .sh_name = shdr.sh_name,
                .sh_type = shdr.sh_type,
                .sh_flags = shdr.sh_flags,
                .sh_addr = shdr.sh_addr,
                .sh_offset = shdr.sh_offset,
                .sh_size = shdr.sh_size,
                .sh_link = shdr.sh_link,
                .sh_info = shdr.sh_info,
                .sh_addralign = shdr.sh_addralign,
                .sh_entsize = shdr.sh_entsize,
            };
        }
    };
}

int()

pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) {
    if (is_64) {
        if (need_bswap) {
            return @byteSwap(int_64);
        } else {
            return int_64;
        }
    } else {
        return int32(need_bswap, int_32, @TypeOf(int_64));
    }
}

int32()

pub fn int32(need_bswap: bool, int_32: anytype, comptime Int64: anytype) Int64 {
    if (need_bswap) {
        return @byteSwap(int_32);
    } else {
        return int_32;
    }
}

EI_NIDENT

pub const EI_NIDENT = 16;

EI_CLASS

pub const EI_CLASS = 4;

ELFCLASSNONE

pub const ELFCLASSNONE = 0;

ELFCLASS32

pub const ELFCLASS32 = 1;

ELFCLASS64

pub const ELFCLASS64 = 2;

ELFCLASSNUM

pub const ELFCLASSNUM = 3;

EI_DATA

pub const EI_DATA = 5;

ELFDATANONE

pub const ELFDATANONE = 0;

ELFDATA2LSB

pub const ELFDATA2LSB = 1;

ELFDATA2MSB

pub const ELFDATA2MSB = 2;

ELFDATANUM

pub const ELFDATANUM = 3;

EI_VERSION

pub const EI_VERSION = 6;

Elf32_Half

pub const Elf32_Half = u16;

Elf64_Half

pub const Elf64_Half = u16;

Elf32_Word

pub const Elf32_Word = u32;

Elf32_Sword

pub const Elf32_Sword = i32;

Elf64_Word

pub const Elf64_Word = u32;

Elf64_Sword

pub const Elf64_Sword = i32;

Elf32_Xword

pub const Elf32_Xword = u64;

Elf32_Sxword

pub const Elf32_Sxword = i64;

Elf64_Xword

pub const Elf64_Xword = u64;

Elf64_Sxword

pub const Elf64_Sxword = i64;

Elf32_Addr

pub const Elf32_Addr = u32;

Elf64_Addr

pub const Elf64_Addr = u64;

Elf32_Off

pub const Elf32_Off = u32;

Elf64_Off

pub const Elf64_Off = u64;

Elf32_Section

pub const Elf32_Section = u16;

Elf64_Section

pub const Elf64_Section = u16;

Elf32_Versym

pub const Elf32_Versym = Elf32_Half;

Elf64_Versym

pub const Elf64_Versym = Elf64_Half;

Elf32_Ehdr

pub const Elf32_Ehdr = extern struct {
    e_ident: [EI_NIDENT]u8,
    e_type: ET,
    e_machine: EM,
    e_version: Elf32_Word,
    e_entry: Elf32_Addr,
    e_phoff: Elf32_Off,
    e_shoff: Elf32_Off,
    e_flags: Elf32_Word,
    e_ehsize: Elf32_Half,
    e_phentsize: Elf32_Half,
    e_phnum: Elf32_Half,
    e_shentsize: Elf32_Half,
    e_shnum: Elf32_Half,
    e_shstrndx: Elf32_Half,
};

Elf64_Ehdr

pub const Elf64_Ehdr = extern struct {
    e_ident: [EI_NIDENT]u8,
    e_type: ET,
    e_machine: EM,
    e_version: Elf64_Word,
    e_entry: Elf64_Addr,
    e_phoff: Elf64_Off,
    e_shoff: Elf64_Off,
    e_flags: Elf64_Word,
    e_ehsize: Elf64_Half,
    e_phentsize: Elf64_Half,
    e_phnum: Elf64_Half,
    e_shentsize: Elf64_Half,
    e_shnum: Elf64_Half,
    e_shstrndx: Elf64_Half,
};

Elf32_Phdr

pub const Elf32_Phdr = extern struct {
    p_type: Elf32_Word,
    p_offset: Elf32_Off,
    p_vaddr: Elf32_Addr,
    p_paddr: Elf32_Addr,
    p_filesz: Elf32_Word,
    p_memsz: Elf32_Word,
    p_flags: Elf32_Word,
    p_align: Elf32_Word,
};

Elf64_Phdr

pub const Elf64_Phdr = extern struct {
    p_type: Elf64_Word,
    p_flags: Elf64_Word,
    p_offset: Elf64_Off,
    p_vaddr: Elf64_Addr,
    p_paddr: Elf64_Addr,
    p_filesz: Elf64_Xword,
    p_memsz: Elf64_Xword,
    p_align: Elf64_Xword,
};

Elf32_Shdr

pub const Elf32_Shdr = extern struct {
    sh_name: Elf32_Word,
    sh_type: Elf32_Word,
    sh_flags: Elf32_Word,
    sh_addr: Elf32_Addr,
    sh_offset: Elf32_Off,
    sh_size: Elf32_Word,
    sh_link: Elf32_Word,
    sh_info: Elf32_Word,
    sh_addralign: Elf32_Word,
    sh_entsize: Elf32_Word,
};

Elf64_Shdr

pub const Elf64_Shdr = extern struct {
    sh_name: Elf64_Word,
    sh_type: Elf64_Word,
    sh_flags: Elf64_Xword,
    sh_addr: Elf64_Addr,
    sh_offset: Elf64_Off,
    sh_size: Elf64_Xword,
    sh_link: Elf64_Word,
    sh_info: Elf64_Word,
    sh_addralign: Elf64_Xword,
    sh_entsize: Elf64_Xword,
};

Elf32_Chdr

pub const Elf32_Chdr = extern struct {
    ch_type: COMPRESS,
    ch_size: Elf32_Word,
    ch_addralign: Elf32_Word,
};

Elf64_Chdr

pub const Elf64_Chdr = extern struct {
    ch_type: COMPRESS,
    ch_reserved: Elf64_Word = 0,
    ch_size: Elf64_Xword,
    ch_addralign: Elf64_Xword,
};

Elf32_Sym

pub const Elf32_Sym = extern struct {
    st_name: Elf32_Word,
    st_value: Elf32_Addr,
    st_size: Elf32_Word,
    st_info: u8,
    st_other: u8,
    st_shndx: Elf32_Section,

st_type()

    pub inline fn st_type(self: @This()) u4 {
        return @truncate(self.st_info);
    }

st_bind()

    pub inline fn st_bind(self: @This()) u4 {
        return @truncate(self.st_info >> 4);
    }
};

Elf64_Sym

pub const Elf64_Sym = extern struct {
    st_name: Elf64_Word,
    st_info: u8,
    st_other: u8,
    st_shndx: Elf64_Section,
    st_value: Elf64_Addr,
    st_size: Elf64_Xword,

st_type()

    pub inline fn st_type(self: @This()) u4 {
        return @truncate(self.st_info);
    }

st_bind()

    pub inline fn st_bind(self: @This()) u4 {
        return @truncate(self.st_info >> 4);
    }
};

Elf32_Syminfo

pub const Elf32_Syminfo = extern struct {
    si_boundto: Elf32_Half,
    si_flags: Elf32_Half,
};

Elf64_Syminfo

pub const Elf64_Syminfo = extern struct {
    si_boundto: Elf64_Half,
    si_flags: Elf64_Half,
};

Elf32_Rel

pub const Elf32_Rel = extern struct {
    r_offset: Elf32_Addr,
    r_info: Elf32_Word,

r_sym()

    pub inline fn r_sym(self: @This()) u24 {
        return @truncate(self.r_info >> 8);
    }

r_type()

    pub inline fn r_type(self: @This()) u8 {
        return @truncate(self.r_info);
    }
};

Elf64_Rel

pub const Elf64_Rel = extern struct {
    r_offset: Elf64_Addr,
    r_info: Elf64_Xword,

r_sym()

    pub inline fn r_sym(self: @This()) u32 {
        return @truncate(self.r_info >> 32);
    }

r_type()

    pub inline fn r_type(self: @This()) u32 {
        return @truncate(self.r_info);
    }
};

Elf32_Rela

pub const Elf32_Rela = extern struct {
    r_offset: Elf32_Addr,
    r_info: Elf32_Word,
    r_addend: Elf32_Sword,

r_sym()

    pub inline fn r_sym(self: @This()) u24 {
        return @truncate(self.r_info >> 8);
    }

r_type()

    pub inline fn r_type(self: @This()) u8 {
        return @truncate(self.r_info);
    }
};

Elf64_Rela

pub const Elf64_Rela = extern struct {
    r_offset: Elf64_Addr,
    r_info: Elf64_Xword,
    r_addend: Elf64_Sxword,

r_sym()

    pub inline fn r_sym(self: @This()) u32 {
        return @truncate(self.r_info >> 32);
    }

r_type()

    pub inline fn r_type(self: @This()) u32 {
        return @truncate(self.r_info);
    }
};

Elf32_Dyn

pub const Elf32_Dyn = extern struct {
    d_tag: Elf32_Sword,
    d_val: Elf32_Addr,
};

Elf64_Dyn

pub const Elf64_Dyn = extern struct {
    d_tag: Elf64_Sxword,
    d_val: Elf64_Addr,
};

Elf32_Verdef

pub const Elf32_Verdef = extern struct {
    vd_version: Elf32_Half,
    vd_flags: Elf32_Half,
    vd_ndx: Elf32_Half,
    vd_cnt: Elf32_Half,
    vd_hash: Elf32_Word,
    vd_aux: Elf32_Word,
    vd_next: Elf32_Word,
};

Elf64_Verdef

pub const Elf64_Verdef = extern struct {
    vd_version: Elf64_Half,
    vd_flags: Elf64_Half,
    vd_ndx: Elf64_Half,
    vd_cnt: Elf64_Half,
    vd_hash: Elf64_Word,
    vd_aux: Elf64_Word,
    vd_next: Elf64_Word,
};

Elf32_Verdaux

pub const Elf32_Verdaux = extern struct {
    vda_name: Elf32_Word,
    vda_next: Elf32_Word,
};

Elf64_Verdaux

pub const Elf64_Verdaux = extern struct {
    vda_name: Elf64_Word,
    vda_next: Elf64_Word,
};

Elf32_Verneed

pub const Elf32_Verneed = extern struct {
    vn_version: Elf32_Half,
    vn_cnt: Elf32_Half,
    vn_file: Elf32_Word,
    vn_aux: Elf32_Word,
    vn_next: Elf32_Word,
};

Elf64_Verneed

pub const Elf64_Verneed = extern struct {
    vn_version: Elf64_Half,
    vn_cnt: Elf64_Half,
    vn_file: Elf64_Word,
    vn_aux: Elf64_Word,
    vn_next: Elf64_Word,
};

Elf32_Vernaux

pub const Elf32_Vernaux = extern struct {
    vna_hash: Elf32_Word,
    vna_flags: Elf32_Half,
    vna_other: Elf32_Half,
    vna_name: Elf32_Word,
    vna_next: Elf32_Word,
};

Elf64_Vernaux

pub const Elf64_Vernaux = extern struct {
    vna_hash: Elf64_Word,
    vna_flags: Elf64_Half,
    vna_other: Elf64_Half,
    vna_name: Elf64_Word,
    vna_next: Elf64_Word,
};

Elf32_auxv_t

pub const Elf32_auxv_t = extern struct {
    a_type: u32,
    a_un: extern union {
        a_val: u32,
    },
};

Elf64_auxv_t

pub const Elf64_auxv_t = extern struct {
    a_type: u64,
    a_un: extern union {
        a_val: u64,
    },
};

Elf32_Nhdr

pub const Elf32_Nhdr = extern struct {
    n_namesz: Elf32_Word,
    n_descsz: Elf32_Word,
    n_type: Elf32_Word,
};

Elf64_Nhdr

pub const Elf64_Nhdr = extern struct {
    n_namesz: Elf64_Word,
    n_descsz: Elf64_Word,
    n_type: Elf64_Word,
};

Elf32_Move

pub const Elf32_Move = extern struct {
    m_value: Elf32_Xword,
    m_info: Elf32_Word,
    m_poffset: Elf32_Word,
    m_repeat: Elf32_Half,
    m_stride: Elf32_Half,
};

Elf64_Move

pub const Elf64_Move = extern struct {
    m_value: Elf64_Xword,
    m_info: Elf64_Xword,
    m_poffset: Elf64_Xword,
    m_repeat: Elf64_Half,
    m_stride: Elf64_Half,
};

Elf32_gptab

pub const Elf32_gptab = extern union {
    gt_header: extern struct {
        gt_current_g_value: Elf32_Word,
        gt_unused: Elf32_Word,
    },
    gt_entry: extern struct {
        gt_g_value: Elf32_Word,
        gt_bytes: Elf32_Word,
    },
};

Elf32_RegInfo

pub const Elf32_RegInfo = extern struct {
    ri_gprmask: Elf32_Word,
    ri_cprmask: [4]Elf32_Word,
    ri_gp_value: Elf32_Sword,
};

Elf_Options

pub const Elf_Options = extern struct {
    kind: u8,
    size: u8,
    section: Elf32_Section,
    info: Elf32_Word,
};

Elf_Options_Hw

pub const Elf_Options_Hw = extern struct {
    hwp_flags1: Elf32_Word,
    hwp_flags2: Elf32_Word,
};

Elf32_Lib

pub const Elf32_Lib = extern struct {
    l_name: Elf32_Word,
    l_time_stamp: Elf32_Word,
    l_checksum: Elf32_Word,
    l_version: Elf32_Word,
    l_flags: Elf32_Word,
};

Elf64_Lib

pub const Elf64_Lib = extern struct {
    l_name: Elf64_Word,
    l_time_stamp: Elf64_Word,
    l_checksum: Elf64_Word,
    l_version: Elf64_Word,
    l_flags: Elf64_Word,
};

Elf32_Conflict

pub const Elf32_Conflict = Elf32_Addr;

Elf_MIPS_ABIFlags_v0

pub const Elf_MIPS_ABIFlags_v0 = extern struct {
    version: Elf32_Half,
    isa_level: u8,
    isa_rev: u8,
    gpr_size: u8,
    cpr1_size: u8,
    cpr2_size: u8,
    fp_abi: u8,
    isa_ext: Elf32_Word,
    ases: Elf32_Word,
    flags1: Elf32_Word,
    flags2: Elf32_Word,
};

comptime {
    assert(@sizeOf(Elf32_Ehdr) == 52);
    assert(@sizeOf(Elf64_Ehdr) == 64);

    assert(@sizeOf(Elf32_Phdr) == 32);
    assert(@sizeOf(Elf64_Phdr) == 56);

    assert(@sizeOf(Elf32_Shdr) == 40);
    assert(@sizeOf(Elf64_Shdr) == 64);
}

Auxv

pub const Auxv = switch (@sizeOf(usize)) {
    4 => Elf32_auxv_t,
    8 => Elf64_auxv_t,
    else => @compileError("expected pointer size of 32 or 64"),
};

Ehdr

pub const Ehdr = switch (@sizeOf(usize)) {
    4 => Elf32_Ehdr,
    8 => Elf64_Ehdr,
    else => @compileError("expected pointer size of 32 or 64"),
};

Phdr

pub const Phdr = switch (@sizeOf(usize)) {
    4 => Elf32_Phdr,
    8 => Elf64_Phdr,
    else => @compileError("expected pointer size of 32 or 64"),
};

Dyn

pub const Dyn = switch (@sizeOf(usize)) {
    4 => Elf32_Dyn,
    8 => Elf64_Dyn,
    else => @compileError("expected pointer size of 32 or 64"),
};

Rel

pub const Rel = switch (@sizeOf(usize)) {
    4 => Elf32_Rel,
    8 => Elf64_Rel,
    else => @compileError("expected pointer size of 32 or 64"),
};

Rela

pub const Rela = switch (@sizeOf(usize)) {
    4 => Elf32_Rela,
    8 => Elf64_Rela,
    else => @compileError("expected pointer size of 32 or 64"),
};

Shdr

pub const Shdr = switch (@sizeOf(usize)) {
    4 => Elf32_Shdr,
    8 => Elf64_Shdr,
    else => @compileError("expected pointer size of 32 or 64"),
};

Chdr

pub const Chdr = switch (@sizeOf(usize)) {
    4 => Elf32_Chdr,
    8 => Elf64_Chdr,
    else => @compileError("expected pointer size of 32 or 64"),
};

Sym

pub const Sym = switch (@sizeOf(usize)) {
    4 => Elf32_Sym,
    8 => Elf64_Sym,
    else => @compileError("expected pointer size of 32 or 64"),
};

Verdef

pub const Verdef = switch (@sizeOf(usize)) {
    4 => Elf32_Verdef,
    8 => Elf64_Verdef,
    else => @compileError("expected pointer size of 32 or 64"),
};

Verdaux

pub const Verdaux = switch (@sizeOf(usize)) {
    4 => Elf32_Verdaux,
    8 => Elf64_Verdaux,
    else => @compileError("expected pointer size of 32 or 64"),
};

Addr

pub const Addr = switch (@sizeOf(usize)) {
    4 => Elf32_Addr,
    8 => Elf64_Addr,
    else => @compileError("expected pointer size of 32 or 64"),
};

Half

pub const Half = switch (@sizeOf(usize)) {
    4 => Elf32_Half,
    8 => Elf64_Half,
    else => @compileError("expected pointer size of 32 or 64"),
};

EM

Machine architectures.

See current registered ELF machine architectures at: http://www.sco.com/developers/gabi/latest/ch4.eheader.html

pub const EM = enum(u16) {
    NONE = 0,

    M32 = 1,

    SPARC = 2,

    @"386" = 3,

    @"68K" = 4,

    @"88K" = 5,

    IAMCU = 6,

    @"860" = 7,

    MIPS = 8,

    S370 = 9,

    MIPS_RS3_LE = 10,

    SPU_2 = 13,

    PARISC = 15,

    VPP500 = 17,

    SPARC32PLUS = 18,

    @"960" = 19,

    PPC = 20,

    PPC64 = 21,

    S390 = 22,

    SPU = 23,

    V800 = 36,

    FR20 = 37,

    RH32 = 38,

    RCE = 39,

    ARM = 40,

    ALPHA = 41,

    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,

    @"68HC12" = 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,

    @"68HC16" = 69,

    @"68HC11" = 70,

    @"68HC08" = 71,

    @"68HC05" = 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,

    MMDSP_PLUS = 160,

    CYPRESS_M8C = 161,

    R32C = 162,

    TRIMEDIA = 163,

    HEXAGON = 164,

    @"8051" = 165,

    STXP7X = 166,

    NDS32 = 167,

    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,

    CUDA = 190,

    TILEGX = 191,

    CLOUDSHIELD = 192,

    COREA_1ST = 193,

    COREA_2ND = 194,

    ARC_COMPACT2 = 195,

    OPEN8 = 196,

    RL78 = 197,

    VIDEOCORE5 = 198,

    @"78KOR" = 199,

    @"56800EX" = 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,

    AMDGPU = 224,

    RISCV = 243,

    LANAI = 244,

    BPF = 247,

    CSKY = 252,

    FRV = 0x5441,

    _,

toTargetCpuArch()

No machine AT&T WE 32100 SPARC Intel 386 Motorola 68000 Motorola 88000 Intel MCU Intel 80860 MIPS R3000 IBM System/370 MIPS RS3000 Little-endian SPU Mark II Hewlett-Packard PA-RISC Fujitsu VPP500 Enhanced instruction set SPARC Intel 80960 PowerPC PowerPC64 IBM System/390 IBM SPU/SPC NEC V800 Fujitsu FR20 TRW RH-32 Motorola RCE ARM DEC Alpha Hitachi SH SPARC V9 Siemens TriCore Argonaut RISC Core Hitachi H8/300 Hitachi H8/300H Hitachi H8S Hitachi H8/500 Intel IA-64 processor architecture Stanford MIPS-X Motorola ColdFire Motorola M68HC12 Fujitsu MMA Multimedia Accelerator Siemens PCP Sony nCPU embedded RISC processor Denso NDR1 microprocessor Motorola Star*Core processor Toyota ME16 processor STMicroelectronics ST100 processor Advanced Logic Corp. TinyJ embedded processor family AMD x86-64 architecture Sony DSP Processor Digital Equipment Corp. PDP-10 Digital Equipment Corp. PDP-11 Siemens FX66 microcontroller STMicroelectronics ST9+ 8/16 bit microcontroller STMicroelectronics ST7 8-bit microcontroller Motorola MC68HC16 Microcontroller Motorola MC68HC11 Microcontroller Motorola MC68HC08 Microcontroller Motorola MC68HC05 Microcontroller Silicon Graphics SVx STMicroelectronics ST19 8-bit microcontroller Digital VAX Axis Communications 32-bit embedded processor Infineon Technologies 32-bit embedded processor Element 14 64-bit DSP Processor LSI Logic 16-bit DSP Processor Donald Knuth's educational 64-bit processor Harvard University machine-independent object files SiTera Prism Atmel AVR 8-bit microcontroller Fujitsu FR30 Mitsubishi D10V Mitsubishi D30V NEC v850 Mitsubishi M32R Matsushita MN10300 Matsushita MN10200 picoJava OpenRISC 32-bit embedded processor ARC International ARCompact processor (old spelling/synonym: EM_ARC_A5) Tensilica Xtensa Architecture Alphamosaic VideoCore processor Thompson Multimedia General Purpose Processor National Semiconductor 32000 series Tenor Network TPC processor Trebia SNP 1000 processor STMicroelectronics (www.st.com) ST200 Ubicom IP2xxx microcontroller family MAX Processor National Semiconductor CompactRISC microprocessor Fujitsu F2MC16 Texas Instruments embedded microcontroller msp430 Analog Devices Blackfin (DSP) processor S1C33 Family of Seiko Epson processors Sharp embedded microprocessor Arca RISC Microprocessor Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University eXcess: 16/32/64-bit configurable embedded CPU Icera Semiconductor Inc. Deep Execution Processor Altera Nios II soft-core processor National Semiconductor CompactRISC CRX Motorola XGATE embedded processor Infineon C16x/XC16x processor Renesas M16C series microprocessors Microchip Technology dsPIC30F Digital Signal Controller Freescale Communication Engine RISC core Renesas M32C series microprocessors Altium TSK3000 core Freescale RS08 embedded processor Analog Devices SHARC family of 32-bit DSP processors Cyan Technology eCOG2 microprocessor Sunplus S+core7 RISC processor New Japan Radio (NJR) 24-bit DSP Processor Broadcom VideoCore III processor RISC processor for Lattice FPGA architecture Seiko Epson C17 family The Texas Instruments TMS320C6000 DSP family The Texas Instruments TMS320C2000 DSP family The Texas Instruments TMS320C55x DSP family STMicroelectronics 64bit VLIW Data Signal Processor Cypress M8C microprocessor Renesas R32C series microprocessors NXP Semiconductors TriMedia architecture family Qualcomm Hexagon processor Intel 8051 and variants STMicroelectronics STxP7x family of configurable and extensible RISC processors Andes Technology compact code size embedded RISC processor family Cyan Technology eCOG1X family Dallas Semiconductor MAXQ30 Core Micro-controllers New Japan Radio (NJR) 16-bit DSP Processor M2000 Reconfigurable RISC Microprocessor Cray Inc. NV2 vector architecture Renesas RX family Imagination Technologies META processor architecture MCST Elbrus general purpose hardware architecture Cyan Technology eCOG16 family National Semiconductor CompactRISC CR16 16-bit microprocessor Freescale Extended Time Processing Unit Infineon Technologies SLE9X core Intel L10M Intel K10M ARM AArch64 Atmel Corporation 32-bit microprocessor family STMicroeletronics STM8 8-bit microcontroller Tilera TILE64 multicore architecture family Tilera TILEPro multicore architecture family NVIDIA CUDA architecture Tilera TILE-Gx multicore architecture family CloudShield architecture family KIPO-KAIST Core-A 1st generation processor family KIPO-KAIST Core-A 2nd generation processor family Synopsys ARCompact V2 Open8 8-bit RISC soft processor core Renesas RL78 family Broadcom VideoCore V processor Renesas 78KOR family Freescale 56800EX Digital Signal Controller (DSC) Beyond BA1 CPU architecture Beyond BA2 CPU architecture XMOS xCORE processor family Microchip 8-bit PIC(r) family Reserved by Intel Reserved by Intel Reserved by Intel Reserved by Intel Reserved by Intel KM211 KM32 32-bit processor KM211 KMX32 32-bit processor KM211 KMX16 16-bit processor KM211 KMX8 8-bit processor KM211 KVARC processor Paneve CDP architecture family Cognitive Smart Memory Processor iCelero CoolEngine Nanoradio Optimized RISC CSR Kalimba architecture family AMD GPU architecture RISC-V Lanai 32-bit processor Linux kernel bpf virtual machine C-SKY Fujitsu FR-V

    pub fn toTargetCpuArch(em: EM) ?std.Target.Cpu.Arch {
        return switch (em) {
            .AVR => .avr,
            .MSP430 => .msp430,
            .ARC => .arc,
            .ARM => .arm,
            .HEXAGON => .hexagon,
            .@"68K" => .m68k,
            .MIPS => .mips,
            .MIPS_RS3_LE => .mipsel,
            .PPC => .powerpc,
            .SPARC => .sparc,
            .@"386" => .x86,
            .XCORE => .xcore,
            .CSR_KALIMBA => .kalimba,
            .LANAI => .lanai,
            .AARCH64 => .aarch64,
            .PPC64 => .powerpc64,
            .RISCV => .riscv64,
            .X86_64 => .x86_64,
            .BPF => .bpfel,
            .SPARCV9 => .sparc64,
            .S390 => .s390x,
            .SPU_2 => .spu_2,
            // there's many cases we don't (yet) handle, or will never have a
            // zig target cpu arch equivalent (such as null).
            else => null,
        };
    }
};

SHF_WRITE

Section data should be writable during execution.

pub const SHF_WRITE = 0x1;

SHF_ALLOC

Section occupies memory during program execution.

pub const SHF_ALLOC = 0x2;

SHF_EXECINSTR

Section contains executable machine instructions.

pub const SHF_EXECINSTR = 0x4;

SHF_MERGE

The data in this section may be merged.

pub const SHF_MERGE = 0x10;

SHF_STRINGS

The data in this section is null-terminated strings.

pub const SHF_STRINGS = 0x20;

SHF_INFO_LINK

A field in this section holds a section header table index.

pub const SHF_INFO_LINK = 0x40;

SHF_LINK_ORDER

Adds special ordering requirements for link editors.

pub const SHF_LINK_ORDER = 0x80;

SHF_OS_NONCONFORMING

This section requires special OS-specific processing to avoid incorrect behavior.

pub const SHF_OS_NONCONFORMING = 0x100;

SHF_GROUP

This section is a member of a section group.

pub const SHF_GROUP = 0x200;

SHF_TLS

This section holds Thread-Local Storage.

pub const SHF_TLS = 0x400;

SHF_COMPRESSED

Identifies a section containing compressed data.

pub const SHF_COMPRESSED = 0x800;

SHF_GNU_RETAIN

Not to be GCed by the linker

pub const SHF_GNU_RETAIN = 0x200000;

SHF_EXCLUDE

This section is excluded from the final executable or shared library.

pub const SHF_EXCLUDE = 0x80000000;

SHF_MASKOS

Start of target-specific flags.

pub const SHF_MASKOS = 0x0ff00000;

SHF_MASKPROC

Bits indicating processor-specific flags.

pub const SHF_MASKPROC = 0xf0000000;

XCORE_SHF_DP_SECTION

All sections with the "d" flag are grouped together by the linker to form the data section and the dp register is set to the start of the section by the boot code.

pub const XCORE_SHF_DP_SECTION = 0x10000000;

XCORE_SHF_CP_SECTION

All sections with the "c" flag are grouped together by the linker to form the constant pool and the cp register is set to the start of the constant pool by the boot code.

pub const XCORE_SHF_CP_SECTION = 0x20000000;

SHF_X86_64_LARGE

If an object file section does not have this flag set, then it may not hold more than 2GB and can be freely referred to in objects using smaller code models. Otherwise, only objects using larger code models can refer to them. For example, a medium code model object can refer to data in a section that sets this flag besides being able to refer to data in a section that does not set it; likewise, a small code model object can refer only to code in a section that does not set this flag.

pub const SHF_X86_64_LARGE = 0x10000000;

SHF_HEX_GPREL

All sections with the GPREL flag are grouped into a global data area for faster accesses

pub const SHF_HEX_GPREL = 0x10000000;

SHF_MIPS_NODUPES

Section contains text/data which may be replicated in other sections. Linker must retain only one copy.

pub const SHF_MIPS_NODUPES = 0x01000000;

SHF_MIPS_NAMES

Linker must generate implicit hidden weak names.

pub const SHF_MIPS_NAMES = 0x02000000;

SHF_MIPS_LOCAL

Section data local to process.

pub const SHF_MIPS_LOCAL = 0x04000000;

SHF_MIPS_NOSTRIP

Do not strip this section.

pub const SHF_MIPS_NOSTRIP = 0x08000000;

SHF_MIPS_GPREL

Section must be part of global data area.

pub const SHF_MIPS_GPREL = 0x10000000;

SHF_MIPS_MERGE

This section should be merged.

pub const SHF_MIPS_MERGE = 0x20000000;

SHF_MIPS_ADDR

Address size to be inferred from section entry size.

pub const SHF_MIPS_ADDR = 0x40000000;

SHF_MIPS_STRING

Section data is string data by default.

pub const SHF_MIPS_STRING = 0x80000000;

SHF_ARM_PURECODE

Make code section unreadable when in execute-only mode

pub const SHF_ARM_PURECODE = 0x2000000;

PF_X

Execute

pub const PF_X = 1;

PF_W

Write

pub const PF_W = 2;

PF_R

Read

pub const PF_R = 4;

PF_MASKOS

Bits for operating system-specific semantics.

pub const PF_MASKOS = 0x0ff00000;

PF_MASKPROC

Bits for processor-specific semantics.

pub const PF_MASKPROC = 0xf0000000;

SHN_UNDEF

Undefined section

pub const SHN_UNDEF = 0;

SHN_LORESERVE

Start of reserved indices

pub const SHN_LORESERVE = 0xff00;

SHN_LOPROC

Start of processor-specific

pub const SHN_LOPROC = 0xff00;

SHN_HIPROC

End of processor-specific

pub const SHN_HIPROC = 0xff1f;

SHN_LIVEPATCH

pub const SHN_LIVEPATCH = 0xff20;

SHN_ABS

Associated symbol is absolute

pub const SHN_ABS = 0xfff1;

SHN_COMMON

Associated symbol is common

pub const SHN_COMMON = 0xfff2;

SHN_HIRESERVE

End of reserved indices

pub const SHN_HIRESERVE = 0xffff;

// Legal values for ch_type (compression algorithm).

COMPRESS

pub const COMPRESS = enum(u32) {
    ZLIB = 1,
    ZSTD = 2,
    LOOS = 0x60000000,
    HIOS = 0x6fffffff,
    LOPROC = 0x70000000,
    HIPROC = 0x7fffffff,
    _,
};

R_X86_64_NONE

AMD x86-64 relocations. No reloc

pub const R_X86_64_NONE = 0;

R_X86_64_64

Direct 64 bit

pub const R_X86_64_64 = 1;

R_X86_64_PC32

PC relative 32 bit signed

pub const R_X86_64_PC32 = 2;

R_X86_64_GOT32

32 bit GOT entry

pub const R_X86_64_GOT32 = 3;

R_X86_64_PLT32

32 bit PLT address

pub const R_X86_64_PLT32 = 4;

R_X86_64_COPY

Copy symbol at runtime

pub const R_X86_64_COPY = 5;

R_X86_64_GLOB_DAT

Create GOT entry

pub const R_X86_64_GLOB_DAT = 6;

R_X86_64_JUMP_SLOT

Create PLT entry

pub const R_X86_64_JUMP_SLOT = 7;

R_X86_64_RELATIVE

Adjust by program base

pub const R_X86_64_RELATIVE = 8;

R_X86_64_GOTPCREL

32 bit signed PC relative offset to GOT

pub const R_X86_64_GOTPCREL = 9;

R_X86_64_32

Direct 32 bit zero extended

pub const R_X86_64_32 = 10;

R_X86_64_32S

Direct 32 bit sign extended

pub const R_X86_64_32S = 11;

R_X86_64_16

Direct 16 bit zero extended

pub const R_X86_64_16 = 12;

R_X86_64_PC16

16 bit sign extended pc relative

pub const R_X86_64_PC16 = 13;

R_X86_64_8

Direct 8 bit sign extended

pub const R_X86_64_8 = 14;

R_X86_64_PC8

8 bit sign extended pc relative

pub const R_X86_64_PC8 = 15;

R_X86_64_DTPMOD64

ID of module containing symbol

pub const R_X86_64_DTPMOD64 = 16;

R_X86_64_DTPOFF64

Offset in module's TLS block

pub const R_X86_64_DTPOFF64 = 17;

R_X86_64_TPOFF64

Offset in initial TLS block

pub const R_X86_64_TPOFF64 = 18;

R_X86_64_TLSGD

32 bit signed PC relative offset to two GOT entries for GD symbol

pub const R_X86_64_TLSGD = 19;

R_X86_64_TLSLD

32 bit signed PC relative offset to two GOT entries for LD symbol

pub const R_X86_64_TLSLD = 20;

R_X86_64_DTPOFF32

Offset in TLS block

pub const R_X86_64_DTPOFF32 = 21;

R_X86_64_GOTTPOFF

32 bit signed PC relative offset to GOT entry for IE symbol

pub const R_X86_64_GOTTPOFF = 22;

R_X86_64_TPOFF32

Offset in initial TLS block

pub const R_X86_64_TPOFF32 = 23;

R_X86_64_PC64

PC relative 64 bit

pub const R_X86_64_PC64 = 24;

R_X86_64_GOTOFF64

64 bit offset to GOT

pub const R_X86_64_GOTOFF64 = 25;

R_X86_64_GOTPC32

32 bit signed pc relative offset to GOT

pub const R_X86_64_GOTPC32 = 26;

R_X86_64_GOT64

64 bit GOT entry offset

pub const R_X86_64_GOT64 = 27;

R_X86_64_GOTPCREL64

64 bit PC relative offset to GOT entry

pub const R_X86_64_GOTPCREL64 = 28;

R_X86_64_GOTPC64

64 bit PC relative offset to GOT

pub const R_X86_64_GOTPC64 = 29;

R_X86_64_GOTPLT64

Like GOT64, says PLT entry needed

pub const R_X86_64_GOTPLT64 = 30;

R_X86_64_PLTOFF64

64-bit GOT relative offset to PLT entry

pub const R_X86_64_PLTOFF64 = 31;

R_X86_64_SIZE32

Size of symbol plus 32-bit addend

pub const R_X86_64_SIZE32 = 32;

R_X86_64_SIZE64

Size of symbol plus 64-bit addend

pub const R_X86_64_SIZE64 = 33;

R_X86_64_GOTPC32_TLSDESC

GOT offset for TLS descriptor

pub const R_X86_64_GOTPC32_TLSDESC = 34;

R_X86_64_TLSDESC_CALL

Marker for call through TLS descriptor

pub const R_X86_64_TLSDESC_CALL = 35;

R_X86_64_TLSDESC

TLS descriptor

pub const R_X86_64_TLSDESC = 36;

R_X86_64_IRELATIVE

Adjust indirectly by program base

pub const R_X86_64_IRELATIVE = 37;

R_X86_64_RELATIVE64

64-bit adjust by program base

pub const R_X86_64_RELATIVE64 = 38;

R_X86_64_GOTPCRELX

39 Reserved was R_X86_64_PC32_BND 40 Reserved was R_X86_64_PLT32_BND Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable

pub const R_X86_64_GOTPCRELX = 41;

R_X86_64_REX_GOTPCRELX

Load from 32 bit signed PC relative offset to GOT entry with REX prefix, relaxable

pub const R_X86_64_REX_GOTPCRELX = 42;

R_X86_64_NUM

pub const R_X86_64_NUM = 43;

STV

pub const STV = enum(u2) {
    DEFAULT = 0,
    INTERNAL = 1,
    HIDDEN = 2,
    PROTECTED = 3,
};