Skip to content

Commit 1d2877d

Browse files
authored
Merge pull request #506 from solson/rustup
Rustup for retagging
2 parents b1be4ee + cb691b7 commit 1d2877d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+671
-354
lines changed

appveyor.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ branches:
1414
- master
1515

1616
install:
17-
# install Rust
17+
# Install Rust.
1818
- set PATH=C:\Program Files\Git\mingw64\bin;C:\msys64\mingw%MSYS2_BITS%\bin;%PATH%
1919
- set /p RUST_TOOLCHAIN=<rust-version
2020
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
2121
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_TOOLCHAIN%
2222
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
2323
- rustc --version
24-
# customize installation
24+
# Customize installation.
2525
- rustup component add rust-src
2626
- cargo install xargo
27-
# prepare a libstd with MIR (cannot use bash script, obviously)
27+
# Prepare a libstd with MIR (cannot use bash script, obviously).
28+
# The flags here should be kept in sync with `add_miri_default_args` in `src/lib.rs`.
2829
- cd xargo
29-
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-validate=1
30+
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-retag -Zmir-opt-level=0
3031
- xargo build
3132
- set RUSTFLAGS=
3233
- cd ..

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2018-10-30
1+
nightly-2018-11-03

src/bin/cargo-miri.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ fn main() {
173173
.chain(Some(sys_root))
174174
.collect()
175175
};
176+
args.splice(0..0, miri::miri_default_args().iter().map(ToString::to_string));
176177

177178
// this check ensures that dependencies are built but not interpreted and the final crate is
178179
// interpreted but not built
@@ -186,7 +187,6 @@ fn main() {
186187
Command::new("rustc")
187188
};
188189

189-
args.extend_from_slice(&["-Z".to_owned(), "always-encode-mir".to_owned()]);
190190
args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]);
191191

192192
match command.args(&args).status() {

src/bin/miri-rustc-tests.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ fn main() {
156156
true
157157
}
158158
}).collect();
159+
args.splice(1..1, miri::miri_default_args().iter().map(ToString::to_string));
159160
// file to process
160161
args.push(path.display().to_string());
161162

@@ -165,10 +166,6 @@ fn main() {
165166
args.push(Path::new(&std::env::var("HOME").unwrap()).join(".xargo").join("HOST").display().to_string());
166167
}
167168

168-
args.push("-Zmir-opt-level=3".to_owned());
169-
// for auxilary builds in unit tests
170-
args.push("-Zalways-encode-mir".to_owned());
171-
172169
// A threadsafe buffer for writing.
173170
#[derive(Default, Clone)]
174171
struct BufWriter(Arc<Mutex<Vec<u8>>>);

src/bin/miri.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ extern crate rustc_codegen_utils;
1010
extern crate env_logger;
1111
extern crate log_settings;
1212
extern crate syntax;
13+
14+
#[macro_use]
1315
extern crate log;
1416

1517
use std::path::PathBuf;
@@ -212,12 +214,7 @@ fn main() {
212214
init_early_loggers();
213215
let mut args: Vec<String> = std::env::args().collect();
214216

215-
let sysroot_flag = String::from("--sysroot");
216-
if !args.contains(&sysroot_flag) {
217-
args.push(sysroot_flag);
218-
args.push(find_sysroot());
219-
}
220-
217+
// Parse our own -Z flags and remove them before rustc gets their hand on them.
221218
let mut validate = true;
222219
args.retain(|arg| {
223220
match arg.as_str() {
@@ -229,7 +226,16 @@ fn main() {
229226
}
230227
});
231228

229+
// Determine sysroot and let rustc know about it
230+
let sysroot_flag = String::from("--sysroot");
231+
if !args.contains(&sysroot_flag) {
232+
args.push(sysroot_flag);
233+
args.push(find_sysroot());
234+
}
235+
// Finally, add the default flags all the way in the beginning, but after the binary name.
236+
args.splice(1..1, miri::miri_default_args().iter().map(ToString::to_string));
232237

238+
trace!("rustc arguments: {:?}", args);
233239
let result = rustc_driver::run(move || {
234240
rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls {
235241
default: Box::new(RustcDefaultCalls),

src/lib.rs

+40-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use syntax::attr;
2626

2727

2828
pub use rustc_mir::interpret::*;
29-
pub use rustc_mir::interpret::{self, AllocMap}; // resolve ambiguity
29+
pub use rustc_mir::interpret::{self, AllocMap, PlaceTy}; // resolve ambiguity
3030

3131
mod fn_call;
3232
mod operator;
@@ -48,7 +48,16 @@ use crate::mono_hash_map::MonoHashMap;
4848
use crate::stacked_borrows::{EvalContextExt as StackedBorEvalContextExt};
4949

5050
// Used by priroda
51-
pub use stacked_borrows::{Borrow, Stacks, Mut as MutBorrow};
51+
pub use crate::stacked_borrows::{Borrow, Stack, Stacks, Mut as MutBorrow, BorStackItem};
52+
53+
/// Insert rustc arguments at the beginning of the argument list that miri wants to be
54+
/// set per default, for maximal validation power.
55+
pub fn miri_default_args() -> &'static [&'static str] {
56+
// The flags here should be kept in sync with what bootstrap adds when `test-miri` is
57+
// set, which happens in `bootstrap/bin/rustc.rs` in the rustc sources; and also
58+
// kept in sync with `xargo/build.sh` in this repo and `appveyor.yml`.
59+
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0"]
60+
}
5261

5362
// Used by priroda
5463
pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
@@ -438,21 +447,30 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
438447
}
439448

440449
#[inline(always)]
441-
fn memory_accessed(
450+
fn memory_read(
442451
alloc: &Allocation<Borrow, Self::AllocExtra>,
443452
ptr: Pointer<Borrow>,
444453
size: Size,
445-
access: MemoryAccess,
446454
) -> EvalResult<'tcx> {
447-
alloc.extra.memory_accessed(ptr, size, access)
455+
alloc.extra.memory_read(ptr, size)
456+
}
457+
458+
#[inline(always)]
459+
fn memory_written(
460+
alloc: &mut Allocation<Borrow, Self::AllocExtra>,
461+
ptr: Pointer<Borrow>,
462+
size: Size,
463+
) -> EvalResult<'tcx> {
464+
alloc.extra.memory_written(ptr, size)
448465
}
449466

450467
#[inline(always)]
451468
fn memory_deallocated(
452469
alloc: &mut Allocation<Borrow, Self::AllocExtra>,
453470
ptr: Pointer<Borrow>,
471+
size: Size,
454472
) -> EvalResult<'tcx> {
455-
alloc.extra.memory_deallocated(ptr)
473+
alloc.extra.memory_deallocated(ptr, size)
456474
}
457475

458476
#[inline(always)]
@@ -507,4 +525,20 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
507525
Ok(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
508526
}
509527
}
528+
529+
#[inline(always)]
530+
fn retag(
531+
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
532+
fn_entry: bool,
533+
place: PlaceTy<'tcx, Borrow>,
534+
) -> EvalResult<'tcx> {
535+
if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !Self::enforce_validity(ecx) {
536+
// No tracking, or no retagging. This is possible because a dependency of ours might be
537+
// called with different flags than we are,
538+
// Also, honor the whitelist in `enforce_validity` because otherwise we might retag
539+
// uninitialized data.
540+
return Ok(())
541+
}
542+
ecx.retag(fn_entry, place)
543+
}
510544
}

0 commit comments

Comments
 (0)