Skip to main content

Module elf

Module elf 

Source
Expand description

ELF32 parser and symbol table loader.

Parses RISC-V 32-bit little-endian ELF files and extracts two things:

  1. Loadable segments (ElfImage) — PT_LOAD program headers copied into RAM by crate::emulator::Emulator::load_elf.
  2. Symbol table (SymbolTable) — STT_FUNC and STT_OBJECT symbols 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:

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 .symtab section.
SymbolTable
Symbol table extracted from an ELF .symtab section.

Enums§

ElfError
SymbolKind
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 .symtab section of an ELF32 RV32 file.