ld-so-cache
A comprehensive Rust parser for Linux ld.so.cache files with 100% compatibility with ldconfig output.
Overview
The ld.so.cache file is used by the Linux dynamic linker to quickly locate shared libraries. This crate provides a complete parser that can read both legacy (ld.so-1.7.0) and modern (glibc) cache formats, extracting library names, paths, and hardware capability information.
Features
- Complete Format Support: Handles both old (ld.so-1.7.0) and new (glibc) cache formats
- Hardware Capabilities: Parses hardware capability flags including ISA levels and processor features
- Extension Support: Handles cache extensions for future format enhancements
- Error Resilience: Gracefully handles corrupted or truncated cache files
- 100% ldconfig Compatibility: Produces identical output to
ldconfig -pacross many major distributions - Cross-Platform: Works on any platform that can read the cache files
Verified Compatibility
This parser has been tested against real cache files from:
- Debian: Bookworm, Trixie
- Ubuntu: Jammy (22.04), Noble (24.04), Questing (25.04)
- AlmaLinux: 8, 9, 10
- Red Hat: UBI 8
All tests show exact matches with ldconfig -p output.
Quick Start
Library Usage
use parse_ld_cache;
use fs;
Command Line Usage
The crate includes a CLI tool for inspecting cache files:
# Parse the system cache
# Parse a specific cache file
# Show detailed information including hardware capabilities
# Output in JSON format
# Show only cache statistics
Cache Formats
Legacy Format (ld.so-1.7.0)
The old format provides basic library name to path mappings:
use OldFileEntry;
let entry = OldFileEntry ;
Modern Format (glibc)
The new format includes hardware capabilities and extensions:
use NewFileEntry;
let entry = NewFileEntry ;
// Extract ISA level (bits 52-61)
let isa_level = & 0x3ff;
// Check for extension flag (bit 62)
let has_extensions = entry.hwcap & != 0;
// Get CPU features (bits 0-51)
let cpu_features = entry.hwcap & ;
Hardware Capabilities
The parser correctly decodes hardware capability information:
- ISA Levels: x86-64-v2, x86-64-v3, etc. (bits 52-61)
- Extension Flag: Indicates additional capability data (bit 62)
- CPU Features: Various processor features like SSE, AVX (bits 0-51)
- Architecture: i386, x86-64, libx32 from flags field
Error Handling
The library provides comprehensive error handling:
use ;
match parse_ld_cache
JSON Output
The library supports JSON serialization with proper formatting:
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Or install the CLI tool:
Documentation
Full API documentation is available at docs.rs.
The library includes extensive documentation with examples for all public APIs.
Testing
The crate includes comprehensive tests:
- Unit Tests: All core parsing functionality
- Integration Tests: Real cache files from multiple distributions
- Compatibility Tests: Verification against
ldconfig -poutput - Documentation Tests: All code examples are tested
Run tests with:
License
This project is licensed under the CC0 License - see the LICENSE.md file for details.
AI Disclaimer
This library was built with the help of Claude Code. This README was significantly written by Claude. I wanted to get this quickly built, so I took a shortcut.