elf_loader 0.15.0

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

use elf_loader::{Loader, 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<M>(
    loader: &mut Loader<M>,
    name: &str,
    output: &ElfWriteOutput,
) -> LoadedCore<()>
where
    M: elf_loader::os::Mmap,
{
    loader
        .load_dylib(ElfBinary::new(name, &output.data))
        .expect("failed to load test dylib")
        .relocator()
        .relocate()
        .expect("failed to relocate test dylib")
}