also accept odd number of hex digits; add README section on randomized alignment testing

This commit is contained in:
Ralf Jung 2022-03-12 10:09:15 -05:00
parent 27d5b846ee
commit 9a6450af95
4 changed files with 22 additions and 26 deletions

7
Cargo.lock generated
View File

@ -155,12 +155,6 @@ dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "humantime"
version = "2.1.0"
@ -258,7 +252,6 @@ dependencies = [
"compiletest_rs",
"env_logger",
"getrandom",
"hex",
"libc",
"log",
"measureme",

View File

@ -22,7 +22,6 @@ getrandom = { version = "0.2", features = ["std"] }
env_logger = "0.9"
log = "0.4"
shell-escape = "0.1.4"
hex = "0.4.0"
rand = "0.8"
smallvec = "1.7"

View File

@ -175,12 +175,28 @@ Here is an example job for GitHub Actions:
The explicit `cargo miri setup` helps to keep the output of the actual test step
clean.
### Testing for alignment issues
Miri can sometimes miss misaligned accesses since allocations can "happen to be"
aligned just right. You can use `-Zmiri-symbolic-alignment-check` to definitely
catch all such issues, but that flag will also cause false positives when code
does manual pointer arithmetic to account for alignment. Another alternative is
to call Miri with various values for `-Zmiri-seed`; that will alter the
randomness that is used to determine allocation base addresses. The following
snippet calls Miri in a loop with different values for the seed:
```
for seed in $({ echo obase=16; seq 255; } | bc); do
MIRIFLAGS=-Zmiri-seed=$seed cargo miri test || { echo "Last seed: $seed"; break; };
done
```
### Common Problems
When using the above instructions, you may encounter a number of confusing compiler
errors.
### "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"
#### "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"
You may see this when trying to get Miri to display a backtrace. By default, Miri
doesn't expose any environment to the program, so running

View File

@ -15,7 +15,6 @@ use std::num::NonZeroU64;
use std::path::PathBuf;
use std::str::FromStr;
use hex::FromHexError;
use log::debug;
use rustc_data_structures::sync::Lrc;
@ -377,22 +376,11 @@ fn main() {
if miri_config.seed.is_some() {
panic!("Cannot specify -Zmiri-seed multiple times!");
}
let seed_raw = hex::decode(arg.strip_prefix("-Zmiri-seed=").unwrap())
.unwrap_or_else(|err| match err {
FromHexError::InvalidHexCharacter { .. } => panic!(
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F]"
),
FromHexError::OddLength =>
panic!("-Zmiri-seed should have an even number of digits"),
err => panic!("unknown error decoding -Zmiri-seed as hex: {:?}", err),
});
if seed_raw.len() > 8 {
panic!("-Zmiri-seed must be at most 8 bytes, was {}", seed_raw.len());
}
let mut bytes = [0; 8];
bytes[..seed_raw.len()].copy_from_slice(&seed_raw);
miri_config.seed = Some(u64::from_be_bytes(bytes));
let seed = u64::from_str_radix(arg.strip_prefix("-Zmiri-seed=").unwrap(), 16)
.unwrap_or_else(|_| panic!(
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F] and fit into a u64 (max 16 characters)"
));
miri_config.seed = Some(seed);
}
arg if arg.starts_with("-Zmiri-env-exclude=") => {
miri_config