ldconfig - Portable Rust Implementation
A Rust implementation of ldconfig for building and managing glibc ld.so.cache files.
This library provides both a command-line tool and a high-level API for:
- Reading and exploring
ld.so.cachefiles - Parsing
ld.so.confconfiguration files - Building cache files by scanning library directories
- Writing cache files to disk
Supported Architectures
This implementation supports the following architectures with proper glibc cache flags:
- x86-64 (64-bit Intel/AMD) -
FLAG_X8664_LIB64 - AArch64 (ARM 64-bit) -
FLAG_AARCH64_LIB64 - RISC-V 64-bit (lp64d ABI with double-precision FP) -
FLAG_RISCV_FLOAT_ABI_DOUBLE - PowerPC 64-bit -
FLAG_POWERPC_LIB64 - i686 (32-bit x86) - Base ELF flag
- ARM (32-bit) -
FLAG_ARM_LIBHFfor hard-float, base flag for soft-float
All architecture flags match the official glibc ldconfig implementation.
Command-Line Usage
Print cache contents
# Print the system cache
# Print a specific cache file
Build/update cache
# Update system cache
# Build cache for a specific root (useful for cross-compilation)
# Write to a different cache file (don't overwrite system cache)
Library Usage
Add to your Cargo.toml:
[]
= "0.1"
Read and display a cache
use Cache;
let cache = from_file?;
// Display the entire cache (uses Display trait)
println!;
// Or iterate over entries
for entry in cache.entries.take
// Find specific libraries
for entry in cache.find
Build and write a cache
use ;
use Utf8Path;
// Parse ld.so.conf
let search_paths = from_file?;
// Build cache by scanning directories
let cache = builder
.prefix
.build?;
// Write to file
cache.write_to_file?;
Examples
The examples/ directory contains complete working examples:
# Build a cache from a sysroot
# Read and query a cache file
# Compare two caches (with ld-so-cache cross-validation)
API Overview
Cache - Reading and writing caches
SearchPaths - Configuration parsing
Testing
The library includes comprehensive testing through examples since it is fairly cumbersome to automate.
You may download any minimal docker image sporting glibc or use chroot-stages to download a Gentoo stage3
# Test with AArch64 libraries
# Test with RISC-V libraries
# Compare against reference implementation
The compare_caches example uses the ld-so-cache crate for cross-validation to ensure compatibility with existing tools.
Development
This code was written with the assistance of:
- Claude - AI assistant by Anthropic
- mistral-vibe - AI assistant by Mistral
The code is manually reviewed and should not contain hallucination on release, but single commits in the history can be nonsensical.
License
MIT