macaw-base
Safe HaskellNone
LanguageHaskell2010

Data.Macaw.Memory.ElfLoader.DynamicDependencies

Description

Functionality for computing the names and addresses of PLT stub functions in a dynamically linked ELF binary.

Note that the API in this library is somewhat experimental, and as we further develop the underlying approach (see Note [Dynamic lookup scope]), we may need to change the API accordingly.

Synopsis

Documentation

loadDynamicDependencies Source #

Arguments

:: forall (w :: Nat). ElfMachine

The architecture of the main binary (x86-64, AArch32, etc.)

-> ElfClass w

Whether the main binary is 32-bit or 64-bit

-> FilePath

The directory in which the shared libraries live

-> ElfHeaderInfo w

The main binary's ELF header info

-> FilePath

The main binary's path

-> IO [(ElfHeaderInfo w, FilePath)]

The shared libraries in order of global lookup scope, paired with their file paths

Given a binary, load all of the shared libraries that it transitively depends on, returning the order in which they were encountered in a breadth-first search. Returning them in this order is important since we rely on the assumption that the binaries are in the same order as the global lookup scope. See Note [Dynamic lookup scope].

This function makes a couple of simplifying assumptions about how shared libraries work that are not true in general:

  • All of the shared libraries that the main binary depends on are located in a single directory.
  • None of the binaries use dlopen, which can load additional shared libraries at runtime.

parseDynNeeded Source #

Arguments

:: forall (w :: Nat). ElfHeaderInfo w 
-> FilePath

The path to the ELF file

-> Maybe (Either DynamicLoadingError [ByteString]) 

Get values of DT_NEEDED entries in an ELF file. If this is not a dynamic executable, then Nothing is returned.

data DynamicLoadingError where Source #

Constructors

NonElfBinaryFormat :: FilePath -> DynamicLoadingError

Encountered a non-ELF binary format, which is not supported.

ElfDynamicParseError :: FilePath -> DynamicError -> DynamicLoadingError

Encountered an error when parsing a dynamic section in an ELF binary.

ElfDynamicNeededError :: FilePath -> String -> DynamicLoadingError

Encountered an error when parsing the DT_NEEDED entries in a dynamic ELF binary.

ElfVirtualAddressMapError :: FilePath -> DynamicLoadingError

Could not constuct a virtual address map for an ELF binary.

ElfMultipleDynamicHeaders :: FilePath -> DynamicLoadingError

Encountered multiple PT_DYNAMIC program headers when parsing an ELF binary.

ElfNonDynamicSharedLib :: FilePath -> DynamicLoadingError

Encountered a shared library that is not dynamically linked.

SoMismatchedElfMachine :: ElfMachine -> ElfMachine -> DynamicLoadingError

A provided shared object had a different ELF machine value than the main binary. The first argument is the ElfMachine for the shared object and the second argument is the ElfMachine for the main binary.

SoMismatchedElfClass :: forall (w :: Nat) (w' :: Nat). ElfClass w -> ElfClass w' -> DynamicLoadingError

A provided shared object had a different ELF class value than the main binary. The first argument is the ElfClass for the shared object and the second argument is the ElfClass for the main binary.