This commit is contained in:
nora 2023-02-11 23:58:25 +01:00
parent 03a4287bee
commit 8aa4068b1b
5 changed files with 234 additions and 49 deletions

View file

@ -1,213 +0,0 @@
#![allow(non_upper_case_globals)]
macro_rules! const_group_with_fmt {
(
pub struct $struct_name:ident($ty:ty): $group_name:literal
$(
pub const $name:ident = $value:expr;
)*
) => {
$(
pub const $name: $ty = $value;
)*
#[derive(Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(transparent)]
pub struct $struct_name(pub $ty);
impl std::fmt::Debug for $struct_name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 {
$(
$value => f.write_str(stringify!($name)),
)*
a => write!(f, "Other {}: {a}", $group_name,)
}
}
}
impl PartialEq<$ty> for $struct_name {
fn eq(&self, other: &$ty) -> bool {
self.0 == *other
}
}
};
}
// ------------------
// Header
// ------------------
/* Conglomeration of the identification bytes, for easy testing as a word. */
pub const ELFMAG: &[u8; SELFMAG] = b"\x7fELF";
pub const SELFMAG: usize = 4;
pub const EI_CLASS: usize = 4; /* File class byte index */
const_group_with_fmt! {
pub struct Class(u8): "Class"
pub const ELFCLASSNONE = 0; /* Invalid class */
pub const ELFCLASS32 = 1; /* 32-bit objects */
pub const ELFCLASS64 = 2; /* 64-bit objects */
}
pub const ELFCLASSNUM: u8 = 3;
pub const EI_DATA: usize = 5; /* Data encoding byte index */
const_group_with_fmt! {
pub struct Data(u8): "Data"
pub const ELFDATANONE = 0; /* Invalid data encoding */
pub const ELFDATA2LSB = 1; /* 2's complement, little endian */
pub const ELFDATA2MSB = 2; /* 2's complement, big endian */
}
pub const ELFDATANUM: u8 = 3;
pub const EI_VERSION: usize = 6; /* File version byte index */
pub const EI_OSABI: usize = 7; /* OS ABI identification */
const_group_with_fmt! {
pub struct OsAbi(u8): "OS ABI"
pub const ELFOSABI_SYSV = 0; /* Alias. */
pub const ELFOSABI_HPUX = 1; /* HP-UX */
pub const ELFOSABI_NETBSD = 2; /* NetBSD. */
pub const ELFOSABI_GNU = 3; /* Object uses GNU ELF extensions. */
pub const ELFOSABI_SOLARIS = 6; /* Sun Solaris. */
pub const ELFOSABI_AIX = 7; /* IBM AIX. */
pub const ELFOSABI_IRIX = 8; /* SGI Irix. */
pub const ELFOSABI_FREEBSD = 9; /* FreeBSD. */
pub const ELFOSABI_TRU64 = 10; /* Compaq TRU64 UNIX. */
pub const ELFOSABI_MODESTO = 11; /* Novell Modesto. */
pub const ELFOSABI_OPENBSD = 12; /* OpenBSD. */
pub const ELFOSABI_ARM_AEABI = 64; /* ARM EABI */
pub const ELFOSABI_ARM = 97; /* ARM */
pub const ELFOSABI_STANDALONE = 255; /* Standalone (embedded) application */
}
pub const ELFOSABI_NONE: u8 = 0; /* UNIX System V ABI */
pub const ELFOSABI_LINUX: u8 = 3; /* Compatibility alias. */
pub const EI_ABIVERSION: usize = 8; /* ABI version */
pub const EI_PAD: usize = 9; /* Byte index of padding bytes */
pub const EI_NIDENT: usize = 16;
pub const ET_NONE: u16 = 0;
pub const ET_REL: u16 = 1;
pub const ET_EXEC: u16 = 2;
pub const ET_DYN: u16 = 3;
pub const ET_CORE: u16 = 4;
pub const EM_NONE: u16 = 0; /* No machine */
pub const EM_X86_64: u16 = 62; /* AMD x86-64 architecture */
pub const EV_NONE: u32 = 0;
// ------------------
// Sections
// ------------------
pub const SHN_UNDEF: u16 = 0; /* Undefined section */
pub const SHN_LORESERVE: u16 = 0xff00; /* Start of reserved indices */
pub const SHN_LOPROC: u16 = 0xff00; /* Start of processor-specific */
pub const SHN_BEFORE: u16 = 0xff00; /* Order section before all others (Solaris). */
pub const SHN_AFTER: u16 = 0xff01; /* Order section after all others (Solaris). */
pub const SHN_HIPROC: u16 = 0xff1f; /* End of processor-specific */
pub const SHN_LOOS: u16 = 0xff20; /* Start of OS-specific */
pub const SHN_HIOS: u16 = 0xff3f; /* End of OS-specific */
pub const SHN_ABS: u16 = 0xfff1; /* Associated symbol is absolute */
pub const SHN_COMMON: u16 = 0xfff2; /* Associated symbol is common */
pub const SHN_XINDEX: u16 = 0xffff; /* Index is in extra table. */
pub const SHN_HIRESERVE: u16 = 0xffff; /* End of reserved indices */
const_group_with_fmt! {
pub struct ShType(u32): "Section header type"
pub const SHT_NULL = 0; /* Section header table entry unused */
pub const SHT_PROGBITS = 1; /* Program data */
pub const SHT_SYMTAB = 2; /* Symbol table */
pub const SHT_STRTAB = 3; /* String table */
pub const SHT_RELA = 4; /* Relocation entries with addends */
pub const SHT_HASH = 5; /* Symbol hash table */
pub const SHT_DYNAMIC = 6; /* Dynamic linking information */
pub const SHT_NOTE = 7; /* Notes */
pub const SHT_NOBITS = 8; /* Program space with no data (bss) */
pub const SHT_REL = 9; /* Relocation entries, no addends */
pub const SHT_SHLIB = 10; /* Reserved */
pub const SHT_DYNSYM = 11; /* Dynamic linker symbol table */
pub const SHT_INIT_ARRAY = 14; /* Array of constructors */
pub const SHT_FINI_ARRAY = 15; /* Array of destructors */
pub const SHT_PREINIT_ARRAY = 16; /* Array of pre-constructors */
pub const SHT_GROUP = 17; /* Section group */
pub const SHT_SYMTAB_SHNDX = 18; /* Extended section indices */
pub const SHT_NUM = 19; /* Number of defined types. */
pub const SHT_GNU_ATTRIBUTES = 0x6ffffff5; /* Object attributes. */
pub const SHT_GNU_HASH = 0x6ffffff6; /* GNU-style hash table. */
pub const SHT_GNU_LIBLIST = 0x6ffffff7; /* Prelink library list */
pub const SHT_CHECKSUM = 0x6ffffff8; /* Checksum for DSO content. */
pub const SHT_SUNW_move = 0x6ffffffa;
pub const SHT_SUNW_COMDAT = 0x6ffffffb;
pub const SHT_SUNW_syminfo = 0x6ffffffc;
pub const SHT_GNU_verdef = 0x6ffffffd; /* Version definition section. */
pub const SHT_GNU_verneed = 0x6ffffffe; /* Version needs section. */
pub const SHT_GNU_versym = 0x6fffffff; /* Version symbol table. */
pub const SHT_LOPROC = 0x70000000; /* Start of processor-specific */
pub const SHT_HIPROC = 0x7fffffff; /* End of processor-specific */
pub const SHT_LOUSER = 0x80000000; /* Start of application-specific */
pub const SHT_HIUSER = 0x8fffffff; /* End of application-specific */
}
pub const SHT_LOOS: u32 = 0x60000000; /* Start OS-specific. */
pub const SHT_LOSUNW: u32 = 0x6ffffffa; /* Sun-specific low bound. */
pub const SHT_HISUNW: u32 = 0x6fffffff; /* Sun-specific high bound. */
pub const SHT_HIOS: u32 = 0x6fffffff; /* End OS-specific type */
const_group_with_fmt! {
pub struct RX86_64(u32): "x86_64 Relocation type"
pub const R_X86_64_NONE = 0; /* No reloc */
pub const R_X86_64_64 = 1; /* Direct 64 bit */
pub const R_X86_64_PC32 = 2; /* PC relative 32 bit signed */
pub const R_X86_64_GOT32 = 3; /* 32 bit GOT entry */
pub const R_X86_64_PLT32 = 4; /* 32 bit PLT address */
pub const R_X86_64_COPY = 5; /* Copy symbol at runtime */
pub const R_X86_64_GLOB_DAT = 6; /* Create GOT entry */
pub const R_X86_64_JUMP_SLOT = 7; /* Create PLT entry */
pub const R_X86_64_RELATIVE = 8; /* Adjust by program base */
pub const R_X86_64_GOTPCREL = 9; /* 32 bit signed PC relative offset to GOT */
pub const R_X86_64_32 = 10; /* Direct 32 bit zero extended */
pub const R_X86_64_32S = 11; /* Direct 32 bit sign extended */
pub const R_X86_64_16 = 12; /* Direct 16 bit zero extended */
pub const R_X86_64_PC16 = 13; /* 16 bit sign extended pc relative */
pub const R_X86_64_8 = 14; /* Direct 8 bit sign extended */
pub const R_X86_64_PC8 = 15; /* 8 bit sign extended pc relative */
pub const R_X86_64_DTPMOD64 = 16; /* ID of module containing symbol */
pub const R_X86_64_DTPOFF64 = 17; /* Offset in module's TLS block */
pub const R_X86_64_TPOFF64 = 18; /* Offset in initial TLS block */
pub const R_X86_64_TLSGD = 19; /* 32 bit signed PC relative offset to two GOT entries for GD symbol */
pub const R_X86_64_TLSLD = 20; /* 32 bit signed PC relative offset to two GOT entries for LD symbol */
pub const R_X86_64_DTPOFF32 = 21; /* Offset in TLS block */
pub const R_X86_64_GOTTPOFF = 22; /* 32 bit signed PC relative offset to GOT entry for IE symbol */
pub const R_X86_64_TPOFF32 = 23; /* Offset in initial TLS block */
pub const R_X86_64_PC64 = 24; /* PC relative 64 bit */
pub const R_X86_64_GOTOFF64 = 25; /* 64 bit offset to GOT */
pub const R_X86_64_GOTPC32 = 26; /* 32 bit signed pc relative offset to GOT */
pub const R_X86_64_GOT64 = 27; /* 64-bit GOT entry offset */
pub const R_X86_64_GOTPCREL64 = 28; /* 64-bit PC relative offset to GOT entry */
pub const R_X86_64_GOTPC64 = 29; /* 64-bit PC relative offset to GOT */
pub const R_X86_64_GOTPLT64 = 30; /* like GOT64, says PLT entry needed */
pub const R_X86_64_PLTOFF64 = 31; /* 64-bit GOT relative offset to PLT entry */
pub const R_X86_64_SIZE32 = 32; /* Size of symbol plus 32-bit addend */
pub const R_X86_64_SIZE64 = 33; /* Size of symbol plus 64-bit addend */
pub const R_X86_64_GOTPC32_TLSDESC = 34; /* GOT offset for TLS descriptor. */
pub const R_X86_64_TLSDESC_CALL = 35; /* Marker for call through TLS descriptor. */
pub const R_X86_64_TLSDESC = 36; /* TLS descriptor. */
pub const R_X86_64_IRELATIVE = 37; /* Adjust indirectly by program base */
pub const R_X86_64_RELATIVE64 = 38; /* 64-bit adjust by program base */
/* 39 Reserved was R_X86_64_PC32_BND */
/* 40 Reserved was R_X86_64_PLT32_BND */
pub const R_X86_64_GOTPCRELX = 41; /* Load from 32 bit signed pc relative offset to GOT entry without REX prefix, relaxable. */
pub const R_X86_64_REX_GOTPCRELX = 42; /* Load from 32 bit signed pc relative offset to GOT entry with REX prefix, relaxable. */
pub const R_X86_64_NUM = 43;
}