Skip to content

rustup for Retagging #505

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

Closed
wants to merge 9 commits into from
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 src/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn main() {
Command::new("rustc")
};

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

match command.args(&args).status() {
Expand Down
4 changes: 1 addition & 3 deletions src/bin/miri-rustc-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ 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());
miri::add_miri_default_args(&mut args);

// A threadsafe buffer for writing.
#[derive(Default, Clone)]
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.
miri::add_miri_default_args(&mut args);

trace!("rustc arguments: {:?}", args);
let result = rustc_driver::run(move || {
rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls {
default: Box::new(RustcDefaultCalls),
Expand Down
51 changes: 45 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,21 @@ use mono_hash_map::MonoHashMap;
use 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 listthat miri wants to be
/// set per default, for maximal validation power.
pub fn add_miri_default_args(args: &mut Vec<String>) {
// 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`.

// Inserting at index 1, after the binary name
args.splice(1..1,
["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0"]
.iter().map(|s| s.to_string())
);
}

// Used by priroda
pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
Expand Down Expand Up @@ -438,21 +452,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 +530,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