Commit Graph

2004 Commits

Author SHA1 Message Date
Ryan Scott
9a3e793d30 Bump semmc submodule
This is needed to bring in the changes from #77, which adds support for
`hashable-1.4.*`. With this change, everything in the `macaw` repo now
builds with `hashable-1.4.*`.
2023-02-20 17:49:35 -05:00
Ryan Scott
fa3f82314a macaw-base: Document hashable-related API changes 2023-02-20 17:49:17 -05:00
Valentin Robert
aa127f240f support hashable-1.4 2023-02-16 13:55:30 -08:00
Daniel Matichuk
07b693a309
ARM: add additional return expression match (#315)
handles an extra case where the 'And' has been
simplified out of the return value expression
2022-12-09 12:17:09 -08:00
Daniel Matichuk
a73ec83ff4
ARM: add additional return expression match (#315)
handles an extra case where the 'And' has been
simplified out of the return value expression
2022-12-09 12:16:49 -08:00
Ryan Scott
da06413771 Add test case for movt semantics
This requires bumping the `asl-translator` submodule to bring the changes from
GaloisInc/asl-translator#47, which are necessary for the test case to work.
2022-10-26 18:15:06 -04:00
Ryan Scott
e6420fc006 macaw-symbolic: Include addresses in populateRelocation
When populating `COPY` relocations, it is helpful to know the address of the
relocation so that it can be related back to the name of the global symbol
whose value it is copying. Unfortunately, the type of `populateRelocation` does
not make it straightforward to compute this address. This patch includes three
additional arguments to `populateRelocation` (the relocation's `Memory`, its
`MemSegment`, and its `MemAddr`) to more easily facilitate computing the
address.

This is a breaking API change, albet it is a fairly straightforward change to
adapt to for most consumers.

This is related to #47, although this is not a full fix for the issue.
2022-09-13 15:26:12 -04:00
Ryan Scott
560f292d16 macaw-base: Support loading R_ARM_COPY ELF relocations
We already have support for `R_X86_64_COPY` relocations, so adding support
for `R_ARM_COPY` on the AArch32 side is straightforward.

This is related to #47, although this is not a full fix for the issue.
2022-09-13 15:20:22 -04:00
Tristan Ravitch
87129af093
Add some additional documentation (#303)
Update README.md and document the design of macaw and macaw-symbolic.

Co-authored-by: Ryan Scott <rscott@galois.com>
2022-08-09 18:40:55 -07:00
robdockins
d9525554ca
Merge pull request #310 from GaloisInc/rwd/redundant-checks
Remove redundant "valid pointer" checks from memory loads and stores.
2022-08-08 14:26:40 -07:00
Tristan Ravitch
20c4083330 Add a ChangeLog entry 2022-08-08 12:37:34 -07:00
Robert Dockins
8cf16cdfcd Remove redundant "valid pointer" checks from memory loads and stores.
The internal memory model operations already assert the same checks.
2022-08-03 09:41:58 -07:00
Ryan Scott
734039274d macaw-symbolic: Generalize some uses of CrucibleState to SimState
This patch was motivated by the need to call `doGetGlobal` from a Crucible
override, where the `SimState` is instantiated with `OverrideLang` rather than
`CrucibleLang`, the latter of which is used in the `CrucibleState` type
synonym. While I was in town, I generalized the types of other operations in
`Data.Macaw.Symbolic.MemOps` where it was reasonable.
2022-07-19 17:03:44 -04:00
Tristan Ravitch
8bce1cf769 Add a script for regenerating CI freeze files 2022-06-30 13:44:35 -07:00
Ryan Scott
2791b1050f Adapt to GaloisInc/crucible#998
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `macaw-symbolic` to accommodate, as well as bumping the
`semmc` submodule to bring in analogous changes from GaloisInc/semmc#76.
2022-06-28 12:10:11 -04:00
Tristan Ravitch
6a4f406c68 Revisit handling of tail calls
It turns out that we have to be more conservative with tail call identification,
as incorrectly identifying a block as the target of a tail call (instead of a
branch) can cause other branch classifiers to fail if that block is the target
of another jump.

Ultimately, we will need to give up some tail call recognition (since they are
in general indistinguishable from jumps), and instead only identify known call
targets as tail call candidates.

With additional global analysis we could do better.

Fixes #294
2022-06-27 15:02:43 -07:00
Tristan Ravitch
857bb72b31 [x86] Add an option to save macaw IR from test cases 2022-06-27 15:02:43 -07:00
Tristan Ravitch
f217bf860e Remove an unused NatRepr 2022-06-09 13:07:30 -07:00
Tristan Ravitch
827be3ca47 ppc: Fix a mistake that inhibited some tests 2022-06-09 13:07:30 -07:00
Tristan Ravitch
bf454fc190 ppc: Rename test modules
They are now not 64-bit specific, update names to reflect that
2022-06-09 13:07:30 -07:00
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