Expand description
ELF32 parser and symbol table loader.
Parses RISC-V 32-bit little-endian ELF files and extracts two things:
- Loadable segments (
ElfImage) —PT_LOADprogram headers copied into RAM bycrate::emulator::Emulator::load_elf. - Symbol table (
SymbolTable) —STT_FUNCandSTT_OBJECTsymbols used by the disassembler to resolve addresses to names.
§Usage
ⓘ
let data = std::fs::read("freertos.elf")?;
let image = elf::parse_elf(&data)?;
let syms = elf::parse_symbol_table(&data)?; // None if stripped§Symbol lookup
SymbolTable supports two lookup directions:
- Address → symbol:
SymbolTable::lookup_addr— used by the disassembler to annotate branch targets and call destinations. - Name → symbol:
SymbolTable::lookup_name— reserved for future breakpoint-by-name support.
Symbols with size == 0 (common in hand-written assembly) only match on
an exact address. Symbols with a known size match any address inside
[sym.addr, sym.addr + sym.size).
Structs§
- ElfImage
- A parsed ELF image ready to be loaded into emulator RAM.
- ElfSegment
- A loadable segment (
PT_LOAD) from an ELF file. - Symbol
- A resolved symbol from the
.symtabsection. - Symbol
Table - Symbol table extracted from an ELF
.symtabsection.
Enums§
- ElfError
- Symbol
Kind - The kind of an ELF symbol, derived from
st_type.
Functions§
- parse_
elf - Parse an ELF32 RV32 little-endian file and return its loadable segments.
- parse_
symbol_ table - Parse the
.symtabsection of an ELF32 RV32 file.