Repository navigation
Add an unstable --target option and a riscv64 machine model #4913
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
Open
calef
wants to merge
21
commits into
model-checking:main
Choose a base branch
from
calef:riscv64-target
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f295764
Add an unstable --target option and a riscv64 machine model
calef 5ce11c8
test the two --target rejections; document the goto-cc arch overwrite
calef 9023df2
drop the local verification shim committed by mistake
calef a5fac6a
Accept only the targets the machine models were written for
calef 2d0a623
Correct the cause of the architecture overwrite in the target docs
calef 450cbc2
Tighten the --target test, docs and build-dev flags after self-review
calef 1eaa2d9
Keep the target's machine model in the linked goto binary
calef 08bbefe
Check the machine model in the linked riscv64 goto binary
calef 409ba07
Record the verification target in --export-json metadata
calef c377470
Drop the fixed machine-model limitation from the target docs
calef 9b72fa0
Mark char as signed in the aarch64-apple-darwin machine model
calef 27bf95e
Test the --c-lib rejection for another target in target_riscv64
calef 7153afd
Refuse --target for autoharness --std, as verify-std does
calef eb6c119
Say in the target docs that bare-metal riscv64 is not supported
calef d67167f
Check --target and --lib-target against one list of supported targets
calef 25e3570
Match the exact target tuple in check_target
calef c8a5d29
Rebuild every target under targets/ on each cargo build-dev
calef 0467068
Merge branch 'main' into riscv64-target
calef 3b69842
Merge branch 'main' into riscv64-target
calef c264c69
Record the --target triple in the RFC 0015 export
calef 629bdb3
Merge branch 'main' into riscv64-target
calef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,6 +211,7 @@ dependencies = [ | |
| "anyhow", | ||
| "cargo_metadata", | ||
| "clap", | ||
| "kani_metadata", | ||
| "which 8.0.6", | ||
| ] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Verifying for another target | ||
|
|
||
| By default Kani verifies a crate as it would be compiled for the host: the same pointer width, | ||
| endianness, `cfg(target_arch)` and C type sizes. With `--target`, Kani verifies it for another | ||
| target triple instead, from the same host. This is useful for code that only compiles for a | ||
| platform you do not develop on, such as a kernel's `riscv64` modules on an x86_64 or Apple | ||
| Silicon machine. | ||
|
|
||
| This is an experimental feature, tracked in [#2402](https://github.com/model-checking/kani/issues/2402). | ||
|
|
||
| ## Supported targets | ||
|
|
||
| A target needs a CBMC machine model in Kani. These are the targets that have one: | ||
|
|
||
| | Target | Notes | | ||
| |--------|-------| | ||
| | `x86_64-unknown-linux-gnu` | | | ||
| | `aarch64-unknown-linux-gnu` | | | ||
| | `riscv64gc-unknown-linux-gnu` | LP64D data model | | ||
| | `x86_64-apple-darwin` | | | ||
| | `aarch64-apple-darwin` | | | ||
|
|
||
| Kani refuses any other `--target`, and `cargo build-dev --lib-target`, with an error that lists | ||
| these. | ||
|
|
||
| The bare-metal `riscv64gc-unknown-none-elf`, which kernels usually build for, is not supported. | ||
| Verifying such a crate as `riscv64gc-unknown-linux-gnu` instead sets `target_os = "linux"` and | ||
| makes `std` available, so code behind `cfg(target_os = "none")` is compiled out and the `linux` | ||
| branch, if there is one, is what Kani verifies. | ||
|
|
||
| ## Building the libraries | ||
|
|
||
| Kani verifies against its own build of the standard library and of the `kani` crate, compiled for | ||
| the target. Release bundles contain these for the host only, so today `--target` needs Kani | ||
| built from source ([build from source](../../build-from-source.md)), with each extra target named: | ||
|
|
||
| ```bash | ||
| cargo build-dev --lib-target riscv64gc-unknown-linux-gnu | ||
| ``` | ||
|
|
||
| The option may be repeated. Each target's libraries go to `targets/<TRIPLE>/lib/` beside the | ||
| host's `lib/`, so one Kani installation can verify for several targets. A later `cargo build-dev` | ||
| rebuilds every target already under `targets/`, named or not, so they stay in step with | ||
| `library/`. The rustup target itself does not need to be installed: the standard library is built | ||
| from the `rust-src` component. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| kani file.rs --target riscv64gc-unknown-linux-gnu -Z unstable-options | ||
| cargo kani --target riscv64gc-unknown-linux-gnu -Z unstable-options | ||
| ``` | ||
|
|
||
| ## Limitations | ||
|
|
||
| * `--concrete-playback` is rejected with a non-host `--target`, because the generated test runs | ||
| on the host. | ||
| * The `verify-std` subcommand and `autoharness --std` do not support `--target`. | ||
| * `--c-lib` is rejected with a non-host `--target`. `goto-cc` compiles C sources with the host's | ||
| C configuration, and a source compiled as part of the link would replace the target's machine | ||
| model in the linked program. | ||
| * Kani's machine model has no operating system, so `__CPROVER_architecture_os` in the linked | ||
| program is the host's, as it is for a host run. A `riscv64gc-unknown-linux-gnu` run on macOS | ||
| therefore has `os = "macos"`. CBMC reads this setting in a few places when it processes C, such | ||
| as the arm64 `va_list` layout. | ||
| * Inline assembly is unsupported on every target, as it is on the host. Code behind | ||
| `core::arch::asm!` has to be [stubbed](stubbing.md) to be verified. | ||
| * Only 64-bit little-endian targets are supported. A 32-bit target needs `goto-cc -m32` and a | ||
| review of Kani's 64-bit assumptions ([#2086](https://github.com/model-checking/kani/issues/2086)). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: kernels usually build for
riscv64gc-unknown-none-elf, whichcheck_targetrejects. Verifying such a crate asriscv64gc-unknown-linux-gnusetstarget_os = "linux"and makesstdavailable, so code behindcfg(target_os = "none")is compiled out and thelinuxbranch is verified in its place. A sentence here saying the bare-metal target isn't supported, and what changes when the Linux one stands in for it, would tell kernel users what they are and aren't verifying.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in eb6c119. The page now says
riscv64gc-unknown-none-elfisn't supported, and that verifying such a crate asriscv64gc-unknown-linux-gnusetstarget_os = "linux"and makesstdavailable, socfg(target_os = "none")code is compiled out and thelinuxbranch is what gets verified.