Commit Graph

2145 Commits

Author SHA1 Message Date
Langston Barrett
dcb4ec1c6a x86-cli: Test suite 2024-08-20 17:17:50 -04:00
Langston Barrett
f5c451021a x86-cli: Libraryfication
Make the code easier to test
2024-08-20 17:17:50 -04:00
Langston Barrett
aba55d77cb x86-cli: A CLI for running macaw-x86-symbolic S-expression CFGs 2024-08-20 17:17:50 -04:00
Langston Barrett
5453edeaa7 ci: Remove conditional in build/test of x86-symbolic
We only run CI on Linux, no need for this conditional.
2024-08-20 13:00:54 -04:00
Langston Barrett
b932885faf ci: Build and test macaw-x86-syntax 2024-08-20 13:00:54 -04:00
Langston Barrett
3dfc22bf41 x86-symbolic: Simplify definitions of Indexs for named registers 2024-08-16 15:32:49 -04:00
Langston Barrett
cc4c8675e1 x86-syntax: set-reg 2024-08-16 15:32:49 -04:00
Langston Barrett
6cce9b1b98 x86-symbolic: Comment on register Index definitions 2024-08-16 15:32:49 -04:00
Langston Barrett
813d057881 x86-{symbolic,syntax}: Indexs and names for GP registers 2024-08-16 15:32:49 -04:00
Langston Barrett
69f63302f8 x86-syntax: Use upstream register indices 2024-08-16 15:32:49 -04:00
Langston Barrett
97751b0895 x86-symbolic: Add Indexs into MacawCrucibleRegTypes for named registers 2024-08-16 15:32:49 -04:00
Langston Barrett
d017106154 x86-symbolic: Minor cleanup (alphabetization, typo fix) 2024-08-16 15:32:49 -04:00
Langston Barrett
ce6a96a348 macaw-x86-syntax: get-reg operation, rip register 2024-08-16 15:32:49 -04:00
Langston Barrett
f77d848ec1 macaw-x86-syntax: Syntactic sugar for macaw-x86-symbolic CFGs 2024-08-16 15:32:49 -04:00
Ryan Scott
1add47389a macaw-x86: Fix call semantics when call target involves the stack pointer
Previously, the `macaw-x86` semantics for `call` would retrieve the call target
*after* pushing the next instruction's address to the stack, but if the call
target involves the stack pointer, then this would mean that it would get the
next instruction's address when retrieving the call target. This is not what is
intended!

This patch fixes the issue by always retrieving the call target *before*
pushing the next instruction's address to the stack. I have added a test case
to the `macaw-x86-symbolic` test suite which demonstrates that this fix works
as intended.

Fixes #420.
2024-08-13 12:31:09 -04:00
Ryan Scott
a05c1cc305 CI: Test GHC 9.8, drop 9.2 2024-08-08 09:34:03 -04:00
Ryan Scott
9954dd6d01 Fix -Wx-partial warnings uncovered by GHC 9.8 2024-08-08 09:34:03 -04:00
Ryan Scott
c1a1449ec2 Enable -Wno-orphans to fix warnings uncovered by GHC 9.8
GHC 9.8 is better about reporting orphan type family instances, which are used
in various spots in Macaw. Enable `-Wno-orphans` to suppress these warnings.
2024-08-08 09:34:03 -04:00
Ryan Scott
85ca3ba8d1 Bump submodules 2024-08-08 09:34:03 -04:00
Ryan Scott
3e83b3eff3 ppcInstructionMatcher: Reference PPCSyscall Haddocks 2024-08-01 10:34:44 -04:00
Ryan Scott
98290062a7 macaw-ppc-symbolic: Add support for simulating syscalls
This adds the necessary changes to `macaw-ppc-symbolic` and `macaw-ppc` in
order to simulate system calls, similarly to how it is done when simulating
x86-64 and AArch32 code:

* In `macaw-ppc`, remove `PPCSyscall` from `TermStmt` and instead make it a
  constructor for `PPCPrimFn`. (Note that there are some minor discrepancies
  between which registers are used in PPC32 versus PPC64, which we explain in
  the Haddocks for the new `PPCSyscall` constructor.)
* Update `macaw-ppc`'s `ppcInstructionMatcher` function so that calls to the
  `sc` (system call) instruction make use of `PPCSyscall`.
* Update `macaw-ppc-symbolic`'s `ppcGenFn` function to make it possible to hook
  into PPC system calls using `MacawLookupSyscallHandle`.

Fixes #387.
2024-08-01 10:34:44 -04:00
Ryan Scott
d36ecf56fe macaw-ppc-symbolic: Export SemanticsError
Fixes #385 (and finishes the work started in #370).
2024-08-01 10:34:44 -04:00
Ryan Scott
1838ebf01d macaw-ppc-symbolic: Remove redundant import 2024-08-01 10:34:44 -04:00
Ryan Scott
1da090f1ee macaw-riscv: Add riscvPLTStubInfo
Now that we can load RISC-V relocations in `macaw` (building on top of the work
in GaloisInc/elf-edit#45), this patch adds PLT stub heuristics for RISC-V
binaries. I have added some test cases in `macaw-riscv-symbolic` which
demonstrate that the basic idea works.

Note that due to #416, these test cases will print warnings when loaded into
`macaw`. These warnings are ultimately harmless, however, as the same
relocations are loaded at the same addresses multiple times, which causes no
change in behavior.

Fixes #414.
2024-07-31 10:11:53 -04:00
Ryan Scott
93b588a58b macaw-base: Resolve RISC-V relocations
This builds on top of the work in GaloisInc/elf-edit#45. For now, I only add
support for a select few relocation types, leaving the rest as future work.

This paves a way for an eventual fix for #414.
2024-07-31 10:11:53 -04:00
Ryan Scott
1a2b9284f1 macaw-{ppc,riscv}-symbolic: Move S definition above functions that use it 2024-07-26 15:25:29 -04:00
Ryan Scott
1966a30909 symbolic: Make {lookup,update}Reg implementations panic rather than error
See https://github.com/GaloisInc/macaw/issues/412 for the remaining task of
allowing the return types of `GenArchVals`' `{lookup,update}Reg` functions to
indicate the possibility of an error.
2024-07-26 15:25:29 -04:00
Ryan Scott
1a758c70eb Implement macaw-riscv-symbolic
This adds the necessary plumbing to simulate Macaw-lifted RISC-V binaries using
`macaw-symbolic`. This proves relatively straightforward, given that RISC-V
does not have a lot of special primitive functions or statements to deal with.
I have also added a basic test suite to ensure that `macaw-riscv-symbolic`
works on end-to-end examples.

Fixes #409.
2024-07-26 15:25:29 -04:00
Valentin Robert
eb0a3c7ccc
Merge pull request #406 from GaloisInc/vr/register-use-bvand
support alignment ops when processing statements in `RegisterUse`
2024-07-25 12:14:33 -07:00
Stanislav Lyakhov
82aae49a00
Merge pull request #403 from GaloisInc/feature/better-jumptable-truncation
Improve handling of JumpBound truncation constraints
2024-07-24 13:45:50 -07:00
Stanislav Lyakhov
75e31f8338 Improve handling of JumpBound truncation constraints
Given some symbolic value, @x@, we'd like to compute its
possible upper and lower bounds after it is truncated to @w@ bits.

To do this, we first find the bound of x by (recursively) calling `exprRangePred`.
This bound is a statement of the following form (see `RangePred` for more info):
"r bits of x are bounded between @low@ and @high@".

Then, we check the following:
- If x has a bound (r, l, w)
AND
- If r is less than or equal to w
=> Pass-through the bound (r, l, w)
Otherwise, we deem x "unbounded"

Declaring x unbounded in the second case seems to throw away useful
information that causes many jump tables to remain unclassified.
We attempt to improve on that in this commit.

Consider an example where x is bounded by (64, 0, 10)
(that is, the 64 bits of x are constrained to be between 0 and 10)
and we want to find the bound of truncating x to 8 bits.

With the current logic, since 64 > 8, we'd declare x unbounded.
However, the bound (8, 0, 10) should also be valid: if 64 bits of
x are bounded to [0, 10], then surely 8 bits of x also lie between
0 and 10.

If the upper bound is instead larger than the largest 8-bit value, we
can truncate it to the largest value.
For example, (64, 0, 10000) becomes (8, 0, 255).
Instead of losing the bound completely, we're able to tighten it!
2024-07-24 13:44:04 -07:00
Valentin Robert
dc1591d168 support alignment ops when processing statements in RegisterUse
For some reason we were very conservative in our support or abstract
operations over the processor state in the `RegisterUse` analysis.

In particular, we were failing to process code such as:

r23 := (bv_and r21 (0xfffffffffffffff0 :: [64]))

whose goal is to align the value in r21 at a 16-byte boundary.

This resulted in us failing to analyze some code that was realigning its
stack pointer.  With this change, the same code succeeds at propagating
the abstract stack pointer offset forward.
2024-07-24 09:59:45 -07:00
Valentin Robert
32244627f2
Merge pull request #405 from GaloisInc/vr/bits-memint
add a `Bits` instance to `MemInt`
2024-07-24 08:43:02 -07:00
Valentin Robert
4b38285191
Merge pull request #404 from GaloisInc/vr/expose-memInt
expose `memInt` in `Memory`
2024-07-23 16:57:49 -07:00
Valentin Robert
d2561b1078 add a Bits instance to MemInt
This helps supporting bitwise operations over `MemInt`s without having
to unwrap/rewrap them into `Int64`s.
2024-07-23 16:57:06 -07:00
Valentin Robert
b380174c8b expose memInt in Memory
A future fix I'm going to submit would benefit from having this exposed,
and we believe this to be a good idea regardless.
2024-07-23 16:09:03 -07:00
Langston Barrett
83d3907054 Use Crucible goal-proving helpers in testing code 2024-07-16 15:30:35 -04:00
Ryan Scott
2c15fcc6ed Cite Macaw paper and blog post in the README
Fixes #343. Fixes #397.
2024-07-16 13:17:44 -04:00
Ryan Scott
a6ff58f473 macaw-x86-symbolic: Fix idiv/div semantics
When converting a Macaw value with the Macaw type `TupleType [x_1, ..., x_n]`
to Crucible, the resulting Crucible value will have the Crucible type
`StructType (EmptyCtx ::> ToCrucibleType x_n ::> ... ::> ToCrucibleType x_1)`.
(See `macawListToCrucible(M)` in `Data.Macaw.Symbolic.PersistentState` for
where this is implemented.) Note that the order of the tuple's fields is
reversed in the process of converting it to a Crucible struct. This is a
convention that one must keep in mind when dealing with Macaw tuples at the
Crucible level.

As it turns out, the part of `macaw-x86-symbolic` reponsible for interpreting
the semantics of the `idiv` instruction (for signed quotient/remainder) and the
`div` instruction (for unsigned quotient/remainder) were _not_ respecting this
convention. This is because the `macaw-x86-symbolic` semantics were returning a
Crucible struct consisting of `Empty :> quotient :> remainder)`, but at the
Macaw level, this was interpreted as the tuple `(remainder, quotient)`, which
is the opposite of the intended order. This led to subtle bugs such as those
observed in #393.

The solution is straightforward: have the `macaw-x86-symbolic` semantics
compute `Empty :> remainder :> quotient` instead. Somewhat counterintuitive,
but it does work.

Fixes #393.
2024-07-12 16:56:51 -04:00
Ryan Scott
645754178a CI: Regenerate freeze files using latest GHC minor versions 2024-06-13 04:25:12 -04:00
Ryan Scott
4db0341e0a Bump submodules to allow building with what4-1.6.*
This bumps the `what4` submodule to the 1.6.* version series and updates the
`.cabal` files in the `macaw` repo accordingly.

Bumping the `what4` submodule also requires bringing in corresponding changes
in the `crucible`, `llvm-pretty`, and `llvm-pretty-bc-parser` submodules, so I
have done that as well.
2024-06-13 04:25:12 -04:00
Eric Mertens
d04f097ba7
Merge pull request #383 from GaloisInc/llvm-pretty-migration
Update llvm-pretty submodule target
2024-05-24 08:09:52 -07:00
Eric Mertens
3b0933d95c Update llvm-pretty submodule target 2024-05-23 16:23:39 -07:00
Valentin Robert
77a6c62352
parse subroutine type declaration formal parameters (#382)
* parse subroutine type declaration formal parameters

This is useful for Reopt as we want to get more accurate type
information for library functions.
2024-05-22 10:47:16 -07:00
Stanislav Lyakhov
4b2f7df44e
Merge pull request #381 from GaloisInc/fix/refinement-cfg-panic
Fix refinement panic caused by duplicate cfg edges
2024-05-10 16:49:31 -07:00
Stanislav Lyakhov
616b266559 Fix refinement panic caused by duplicate cfg edges
Refinement frequently tried to add duplicate edges to the cfg
when encountering jump tables, since jump tables often have common targets
(e.g. because of a `default` case).

Instead of panicking, this is now handled as a benign case where no edge
insertion is needed.
2024-05-10 15:40:11 -07:00
Ryan Scott
442b0e9f00 macaw-base: Fix R_X86_64_RELATIVE offset computation
Fixes #316.
2024-04-11 09:06:50 -04:00
Valentin Robert
e7c4005359
Merge pull request #379 from GaloisInc/vr/bump-ci-actions
bump CI actions versions
2024-04-08 13:09:41 -07:00
Valentin Robert
8e5d9de534 bump CI actions versions 2024-04-08 11:25:03 -07:00
Valentin Robert
da66e03973
Merge pull request #377 from GaloisInc/vr/fix-doc
fix copy-pasted docstring
2024-04-08 11:24:20 -07:00