Skip to main content

Crate alpm_soname

Crate alpm_soname 

Source
Expand description

§alpm-soname

A library and command line interface for looking up soname data in an ALPM context

§Examples

The examples below assume that the following shared object setup exists in a package file example-1.0.0-1-x86_64.pkg.tar.zst:

/usr/lib/libexample.so -> libexample.so.1
/usr/lib/libexample.so.1 -> libexample.so.1.0.0
/usr/lib/libexample.so.1.0.0

Here, /usr/lib/libexample.so.1.0.0 encodes the soname libexample.so.1 in its ELF dynamic section.

For the examples below, the environment variables are set as follows:

  • LIB_PACKAGE_PATH: example-1.0.0-1-x86_64.pkg.tar.zst
  • BIN_PACKAGE_PATH: application-1.0.0-1-x86_64.pkg.tar.zst

§Command Line

You can use the subcommands to find the sonames provided by a package and the sonames required by a package.

The -v option can be used to set the verbosity level. (e.g. -v for debug and -vv for trace)

§Finding Provisions

You can retrieve the sonames provided by the package:

alpm-soname get-provisions --lookup-dir 'lib:/usr/lib' "$LIB_PACKAGE_PATH" | tee "$OUTPUT_DIR/output.txt"

# lib:libexample.so.1
§Finding Dependencies

You can retrieve the sonames required by the package:

alpm-soname get-dependencies --lookup-dir 'lib:/usr/lib' "$BIN_PACKAGE_PATH" | tee "$OUTPUT_DIR/output.txt"

# lib:libexample.so.1
§Finding Raw Dependencies

get-dependencies subcommand only returns the soname dependencies, that have a matching entry in the package’s metadata.

If you are interested in all soname dependencies encoded in the ELF files of a package, you can use the get-raw-dependencies subcommand.

alpm-soname get-raw-dependencies $BIN_PACKAGE_PATH --output-format json | tee "$OUTPUT_DIR/output.txt"

# [{"name":"libc.so","version":"6"},{"name":"libexample.so","version":"1"}]

As demonstrated above, the output format can be set to json using the --output-format option.

To see which ELF files reference each dependency, add the --detail flag. When combined with JSON output, the command then returns a structured list of ELF paths with their dependencies.

§Library

§Finding Provisions
use std::{path::PathBuf, str::FromStr};

use alpm_soname::find_provisions;
use alpm_types::SonameLookupDirectory;

fn main() -> Result<(), alpm_soname::Error> {
  let provisions = find_provisions(
    PathBuf::from("example-1.0.0-x86_64.pkg.tar.zst"),
    SonameLookupDirectory::from_str("lib:/usr/lib")?,
  )?;

  println!("{provisions:?}"); // [ SonameV2 { ... }, ...]
  Ok(())
}
§Finding Dependencies
use std::{path::PathBuf, str::FromStr};

use alpm_soname::find_dependencies;
use alpm_types::SonameLookupDirectory;

fn main() -> Result<(), alpm_soname::Error> {
  let dependencies = find_dependencies(
    PathBuf::from("application-1.0.0-x86_64.pkg.tar.zst"),
    SonameLookupDirectory::from_str("lib:/usr/lib")?,
  )?;

  println!("{dependencies:?}"); // [ SonameV2 { ... }, ...]
  Ok(())
}

§Extracting Soname Data

use std::path::PathBuf;

use alpm_soname::extract_elf_sonames;

fn main() -> Result<(), alpm_soname::Error> {
  let elf_sonames = extract_elf_sonames(
    PathBuf::from("application-1.0.0-x86_64.pkg.tar.zst"),
  )?;

  println!("{elf_sonames:?}"); // [ ElfSonames { path: ..., sonames: [Soname { ... }, ...] }, ...]
  Ok(())
}

§Features

  • cli adds dependencies required for the alpm-soname command line interface.

§Contributing

Please refer to the contribution guidelines to learn how to contribute to this project.

§License

This project can be used under the terms of the Apache-2.0 or MIT. Contributions to this project, unless noted otherwise, are automatically licensed under the terms of both of those licenses.

Structs§

ElfSonames
Represents a shared library and its associated sonames.

Enums§

Error
The error that can occur when working with the library.

Functions§

extract_elf_sonames
Extracts the sonames from ELF files contained in a package.
find_dependencies
Finds the soname dependencies required by a package.
find_provisions
Finds the soname data provided by a package.