Commit Graph

336 Commits

Author SHA1 Message Date
Ryan Scott
049096c506 Support building with GHC 9.0
This contains a variety of fixes needed to make the packages in the `macaw`
repo compile with GHC 9.0:

* GHC 9.0 implements simplified subsumption (see
  [here](https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.0?version_id=5fcd0a50e0872efb3c38a32db140506da8310d87#simplified-subsumption)).
  In most cases, adapting to this is a matter of manually eta expanding
  definitions, such as in `base:Data.Macaw.Analysis.RegisterUse`. In the case
  of `macaw-x86-symbolic:Data.Macaw.X86.Crucible`, the type signature of
  `evalExt` had to be made more specific to adapt to the loss of contravariance
  when typechecking `(->)`.
* GHC's constraint solver now solves constraints in each top-level group
  sooner (see
  [here](https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.0?version_id=5fcd0a50e0872efb3c38a32db140506da8310d87#the-order-of-th-splices-is-more-important)).
  This affects `macaw-aarch32` and `macaw-symbolic`, as they separate top-level
  groups with `$(return [])` Template Haskell splices. The previous locations
  of these splices made it so that the TH-generated instances in that package
  were not available to any code before the splice, resulting in type errors
  when compiled with GHC 9.0.

  To overcome this, I rearranged the TH-generated instances so that they appear
  before the top-level groups that make use of them.
* GHC 9.0 now enables `-Wstar-is-type` in `-Wall`, so this patch replaces some
  uses of `*` with `Data.Kind.Type`. `Data.Kind` requires the use of GHC 8.0 or
  later, so this patch also updates thes lower bounds on `base` to `>= 4.9` in
  the appropriate `.cabal` files. (I'm fairly certain that this requirement was
  already present implicity, but better to be explicit about it.)
* The `asl-translator`, `crucible`, and `semmc` submodules were updated to
  allow them to build with GHC 9.0. The `llvm-pretty` and
  `llvm-pretty-bc-parser` submodules were also bumped to accommodate unrelated
  changes in `crucible` that were brought in.
* The upper version bounds on `doctest` in `macaw-symbolic`'s test suite were
  raised to allow it to build with GHC 9.0.
2022-01-10 16:40:23 -05:00
Tristan Ravitch
9ce3d43188
AArch32: Support conditional returns (#243)
Adds support in macaw-aarch32 for conditional returns. These are not supported in core macaw, and are thus architecture-specific block terminators.

This required changes to the type of arch-specific block terminators. Before, `ArchTermStmt` was only parameterized by a state thread (`ids`).  This meant that they could not contain macaw (or crucible) values.  Some work on. AArch32 requires being able to store condition values in arch terminators (to support conditional returns). This change modifies the `ArchTermStmt` to enable this, which requires a bit of plumbing through various definitions and some extra instances.

In support of actually using this, it also became necessary to plumb fallthrough block labels through the architecture-specific terminator translation in macaw-symbolic.

Note that this change was overdue, as the PowerPC backend was storing macaw values in a way that would have rendered them unusable in the macaw-ppc-symbolic translation, had any interpretation been provided.  These new changes will enable a handler to be written for the conditional PowerPC trap instructions.

PowerPC, x86, and ARM have been updated.

Improves the macaw-aarch32 tests. There is now a command line option to save the generated macaw IR for each
discovered function to /tmp. Note that this reuses some infrastructure from the macaw-symbolic tests. This
shared functionality should be extracted into a macaw-testing library.
2021-11-19 16:20:50 -08:00
Tristan Ravitch
2c85dce18e Expose block classification in the ArchitectureInfo
This change makes the block classifier heuristic part of the `ArchitectureInfo`
structure.  This enables clients and architecture backends to customize the
block classification heuristics.  This is most useful for architectures that
have complex architecture-specific block terminators that require analysis to
generate (e.g., conditional returns).  It will also make macaw-refinement
simpler in the future, as the SMT-based refinement is just an additional block
classifier (but is currently implemented via a hacky side channel).

This change introduces an ancillary change, which should not be very
user-visible.

It splits the Macaw.Discovery and Macaw.Discovery.State modules to break
module import cycles in a way that enables us to expose the classifier.  This
should not be user-visible, as Macaw.Discovery still exports the same
names (with one minor exception that should not appear in user code).

It also moves the definition of the `ArchBlockPrecond` type family; the few
affected places should be updated. User code should probably not be able to see
this.
2021-11-05 18:25:03 -07:00
Ryan Scott
49a6d9d7b8
stripPLTRead: Avoid referencing dropped IDs in ArchStates (#233)
It is possible for later `ArchState` updates to reference the `AssignId` of
the `AssignStmt` that is dropped as a part of `stripPLTRead`, so make sure to
prune such updates from the `ArchState` to avoid referencing the now
out-of-scope `AssignId`.
2021-09-28 09:17:20 -04:00
Joe Hendrix
4afe6fd82e Specify function name in register use error message 2021-07-12 11:59:43 -07:00
Joe Hendrix
a50faaebd1 Move isExecutableSegOff check in discovery 2021-06-13 11:55:08 -07:00
Joe Hendrix
cda1d50b28 Expand register use error reasons.
This allows architecture-specific functions to add additional detail.
2021-06-12 12:33:42 -07:00
Joe Hendrix
ad6573556b Cleanups, formatting changes, and remove unused functionality. 2021-06-10 14:09:04 -07:00
Joe Hendrix
7729de2d2c Fix typos in error message; export ArchAddrWidth 2021-06-05 16:07:03 -07:00
Joe Hendrix
e55ebc95cd WIP. Improved error messages 2021-05-27 14:13:13 -07:00
Joe Hendrix
8216088158 Invariant inference changes.
This refactors demand analysis so we export assignment inferred values
and also no longer compute demands for assigments when inference
infers a value for them.

This exposes more information but requires changes to consumers of
information.
2021-05-24 14:03:24 -07:00
Joe Hendrix
7db9baf439 Support elf-edit changes 2021-05-07 14:18:56 -07:00
Joe Hendrix
12c3829a1e Reorganize event reporting for Reopt compatibility. 2021-04-27 23:54:11 -07:00
Joe Hendrix
e2ae54cd04 Add error messages and generalize function argument analysis. 2021-04-27 23:54:11 -07:00
Joe Hendrix
3fb39610bb Export lower level function for getting memory from elf segments. 2021-04-27 23:54:11 -07:00
Joe Hendrix
b26a4e64d8 Declare BlockInvariantMap 2021-04-27 23:54:11 -07:00
Joe Hendrix
483cc25553 Relax requirement on pointer type byte size attribute. 2021-04-27 23:54:11 -07:00
Joe Hendrix
1cb86f771c Cleanup discovery; fix macaw-symbolic 2021-04-21 11:27:27 -07:00
Joe Hendrix
1dd776b636 Introduce incremental computation monad; use in discovery. 2021-04-21 11:27:27 -07:00
Kevin Quick
05f10ed6c9
Update ElfLoader error messages to be more generic. 2021-04-05 08:45:00 -07:00
Kevin Quick
b5c5ebcf42
Comment/haddock updates in ElfLoader. 2021-04-05 08:44:59 -07:00
Joe Hendrix
7f32ea5b42 Vector operations; widthEqSym 2021-03-23 21:58:37 -07:00
Joe Hendrix
19f0e9814e Remove unused import 2021-03-23 21:58:15 -07:00
Joe Hendrix
8756d2e9d3 Minor layout changes 2021-01-29 12:01:16 -08:00
Joe Hendrix
4abbe8817f Relax constraints on stack read/write for register use. 2021-01-29 12:00:58 -08:00
Joe Hendrix
6d1e47623d Provide jumptable layout info 2021-01-27 15:27:53 -08:00
Tristan Ravitch
a84fa82d90
Export the DwarfExpr constructor (#182)
This enables client code to decode the rest of the DWARF structure (which may
produce errors that we don't want to expose in the macaw-provided API).
2020-12-10 12:55:03 -08:00
Brian Huffman
b3af7d63e9 Use OverloadedStrings for the prettyprinter Doc type. 2020-12-02 17:23:47 -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
d977d72006 Minr format change. 2020-11-12 13:59:06 -08:00
Joe Hendrix
0ec2dae8e6 Minor refactorings to clarify and simplify macaw base. 2020-11-12 12:37:30 -08:00
Joe Hendrix
d2b81d3c2f Fixes for jump table tests.
* Update macaw-x86-tests to build properly.
* Fix off by two error in memMapOverwrite
* Introduce some special handling for unsigned-extension in stack
  analysis so it knows one value is the unsigned extension of another.
* Error report formating improvements
* Slightly more precise treatment of archfn is bound updates.
2020-11-12 11:25:30 -08:00
Joe Hendrix
5aad8ca32e Upgrade to elf-edit 0.39 and other libraries. 2020-11-10 17:15:47 -08:00
Joe Hendrix
95f7fd7db7 Add limited global address checking for jump table bounds check.
This also fixes a bug in extendDyn and gets better jump table coverage.
2020-11-06 14:37:13 -08:00
Joe Hendrix
5f5de06e70 Remove unused constraint on MemAddr instance. 2020-11-06 14:37:13 -08:00
Joe Hendrix
22a9104faa Various cleanups.
Consolidate three different checks that control when to explore
a function into a single one defined in exploreFunPred.

Modify noreturn function calls to not treat the return address
as a potential function entry point.

Add basic checking of LSDA address to compare-dwarfdump.

Minor code refactoring and submodule updates.
2020-11-06 14:37:13 -08:00
Joe Hendrix
9203a37b94 Minor cleanups; dwarf updates 2020-11-06 14:35:06 -08:00
Joe Hendrix
b180145002 Generalize symbol resolver to support low-level elf-edit functions. 2020-11-06 14:29:04 -08:00
Joe Hendrix
42f7a43b32 Update dwarf parsing to increase laziness and robustness. 2020-11-06 14:27:36 -08:00
Joe Hendrix
a276dbaea4 Update to work with latest elf-edit. 2020-11-06 14:01:04 -08:00
Joe Hendrix
f2c0f00075 Allow functions to be explicitly marked as no-return. 2020-11-06 14:01:04 -08:00
Joe Hendrix
ab2bf08946 Merge subprograms with abstract origin. 2020-11-06 14:01:04 -08:00
Joe Hendrix
cbd16ed481 Update dwarf parsing to increase laziness and robustness. 2020-11-06 13:56:37 -08:00
Joe Hendrix
c9218a9284 Fix undefined MkTuple typeRepr 2020-11-06 13:48:26 -08:00
Joe Hendrix
da3d43d805 Update elf-edit; export additional capabilities for Reopt.
This adds a mechanism for filtering out function addressses.  Used by
Reopt for the PLT table.
2020-11-06 13:48:26 -08:00
Joe Hendrix
c356694627 Update to work with latest elf-edit. 2020-11-06 13:48:26 -08:00
Joe Hendrix
1510c247e3 Add MkTuple primitive. 2020-11-06 13:02:09 -08:00
Lisanna Dettwyler
47544e4b2d Fix warnings in GHC 8.10 2020-10-20 13:53:22 -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
Sam Breese
02c6cc3cb5
Handle bitwise operations on stack offset abstract values (#136)
- Generalize handling of bitwise operations to also apply them to stack offsets
- Use the extended bitwise handling on AND
2020-05-28 14:04:06 -04:00