elf_loader 0.16.0

A no_std-friendly ELF loader and runtime linker for Rust.
Documentation
#![allow(dead_code)]

use elf_loader::{Loader, Relocator, image::LoadedCore, input::ElfBinary};
use gen_elf::{Arch, DylibWriter, ElfWriteOutput, ElfWriterConfig, RelocEntry, SymbolDesc};

pub(crate) fn write_test_dylib(relocs: &[RelocEntry], symbols: &[SymbolDesc]) -> ElfWriteOutput {
    write_test_dylib_with_config(
        ElfWriterConfig::default().with_bind_now(true),
        relocs,
        symbols,
    )
}

pub(crate) fn write_test_dylib_with_config(
    config: ElfWriterConfig,
    relocs: &[RelocEntry],
    symbols: &[SymbolDesc],
) -> ElfWriteOutput {
    DylibWriter::with_config(Arch::current(), config)
        .write(relocs, symbols)
        .expect("failed to generate test dylib")
}

pub(crate) fn load_relocated_dylib(
    loader: &mut Loader,
    name: &str,
    output: &ElfWriteOutput,
) -> LoadedCore<()> {
    Relocator::new()
        .run(
            loader
                .load_dylib(ElfBinary::new(name, &output.data))
                .expect("failed to load test dylib"),
        )
        .relocate()
        .expect("failed to relocate test dylib")
}