Relink is a high-performance runtime linker (JIT Linker) tailor-made for the Rust ecosystem. It efficiently parses various ELF formats—not only from traditional file systems but also directly from memory images—and performs flexible dynamic and static hybrid linking.
Whether you are developing OS kernels, embedded systems, JIT compilers, or building plugin-based applications, Relink provides a solid foundation with zero-cost abstractions, high-speed execution, and powerful extensibility.
Leveraging Rust's ownership system and smart pointers, Relink ensures safety at runtime.
- Lifetime Binding: Symbols retrieved from a library carry lifetime markers. The compiler ensures they do not outlive the library itself, erasing
use-after-freerisks. - Automatic Dependency Management: Uses
Arcto automatically maintain dependency trees between libraries, preventing a required library from being dropped prematurely.
// 🛡️ The compiler protects you:
let sym = unsafe { lib.get::<fn()>("plugin_fn")? };
drop(lib); // If the library is dropped here...
// sym(); // ❌ Compilation Error! The symbol's lifetime ends with the library.Relink supports mixing Relocatable Object files (.o) and Dynamic Shared Objects (.so). You can load a .o file just like a dynamic library and link its undefined symbols to the system or other loaded libraries at runtime.
By implementing the SymbolLookup and RelocationHandler traits, users can deeply intervene in the linking process.
- Symbol Interception: Intercept and replace external dependency symbols during loading. Perfect for function mocking, behavioral monitoring, or hot-patching.
- Custom Linking Logic: Take full control over symbol resolution strategies to build highly flexible plugin systems.
- Zero-Cost Abstractions: Built with Rust to provide near-native loading and symbol resolution speeds.
no_stdSupport: The core library has no OS dependencies, making it ideal for OS kernels, embedded devices, and bare-metal development.- Modern Features: Supports RELR for modern ELF optimization; supports Lazy Binding to improve cold-start times for large dynamic libraries.
| Scenario | The Relink Advantage |
|---|---|
| Plugin Architectures | Enables safer, finer-grained dynamic module loading than dlopen, supporting .o files as direct plugins. |
| JIT Compilers & Runtimes | Instantly link compiled machine code fragments without manual memory offset management. |
| OS/Kernel Development | Provides a high-quality loader prototype for user-space programs or dynamic kernel module loading. |
| Game Engine Hot-Reloading | Dynamically swap game logic modules for a "code-change-to-live-effect" development experience. |
| Embedded & Edge Computing | Securely update firmware modules or combine features dynamically on resource-constrained devices. |
| Security Research | Use the Hook mechanism to non-invasively analyze binary behavior and interactions. |
[dependencies]
elf_loader = "0.13" # Your runtime linking engine
use elf_loader::load_dylib;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Load the library and perform instant linking
let lib = load_dylib!("path/to/your_library.so")?
.relocator()
// Optional: Provide custom symbol resolution (e.g., export symbols from host)
.pre_find_fn(|sym_name| {
if sym_name == "my_host_function" {
Some(my_host_function as *const ())
} else {
None
}
})
.relocate()?; // Complete all relocations
// 2. Safely retrieve and call the function
let awesome_func = unsafe { lib.get::<fn(i32) -> i32>("awesome_func")? };
let result = awesome_func(42);
println!("Result: {}", result);
Ok(())
}
// A host function that can be called by the plugin
extern "C" fn my_host_function(value: i32) -> i32 {
value * 2
}Relink is committed to broad cross-platform support. Current support matrix:
| Architecture | Dynamic Linking | Lazy Binding | Hybrid Linking (.o) |
|---|---|---|---|
| x86_64 | ✅ | ✅ | ✅ |
| x86 | ✅ | ✅ | 🔶 |
| AArch64 | ✅ | ✅ | 🔶 |
| Arm | ✅ | ✅ | 🔶 |
| RISC-V 64/32 | ✅ | ✅ | 🔶 |
| LoongArch64 | ✅ | ✅ | 🔶 |
If you are interested in low-level systems, binary security, or linker internals, we’d love to have you!
- Open an Issue: Report bugs or propose your next big idea.
- Star the Project: Show your support for the developers! ⭐
- Code Contributions: PRs are always welcome—help us build the ultimate Rust runtime linker.
This project is dual-licensed under:
Choose the one that best suits your needs.
Relink — Empowering your projects with high-performance runtime linking. 🚀
