Expand description
A versatile Rust library designed for loading ELF dynamic libraries from memory or from files.
This library serves three purposes:
- Provide a pure Rust alternative to musl ld.so or glibc ld.so.
- Provide loading ELF dynamic libraries support for
#![no_std]targets. - Easily swap out symbols in shared libraries with your own custom symbols at runtime
Additional, it integrates seamlessly with the system’s dynamic linker in std environments when the ldso feature is enabled.
Currently, it supports x86_64, x86, RV64, and AArch64 architectures.
§Examples
use dlopen_rs::ELFLibrary;
use std::path::Path;
let path = Path::new("./target/release/libexample.so");
let libc = ELFLibrary::sys_load("libc.so.6").unwrap();
let libgcc = ELFLibrary::sys_load("libgcc_s.so.1").unwrap();
let libexample = ELFLibrary::from_file(path)
.unwrap()
.relocate(&[libgcc, libc])
.unwrap();
let add = unsafe {
libexample
.get::<fn(i32, i32) -> i32>("add")
.unwrap()
};
println!("{}", add(1,1));