Update dwarf parsing to increase laziness and robustness.

This commit is contained in:
Joe Hendrix 2020-07-07 15:10:36 -07:00
parent c9218a9284
commit cbd16ed481
4 changed files with 878 additions and 661 deletions

View File

@ -1,5 +1,5 @@
name: macaw-base name: macaw-base
version: 0.3.15.1 version: 0.3.15.2
author: Galois, Inc. author: Galois, Inc.
maintainer: jhendrix@galois.com maintainer: jhendrix@galois.com
build-type: Simple build-type: Simple
@ -34,12 +34,8 @@ library
binary-symbols >= 0.1.3, binary-symbols >= 0.1.3,
bytestring, bytestring,
containers >= 0.5.8.1, containers >= 0.5.8.1,
<<<<<<< HEAD elf-edit >= 0.38,
elf-edit >= 0.35, galois-dwarf >= 0.2.2,
=======
elf-edit >= 0.37,
>>>>>>> Update elf-edit; export additional capabilities for Reopt.
galois-dwarf,
IntervalMap >= 0.5, IntervalMap >= 0.5,
lens >= 4.7, lens >= 4.7,
mtl, mtl,

View File

@ -478,7 +478,6 @@ ppApp pp a0 = runIdentity $ ppAppA (Identity . pp) a0
instance HasRepr (App f) TypeRepr where instance HasRepr (App f) TypeRepr where
typeRepr a = typeRepr a =
case a of case a of
MkTuple fieldTypes _ -> TupleTypeRepr fieldTypes
Eq _ _ -> knownRepr Eq _ _ -> knownRepr
Mux tp _ _ _ -> tp Mux tp _ _ _ -> tp
MkTuple fieldTypes _ -> TupleTypeRepr fieldTypes MkTuple fieldTypes _ -> TupleTypeRepr fieldTypes

File diff suppressed because it is too large Load Diff

View File

@ -1301,20 +1301,30 @@ insertAllocatedSection hdr symtab sectionMap regIdx nm = do
memoryForElfSections :: forall w memoryForElfSections :: forall w
. Elf w . Elf w
-> Either String (Memory w, SectionIndexMap w, [MemLoadWarning]) -> Either String (Memory w, SectionIndexMap w, [MemLoadWarning])
memoryForElfSections e = memoryForElfSections e = do
runMemLoader (toEndianness (Elf.elfData e)) (emptyMemory (elfAddrWidth (elfClass e))) $ do let hdr = Elf.elfHeader e
let hdr = Elf.elfHeader e -- Create map from section name to sections with that name.
-- Create map from section name to sections with that name. let sectionMap :: SectionNameMap w
let sectionMap :: SectionNameMap w sectionMap = foldlOf elfSections insSec Map.empty e
sectionMap = foldlOf elfSections insSec Map.empty e where insSec m sec = Map.insertWith (\new old -> old ++ new) (elfSectionName sec) [sec] m
where insSec m sec = Map.insertWith (\new old -> old ++ new) (elfSectionName sec) [sec] m -- Parse Elf symbol table
let symtab =
-- Parse Elf symbol table case Elf.elfSymtab e of
let symtab = [] -> NoSymbolTable
case Elf.elfSymtab e of symTab:_rest -> StaticSymbolTable (Elf.elfSymbolTableEntries symTab)
[] -> NoSymbolTable memoryForElfSections' hdr sectionMap symtab
symTab:_rest -> StaticSymbolTable (Elf.elfSymbolTableEntries symTab)
-- | Load allocated Elf sections into memory.
--
-- This is only used for object files. This version uses low-level types
-- for less complex parsing.
memoryForElfSections' :: forall w
. Elf.ElfHeader w -- ^ Header for elf
-> SectionNameMap w -- ^ Map from section name to contents.
-> SymbolTable w -- ^ Symbol table for names.
-> Either String (Memory w, SectionIndexMap w, [MemLoadWarning])
memoryForElfSections' hdr sectionMap symtab =
runMemLoader (toEndianness (Elf.headerData hdr)) (emptyMemory (elfAddrWidth (Elf.headerClass hdr))) $ do
-- Insert sections -- Insert sections
forM_ (zip [1..] allocatedSectionInfo) $ \(idx, (nm,_)) -> do forM_ (zip [1..] allocatedSectionInfo) $ \(idx, (nm,_)) -> do
insertAllocatedSection hdr symtab sectionMap idx nm insertAllocatedSection hdr symtab sectionMap idx nm