Skip to content

Commit 911cbf8

Browse files
committed
Auto merge of #104617 - RalfJung:miri, r=RalfJung
update Miri r? `@thomcc` for the lib changes (removing a `cfg(miri)` that is no longer needed)
2 parents 9cdfe03 + c043a0e commit 911cbf8

File tree

17 files changed

+154
-117
lines changed

17 files changed

+154
-117
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,6 @@ dependencies = [
23302330
"regex",
23312331
"rustc-workspace-hack",
23322332
"rustc_version",
2333-
"shell-escape",
23342333
"smallvec",
23352334
"ui_test",
23362335
]

library/std/src/sys/unix/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl From<libc::timespec> for Timespec {
150150
}
151151

152152
#[cfg(any(
153-
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
153+
all(target_os = "macos", any(not(target_arch = "aarch64"))),
154154
target_os = "ios",
155155
target_os = "watchos"
156156
))]
@@ -270,7 +270,7 @@ mod inner {
270270
}
271271

272272
#[cfg(not(any(
273-
all(target_os = "macos", any(not(target_arch = "aarch64"), miri)),
273+
all(target_os = "macos", any(not(target_arch = "aarch64"))),
274274
target_os = "ios",
275275
target_os = "watchos"
276276
)))]

src/tools/miri/Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ dependencies = [
383383
"regex",
384384
"rustc-workspace-hack",
385385
"rustc_version",
386-
"shell-escape",
387386
"smallvec",
388387
"ui_test",
389388
]
@@ -632,12 +631,6 @@ dependencies = [
632631
"lazy_static",
633632
]
634633

635-
[[package]]
636-
name = "shell-escape"
637-
version = "0.1.5"
638-
source = "registry+https://github.com/rust-lang/crates.io-index"
639-
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
640-
641634
[[package]]
642635
name = "smallvec"
643636
version = "1.9.0"

src/tools/miri/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ doctest = false # and no doc tests
2121
getrandom = { version = "0.2", features = ["std"] }
2222
env_logger = "0.9"
2323
log = "0.4"
24-
shell-escape = "0.1.4"
2524
rand = "0.8"
2625
smallvec = "1.7"
2726

src/tools/miri/README.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# Miri
22

3-
[![Actions build status][actions-badge]][actions-url]
4-
5-
[actions-badge]: https://github.com/rust-lang/miri/workflows/CI/badge.svg?branch=master
6-
[actions-url]: https://github.com/rust-lang/miri/actions
7-
83
An experimental interpreter for [Rust][rust]'s
94
[mid-level intermediate representation][mir] (MIR). It can run binaries and
105
test suites of cargo projects and detect certain classes of
@@ -200,7 +195,7 @@ randomness that is used to determine allocation base addresses. The following
200195
snippet calls Miri in a loop with different values for the seed:
201196

202197
```
203-
for SEED in $({ echo obase=16; seq 0 255; } | bc); do
198+
for SEED in $(seq 0 255); do
204199
echo "Trying seed: $SEED"
205200
MIRIFLAGS=-Zmiri-seed=$SEED cargo miri test || { echo "Failing seed: $SEED"; break; };
206201
done
@@ -308,7 +303,7 @@ environment variable. We first document the most relevant and most commonly used
308303
tell what it is doing when a program just keeps running. You can customize how frequently the
309304
report is printed via `-Zmiri-report-progress=<blocks>`, which prints the report every N basic
310305
blocks.
311-
* `-Zmiri-seed=<hex>` configures the seed of the RNG that Miri uses to resolve non-determinism. This
306+
* `-Zmiri-seed=<num>` configures the seed of the RNG that Miri uses to resolve non-determinism. This
312307
RNG is used to pick base addresses for allocations, to determine preemption and failure of
313308
`compare_exchange_weak`, and to control store buffering for weak memory emulation. When isolation
314309
is enabled (the default), this is also used to emulate system entropy. The default seed is 0. You

src/tools/miri/miri

+27-17
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Update and activate the rustup toolchain 'miri' to the commit given in the
4848
`rustup-toolchain-install-master` must be installed for this to work. Any extra
4949
flags are passed to `rustup-toolchain-install-master`.
5050
51-
./miri rustc-pull:
52-
Pull and merge Miri changes from the rustc repo. The fetched commit is stored in
53-
the `rust-version` file, so the next `./miri toolchain` will install the rustc
54-
we just pulled.
51+
./miri rustc-pull <commit>:
52+
Pull and merge Miri changes from the rustc repo. Defaults to fetching the latest
53+
rustc commit. The fetched commit is stored in the `rust-version` file, so the
54+
next `./miri toolchain` will install the rustc that just got pulled.
5555
5656
./miri rustc-push <github user> <branch>:
5757
Push Miri changes back to the rustc repo. This will pull a copy of the rustc
@@ -113,18 +113,17 @@ toolchain)
113113
;;
114114
rustc-pull)
115115
cd "$MIRIDIR"
116-
FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
117-
# We can't pull from a commit with josh
118-
# (https://github.com/josh-project/josh/issues/1034), so we just hope that
119-
# nothing gets merged into rustc *during* this pull.
120-
git fetch http://localhost:8000/rust-lang/rust.git$JOSH_FILTER.git master
121-
# Just verify that `master` didn't move.
122-
if [[ $FETCH_COMMIT != $(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1) ]]; then
123-
echo "Looks like something got merged into Rust *while we were pulling*. Aborting. Please try again."
116+
FETCH_COMMIT="$1"
117+
if [ -z "$FETCH_COMMIT" ]; then
118+
FETCH_COMMIT=$(git ls-remote https://github.com/rust-lang/rust/ HEAD | cut -f 1)
124119
fi
125-
echo "$FETCH_COMMIT" > rust-version # do this *before* merging as merging will fail in case of conflicts
120+
# Update rust-version file. As a separate commit, since making it part of
121+
# the merge has confused the heck out of josh in the past.
122+
echo "$FETCH_COMMIT" > rust-version
123+
git commit rust-version -m "Preparing for merge from rustc"
124+
# Fetch given rustc commit and note down which one that was
125+
git fetch http://localhost:8000/rust-lang/rust.git@$FETCH_COMMIT$JOSH_FILTER.git
126126
git merge FETCH_HEAD --no-ff -m "Merge from rustc"
127-
git commit rust-version --amend -m "Merge from rustc"
128127
exit 0
129128
;;
130129
rustc-push)
@@ -157,16 +156,27 @@ rustc-push)
157156
fi
158157
git fetch https://github.com/rust-lang/rust $BASE
159158
git push https://github.com/$USER/rust $BASE:refs/heads/$BRANCH -f
159+
echo
160160
# Do the actual push.
161161
cd "$MIRIDIR"
162162
echo "Pushing Miri changes..."
163163
git push http://localhost:8000/$USER/rust.git$JOSH_FILTER.git HEAD:$BRANCH
164-
exit 0
164+
# Do a round-trip check to make sure the push worked as expected.
165+
echo
166+
git fetch http://localhost:8000/$USER/rust.git@$JOSH_FILTER.git $BRANCH &>/dev/null
167+
if [[ $(git rev-parse HEAD) != $(git rev-parse FETCH_HEAD) ]]; then
168+
echo "ERROR: Josh created a non-roundtrip push! Do NOT merge this into rustc!"
169+
exit 1
170+
else
171+
echo "Confirmed that the push round-trips back to Miri properly. Please create a rustc PR:"
172+
echo " https://github.com/$USER/rust/pull/new/$BRANCH"
173+
exit 0
174+
fi
165175
;;
166176
many-seeds)
167-
for SEED in $({ echo obase=16; seq 0 255; } | bc); do
177+
for SEED in $(seq 0 255); do
168178
echo "Trying seed: $SEED"
169-
MIRIFLAGS="$MIRIFLAGS -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
179+
MIRIFLAGS="$MIRIFLAGS -Zlayout-seed=$SEED -Zmiri-seed=$SEED" $@ || { echo "Failing seed: $SEED"; break; }
170180
done
171181
exit 0
172182
;;

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
101e1822c3e54e63996c8aaa014d55716f3937eb
1+
7477c1f4f7d6bef037d523099b240d22aa1b63a0

src/tools/miri/src/bin/miri.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,9 @@ fn main() {
394394
if miri_config.seed.is_some() {
395395
show_error!("Cannot specify -Zmiri-seed multiple times!");
396396
}
397-
let seed = u64::from_str_radix(param, 16)
398-
.unwrap_or_else(|_| show_error!(
399-
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F] and must fit into a u64 (max 16 characters)"
400-
));
397+
let seed = param.parse::<u64>().unwrap_or_else(|_| {
398+
show_error!("-Zmiri-seed must be an integer that fits into u64")
399+
});
401400
miri_config.seed = Some(seed);
402401
} else if let Some(_param) = arg.strip_prefix("-Zmiri-env-exclude=") {
403402
show_error!(

src/tools/miri/src/shims/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8989
}
9090

9191
let ptr = this.read_pointer(ptr_op)?;
92+
// If this carries no provenance, treat it like an integer.
93+
if ptr.provenance.is_none() {
94+
// Use actual implementation.
95+
return Ok(false);
96+
}
97+
9298
if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
9399
// Only do anything if we can identify the allocation this goes to.
94100
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);

src/tools/miri/src/shims/time.rs

+36-12
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,52 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2222

2323
let this = self.eval_context_mut();
2424

25-
this.assert_target_os("linux", "clock_gettime");
25+
this.assert_target_os_is_unix("clock_gettime");
2626

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

29-
// Linux has two main kinds of clocks. REALTIME clocks return the actual time since the
30-
// Unix epoch, including effects which may cause time to move backwards such as NTP.
31-
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
32-
// is just specified to be "faster and less precise", so we implement both the same way.
33-
let absolute_clocks =
34-
[this.eval_libc_i32("CLOCK_REALTIME")?, this.eval_libc_i32("CLOCK_REALTIME_COARSE")?];
35-
// The second kind is MONOTONIC clocks for which 0 is an arbitrary time point, but they are
36-
// never allowed to go backwards. We don't need to do any additonal monotonicity
37-
// enforcement because std::time::Instant already guarantees that it is monotonic.
38-
let relative_clocks =
39-
[this.eval_libc_i32("CLOCK_MONOTONIC")?, this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?];
29+
let absolute_clocks;
30+
let mut relative_clocks;
31+
32+
match this.tcx.sess.target.os.as_ref() {
33+
"linux" => {
34+
// Linux has two main kinds of clocks. REALTIME clocks return the actual time since the
35+
// Unix epoch, including effects which may cause time to move backwards such as NTP.
36+
// Linux further distinguishes regular and "coarse" clocks, but the "coarse" version
37+
// is just specified to be "faster and less precise", so we implement both the same way.
38+
absolute_clocks = vec![
39+
this.eval_libc_i32("CLOCK_REALTIME")?,
40+
this.eval_libc_i32("CLOCK_REALTIME_COARSE")?,
41+
];
42+
// The second kind is MONOTONIC clocks for which 0 is an arbitrary time point, but they are
43+
// never allowed to go backwards. We don't need to do any additonal monotonicity
44+
// enforcement because std::time::Instant already guarantees that it is monotonic.
45+
relative_clocks = vec![
46+
this.eval_libc_i32("CLOCK_MONOTONIC")?,
47+
this.eval_libc_i32("CLOCK_MONOTONIC_COARSE")?,
48+
];
49+
}
50+
"macos" => {
51+
absolute_clocks = vec![this.eval_libc_i32("CLOCK_REALTIME")?];
52+
relative_clocks = vec![this.eval_libc_i32("CLOCK_MONOTONIC")?];
53+
// Some clocks only seem to exist in the aarch64 version of the target.
54+
if this.tcx.sess.target.arch == "aarch64" {
55+
// `CLOCK_UPTIME_RAW` supposed to not increment while the system is asleep... but
56+
// that's not really something a program running inside Miri can tell, anyway.
57+
// We need to support it because std uses it.
58+
relative_clocks.push(this.eval_libc_i32("CLOCK_UPTIME_RAW")?);
59+
}
60+
}
61+
target => throw_unsup_format!("`clock_gettime` is not supported on target OS {target}"),
62+
}
4063

4164
let duration = if absolute_clocks.contains(&clk_id) {
4265
this.check_no_isolation("`clock_gettime` with `REALTIME` clocks")?;
4366
system_time_to_duration(&SystemTime::now())?
4467
} else if relative_clocks.contains(&clk_id) {
4568
this.machine.clock.now().duration_since(this.machine.clock.anchor())
4669
} else {
70+
// Unsupported clock.
4771
let einval = this.eval_libc("EINVAL")?;
4872
this.set_last_error(einval)?;
4973
return Ok(Scalar::from_i32(-1));

src/tools/miri/src/shims/unix/foreign_items.rs

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
180180
let result = this.gettimeofday(tv, tz)?;
181181
this.write_scalar(Scalar::from_i32(result), dest)?;
182182
}
183+
"clock_gettime" => {
184+
let [clk_id, tp] =
185+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
186+
let result = this.clock_gettime(clk_id, tp)?;
187+
this.write_scalar(result, dest)?;
188+
}
183189

184190
// Allocation
185191
"posix_memalign" => {

src/tools/miri/src/shims/unix/linux/foreign_items.rs

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4343
this.write_scalar(result, dest)?;
4444
}
4545

46-
// Time related shims
47-
"clock_gettime" => {
48-
// This is a POSIX function but it has only been tested on linux.
49-
let [clk_id, tp] =
50-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
51-
let result = this.clock_gettime(clk_id, tp)?;
52-
this.write_scalar(result, dest)?;
53-
}
54-
5546
// Threading
5647
"pthread_condattr_setclock" => {
5748
let [attr, clock_id] =

0 commit comments

Comments
 (0)