Commit Graph

1984 Commits

Author SHA1 Message Date
Tristan Ravitch
3011920fc5 Improve a classifier failure diagnostic and fix a typo
The call classifier was missing a label, which led to a less readable error
message in the case where all classifiers fail.
2022-06-09 13:07:30 -07:00
Tristan Ravitch
c07ed519dd Add a test for indirect calls 2022-06-09 13:07:30 -07:00
Tristan Ravitch
9296692138 Fix a sign extension bug in the abstract domain calculation
The bug arose in the handling of `StackOffsetAbsVal`, which track an abstraction
of references relative to the stack pointer. The offsets in `StackOffsetAbsVal`
are `Int64`; they are signed because references are both above and below the
stack pointer.  The code constructing new values of this type was incorrectly
zero-extending new offsets instead of sign extending them.  This did not matter
on 64 bit architectures, as it happened to result in the same values.  It
substantially corrupted the abstract stack on PowerPC 32.  It did not seem to
affect AArch32, but that is likely just due to luck in compiler code generation
that does not require this level of precision in the abstract stack.

The resulting errors manifest in the `absEvalCall` function. Because of the lack
of sign extension in `StackOffsetAbsVal`s, it made the current stack pointer
look like a huge number, which caused *all* stack entries to be dropped after
function calls.

This fix simplifies the stack offset abstract value computation substantially
and ensures that signs are extended correctly. The commit adds a PowerPC32 test
case that only passes with this fix.
2022-06-09 13:07:30 -07:00
Tristan Ravitch
3d95517097 Remove an unused export
This function is used internally, but no clients use it
2022-06-09 13:07:30 -07:00
Tristan Ravitch
fa840a2152 Add tests for 32 bit PowerPC 2022-06-09 13:07:30 -07:00
Ryan Scott
9d2e1d4b9f CI: Test GHC 9.2.2 2022-05-31 15:50:48 -04:00
Ryan Scott
00104542f5 CI: Regenerate freeze files 2022-05-31 15:50:48 -04:00
Ryan Scott
6e020bcde6 Fix -Wincomplete-uni-patterns warnings
GHC 9.2 adds `-Wincomplete-uni-patterns` to `-Wall`, which uncovers a slew of
previously unnoticed warnings in `macaw`. This patch fixes them, mostly by
adding explicit fall-through cases.
2022-05-31 15:50:48 -04:00
Ryan Scott
6237d615c3 Fix -Wnoncanonical-monad-instances warnings
GHC 9.2 adds `-Wnoncanonical-monad-instances` to `-Wall`, which warns whenever
one has explicit implementations of `return` or `(>>)` that aren't simply
`return = pure` or `(>>) = (*>)`. Since these are the default
implementations of `return` and `(>>)` since `base-4.11`, the simplest
way to fix the warnings is to simply remove all explicit definitions of
`return` and `(>>)` and rely on the defaults, which this patch accomplishes.
2022-05-31 15:50:48 -04:00
Ryan Scott
3f65a253a1 Fix -Wunused-imports warning with base-4.16.*
In `base-4.16.*`, `Nat` is now a type synonym for `Natural`, and `GHC.TypeLits`
now re-exports `Natural`. This causes a `-Wunused-imports` warning in
`macaw-base` as a consequence. I fixed the warning by tightening up the imports
slightly.
2022-05-31 15:50:48 -04:00
Ryan Scott
c9cbb4c7fc Support building with GHC 9.2
This contains various tweaks needed to make the packages in the `macaw` repo
build with GHC 9.2:

* In `template-haskell-2.18.*`, the type of `ConP` gained an additional field
  (see [here](https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.2?version_id=7e2ce63ba042c1934654c4316dc02028d8d3dd31#template-haskell-218)).
  As a result, I needed to use some CPP in `macaw-semmc:Data.Macaw.SemMC.TH` to
  make the two uses of `ConP` compile. To minimize the amount of CPP that I
  needed, I factored out this logic into a `conPCompat` function.
* The following submodules were bumped to bring in changes needed to support
  building with GHC 9.2:
  * `asl-translator`: GaloisInc/asl-translator#45
  * `dismantle`: travitch/dismantle#39
  * `dwarf`: GaloisInc/dwarf#5
  * `elf-edit`: GaloisInc/elf-edit#32
  * `flexdis86`: GaloisInc/flexdis86#39
  * `grift`: GaloisInc/grift#6
  * `semmc`: GaloisInc/semmc#75
2022-05-31 15:50:48 -04:00
Tristan Ravitch
54f8793145
Submodule updates (#291)
The primary changes are version bounds to let everything build against the
latest what4 release (1.3)
2022-05-24 18:45:23 -07:00
Tristan Ravitch
659cfff6c9
aarch32: Implement support for conditional calls (#289)
The core of macaw cannot represent conditional calls because the existing block terminators are not sufficiently expressive and it doesn't support creating synthetic blocks to represent control flow not directly tied to machine addresses.

To work around this, we introduce ARM-specific block terminators for conditional calls and plumb them through up to macaw-aarch32-symbolic.

Fixes #288
2022-05-20 15:17:26 -07:00
Tristan Ravitch
8e10643b0f
Fix tail call classification (#286)
The tail call classifier came after the jump classifier, which was a problem because it is less strict than the tail call classifier, meaning it would always fire.  This commit moves direct jump to be the last classifier applied, giving the others a chance.

Includes a test case in the ARM backend.

This requires some updates to some of the expected test results, as a few blocks are now classified as tail calls that were
plain jumps before.  They really could be considered either.  I think it would be nice if these could be classified as jumps instead, but the reason they are flagged as tail calls is mostly down to the fact that their surrounding context is so simple that either interpretation works.

Correcting this would require some heuristics based on additional analysis passes.

The test harness for macaw symbolic required a few changes because the new detection of some jumps as tail calls introduces new calls into the symbolic test suites. However, the symbolic testing harness did not support calls before.  Adding support required a bit of plumbing, including a more extensive code discovery pass.


Fixes #285
2022-05-10 07:29:55 -07:00
Brett Boston
a5796fc955
Reverse syscall override return register ordering (#284)
When a user overrides a system call on an architecture that supports returning two values from a system call and they provide a context containing the result of the system call in the form

```
empty :> v0 :> v1
```

macaw will perform the register assignment

```
r0 := v1
r1 := v0
```

This change reverses this behavior so that the assignment becomes

```
r0 := v0
r1 := v1
```

This brings the expected ordering of the result context in agreement
with the left-to-right ordering of the argument context:

```
empty :> arg1 :> arg2 :> ...
```
2022-05-04 12:41:02 -07:00
Daniel Matichuk
bbc0b6a40a
Bump ASL revision to handle slicing issues with UBFX instruction on ARM (#280)
* bump asl-translator

* add ubfx tests

* add CI version to workflow
2022-04-20 10:08:36 -07:00
Daniel Matichuk
5b4d16dd8a
generalize treatment for terminal statements in CFG slicing code (#278)
* remove/generalize MacawBlockEnd from CFG slicing

* expose functions in symbolic backend

* hide bvLit from Backend import

* add CI version to workflow
2022-04-20 10:08:15 -07:00
Ryan Scott
7300149315 CI: Use CACHE_VERSION 2022-04-19 12:47:24 -04:00
Ryan Scott
c86e13d35c Adapt to dynSymEntry being definition-aware in elf-edit
This bump the `elf-edit` submodule to bring in the changes from
https://github.com/GaloisInc/elf-edit/pull/29, which adds an additional
`VersionDefMap` argument to `elf-edit` to make it aware of version definitions.
This requires some changes to the API in `Data.Macaw.Memory.ElfLoader` to
accommodate.
2022-04-19 12:47:24 -04:00
Ryan Scott
ef0ece6a72 Make newMergedGlobalMemoryWith work over any Foldable collection
This would come in handy for an application where I wish to pass a
`NonEmptyVector` to `newMergedGlobalMemoryWith`. Currently, I have to convert
the `NonEmptyVector` to a `NonEmpty` list to accomplish this, wish seems
wasteful given that `newMergedGlobalMemoryWith` only needs to use the
`Foldable` interface.
2022-04-04 15:03:56 -04:00
Brett Boston
93ca88c2fc
Export Data.Macaw.Discovery.Classifier.classifierEndBlock (#275) 2022-04-04 11:57:19 -07:00
Tristan Ravitch
11c5a04b3d Fix a bug in handling return detection in thumb mode
The return address gets masked and has the low-bit set in an obtuse way due to
the semantics. This threw off the call detection.

This change matches against the quirky pattern.
2022-03-30 20:19:06 -07:00
simonjwinwood
4e8efbf09b
Merge pull request #272 from GaloisInc/wip/zero-sized-reloc-workaround
Ignore relocations with zero size when constructing Memory
2022-03-24 07:42:15 +11:00
Simon Winwood
7ca8e4c237
Ignore relocations with zero size when constructing Memory 2022-03-23 01:36:07 -07:00
Brett Boston
3f895bed1b
Add RV32GC support to macaw-riscv (#269)
This change adds support for RV32GC RISCV binaries.  Specifically, it:

* Updates the return matcher to recognize returns in 32-bit binaries
* Updates detection of unsupported binaries to allow RV32GC binaries
* Adds RV32GC versions of the RV64GC tests
2022-03-21 14:08:50 -07:00
Tristan Ravitch
dd9448db3c Export an extra function from the discovery API
This is necessary to implement custom logic using the incremental computation
monad, as the even lower-level infrastructure is not exposed at all.
2022-03-21 09:20:35 -07:00
Brett Boston
adf3d67614
Add ability to load multiple memories into a flat address space (#268)
This change adds a function `newMergedGlobalMemoryWith`, which acts like
`newGlobalMemoryWith` but takes a list of macaw memories and merges them
into a flat address space.  This aids in reasoning dynamically linked
programs.
2022-03-17 20:34:30 -07:00
Tristan Ravitch
45f8af1e5a
[symbolic] Optimize how initial binary memories are populated (#267)
Before, the API provided by macaw-symbolic asserted the initial value of each byte of memory individually. This was fairly expensive for large binaries, as each such assertion flushed the solver pipe.

This change generates a large conjunction of assertions and sends them all at once. In unscientific testing, this saved half an hour on a large binary.

API Changes:

- Note that it introduces a minor API change. The optimization required that the `sym` parameter be concretely an `ExprBuilder`.
2022-03-10 16:43:00 -08:00
Brett Boston
9d0d9d762c
Update softfloat-hs repo to eliminate manual build step (#265)
* Update softfloat-hs repo to eliminate manual build step

* Fix small typo in README (softfloat -> softfloat-hs)
2022-03-04 15:49:36 -08:00
Brett Boston
82640e7a4b
Add RISC-V backend (#259)
* riscv: added grift as submodule

* added macaw-riscv project

* make arch polykinded everywhere in macaw base

* stubbed out riscv_info

* update grift

* started on RISCVReg

* started on RISCVReg

* RegisterInfo instance for RISCVReg (a few unimplemented fields)

* filled out archRegSet

* filled out withArchConstraints, archAddrWidth, and archEndianness

* added Arch module

* RISCV initialBlockRegs

* preliminary work on disassembleFn

* wip: disassembleFn

* made things more lens-y

* wip: disassemble instruction

* finished disassembly of grift assignment statements

* separated out DisInstM into separate module

* disassembly wip

* finished disassembleBlock

* Finished riscvDisassembleFn

* bump grift submodule

* made macaw discovery poly-kinded

* added risc-v test suite

* added risc-v test suite

* fixed macaw semantics to hardware x0 to constant value 0

* added riscvPreserveReg based on assembler's manual

* riscvDemandContext

* successfully disassembled a block!

* enhanced tests to allow optional entry point spec

* stubbed out identifyCall

* stubbed out identifyReturn

* passing initial test

* added checkForReturnAddr stub

* fleshed out identifyCall and identifyReturn

* update grift submodule

* bug fix and exception handling

* added EXC register, which tracks whether or not we've attempted to
read from/write to any system registers.

* Replaced custom CSR type with GRIFT's (but we're not using it
currently)

* added better show instance for GPRs we should migrate this to a
GRIFT pretty printer at some point)

* Fixed a vicious bug in the semantics; unsigned and signed LT were
getting swapped in translation

* added pattern synonyms for GPRs

* improved docs and fixed RISCVReg bug (GP was 3 instead of 4)

* changed undefineds to errors

* changed RISCV class to RISCVConstraints

* wrapped GRIFT's "RV" parameter in a type to remove the need to make
macaw architecture parameter polykinded

* rolled back all changes to macaw base that made things poly-kinded

* reverted two more macaw core changes, updated license, removed old PPC test

* macaw: update to upstream changes in bv-sized and grift

* address code review comments

* macaw-riscv: expose fewer modules

* Update RISCVTermStmt definition

* Update riscv_info.  macaw-riscv now builds against master

* Update bv-sized and cabal freeze files

* Update cabal freeze files with satisfying lens version

* Get tests building

* Fix printf runtime error

* Add simpler tests

* Change RISCV target version and update grift pointer

[skip ci]

* Compressed branch test passes

[skip ci]

* Add additional small tests

[skip ci]

* Introduce a syscall PrimFn

* Syscalls now correctly classified

* Fix return regs from syscall

* Extract syscall arguments

* Update expected riscv test results

* Add macaw-riscv build + test to CI

* Get building with GHC 9.0.2

* Revert "Update cabal freeze files with satisfying lens version"

This reverts commit 4aa95c19c3.

* Install softfloat in CI

* Update Grift

* Some initial cleanup

* More cleanup

* Resolve FIXME on getReg

* Detect and only accept rv64gc rvreprs

* Address Tristan's PR comments

* Update Grift pointer

* Add info on installing Softfloat to README for macaw-riscv

* Add missing submodule step to softfloat build instructions

Co-authored-by: Ben Selfridge <benselfridge@000279.local>
Co-authored-by: Valentin Robert <val@galois.com>
2022-03-04 12:44:46 -08:00
Ryan Scott
a43151963d Note personality-related tweaks in the changelog 2022-02-21 13:27:20 -05:00
Ryan Scott
5c801c5803 Universally quantify personality type in Lookup{Function,Syscall}Handle
This is needed for situations where you want to be able to inspect the
personality type in function/syscall lookups.
2022-02-21 13:27:20 -05:00
Kevin Quick
78b45a10c6 Only fix personality to (MS.MacawSimulatorState sym) where required. 2022-02-21 13:27:20 -05:00
Brett Boston
719aa8fb01
Translate PLTStubs as tail calls (#263)
* Translate PLTStubs as tail calls

This change modifies `addMacawParsedTermStmt` to translate `PLTStub`s as
tail calls.

* Replace CR.Call + CR.Return with CR.TailCall
2022-02-18 15:02:59 -08:00
Brett Boston
ad51ae3c54
Add support for standalone PIEs (#262)
* Add support for standalone PIEs

This changeset adds support for standalone position independent
executables (PIEs) that do not make use of procedure linkage tables.  It
does so by adding relative address support to `populateSegmentChunk` and
adding an additional simplification rule for Aarch32.

This covers part of the work for #234.

* Remove NoOp + replace mult with left shift
2022-02-03 13:51:11 -08:00
robdockins
d1d71fd973
Merge pull request #257 from GaloisInc/separate-backend
Update with changes flowing from GaloicInc/crucible#945.
2022-01-25 08:54:44 -08:00
Rob Dockins
c572e372db Update changelog 2022-01-24 16:28:32 -08:00
Rob Dockins
465a84ee49 Update with changes flowing from GaloicInc/crucible#945.
This mostly deals with the splitting of the old `sym` type into
two: one for dealing with expression creation, and a new simulator
backend type for dealing with control-flow and assertions.
2022-01-24 16:24:07 -08:00
Rob Dockins
2845d6fd74 Update what4 and crucible submodules 2022-01-24 16:24:07 -08:00
Tristan Ravitch
63a65c3d85 x86: Fix failing proof obligations due to EvenParity
See the writeup in Crucible.hs in this commit for details. In short, the recent
changes to generalize `PtrAdd` triggered a failing proof obligation due to a use
of `llvmPointer_bv`.  The new implementation is as sound as the previous one,
but more general.

Fixes #260
2022-01-21 15:33:10 -08:00
Ryan Scott
729c65054b Replace deprecated prettyprinter import with modern equivalent
Also bump the lower version bounds on `prettyprinter`.
2022-01-10 16:40:23 -05:00
Ryan Scott
ce10bc9243 Drop support for GHC 8.6
This allows us to remove gobs of CPP as a consequence.
2022-01-10 16:40:23 -05:00
Ryan Scott
c3b8bac579 CI: Test GHC 9.0.2 2022-01-10 16:40:23 -05:00
Ryan Scott
ce3e9cba13 Add notes on freeze file generation to README 2022-01-10 16:40:23 -05:00
Ryan Scott
dfeef5f332 Regenerate freeze files 2022-01-10 16:40:23 -05:00
Ryan Scott
7819377d84 macaw-x86-symbolic: Remove unused FloatInfoFromSSEType definition
GHC 9.0 uncovered this type family as being unused. (See
https://gitlab.haskell.org/ghc/ghc/-/issues/18470, which made
`-Wunused-top-binds` more clever about detecting unused, closed
type families like `FloatInfoFromSSEType`.) Let's remove it to avoid
an `-Wunused-top-binds` warning.
2022-01-10 16:40:23 -05:00
Ryan Scott
2f2ba118bd macaw-semmc: Avoid arithmetic overflow from negative shift amounts
While pre-9.0 versions of GHC would silently turn negative right shifts into
left shifts, GHC 9.0 will throw an `arithmetic overflow` exception instead.
This patch makes this behavior explicit in `macaw-semmc` to allow the code to
work on GHC 9.0.

Fixes #212.
2022-01-10 16:40:23 -05:00
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
Ryan Scott
f9b300a3d1 macaw-symbolic: Add fromCrucibleEndian function
This is like `toCrucibleEndian`, but in the opposite direction.
2022-01-04 16:27:57 -06:00
Ryan Scott
45f991ccdf macaw-symbolic: Consolidate duplicate definitions of toCrucibleEndian
There were two identical definitions of `toCrucibleEndian`, one in
`D.M.S.Memory` and another in `D.M.S.Testing`. This commit removes the
latter in favor of the former, which is actually exported.
2022-01-04 16:27:57 -06:00