Skip to content

Commit

Permalink
Remove extra references to the original ELF
Browse files Browse the repository at this point in the history
  • Loading branch information
langston-barrett committed Dec 19, 2024
1 parent 57ebded commit a9ca082
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
10 changes: 4 additions & 6 deletions macaw-loader-aarch32/src/Data/Macaw/BinaryLoader/AArch32.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import Data.Word ( Word32 )
import qualified Data.Macaw.ARM as MA

data AArch32ElfData =
AArch32ElfData { elf :: EE.ElfHeaderInfo 32
, memSymbols :: [EL.MemSymbol 32]
AArch32ElfData { memSymbols :: [EL.MemSymbol 32]
, symbolIndex :: Map.Map (MM.MemAddr 32) BS.ByteString
}

Expand Down Expand Up @@ -60,8 +59,8 @@ aarch32EntryPoints loadedBinary =
where
offset = fromMaybe 0 (LC.loadOffset (MBL.loadOptions loadedBinary))
mem = MBL.memoryImage loadedBinary
addr = MM.memWord (offset + fromIntegral (EE.headerEntry (EE.header (elf (MBL.binaryFormatData loadedBinary)))))
elfData = elf (MBL.binaryFormatData loadedBinary)
elfData = BL.originalBinary loadedBinary
addr = MM.memWord (offset + fromIntegral (EE.headerEntry (EE.header elfData)))
staticSyms = symtabEntriesList $ EE.decodeHeaderSymtab elfData
dynSyms = symtabEntriesList $ EE.decodeHeaderDynsym elfData
symbols = [ MM.memWord (offset + fromIntegral (EE.steValue entry))
Expand Down Expand Up @@ -89,8 +88,7 @@ loadAArch32Binary lopts e =
, MBL.memoryEndianness = MM.LittleEndian
, MBL.archBinaryData = ()
, MBL.binaryFormatData =
AArch32ElfData { elf = e
, memSymbols = symbols
AArch32ElfData { memSymbols = symbols
, symbolIndex = indexSymbols symbols
}
, MBL.loadDiagnostics = warnings
Expand Down
10 changes: 4 additions & 6 deletions macaw-loader-ppc/src/Data/Macaw/BinaryLoader/PPC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import qualified SemMC.Architecture.PPC64 as PPC64
class HasTOC arch binFmt where
getTOC :: BL.LoadedBinary arch binFmt -> TOC.TOC (MC.ArchAddrWidth arch)

data PPCElfData w = PPCElfData { elf :: E.ElfHeaderInfo w
, memSymbols :: [EL.MemSymbol w]
data PPCElfData w = PPCElfData { memSymbols :: [EL.MemSymbol w]
, symbolIndex :: Map.Map (MC.MemAddr w) BS.ByteString
}

Expand Down Expand Up @@ -114,8 +113,8 @@ ppc32EntryPoints loadedBinary =
where
offset = fromMaybe 0 (LC.loadOffset (BL.loadOptions loadedBinary))
mem = BL.memoryImage loadedBinary
entryAddr = MM.memWord (offset + fromIntegral (E.headerEntry (E.header (elf (BL.binaryFormatData loadedBinary)))))
elfData = elf (BL.binaryFormatData loadedBinary)
elfData = BL.originalBinary loadedBinary
entryAddr = MM.memWord (offset + fromIntegral (E.headerEntry (E.header elfData)))
staticSyms = symtabEntriesList $ E.decodeHeaderSymtab elfData
dynSyms = symtabEntriesList $ E.decodeHeaderDynsym elfData
symbols = [ MM.memWord (offset + fromIntegral (E.steValue entry))
Expand Down Expand Up @@ -144,8 +143,7 @@ loadPPC32Binary lopts e =
, BL.memoryEndianness = MC.BigEndian
, BL.archBinaryData = ()
, BL.binaryFormatData =
PPCElfData { elf = e
, memSymbols = symbols
PPCElfData { memSymbols = symbols
, symbolIndex = index32 symbols
}
, BL.loadDiagnostics = warnings
Expand Down
10 changes: 4 additions & 6 deletions macaw-loader-riscv/src/Data/Macaw/BinaryLoader/RISCV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import qualified GRIFT.Types as G
import qualified Data.Macaw.RISCV as MR

data RISCVElfData w =
RISCVElfData { elf :: EE.ElfHeaderInfo w
, memSymbols :: [EL.MemSymbol w]
RISCVElfData { memSymbols :: [EL.MemSymbol w]
, symbolIndex :: Map.Map (MM.MemAddr w) BS.ByteString
}

Expand Down Expand Up @@ -58,7 +57,7 @@ riscvEntryPoints :: forall m rv
-> m (DLN.NonEmpty (MM.MemSegmentOff (G.RVWidth rv)))
riscvEntryPoints loadedBinary =
EE.elfClassInstances elfClass $
let addr = MM.memWord (offset + fromIntegral (EE.headerEntry (EE.header (elf (MBL.binaryFormatData loadedBinary))))) in
let addr = MM.memWord (offset + fromIntegral (EE.headerEntry (EE.header elfData))) in
let symbols = [ MM.memWord (offset + fromIntegral (EE.steValue entry))
| entry <- staticSyms ++ dynSyms
, EE.steType entry == EE.STT_FUNC
Expand All @@ -70,7 +69,7 @@ riscvEntryPoints loadedBinary =
where
offset = fromMaybe 0 (LC.loadOffset (MBL.loadOptions loadedBinary))
mem = MBL.memoryImage loadedBinary
elfData = elf (MBL.binaryFormatData loadedBinary)
elfData = BL.originalBinary loadedBinary
elfHeader = EE.header elfData
elfClass = EE.headerClass elfHeader
staticSyms = symtabEntriesList $ EE.decodeHeaderSymtab elfData
Expand All @@ -97,8 +96,7 @@ loadRiscvBinary lopts e =
, MBL.memoryEndianness = MM.LittleEndian
, MBL.archBinaryData = ()
, MBL.binaryFormatData =
RISCVElfData { elf = e
, memSymbols = symbols
RISCVElfData { memSymbols = symbols
, symbolIndex = indexSymbols symbols
}
, MBL.loadDiagnostics = warnings
Expand Down
10 changes: 4 additions & 6 deletions macaw-loader-x86/src/Data/Macaw/BinaryLoader/X86.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import Data.Word ( Word64 )

import qualified Data.Macaw.X86 as MX

data X86ElfData w = X86ElfData { elf :: E.ElfHeaderInfo w
, memSymbols :: [EL.MemSymbol w]
data X86ElfData w = X86ElfData { memSymbols :: [EL.MemSymbol w]
, symbolIndex :: Map.Map (MM.MemAddr 64) BS.ByteString
}

Expand Down Expand Up @@ -59,8 +58,8 @@ x86EntryPoints loadedBinary = do
where
offset = fromMaybe 0 (LC.loadOffset (BL.loadOptions loadedBinary))
mem = BL.memoryImage loadedBinary
addrWord = MM.memWord (offset + (fromIntegral (E.headerEntry (E.header (elf (BL.binaryFormatData loadedBinary))))))
elfData = elf (BL.binaryFormatData loadedBinary)
elfData = BL.originalBinary loadedBinary
addrWord = MM.memWord (offset + fromIntegral (E.headerEntry (E.header elfData)))
staticSyms = symtabEntriesList $ E.decodeHeaderSymtab elfData
dynSyms = symtabEntriesList $ E.decodeHeaderDynsym elfData
symbolWords = [ MM.memWord (offset + E.steValue entry)
Expand Down Expand Up @@ -88,8 +87,7 @@ loadX86Binary lopts e = do
, BL.memoryEndianness = MM.LittleEndian
, BL.archBinaryData = ()
, BL.binaryFormatData =
X86ElfData { elf = e
, memSymbols = symbols
X86ElfData { memSymbols = symbols
, symbolIndex = indexSymbols symbols
}
, BL.loadDiagnostics = warnings
Expand Down

0 comments on commit a9ca082

Please sign in to comment.