A high-performance, pure-Rust implementation of an ELF dynamic linker.
dlopen-rs is a full-featured dynamic linker implemented entirely in Rust. It provides a set of Rust-friendly interfaces for manipulating dynamic libraries, as well as C-compatible interfaces consistent with libc behavior.
- Pure Rust: Zero dependency on C runtime for core loading and linking logic.
#![no_std]Support: Can be used in bare-metal environments, kernels, or embedded systems.LD_PRELOADCompatible: Can replacelibc'sdlopen,dlsym, anddl_iterate_phdrwithout code modification.- Modern API: Offers a safe and ergonomic Rust API for dynamic library management.
Add dlopen-rs to your Cargo.toml:
[dependencies]
dlopen-rs = "0.8.0"You can use dlopen-rs to intercept standard library calls:
# 1. Compile the compatibility library
$ cargo build -r -p cdylib
# 2. Compile your application/example
$ cargo build -r -p dlopen-rs --example preload
# 3. Interpose libc implementations
$ RUST_LOG=trace LD_PRELOAD=./target/release/libdlopen.so ./target/release/examples/preload| Architecture | Load Support | Lazy Binding | Test Status |
|---|---|---|---|
| x86_64 | ✅ | ✅ | ✅ (CI) |
| aarch64 | ✅ | ✅ | 🛠️ (Manual) |
| riscv64 | ✅ | ✅ | 🛠️ (Manual) |
use dlopen_rs::{ElfLibrary, OpenFlags, Result};
fn main() -> Result<()> {
// 1. Load the library
let lib = ElfLibrary::dlopen("./target/release/libexample.so", OpenFlags::RTLD_LAZY)?;
// 2. Get and call a simple function: fn(i32, i32) -> i32
let add = unsafe { lib.get::<fn(i32, i32) -> i32>("add")? };
println!("add(1, 1) = {}", add(1, 1));
Ok(())
}| Feature | Default | Description |
|---|---|---|
use-syscall |
❌ | Uses direct syscalls to load libraries (useful for no_std). |
version |
❌ | Enables support for ELF symbol versioning. |
std |
✅ | Enables standard library integration. Disable for no_std environments. |
Licensed under the Apache License 2.0.
Contributions are welcome! If you encounter issues or have ideas for performance improvements, please open an Issue or PR. For specific GDB-related debugging issues, please refer to TroubleshootingGdb.md.
Minimum Supported Rust Version (MSRV): 1.93.0 or higher.