Crate dlopen_rs

Source
Expand description

A pure-rust library designed for loading ELF dynamic libraries from memory or from files.

This library serves four purposes:

  1. Provide a pure Rust alternative to musl ld.so or glibc ld.so.
  2. Provide loading ELF dynamic libraries support for #![no_std] targets.
  3. Easily swap out symbols in shared libraries with your own custom symbols at runtime
  4. Faster than ld.so in most cases (loading dynamic libraries and getting symbols)

Additional, it integrates seamlessly with the system’s dynamic linker in std environments when the ldso feature is enabled. Currently, it supports x86_64, 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, None)
   	.unwrap()
   	.relocate(&[libgcc, libc])
    .finish()
   	.unwrap();

let add = unsafe {
	libexample
	.get::<fn(i32, i32) -> i32>("add")
	.unwrap()
};
println!("{}", add(1,1));

Structs§

Enums§

  • dlopen-rs error type

Type Aliases§