Repository navigation
Closed
Labels
[C] Feature / EnhancementA new feature request or enhancement to an existing feature.A new feature request or enhancement to an existing feature.
Description
Currently, kani supports a limited number of targets (x86_64-unknown-linux-gnu, x86_64-apple-darwin and aarch64-apple-darwin ) and the verification target should be the same with the host environment.
I think that being able to verify a code for the target different to the host environment would enhance the kani's overall applicability especially for the embedded environment.
To verify a code for the target different to the host environment, I've tried the following steps.
- prepare for the CBMC machine model by modifying machine_model_from_session()
- prepare for the kani session for the target environment by modifying cargo_build() so that kani's
cargo buildcould be called with the custom target triple (e.g., 32bit architecture). - build kani-library (
libkani.rlibandlibstd.rlib) for the target environment while building kani-compiler and kani-driver for the host environment
I initially thought the the above steps might be enough, but I've encountered the following error.
$ cargo kani --verbose
[Kani] Running: `KANIFLAGS="--goto-c --log-level=info --assertion-reach-checks -C symbol-mangling-version=v0" RUSTC="/home/xxx/kani/target/debug/kani-compiler" RUSTFLAGS="--kani-flags" cargo rustc --target armv7-unknown-linux-gnueabi --target-dir /home/xxx/test/kani-test/size/target/kani -v -p size --lib -- --reachability=harnesses`
Running `/home/xxx/kani/target/debug/kani-compiler --crate-name size --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --reachability=harnesses -C metadata=0446ecd2f07a989c -C extra-filename=-0446ecd2f07a989c --out-dir /home/xxx/test/kani-test/size/target/kani/armv7-unknown-linux-gnueabi/debug/deps --target armv7-unknown-linux-gnueabi -C incremental=/home/xxx/test/kani-test/size/target/kani/armv7-unknown-linux-gnueabi/debug/incremental -L dependency=/home/xxx/test/kani-test/size/target/kani/armv7-unknown-linux-gnueabi/debug/deps -L dependency=/home/xxx/test/kani-test/size/target/kani/debug/deps --kani-flags`
error[E0460]: found possibly newer version of crate `std` which `std` depends on
|
= note: perhaps that crate needs to be recompiled?
= note: the following crate versions were found:
crate `std`: /home/xxx/kani/target/lib/libstd.rlib
crate `std`: /home/xxx/kani/target/lib/libstd.rlib
Am I miss something or what additional steps needs to be done?
Metadata
Metadata
Assignees
Labels
[C] Feature / EnhancementA new feature request or enhancement to an existing feature.A new feature request or enhancement to an existing feature.
Activity
celinval commentedon Jan 6, 2023
Hi @zpzigi754, how did you build the kani-library? Kani also rebuild the standard library. Also in the process of doing so, there is a name conflict since we are building 2 std. You can see how we build our libraries here:
kani/tools/build-kani/src/sysroot.rs
Line 70 in c2690ab
Also, be aware that we have never tested Kani with 32bit architectures, so there could be hidden assumptions in our code that consider that the platform is 64bits.
zpzigi754 commentedon Jan 9, 2023
Thank you for the reference, @celinval. By that time, I built the kani-library with
cargo build -Z build-stdin each of the sub-directory (kaniandstd). Using the mentioned link aboutbuild_lib(), I could resolve the initial std-related error and verify a tiny code for 32 bit architecture. However, it seems that more engineering effort is needed because of the hidden assumptions about 64 bit architecture.zpzigi754 commentedon Jan 10, 2023
During the work for 32bit architecture support, one problem appeared when using a reference operator.
With the above harness, it generates a cbmc fault like
I'm not sure why there is the width of 64 while the place and pointer's width is 32.
zhassan-aws commentedon Jan 11, 2023
There might be a hard-coded assumption about the pointer size. Can you point to the branch you're using so that we can debug this issue?
zpzigi754 commentedon Jan 12, 2023
Sure. I've made a branch here. Kani could be built and run with the normal commands there (
cargo build-devfor building kani andcargo kanifor the verfication).With that branch, the below harness would be successfully verified.
However, the reference operator would not work as mentioned.
zhassan-aws commentedon Jan 12, 2023
Thanks for the branch! It turns out that the 64-bit value is introduced by CBMC (specifically the
goto-ccinvokation). Apparently,goto-ccneeds to be invoked with-m32to target a 32-bit architecture.This diff on top of your branch makes the program go through:
zpzigi754 commentedon Jan 13, 2023
@zhassan-aws, thanks a lot for the help! I've confirmed that it works with the fix.
DianaNites commentedon Apr 23, 2023
Could this feature be supported upstream with a command-line flag?
zhassan-aws commentedon Apr 23, 2023
@DianaNites can you open a separate issue describing what you want the command-line flag to do?