macaw-base
CopyrightGalois Inc 2016-18
Maintainerjhendrix@galois.com
Safe HaskellNone
LanguageHaskell2010

Data.Macaw.Memory.ElfLoader

Description

Operations for creating a view of memory from an elf file.

Synopsis

Documentation

memoryForElf :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) Source #

Load allocated Elf sections into memory, using the section table information map.

Normally, Elf uses segments for loading, but the section information tends to be more precise.

The return value includes a list of all function symbols (STT_FUNC Symbol table entry types).

memoryForElf' Source #

Arguments

:: forall (w :: Nat). LoadOptions 
-> ElfHeaderInfo w 
-> (SymtabEntry ByteString (ElfWordType w) -> Bool)

Filter on symbol table entries

-> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) 

Deprecated: Use memoryForElf

memoryForElfAllSymbols :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, [MemSymbol w], [MemLoadWarning], [SymbolResolutionError]) Source #

Load allocated Elf sections into memory, using the section table information map.

Normally, Elf uses segments for loading, but the section information tends to be more precise.

The return value includes a list of *all* symbols, whether they are functions or not.

memoryForElfSections :: forall (w :: Nat). ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #

Load allocated Elf sections into memory.

This is only used for object files.

memoryForElfSegments :: forall (w :: Nat). LoadOptions -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #

Load an elf file into memory by parsing segments.

memoryForElfSegments' :: forall (w :: Nat). RegionIndex -> Integer -> ElfHeaderInfo w -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) Source #

Load an elf file into memory by parsing segments.

type SectionIndexMap (w :: Nat) = Map Word16 (MemSegmentOff w) Source #

Maps section indices that are loaded in memory to their associated base address and section contents.

The base address is expressed in terms of the underlying memory segment.

data MemLoadWarning Source #

Constructors

SectionNotAlloc !SectionName 
MultipleSectionsWithName !SectionName 
MultipleDynamicSegments 
OverlappingLoadableSegments 
UnsupportedSection !SectionName 
UnknownDefinedSymbolBinding !SymbolName ElfSymbolBinding 
UnknownDefinedSymbolType !SymbolName ElfSymbolType 
UnknownUndefinedSymbolBinding !SymbolName ElfSymbolBinding 
UnknownUndefinedSymbolType !SymbolName ElfSymbolType 
ExpectedSectionSymbolNameEmpty !SymbolName 
ExpectedSectionSymbolLocal 
InvalidSectionSymbolIndex !ElfSectionIndex 
UnsupportedProcessorSpecificSymbolIndex !SymbolName !ElfSectionIndex 
MultipleRelocationTables

Issued if the file contains multiple relocation tables.

RelocationParseFailure !String 
DynamicTagsOutOfRange !ElfDynamicTag !ElfDynamicTag !Word64 !Word64

The range referenced by the dynamic tags was range.

DynamicTagPairMismatch !ElfDynamicTag !ElfDynamicTag

We expected either both tags or neither.

DynamicMultipleTags !ElfDynamicTag

We expected at most a single value of the given tag, but failed multiple.

AndroidRelWithNonzeroAddend

The DT_ANDROID_REL section contains Android relocations with non-zero addends.

AndroidRelDecodingError !ElfDynamicTag !AndroidDecodeError

We could not decode the table identified by the given dynamic tag.

MultipleRelocationsAtAddr !Word64

Multiple relocations at the given offset

IgnoreRelocation !RelocationError

IgnoreRelocation err warns we ignored a relocation.

ShdrPhdrOverlap

A section header overlaps with a program header.

Instances

Instances details
Show MemLoadWarning Source # 
Instance details

Defined in Data.Macaw.Memory.ElfLoader

resolveElfContents Source #

Arguments

:: forall (w :: Nat). LoadOptions

Options for loading contents

-> ElfHeaderInfo w 
-> Either String ([String], Memory w, Maybe (MemSegmentOff w), [MemSymbol w]) 

This interprets the Elf file to construct the initial memory, entry points, and functions symbols.

If it encounters a fatal error it returns the error message in the left value, and otherwise it returns the interpreted information as a 4-tuple of: warnings, the initial memory image, possible entry points (e.g. for an executable or shared library), and function symbols.

elfAddrWidth :: forall (w :: Nat). ElfClass w -> AddrWidthRepr w Source #

Return the addr width repr associated with an elf class

adjustedLoadRegionIndex :: ElfType -> LoadOptions -> RegionIndex Source #

Return default region index to use when loading.

Symbols

data MemSymbol (w :: Nat) Source #

Type for representing a symbol that has a defined location in this memory.

Constructors

MemSymbol 

Fields

Instances

Instances details
MemWidth w => Show (MemSymbol w) Source # 
Instance details

Defined in Data.Macaw.Memory.ElfLoader

Eq (MemSymbol w) Source # 
Instance details

Defined in Data.Macaw.Memory.ElfLoader

Methods

(==) :: MemSymbol w -> MemSymbol w -> Bool #

(/=) :: MemSymbol w -> MemSymbol w -> Bool #

Ord (MemSymbol w) Source # 
Instance details

Defined in Data.Macaw.Memory.ElfLoader

data SymbolResolutionError Source #

Error when resolving symbols.

Constructors

EmptySymbolName !Int !ElfSymbolType

Symbol names must be non-empty

UndefSymbol !ByteString

Symbol was in the undefined section.

CouldNotResolveAddr !ByteString

Symbol address could not be resolved.

MultipleSymbolTables

The elf file contained multiple symbol tables

data SymbolTable (w :: Nat) Source #

This wraps a callback function that lets users lookup symbol information by index from the Elf file.

It is implemented using a callback function as the Elf dynamic section doesn't provide an explicit number of symbol table elements, and we decided not to depend on meta data such as section names that could be stripped from executables/shared objects.

Constructors

NoSymbolTable 
StaticSymbolTable !(Vector (SymtabEntry ByteString (ElfWordType w))) 
DynamicSymbolTable !(DynamicSection w) !(VirtAddrMap w) !VersionDefMap !VersionReqMap 

Re-exports