Module Tolk.Elf
Relocatable ELF object loading.
Parses 64-bit little-endian ELF relocatable objects (ET_REL) and lays out their allocatable sections into a contiguous flat image. Section and relocation metadata is preserved for backend-specific loaders, but no machine-specific relocations are applied.
Types
type section = private {name : string;(*The ELF section name (e.g.
*)".text",".data",".bss").addr : int;size : int;(*Size of the section in bytes.
*)content : Stdlib.Bytes.t;(*Section contents. For
*)SHT_NOBITSsections (e.g..bss),contentis a zero-filled buffer of lengthsize.
}The type for sections after image layout.
type symbol = private {name : string;(*The symbol name from the string table.
*)shndx : int;(*Section header index the symbol belongs to.
*)0for undefined symbols.value : int;(*Symbol value: byte offset from the start of the symbol's section.
*)
}The type for symbols from the object's symbol table.
type reloc = private {offset : int;symbol : symbol;r_type : int;(*Machine-specific relocation type (e.g.
*)R_AARCH64_CALL26,R_X86_64_PC32).addend : int;(*Relocation addend.
*)0forSHT_RELentries.
}The type for relocations anchored at absolute image offsets.
The type for a laid-out relocatable ELF object. Holds the flat image, resolved section addresses, symbols, and pending relocations.
Loading
val load : ?force_section_align:int -> Stdlib.Bytes.t -> tload ?force_section_align obj parses ELF relocatable object obj and lays out its allocatable sections into a flat image.
Sections with a fixed address (sh_addr <> 0) are placed first. Remaining allocatable sections are appended sequentially, each aligned to the maximum of the ELF section alignment and force_section_align (defaults to 1).
Raises Invalid_argument if obj is not a valid 64-bit little-endian ELF relocatable object.
Accessors
val image : t -> Stdlib.Bytes.timage t is the flat image built from allocatable sections.
sections t is all object sections in section-header order, with addr set to their final image offsets.
relocs t is the list of relocations with offsets resolved to absolute image positions.
Lookup
find_section t name is the section named name, if any.