Skip to content

Commit

Permalink
Merge pull request #506 from solson/rustup
Browse files Browse the repository at this point in the history
Rustup for retagging
  • Loading branch information
RalfJung committed Nov 3, 2018
2 parents b1be4ee + cb691b7 commit 1d2877d
Show file tree
Hide file tree
Showing 59 changed files with 671 additions and 354 deletions.
9 changes: 5 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ branches:
- master

install:
# install Rust
# Install Rust.
- set PATH=C:\Program Files\Git\mingw64\bin;C:\msys64\mingw%MSYS2_BITS%\bin;%PATH%
- set /p RUST_TOOLCHAIN=<rust-version
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_TOOLCHAIN%
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
- rustc --version
# customize installation
# Customize installation.
- rustup component add rust-src
- cargo install xargo
# prepare a libstd with MIR (cannot use bash script, obviously)
# Prepare a libstd with MIR (cannot use bash script, obviously).
# The flags here should be kept in sync with `add_miri_default_args` in `src/lib.rs`.
- cd xargo
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-validate=1
- set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-retag -Zmir-opt-level=0
- xargo build
- set RUSTFLAGS=
- cd ..
Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2018-10-30
nightly-2018-11-03
2 changes: 1 addition & 1 deletion src/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn main() {
.chain(Some(sys_root))
.collect()
};
args.splice(0..0, miri::miri_default_args().iter().map(ToString::to_string));

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

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

match command.args(&args).status() {
Expand Down
5 changes: 1 addition & 4 deletions src/bin/miri-rustc-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn main() {
true
}
}).collect();
args.splice(1..1, miri::miri_default_args().iter().map(ToString::to_string));
// file to process
args.push(path.display().to_string());

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

args.push("-Zmir-opt-level=3".to_owned());
// for auxilary builds in unit tests
args.push("-Zalways-encode-mir".to_owned());

// A threadsafe buffer for writing.
#[derive(Default, Clone)]
struct BufWriter(Arc<Mutex<Vec<u8>>>);
Expand Down
18 changes: 12 additions & 6 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ extern crate rustc_codegen_utils;
extern crate env_logger;
extern crate log_settings;
extern crate syntax;

#[macro_use]
extern crate log;

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

let sysroot_flag = String::from("--sysroot");
if !args.contains(&sysroot_flag) {
args.push(sysroot_flag);
args.push(find_sysroot());
}

// Parse our own -Z flags and remove them before rustc gets their hand on them.
let mut validate = true;
args.retain(|arg| {
match arg.as_str() {
Expand All @@ -229,7 +226,16 @@ fn main() {
}
});

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

trace!("rustc arguments: {:?}", args);
let result = rustc_driver::run(move || {
rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls {
default: Box::new(RustcDefaultCalls),
Expand Down
46 changes: 40 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use syntax::attr;


pub use rustc_mir::interpret::*;
pub use rustc_mir::interpret::{self, AllocMap}; // resolve ambiguity
pub use rustc_mir::interpret::{self, AllocMap, PlaceTy}; // resolve ambiguity

mod fn_call;
mod operator;
Expand All @@ -48,7 +48,16 @@ use crate::mono_hash_map::MonoHashMap;
use crate::stacked_borrows::{EvalContextExt as StackedBorEvalContextExt};

// Used by priroda
pub use stacked_borrows::{Borrow, Stacks, Mut as MutBorrow};
pub use crate::stacked_borrows::{Borrow, Stack, Stacks, Mut as MutBorrow, BorStackItem};

/// Insert rustc arguments at the beginning of the argument list that miri wants to be
/// set per default, for maximal validation power.
pub fn miri_default_args() -> &'static [&'static str] {
// The flags here should be kept in sync with what bootstrap adds when `test-miri` is
// set, which happens in `bootstrap/bin/rustc.rs` in the rustc sources; and also
// kept in sync with `xargo/build.sh` in this repo and `appveyor.yml`.
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0"]
}

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

#[inline(always)]
fn memory_accessed(
fn memory_read(
alloc: &Allocation<Borrow, Self::AllocExtra>,
ptr: Pointer<Borrow>,
size: Size,
access: MemoryAccess,
) -> EvalResult<'tcx> {
alloc.extra.memory_accessed(ptr, size, access)
alloc.extra.memory_read(ptr, size)
}

#[inline(always)]
fn memory_written(
alloc: &mut Allocation<Borrow, Self::AllocExtra>,
ptr: Pointer<Borrow>,
size: Size,
) -> EvalResult<'tcx> {
alloc.extra.memory_written(ptr, size)
}

#[inline(always)]
fn memory_deallocated(
alloc: &mut Allocation<Borrow, Self::AllocExtra>,
ptr: Pointer<Borrow>,
size: Size,
) -> EvalResult<'tcx> {
alloc.extra.memory_deallocated(ptr)
alloc.extra.memory_deallocated(ptr, size)
}

#[inline(always)]
Expand Down Expand Up @@ -507,4 +525,20 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
Ok(Pointer::new_with_tag(ptr.alloc_id, ptr.offset, tag))
}
}

#[inline(always)]
fn retag(
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
fn_entry: bool,
place: PlaceTy<'tcx, Borrow>,
) -> EvalResult<'tcx> {
if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !Self::enforce_validity(ecx) {
// No tracking, or no retagging. This is possible because a dependency of ours might be
// called with different flags than we are,
// Also, honor the whitelist in `enforce_validity` because otherwise we might retag
// uninitialized data.
return Ok(())
}
ecx.retag(fn_entry, place)
}
}
Loading

0 comments on commit 1d2877d

Please sign in to comment.