Rustld
A modern x86_64 & AArch64 ELF loader (static & dynamic linker + compatible glibc & musl) written in Rust
Build
# Need gcc to compile
# Need nightly toolchain
# Run any binary (static, glibc, musl) on host arch
# If you want to embed the custom linker path into your binary
&& &&
# Build C wrapper example using rustld.h (links against librustld.so)
Notes
- On modern systemd-based hosts, runtime NSS backends are restricted to
libnss_files.so.2andlibnss_dns.so.2by default. This keeps threaded resolver paths stable for commands likecurlandgetent. - If you need the full host NSS stack for debugging, set
RUSTLD_ALLOW_UNSAFE_SYSTEMD_NSS=1before runningrustld. That disables the safety gate and may reintroduce intermittent crashes on newer glibc hosts.
Run from the SDK
// In Rust:
// See exact implementation in ./examples/rustld.rs
// With syscall trampoline obfuscation:
new_with_obf.execute_from_bytes;
// Without obfuscation:
new.execute_from_bytes;
// Optional explicit entrypoint:
new_with_obf.execute_from_bytes_with_entry;
// In C:
// See exact implementation in ./examples/rustld_c.c
// Last argument: 1 = indirect trampoline syscalls
// 0 = direct inline syscalls
int32_t rc = ;
// Optional explicit entrypoint override
int32_t rc2 = ;
Build & Run AArch64 From x86_64 host
# From repo root, create linker wrapper
# Build AArch64 rustld
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=./tools/zigcc-aarch64-gnu.sh \
# Works with hello_arm64_glibc_static, hello_arm64_musl, hello_arm64_musl_static
# If you want to run all the test suite in one command
RUSTLD_X86=./target/release/examples/rustld AARCH64_ROOT=/tmp/aarch64-root
Known Limitations
- Loading
/usr/bin/fishthroughrustldis currently unstable in PTY mode and can abort after startup when typing commands.
References:
https://github.com/bminor/glibc/blob/master/elf/rtld.c
https://github.com/kraj/musl/blob/kraj/master/ldso/dynlink.c
https://github.com/5-pebbles/miros
https://github.com/pauldcs/macho-loader-rs
https://github.com/apple-oss-distributions/dyld/blob/main/dyld/Loader.cpp