#elf #musl #dependencies #glibc #ldd #api-bindings

elb-dl

A library that resolves ELF dependencies without loading and executing them

2 unstable releases

new 0.2.0 Mar 31, 2025
0.1.0 Mar 30, 2025

#2 in #musl

44 downloads per month
Used in elb-cli

MIT/Apache

195KB
5K SLoC

elb-dl

Crates.io Version Docs dependency status

A library that resolves ELF dependencies without loading and executing them.

Based on elb crate.

Examples

Resolve immediate dependencies

use elb_dl::{DynamicLoader, Error, glibc};

fn resolve_immediate() -> Result<(), Error> {
    let loader = DynamicLoader::options()
        .search_dirs(glibc::get_search_dirs("/")?)
        .new_loader();
    let (_elf, deps) = loader.resolve_dependencies("/bin/sh")?;
    for path in deps.iter() {
        eprintln!("{:?}", path);
    }
    Ok(())
}

Resolve dependencies recursively

use elb_dl::{DynamicLoader, Error, glibc};
use std::collections::{BTreeSet, VecDeque};
use std::path::Path;

fn resolve_all() -> Result<(), Error> {
    let loader = DynamicLoader::options()
        .search_dirs(glibc::get_search_dirs("/")?)
        .new_loader();
    let mut all_deps = BTreeSet::new();
    let mut queue = VecDeque::new();
    queue.push_back(Path::new("/bin/sh").to_path_buf());
    while let Some(path) = queue.pop_front() {
        let (_elf, deps) = loader.resolve_dependencies(&path)?;
        for path in deps.into_iter() {
            if all_deps.insert(path.clone()) {
                // Recurse into previously unseen dependency.
                queue.push_back(path);
            }
        }
    }
    // Print deduplicated and ordered list of depedencies.
    for path in all_deps.iter() {
        eprintln!("{:?}", path);
    }
    Ok(())
}

Dependencies

~0.4–1MB
~21K SLoC