rcrt1 is a Rust library developed by the Enarx project for relocating ELF dynamic symbols. It serves as a replacement for the traditional C runtime (crt1) and handles the crucial task of properly loading and relocating ELF binaries at runtime, specifically focusing on relocating dynamic symbols.
- Dynamic Relocation: Provides functionality to relocate ELF dynamic symbols in a static Position Independent Executable (PIE)
- No Standard Library: Operates as a
no_std
crate, making it suitable for system-level programming without relying on the Rust standard library - ELF Support: Specifically handles ELF64 binaries using the Goblin library for parsing ELF structures
- x86_64 Focus: Primarily targets x86_64 architecture, with specific handling for x86_64 relative relocations
- Dynamic Symbol Relocation: The
dyn_reloc
function handles the relocation of dynamic symbols by applying base address offsets - Runtime Initialization: The
rcrt
function serves as a replacement for the traditionalcrt1.o
, handling initial program setup from the stack pointer - Startup Macro: Provides a convenient
x86_64_linux_startup!
macro for defining the program entry point
- Handles both REL and RELA relocation types for ELF binaries
- Works with Position Independent Executables (PIEs)
- Requires specific compiler optimizations in the binary's Cargo.toml for correct operation
- Manages program headers and the
_DYNAMIC
section to calculate load offsets - Uses naked functions and assembly for low-level operations
When using this crate, specific compiler optimizations must be set in the binary's Cargo.toml:
[profile.dev.package.rcrt1]
opt-level = 3
debug-assertions = false
overflow-checks = false