Skip to content

Commit bfca3b6

Browse files
committed
Add ability to allocate all globals
This is necessary when global constants depend on the addresses of global variables.
1 parent 1167b32 commit bfca3b6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

saw-central/src/SAWCentral/Crucible/LLVM/Builtins.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ setupLLVMCrucibleContext pathSat lm action =
17011701
what4PushMuxOps <- gets rwWhat4PushMuxOps
17021702
laxPointerOrdering <- gets rwLaxPointerOrdering
17031703
laxLoadsAndStores <- gets rwLaxLoadsAndStores
1704+
allocAllGlobals <- gets rwAllocAllGlobals
17041705
noSatisfyingWriteFreshConstant <- gets rwNoSatisfyingWriteFreshConstant
17051706
pathSatSolver <- gets rwPathSatSolver
17061707
what4Eval <- gets rwWhat4Eval
@@ -1759,8 +1760,11 @@ setupLLVMCrucibleContext pathSat lm action =
17591760
intrinsics halloc stdout
17601761
bindings (Crucible.llvmExtensionImpl ?memOpts)
17611762
Common.SAWCruciblePersonality
1763+
let memoryInitializer = if allocAllGlobals
1764+
then Crucible.initializeAllMemory
1765+
else Crucible.initializeMemoryConstGlobals
17621766
mem <- Crucible.populateConstGlobals bak (view Crucible.globalInitMap mtrans)
1763-
=<< Crucible.initializeMemoryConstGlobals bak ctx llvm_mod
1767+
=<< memoryInitializer bak ctx llvm_mod
17641768

17651769
let globals = Crucible.llvmGlobals (Crucible.llvmMemVar ctx) mem
17661770

saw-central/src/SAWCentral/Crucible/LLVM/CrucibleLLVM.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module SAWCentral.Crucible.LLVM.CrucibleLLVM
6767
-- * Re-exports from "Lang.Crucible.LLVM.Globals"
6868
, GlobalInitializerMap
6969
, initializeMemoryConstGlobals
70+
, initializeAllMemory
7071
, makeGlobalMap
7172
, populateConstGlobals
7273
-- * Re-exports from "Lang.Crucible.LLVM.Translation"
@@ -164,7 +165,8 @@ import Lang.Crucible.LLVM.TypeContext
164165
import qualified Lang.Crucible.LLVM.TypeContext as TyCtx
165166

166167
import Lang.Crucible.LLVM.Globals
167-
(GlobalInitializerMap, initializeMemoryConstGlobals, makeGlobalMap, populateConstGlobals)
168+
(GlobalInitializerMap, makeGlobalMap, populateConstGlobals,
169+
initializeAllMemory, initializeMemoryConstGlobals)
168170

169171
import Lang.Crucible.LLVM.Translation
170172
(llvmMemVar, transContext, llvmPtrWidth, llvmTypeCtx,

saw-central/src/SAWCentral/Value.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ data TopLevelRW =
847847
, rwLaxLoadsAndStores :: Bool
848848
, rwLaxPointerOrdering :: Bool
849849
, rwDebugIntrinsics :: Bool
850+
, rwAllocAllGlobals :: Bool -- ^ allocate all globals unconditionally
850851

851852
-- FIXME: These might be better split into "simulator hash-consing" and "tactic hash-consing"
852853
, rwWhat4HashConsing :: Bool

saw-script/src/SAWScript/Interpreter.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ buildTopLevelEnv proxy opts scriptArgv =
10791079
, rwLaxArith = False
10801080
, rwLaxPointerOrdering = False
10811081
, rwLaxLoadsAndStores = False
1082+
, rwAllocAllGlobals = False
10821083
, rwDebugIntrinsics = True
10831084
, rwWhat4HashConsing = False
10841085
, rwWhat4HashConsingX86 = False
@@ -1885,6 +1886,16 @@ disable_lax_loads_and_stores = do
18851886
rw <- getTopLevelRW
18861887
putTopLevelRW rw { rwLaxLoadsAndStores = False }
18871888

1889+
enable_alloc_all_globals :: TopLevel ()
1890+
enable_alloc_all_globals = do
1891+
rw <- getTopLevelRW
1892+
putTopLevelRW rw { rwAllocAllGlobals = True }
1893+
1894+
disable_alloc_all_globals :: TopLevel ()
1895+
disable_alloc_all_globals = do
1896+
rw <- getTopLevelRW
1897+
putTopLevelRW rw { rwAllocAllGlobals = False }
1898+
18881899
set_solver_cache_path :: Text -> TopLevel ()
18891900
set_solver_cache_path pathtxt = do
18901901
let path :: FilePath = Text.unpack pathtxt
@@ -2693,6 +2704,18 @@ primitives = Map.fromList
26932704
Current
26942705
[ "Disable relaxed validity checking for memory loads and stores in Crucible." ]
26952706

2707+
, prim "enable_alloc_all_globals" "TopLevel ()"
2708+
(pureVal enable_alloc_all_globals)
2709+
Experimental
2710+
[ "Enable allocation of all globals automatically. This is necessary when"
2711+
, " constants depend on the addresses of globals."
2712+
]
2713+
2714+
, prim "disable_alloc_all_globals" "TopLevel ()"
2715+
(pureVal disable_alloc_all_globals)
2716+
Experimental
2717+
[ "Disable allocation of all globals automatically." ]
2718+
26962719
, prim "set_path_sat_solver" "String -> TopLevel ()"
26972720
(pureVal set_path_sat_solver)
26982721
Experimental

0 commit comments

Comments
 (0)