Skip to content

Commit 74e26cb

Browse files
committed
Support mutable globals during x86 verification
1 parent 9983cc4 commit 74e26cb

File tree

1 file changed

+20
-3
lines changed
  • src/SAWScript/Crucible/LLVM

1 file changed

+20
-3
lines changed

src/SAWScript/Crucible/LLVM/X86.hs

+20-3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ data X86State = X86State
128128
, _x86Options :: Options
129129
, _x86SharedContext :: SharedContext
130130
, _x86CrucibleContext :: LLVMCrucibleContext LLVMArch
131+
, _x86Elf :: Elf.Elf 64
131132
, _x86RelevantElf :: RelevantElf
132133
, _x86MethodSpec :: MS.CrucibleMethodSpecIR LLVM
133134
, _x86Mem :: Mem
@@ -384,6 +385,8 @@ initialState sym opts sc cc elf relf ms globs maxAddr = do
384385
emptyRegs <- traverseWithIndex (freshRegister sym) C.knownRepr
385386
let
386387
align = C.LLVM.exponentToAlignment 4
388+
allocGlobalEnd :: MS.AllocGlobal LLVM -> Integer
389+
allocGlobalEnd (LLVMAllocGlobal _ (LLVM.Symbol nm)) = globalEnd nm
387390
globalEnd :: String -> Integer
388391
globalEnd nm = case
389392
Vector.headM
@@ -396,6 +399,7 @@ initialState sym opts sc cc elf relf ms globs maxAddr = do
396399
sz <- W4.bvLit sym knownNat . maximum $ mconcat
397400
[ [maxAddr]
398401
, globalEnd . fst <$> globs
402+
, allocGlobalEnd <$> ms ^. MS.csGlobalAllocs
399403
]
400404
(base, mem) <- C.LLVM.doMalloc sym C.LLVM.GlobalAlloc C.LLVM.Immutable
401405
"globals" emptyMem sz align
@@ -404,6 +408,7 @@ initialState sym opts sc cc elf relf ms globs maxAddr = do
404408
, _x86Options = opts
405409
, _x86SharedContext = sc
406410
, _x86CrucibleContext = cc
411+
, _x86Elf = elf
407412
, _x86RelevantElf = relf
408413
, _x86MethodSpec = ms
409414
, _x86Mem = mem
@@ -530,8 +535,21 @@ executePointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr tval)
530535
sym <- use x86Sym
531536
cc <- use x86CrucibleContext
532537
mem <- use x86Mem
533-
ptr <- liftIO $ C.LLVM.unpackMemValue sym (C.LLVM.LLVMPointerRepr $ knownNat @64)
534-
=<< resolveSetupVal cc mem env tyenv Map.empty tptr
538+
elf <- use x86Elf
539+
base <- use x86GlobalBase
540+
ptr <- case tptr of
541+
MS.SetupGlobal () nm -> case
542+
Vector.headM
543+
. Vector.filter (\e -> Elf.steName e == encodeUtf8 (Text.pack nm))
544+
. mconcat
545+
. fmap Elf.elfSymbolTableEntries
546+
$ Elf.elfSymtab elf of
547+
Nothing -> throwX86 "not found"
548+
Just entry -> do
549+
let addr = fromIntegral $ Elf.steValue entry
550+
liftIO $ C.LLVM.doPtrAddOffset sym mem base =<< W4.bvLit sym knownNat addr
551+
_ -> liftIO $ C.LLVM.unpackMemValue sym (C.LLVM.LLVMPointerRepr $ knownNat @64)
552+
=<< resolveSetupVal cc mem env tyenv Map.empty tptr
535553
val <- liftIO $ resolveSetupVal cc mem env tyenv Map.empty tval
536554
storTy <- liftIO $ C.LLVM.toStorableType =<< typeOfSetupValue cc tyenv nameEnv tval
537555
mem' <- liftIO $ C.LLVM.storeConstRaw sym mem ptr storTy C.LLVM.noAlignment val
@@ -667,7 +685,6 @@ checkGoals = do
667685
case mb of
668686
Nothing -> printOutLn opts Info "Goal succeeded"
669687
Just ex -> do
670-
print g
671688
fail $ mconcat
672689
["Failure (", show $ gLoc g
673690
, "): ", show $ gMessage g

0 commit comments

Comments
 (0)