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
base: main
Are you sure you want to change the base?
Changes from all commits
f295764
5ce11c8
9023df2
a5fac6a
2d0a623
450cbc2
1eaa2d9
08bbefe
409ba07
c377470
9b72fa0
27bf95e
7153afd
eb6c119
d67167f
25e3570
c8a5d29
0467068
3b69842
c264c69
629bdb3
e2e4a07
f9c72e8
9d8eb59
bb0fd81
a147c47
786ddf2
7f0339c
8092e88
e7239cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # 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's compiler refuses any other target, so `cargo build-dev --lib-target` fails for one with an | ||
| error that lists these. | ||
|
|
||
| ## 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 `cargo build-dev` that | ||
| does not name a target leaves its libraries as they were, so name it again after changing | ||
| `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. For the same reason Kani compiles its own `kani_lib.c` on its own | ||
| and links it after the Rust code, which keeps the target's model. | ||
| * 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)). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,14 @@ impl ValidateArgs for VerifyStdArgs { | |
| )); | ||
| } | ||
|
|
||
| if self.verify_opts.target_triple.is_some() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, fixed in 7153afd. |
||
| // Kani's `no_core` library, which `verify-std` builds against, exists for the host only. | ||
| return Err(Error::raw( | ||
| ErrorKind::ArgumentConflict, | ||
| "The `verify-std` subcommand does not support `--target`", | ||
| )); | ||
| } | ||
|
|
||
| validate_std_path(&self.std_path) | ||
| } | ||
| } | ||
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.