Skip to content

update Miri #104617

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

Merged
merged 24 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f1a8701
clean up retagging recursive traversal a bit
RalfJung Nov 16, 2022
331b93a
Auto merge of #2670 - RalfJung:retag, r=RalfJung
RalfJung Nov 17, 2022
d0a7ae1
remove unused shell_escape dep
klensy Nov 16, 2022
3de7c28
Auto merge of #2671 - klensy:shell_escape, r=RalfJung
RalfJung Nov 17, 2022
da4eb35
update josh scripts
RalfJung Nov 17, 2022
9554395
update rust-version
RalfJung Nov 17, 2022
a00a094
empty commit to go through bors
RalfJung Nov 17, 2022
db0a48c
Auto merge of #2676 - RalfJung:empty, r=RalfJung
bors Nov 17, 2022
8ec2149
remove CI badge
RalfJung Nov 17, 2022
cf4da2d
Auto merge of #2677 - RalfJung:badge, r=RalfJung
bors Nov 17, 2022
e2f6a1b
Preparing for merge from rustc
RalfJung Nov 19, 2022
81ee8c1
Merge from rustc
RalfJung Nov 19, 2022
21321f5
implement clock_gettime on macos
RalfJung Nov 19, 2022
fc105ef
Auto merge of #2679 - RalfJung:clock_gettime, r=RalfJung
bors Nov 19, 2022
aada2d1
Preparing for merge from rustc
RalfJung Nov 20, 2022
3865e65
Merge from rustc
RalfJung Nov 20, 2022
4da7d4b
fix unused warning in a test
RalfJung Nov 20, 2022
0a9e5e8
Auto merge of #2680 - RalfJung:rustup, r=RalfJung
bors Nov 20, 2022
772d521
make miri-seed a regular integer, and also set layout-seed in many-seeds
RalfJung Nov 20, 2022
c26b510
Auto merge of #2681 - RalfJung:seed, r=oli-obk
bors Nov 20, 2022
c8c82a0
make align_offset always work on no-provenance pointers
RalfJung Nov 20, 2022
8459a16
Auto merge of #2683 - RalfJung:align_offset, r=RalfJung
bors Nov 20, 2022
a689eb0
update lockfile
RalfJung Nov 20, 2022
c043a0e
cfg(miri) no longer needed in sys/unix/time.rs
RalfJung Nov 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,6 @@ dependencies = [
"regex",
"rustc-workspace-hack",
"rustc_version",
"shell-escape",
"smallvec",
"ui_test",
]
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl From<libc::timespec> for Timespec {
}

#[cfg(any(
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
all(target_os = "macos", any(not(target_arch = "aarch64"))),
target_os = "ios",
target_os = "watchos"
))]
Expand Down Expand Up @@ -270,7 +270,7 @@ mod inner {
}

#[cfg(not(any(
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
all(target_os = "macos", any(not(target_arch = "aarch64"))),
target_os = "ios",
target_os = "watchos"
)))]
Expand Down
7 changes: 0 additions & 7 deletions src/tools/miri/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ dependencies = [
"regex",
"rustc-workspace-hack",
"rustc_version",
"shell-escape",
"smallvec",
"ui_test",
]
Expand Down Expand Up @@ -632,12 +631,6 @@ dependencies = [
"lazy_static",
]

[[package]]
name = "shell-escape"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"

[[package]]
name = "smallvec"
version = "1.9.0"
Expand Down
1 change: 0 additions & 1 deletion src/tools/miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ doctest = false # and no doc tests
getrandom = { version = "0.2", features = ["std"] }
env_logger = "0.9"
log = "0.4"
shell-escape = "0.1.4"
rand = "0.8"
smallvec = "1.7"

Expand Down
9 changes: 2 additions & 7 deletions src/tools/miri/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Miri

[![Actions build status][actions-badge]][actions-url]

[actions-badge]: https://github.com/rust-lang/miri/workflows/CI/badge.svg?branch=master
[actions-url]: https://github.com/rust-lang/miri/actions

An experimental interpreter for [Rust][rust]'s
[mid-level intermediate representation][mir] (MIR). It can run binaries and
test suites of cargo projects and detect certain classes of
Expand Down Expand Up @@ -200,7 +195,7 @@ 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 0 255; } | bc); do
for SEED in $(seq 0 255); do
echo "Trying seed: $SEED"
MIRIFLAGS=-Zmiri-seed=$SEED cargo miri test || { echo "Failing seed: $SEED"; break; };
done
Expand Down Expand Up @@ -308,7 +303,7 @@ environment variable. We first document the most relevant and most commonly used
tell what it is doing when a program just keeps running. You can customize how frequently the
report is printed via `-Zmiri-report-progress=<blocks>`, which prints the report every N basic
blocks.
* `-Zmiri-seed=<hex>` configures the seed of the RNG that Miri uses to resolve non-determinism. This
* `-Zmiri-seed=<num>` configures the seed of the RNG that Miri uses to resolve non-determinism. This
RNG is used to pick base addresses for allocations, to determine preemption and failure of
`compare_exchange_weak`, and to control store buffering for weak memory emulation. When isolation
is enabled (the default), this is also used to emulate system entropy. The default seed is 0. You
Expand Down
44 changes: 27 additions & 17 deletions src/tools/miri/miri
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Update and activate the rustup toolchain 'miri' to the commit given in the
`rustup-toolchain-install-master` must be installed for this to work. Any extra
flags are passed to `rustup-toolchain-install-master`.

./miri rustc-pull:
Pull and merge Miri changes from the rustc repo. The fetched commit is stored in
the `rust-version` file, so the next `./miri toolchain` will install the rustc
we just pulled.
./miri rustc-pull <commit>:
Pull and merge Miri changes from the rustc repo. Defaults to fetching the latest
rustc commit. The fetched commit is stored in the `rust-version` file, so the
next `./miri toolchain` will install the rustc that just got pulled.

./miri rustc-push <github user> <branch>:
Push Miri changes back to the rustc repo. This will pull a copy of the rustc
Expand Down Expand Up @@ -113,18 +113,17 @@ toolchain)
;;
rustc-pull)
cd "$MIRIDIR"
FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
# We can't pull from a commit with josh
# (https://github.com/josh-project/josh/issues/1034), so we just hope that
# nothing gets merged into rustc *during* this pull.
git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER.git master
# Just verify that `master` didn't move.
if [[ $FETCH_COMMIT != $(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1) ]]; then
echo "Looks like something got merged into Rust *while we were pulling*. Aborting. Please try again."
FETCH_COMMIT="$1"
if [ -z "$FETCH_COMMIT" ]; then
FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
fi
echo "$FETCH_COMMIT" > rust-version # do this *before* merging as merging will fail in case of conflicts
# Update rust-version file. As a separate commit, since making it part of
# the merge has confused the heck out of josh in the past.
echo "$FETCH_COMMIT" > rust-version
git commit rust-version -m "Preparing for merge from rustc"
# Fetch given rustc commit and note down which one that was
git fetch http://localhost:8000/rust-lang/rust.git@$FETCH_COMMIT$JOSH_FILTER.git
git merge FETCH_HEAD --no-ff -m "Merge from rustc"
git commit rust-version --amend -m "Merge from rustc"
exit 0
;;
rustc-push)
Expand Down Expand Up @@ -157,16 +156,27 @@ rustc-push)
fi
git fetch https://github.com/rust-lang/rust $BASE
git push https://github.com/$USER/rust $BASE:refs/heads/$BRANCH -f
echo
# Do the actual push.
cd "$MIRIDIR"
echo "Pushing Miri changes..."
git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH
exit 0
# Do a round-trip check to make sure the push worked as expected.
echo
git fetch http://localhost:8000/$USER/rust.git@$JOSH_FILTER.git $BRANCH &>/dev/null
if [[ $(git rev-parse HEAD) != $(git rev-parse FETCH_HEAD) ]]; then
echo "ERROR: Josh created a non-roundtrip push! Do NOT merge this into rustc!"
exit 1
else
echo "Confirmed that the push round-trips back to Miri properly. Please create a rustc PR:"
echo " https://github.com/$USER/rust/pull/new/$BRANCH"
exit 0
fi
;;
many-seeds)
for SEED in $({ echo obase=16; seq 0 255; } | bc); do
for SEED in $(seq 0 255); do
echo "Trying seed: $SEED"
MIRIFLAGS="$MIRIFLAGS -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
MIRIFLAGS="$MIRIFLAGS -Zlayout-seed=$SEED -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
done
exit 0
;;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
101e1822c3e54e63996c8aaa014d55716f3937eb
7477c1f4f7d6bef037d523099b240d22aa1b63a0
7 changes: 3 additions & 4 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,9 @@ fn main() {
if miri_config.seed.is_some() {
show_error!("Cannot specify -Zmiri-seed multiple times!");
}
let seed = u64::from_str_radix(param, 16)
.unwrap_or_else(|_| show_error!(
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F] and must fit into a u64 (max 16 characters)"
));
let seed = param.parse::<u64>().unwrap_or_else(|_| {
show_error!("-Zmiri-seed must be an integer that fits into u64")
});
miri_config.seed = Some(seed);
} else if let Some(_param) = arg.strip_prefix("-Zmiri-env-exclude=") {
show_error!(
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/src/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

let ptr = this.read_pointer(ptr_op)?;
// If this carries no provenance, treat it like an integer.
if ptr.provenance.is_none() {
// Use actual implementation.
return Ok(false);
}

if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
// Only do anything if we can identify the allocation this goes to.
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);
Expand Down
48 changes: 36 additions & 12 deletions src/tools/miri/src/shims/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,52 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {

let this = self.eval_context_mut();

this.assert_target_os("linux", "clock_gettime");
this.assert_target_os_is_unix("clock_gettime");

let clk_id = this.read_scalar(clk_id_op)?.to_i32()?;

// Linux has two main kinds of clocks. REALTIME clocks return the actual time since the
// Unix epoch, including effects which may cause time to move backwards such as NTP.
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
// is just specified to be "faster and less precise", so we implement both the same way.
let absolute_clocks =
[this.eval_libc_i32("CLOCK_REALTIME")?, this.eval_libc_i32("CLOCK_REALTIME_COARSE")?];
// The second kind is MONOTONIC clocks for which 0 is an arbitrary time point, but they are
// never allowed to go backwards. We don't need to do any additonal monotonicity
// enforcement because std::time::Instant already guarantees that it is monotonic.
let relative_clocks =
[this.eval_libc_i32("CLOCK_MONOTONIC")?, this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?];
let absolute_clocks;
let mut relative_clocks;

match this.tcx.sess.target.os.as_ref() {
"linux" => {
// Linux has two main kinds of clocks. REALTIME clocks return the actual time since the
// Unix epoch, including effects which may cause time to move backwards such as NTP.
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
// is just specified to be "faster and less precise", so we implement both the same way.
absolute_clocks = vec![
this.eval_libc_i32("CLOCK_REALTIME")?,
this.eval_libc_i32("CLOCK_REALTIME_COARSE")?,
];
// The second kind is MONOTONIC clocks for which 0 is an arbitrary time point, but they are
// never allowed to go backwards. We don't need to do any additonal monotonicity
// enforcement because std::time::Instant already guarantees that it is monotonic.
relative_clocks = vec![
this.eval_libc_i32("CLOCK_MONOTONIC")?,
this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?,
];
}
"macos" => {
absolute_clocks = vec![this.eval_libc_i32("CLOCK_REALTIME")?];
relative_clocks = vec![this.eval_libc_i32("CLOCK_MONOTONIC")?];
// Some clocks only seem to exist in the aarch64 version of the target.
if this.tcx.sess.target.arch == "aarch64" {
// `CLOCK_UPTIME_RAW` supposed to not increment while the system is asleep... but
// that's not really something a program running inside Miri can tell, anyway.
// We need to support it because std uses it.
relative_clocks.push(this.eval_libc_i32("CLOCK_UPTIME_RAW")?);
}
}
target => throw_unsup_format!("`clock_gettime` is not supported on target OS {target}"),
}

let duration = if absolute_clocks.contains(&clk_id) {
this.check_no_isolation("`clock_gettime` with `REALTIME` clocks")?;
system_time_to_duration(&SystemTime::now())?
} else if relative_clocks.contains(&clk_id) {
this.machine.clock.now().duration_since(this.machine.clock.anchor())
} else {
// Unsupported clock.
let einval = this.eval_libc("EINVAL")?;
this.set_last_error(einval)?;
return Ok(Scalar::from_i32(-1));
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let result = this.gettimeofday(tv, tz)?;
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"clock_gettime" => {
let [clk_id, tp] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let result = this.clock_gettime(clk_id, tp)?;
this.write_scalar(result, dest)?;
}

// Allocation
"posix_memalign" => {
Expand Down
9 changes: 0 additions & 9 deletions src/tools/miri/src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_scalar(result, dest)?;
}

// Time related shims
"clock_gettime" => {
// This is a POSIX function but it has only been tested on linux.
let [clk_id, tp] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let result = this.clock_gettime(clk_id, tp)?;
this.write_scalar(result, dest)?;
}

// Threading
"pthread_condattr_setclock" => {
let [attr, clock_id] =
Expand Down
Loading