Crate elf_loader

Source
Expand description

§elf_loader

A safe, lightweight, extensible, and high-performance library for loading ELF files.

§Usage

elf_loader can load various ELF files and provides interfaces for extended functionality. It can be used in the following areas:

  • Use it as an ELF file loader in operating system kernels
  • Use it to implement a Rust version of the dynamic linker
  • Use it to load ELF dynamic libraries on embedded devices

§Example

use elf_loader::{Loader, mmap::MmapImpl, object::ElfFile};
use std::collections::HashMap;

fn print(s: &str) {
    println!("{}", s);
}
// Symbols required by dynamic library liba.so
let mut map = HashMap::new();
map.insert("print", print as _);
let pre_find = |name: &str| -> Option<*const ()> { map.get(name).copied() };
// Load dynamic library liba.so
let mut loader = Loader::<MmapImpl>::new();
let liba = loader
    .easy_load_dylib(ElfFile::from_path("target/liba.so").unwrap())
    .unwrap();
    // Relocate symbols in liba.so
let a = liba.easy_relocate([].iter(), &pre_find).unwrap();
// Call function a in liba.so
let f = unsafe { a.get::<fn() -> i32>("a").unwrap() };
f();

Modules§

abi
Contains ELF constants defined in the ELF gABI and various extensions
arch
Contains content related to the CPU instruction set
dynamic
Parsing .dynamic section
mmap
Map memory to address space
object
The original elf object
segment
The Memory mapping of elf object

Macros§

load
Load a elf file into memory
load_dylib
Load a dynamic library into memory
load_exec
Load a executable file into memory

Structs§

CoreComponent
The core part of an elf object
CoreComponentRef
CoreComponentRef is a version of CoreComponent that holds a non-owning reference to the managed allocation.
ElfDylib
An unrelocated dynamic library
ElfExec
An unrelocated executable file
Loader
The elf object loader
RelocatedDylib
A dynamic library that has been relocated
RelocatedExec
A executable file that has been relocated
Symbol
A symbol from elf object
UserData
User-defined data associated with the loaded ELF file

Enums§

Elf
An unrelocated elf file
Error
elf_loader error types

Functions§

set_global_scope
Set the global scope, lazy binding will look for the symbol in the global scope.

Type Aliases§

Result