Commit Graph

224 Commits

Author SHA1 Message Date
Tristan Ravitch
dbb4c83f08
Add a testing framework for macaw-symbolic (#184)
The new test suites cover x86_64, PowerPC, and ARM. They test that the semantics are actually correct (rather than just seeing if symbolic execution produces any result). The `Data.Macaw.Symbolic.Testing` module in macaw-symbolic provides some common utilities for symbolic execution engine setup, while there are tailored test harnesses for each architecture.

The semantics of the test harnesses are documented in each architecture test suite, but they:
1. Discover all of the test binaries (which are generated from the included makefiles)
2. Treat each function whose name begins with `test_` as a test entry point
3. Symbolically executes each test case with fully symbolic register states
4. Extracts the return value after symbolic execution, which is treated as the predicate to an assertion that must be proved
    - If the test case is in the `pass` subdirectory, it is proved and expected to hold
    - If the test case is in the `fail` subdirectory, it is proved and expected to not hold.

Each test harness supports two options for debugging:
- Dumping generated SMT queries
- Dumping generated Macaw IR for inspection

This testing uncovered a bug in the (previously untested) macaw-aarch32-symbolic code. It required a number of submodule updates to:

- Adapt to some what4 changes
- Fix a bug in the LLVM memory model that lets these tests pass
- Adapt to changes to some crucible APIs

This change also modifies the CI configuration to install SMT solvers earlier (which are now needed for all of the symbolic package tests).
2021-03-01 09:21:44 -08:00
robdockins
a58f1e25dd
Update to follow changes in What4. Nat is no longer a base type (#190)
Nat is no longer a what4 base type, so we have to adapt various APIs to accommodate that. The template haskell in macaw-semmc is updated to remove Nat cases. Changes to the `SymFn` type required removing a type parameter.

This commit also adds macaw-refinement to CI (which requires installing SMT solvers); that code had to be updated due to the what4 changes.


Co-authored-by: Tristan Ravitch <tristan@galois.com>
2021-02-19 15:44:56 -08:00
Joe Hendrix
6d1e47623d Provide jumptable layout info 2021-01-27 15:27:53 -08:00
Daniel Matichuk
cd5dfe8c65
macaw-symbolic: record original block endings when making a CFG slice (#185)
* reify block exit in macaw extension

* add return address to block end classification

* use global variable to retain block endings

* update to mkBlockSliceCFG signature

* add haddocks for MacawBlockEnd

Co-authored-by: Tristan Ravitch <tristan@galois.com>
2021-01-11 16:56:54 -08:00
Brian Huffman
2a620d41de Switch from ansi-wl-pprint to the prettyprinter package.
This patch relies on the following submodule updates:
- GaloisInc/what4#77
- GaloisInc/elf-edit#20
- GaloisInc/crucible#586
- GaloisInc/asl-translator#28

This patch updates the following packages:
- macaw-base
- macaw-symbolic
- macaw-x86
- macaw-x86-symbolic
- macaw-aarch32
- macaw-ppc
- macaw-semmc
- macaw-refinement
2020-12-02 11:38:19 -08:00
Joe Hendrix
402f99071f Fix warnings and ensure travis uses werror on some packages. 2020-11-06 13:58:39 -08:00
Joe Hendrix
c356694627 Update to work with latest elf-edit. 2020-11-06 13:48:26 -08:00
Daniel Matichuk
adeeac988a
Merge branch 'master' into memgen 2020-10-28 10:47:21 -07:00
Kevin Quick
923089d767
Extract single Assignment element without redundant pattern case 2020-10-20 21:09:15 -07:00
Sam Breese
3a071e317b
symbolic: Fix PackBits and UnpackBits (#166) 2020-10-12 14:20:05 -04:00
Sam Breese
00d8530255
symbolic: Add special cases for null pointers in doPtrEq (#165) 2020-10-08 14:38:46 -04:00
Daniel Matichuk
11ceebb592 more haddock fixes 2020-10-06 16:52:21 -07:00
Daniel Matichuk
aab0010d0a more haddock fixes 2020-10-06 14:57:43 -07:00
Daniel Matichuk
a595bdc6a4 fix haddocks 2020-10-06 11:20:59 -07:00
Daniel Matichuk
3765c5eaab remove 'constraints' dependency 2020-10-06 11:20:40 -07:00
Daniel Matichuk
af7758032c
Merge branch 'master' into memgen 2020-10-05 12:23:36 -07:00
Rob Dockins
99f8cb0bdf Update to use new HasLLVMAnn API, which requires an action for
recording (or discarding) annotations rather than a map.
2020-09-11 14:40:02 -07:00
Daniel Matichuk
70d35d44e4 parameterize ArchInfo and ArchVals over mem type 2020-09-02 10:21:39 -07:00
Daniel Matichuk
84f2fac999 cleanup unused language extensions 2020-09-01 17:55:11 -07:00
Daniel Matichuk
2da172b3ea generalize ArchInfo over memory model 2020-09-01 17:07:04 -07:00
Kevin Quick
1db2d1669c
[symbolic] Defer badBehaviorMap creation to caller instead. 2020-08-10 14:50:45 -07:00
Kevin Quick
ad46e191c6
Update for addition of badBehaviorMap implicit for LLVM annotations.
See https://github.com/GaloisInc/crucible/pull/453
2020-08-08 22:16:48 -07:00
Ben Selfridge
039b8497fc
updates what4, crucible, etc. (#146)
* update to bv-sized branch of what4 and other things

* removed parameterized-utils submodule completely

* Updates submodules

* Fixes macaw-symbolic w.r.t. crucible-llvm changes

Co-authored-by: Ben Selfridge <ben@000548-benselfridge.local>
2020-06-16 16:49:55 -07:00
Tristan Ravitch
5ba28484f9
symbolic: Add some documentation on pointer operations (#145)
symbolic: Add some documentation on pointer operations

Their behavior is not entirely obvious, so hopefully this should be useful to
someone in the future.
2020-06-13 10:27:43 -07:00
Brian Huffman
f65c80d7b1 Make code compile without warnings in ghc-8.6 and ghc-8.8. 2020-04-23 20:22:30 -07:00
Kevin Quick
34c40e086b
Update doctest fix to support older GHC 8.4. 2020-04-13 07:25:54 +00:00
Kevin Quick
dd368540fd
Small fixes to macaw-symbolic tests for recent changes. 2020-04-13 06:59:16 +00:00
Tristan Ravitch
c0717413e5 Fix warnings 2020-04-12 20:15:20 -07:00
Daniel Wagner
4ffec20d0a complete the merge 2020-04-03 22:49:34 -04:00
Daniel Wagner
d39ad7a024 Merge branch 'master' into wip/equiv 2020-04-03 00:20:53 -04:00
Andrei Stefanescu
0be59e5815
Update Macaw to use HasLLVMAnn. (#122) 2020-04-02 17:58:47 -07:00
Daniel Wagner
c8328006ac warning police 2020-04-02 13:49:41 -04:00
Daniel Wagner
97c9e20089 add memory model as type argument in a few places 2020-03-18 00:21:15 -04:00
Tristan Ravitch
e024646860
macaw-refinement (#114)
This commit updates macaw-refinement to work with the latest macaw/crucible and makes a few improvements along the way.

The major changes involved in this are:
* Block labels were removed from macaw, so we had to come up with an alternative approach to making synthetic blocks to represent dispatch resolved by macaw-refinement that is not really a jump table. We considered adding a new terminator that encoded "computed IP-based dispatch", but there was concern about the impact on client code. Instead, we added a field to the `DiscoveryFunInfo` that records "external" resolutions to indirect control flow (e.g., as by an SMT solver in macaw-refinement). The hook by which we feed SMT-based resolutions back into macaw was modified accordingly (`addDiscoveredFunctionBlockTargets`).
* Solver invocation changed to allow solver selection and parallel solver application.
* Logging is now done via the `lumberjack` library.
* macaw-symbolic now uses the "external" resolutions in `DiscoveryFunInfo` while building crucible CFGs.
* The path creation code in macaw-refinement was simplified significantly and the approach to path creation has been documented.
* The run-refinement tool is now more featureful.
* The test suite is a bit more structured and no longer depends on the printed output of the discovery process.
2020-03-12 17:15:08 -07:00
Daniel Wagner
1daee7da6b write a bit about how CFG-edge-killing is implemented 2020-03-12 18:11:07 -04:00
Daniel Wagner
ef91508325 naming only: trace, not 2 2020-03-12 16:57:01 -04:00
Daniel Wagner
f4daaa7e81 start working on execMacawStmtExtension for new memory model 2020-03-09 23:46:58 -04:00
Tristan Ravitch
c825332f39
Update/ghc 8.8 (#112)
Updates for GHC 8.8

The two main classes of update are related to MonadFail and type alias expansion.

The MonadFail updates introduce explicit MonadFail instances and backward-compatible `fail` implementations under `Monad` for older GHC versions.

The type alias expansion rules changed in GHC 8.8 in a way that breaks the `Simple Lens` idiom; instead, we have to use `Lens'`.  Lens started supporting this alias in version 3.8, which was released in 2013.

This change includes necessary submodule updates, as well as the update for the split of what4 into its own repository.
2020-03-03 13:28:26 -08:00
Daniel Wagner
5506e05486 Merge branch 'tr/new-macaw-symbolic-entry' into wip/equiv 2020-02-19 17:38:27 -05:00
Daniel Wagner
66c2fc4a98 provide a way to mark certain jumps as terminal 2020-02-19 17:37:18 -05:00
Tristan Ravitch
80125921a9 This commit re-implements the memory model used by macaw symbolic
There are two major changes:
- The interface to memory models in Data.Macaw.Symbolic has changed
- The suggested implementation in Data.Macaw.Symbolic.Memory has changed

The change improves performance and fixes a soundness bug.

* `macawExtensions` (Data.Macaw.Symbolic) takes a new argument: a `MkGlobalPointerValidityPred`.  Use `mkGlobalPointerValidityPred` to provide one.
* `mapRegionPointers` no longer takes a default pointer argument (delete it at call sites)
* `GlobalMap` returns an `LLVMPtr sym w` instead of a `Maybe (LLVMPtr sym w)`

Users of the suggested memory model do not need to worry about the last change,
as it has been migrated.  If you provided your own address mapping function, it
must now be total.  This is annoying, but the old API was unsound because
macaw-symbolic did not have enough information to correctly handle the `Nothing`
case.  The idea of the change is that the mapping function should translate any
concrete pointers as appropriate, while symbolic pointers should generate a mux
over all possible allocations.  Unfortunately, macaw-symbolic does not have
enough information to generate the mux itself, as there may be allocations
created externally.

This interface and implementation is concerned with handling pointers to static
memory in a binary.  These are distinguished from pointers to
dynamically-allocated or stack memory because many machine code instructions
compute bitvectors and treat them as pointers.  In the LLVM memory model used by
macaw-symbolic, each memory allocation has a block identifier (a natural
number).  The stack and each heap allocation get unique block identifiers.
However, pointers to static memory have no block identifier and must be mapped
to a block in order to fit into the LLVM memory model.

The previous implementation assigned each mapped memory segment in a binary to
its own LLVM memory allocation.  This had the nice property of implicitly
proving that no memory access was touching unmapped memory.  Unfortunately, it
was especially inefficient in the presence of symbolic reads and writes, as it
generated mux trees over all possible allocations and significantly slowed
symbolic execution.

The new memory model implementation (in Data.Macaw.Symbolic.Memory) instead uses
a single allocation for all static allocations.  This pushes more of the logic
for resolving reads and writes into the SMT solver and the theory of arrays.  In
cases where sufficient constraints exist in path conditions, this means that we
can support symbolic reads and writes.  Additionally, since we have only a
single SMT array backing all allocations, mapping bitvectors to LLVM pointers in
the memory model is trivial: we just change their block identifier from zero
(denoting a bitvector) to the block identifier of the unique allocation backing
static data.

This change has to do some extra work to ensure safety (especially that unmapped
memory is never written to or read from).  This is handled with the
MkGlobalPointerValidityPred interface in Data.Macaw.Symbolic.  This function,
which is passed to the macaw-symbolic initialization, constructs well-formedness
predicates for all pointers used to access memory.  Symbolic execution tasks
that do not need to enforce this property can simply provide a function that
never returns any predicates to check.  Implementations that want a reasonable
default can use the mkGlobalPointerValidityPred from Data.Macaw.Symbolic.Memory.
The default implementation ensures that no reads or writes touch unmapped memory
and that writes to static data never write to read-only segments.

This change also converts the examples in macaw-symbolic haddocks to use doctest
to ensure that they do not get out of date.  These are checked as part of CI.
2020-02-11 09:58:53 -08:00
Tristan Ravitch
39cf7d9682
Merge branch 'master' into tr/new-macaw-symbolic-entry 2020-02-05 10:43:24 -08:00
Daniel Wagner
95dd08bce9 Merge branch 'master' into wip/equiv 2020-02-04 12:21:51 -05:00
Daniel Wagner
c22f140a3b Merge branch 'tr/new-macaw-symbolic-entry' into wip/equiv 2020-01-13 22:21:51 -05:00
Daniel Wagner
b5c15af0da start on alternative memory model 2020-01-13 22:11:40 -05:00
Daniel Wagner
e5daa87dd0 fix typo in comment 2020-01-13 22:10:17 -05:00
Tristan Ravitch
6b490a8193 Update the crucible submodule
The only real code change required is that simulation failure messages have an
extra argument.  The goal with this update is to pull in some fixes to the
solver feature detection for yices in the latest crucible.
2019-12-19 15:03:09 -08:00
Tristan Ravitch
b76bfdb395 Add a new entry point to macaw-symbolic
This version constructs a Crucible CFG for a collection of blocks while
preserving control flow between them.  It allows the caller to specify blocks
that are considered "terminal": those blocks return the current register state.
Control flow to blocks no included in the "slice" are directed to synthetic
blocks that assume False in order to stop the symbolic simulator from exploring
those branches.
2019-12-19 11:21:05 -08:00
Rob Dockins
13aefd82f2 Update macaw-symbolic with changes to string literals in what4 2019-11-15 14:39:38 -08:00
Daniel Wagner
8d275627ba export a few handy internals 2019-10-30 16:07:21 -04:00