Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly pin the mir-json version that SAW requires #2115

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
[submodule "deps/lmdb"]
path = deps/lmdb
url = https://github.com/GaloisInc/lmdb.git
[submodule "deps/mir-json"]
path = deps/mir-json
url = https://github.com/GaloisInc/mir-json.git
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ will be possible for all language constructs. There are various
instructions that are not supported during verification. However,
any failure during `llvm_load_module` should be considered a bug.

## Notes on Rust

SAW has experimental support for analyzing Rust programs. To do so, one must
compile Rust code using [`mir-json`](https://github.com/GaloisInc/mir-json), a
tool which compiles Rust code to a machine-readable, JSON-based format.
Note that:

* Each version of SAW understands the JSON output of a particular version of
`mir-json`, so make sure that you build the version `mir-json` that is
included in the `mir-json` submodule (located in `deps/mir-json`).
* Moreover, SAW requires slightly modified versions of the Rust standard
libraries that are suited to verification purposes. SAW consults the value
of the `SAW_RUST_LIBRARY_PATH` environment variable to determine where to
look for these modified standard libraries.

For complete instructions on how to install `mir-json`, the modified Rust
standard libraries, and how to defined the `SAW_RUST_LIBRARY_PATH` environment
variable, follow the instructions
[here](https://github.com/GaloisInc/mir-json#installation-instructions).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this section ought to say something about translate-libs and $SAW_RUST_LIBRARY_PATH, but maybe that belongs in a separate branch.

Otherwise, LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point, although I wonder if the README is the best place to list instructions at this level of depth. Let me know if you feel differently, but I am more inclined to describe translate-libs, SAW_RUST_LIBRARY_PATH, and other topics related to mir-json in the SAW manual, and then include a forward reference to the SAW manual in this part of the README.

That being said, I just checked the relevant part of the SAW manual, and it is unfortunately somewhat scarce on details of how one actually installs mir-json. I definitely think we should rectify that, and since this PR is mostly a documentation-related change, I would be fine with adding such details to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there's two aspects to this: (1) the translate-libs process should be documented somewhere, but also (2) all the critical pieces of the complete setup process for doing MIR verification should be mentioned in the same places, especially as long as things fail in a non-obvious way if you forget parts of it. So I think if we're going to mention setting up mir-json in the README, it should also mention the translate-libs process, even if just as a reference into the manual.

(I actually think it's probably good to have the complete setup process in the README, but I'm not totally committed to this given that the whole thing is experimental and hopefully by the time it isn't it'll all be less complicated and less fragile)

So... carry on I guess :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a new version of the PR that expands the discussion in the README somewhat, mentioning both the need for a specific mir-json version and the need for custom Rust standard libraries. I've also fleshed out the relevant section in the SAW manual to mention the mir-json submodule, translate_libs.sh, and the SAW_RUST_LIBRARY_PATH environment variable. I think this should be much better than it was before—PTAL.

The manual currently assumes that you are starting from a saw-script repo checkout. This is not ideal, since many SAW users download a binary distribution instead. In order to do better here, however, I think we need to first explicitly version mir-json's schema. I've started work on that in GaloisInc/mir-json#75.

## Notes on Windows

If you have trouble loading the SAW REPL on Windows, try invoking it
Expand Down
1 change: 1 addition & 0 deletions deps/mir-json
Submodule mir-json added at 131980
53 changes: 50 additions & 3 deletions doc/manual/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1812,15 +1812,62 @@ In order to verify Rust code, SAW analyzes Rust's MIR (mid-level intermediate
representation) language. In particular, SAW analyzes a particular form of MIR
that the [`mir-json`](https://github.com/GaloisInc/mir-json) tool produces. You
will need to intall `mir-json` and run it on Rust code in order to produce MIR
JSON files that SAW can load (see [this section](#loading-mir)).
JSON files that SAW can load (see [this section](#loading-mir)). You will also
need to use `mir-json` to build custom versions of the Rust standard libraries
that are more suited to verification purposes.

If you are working from a checkout of the `saw-script` repo, you can install
the `mir-json` tool and the custom Rust standard libraries by performing the
following steps:

1. Clone the [`crucible`](https://github.com/GaloisInc/crucible) and `mir-json`
submodules like so:

```
$ git submodule update deps/crucible deps/mir-json
```

2. Navigate to the `mir-json` submodule:

```
$ cd deps/mir-json
```

3. Follow the instructions laid out in the [`mir-json` installation
instructions](https://github.com/GaloisInc/mir-json#installation-instructions)
in order to install `mir-json`.

4. Navigate to the
[`crux-mir`](https://github.com/GaloisInc/crucible/tree/master/crux-mir)
subdirectory of the `crucible` submodule:

```
$ cd ../crucible/crux-mir/
```

5. Run the `translate_libs.sh` script:

```
$ ./translate_libs.sh
```

This will compile the custom versions of the Rust standard libraries using
`mir-json`, placing the results under the `rlibs` subdirectory.

6. Finally, define a `SAW_RUST_LIBRARY_PATH` environment variable that points
to the newly created `rlibs` subdirectory:

```
$ export SAW_RUST_LIBRARY_PATH=<...>/crucible/crux-mir/rlibs
```

For `cargo`-based projects, `mir-json` provides a `cargo` subcommand called
`cargo saw-build` that builds a JSON file suitable for use with SAW. `cargo
saw-build` integrates directly with `cargo`, so you can pass flags to it like
any other `cargo` subcommand. For example:

```
$ export SAW_RUST_LIBRARY_PATH=<...>
# Make sure that SAW_RUST_LIBRARY_PATH is defined, as described above
$ cargo saw-build <other cargo flags>
<snip>
linking 11 mir files into <...>/example-364cf2df365c7055.linked-mir.json
Expand All @@ -1840,7 +1887,7 @@ Note that:
`rustc` accepts. For example:

```
$ export SAW_RUST_LIBRARY_PATH=<...>
# Make sure that SAW_RUST_LIBRARY_PATH is defined, as described above
$ saw-rustc example.rs <other rustc flags>
<snip>
linking 11 mir files into <...>/example.linked-mir.json
Expand Down
Binary file modified doc/manual/manual.pdf
Binary file not shown.
Loading