dlopen-rs
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.
🚀 Key Features
- 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.
🛠 Usage
As a Rust Library
Add dlopen-rs to your Cargo.toml:
[]
= "0.8.0"
As an LD_PRELOAD Replacement
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 Support
| Architecture | Load Support | Lazy Binding | Test Status |
|---|---|---|---|
| x86_64 | ✅ | ✅ | ✅ (CI) |
| aarch64 | ✅ | ✅ | 🛠️ (Manual) |
| riscv64 | ✅ | ✅ | 🛠️ (Manual) |
💻 Example
use ;
⚙️ Feature Flags
| 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. |
⚖️ License
Licensed under the Apache License 2.0.
🤝 Contribution
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.