Skip to content

Commit 76d99c3

Browse files
committed
fix RUSTC_BACKTRACE always being set
1 parent f633537 commit 76d99c3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/bin/miri.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ fn parse_comma_list<T: FromStr>(input: &str) -> Result<Vec<T>, T::Err> {
306306
}
307307

308308
fn main() {
309+
// Snapshot a copy of the environment before `rustc` starts messing with it.
310+
// (`install_ice_hook` might change `RUST_BACKTRACE`.)
311+
let env_snapshot = env::vars_os().collect::<Vec<_>>();
312+
313+
// Earliest rustc setup.
309314
rustc_driver::install_ice_hook();
310315

311316
// If the environment asks us to actually be rustc, then do that.
@@ -333,6 +338,8 @@ fn main() {
333338

334339
// Parse our arguments and split them across `rustc` and `miri`.
335340
let mut miri_config = miri::MiriConfig::default();
341+
miri_config.env = env_snapshot;
342+
336343
let mut rustc_args = vec![];
337344
let mut after_dashdash = false;
338345

src/eval.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Main evaluator loop and setting up the initial stack frame.
22
33
use std::collections::HashSet;
4-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
55
use std::iter;
66
use std::panic::{self, AssertUnwindSafe};
77
use std::thread;
@@ -72,6 +72,9 @@ pub enum BacktraceStyle {
7272
/// Configuration needed to spawn a Miri instance.
7373
#[derive(Clone)]
7474
pub struct MiriConfig {
75+
/// The host environment snapshot to use as basis for what is provided to the interpreted program.
76+
/// (This is still subject to isolation as well as `excluded_env_vars` and `forwarded_env_vars`.)
77+
pub env: Vec<(OsString, OsString)>,
7578
/// Determine if validity checking is enabled.
7679
pub validate: bool,
7780
/// Determines if Stacked Borrows is enabled.
@@ -130,6 +133,7 @@ pub struct MiriConfig {
130133
impl Default for MiriConfig {
131134
fn default() -> MiriConfig {
132135
MiriConfig {
136+
env: vec![],
133137
validate: true,
134138
stacked_borrows: true,
135139
check_alignment: AlignmentCheck::Int,

src/shims/env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ impl<'tcx> EnvVars<'tcx> {
4949

5050
// Skip the loop entirely if we don't want to forward anything.
5151
if ecx.machine.communicate() || !config.forwarded_env_vars.is_empty() {
52-
for (name, value) in env::vars_os() {
52+
for (name, value) in &config.env {
5353
// Always forward what is in `forwarded_env_vars`; that list can take precedence over excluded_env_vars.
54-
let forward = config.forwarded_env_vars.iter().any(|v| **v == name)
54+
let forward = config.forwarded_env_vars.iter().any(|v| **v == *name)
5555
|| (ecx.machine.communicate()
56-
&& !excluded_env_vars.iter().any(|v| **v == name));
56+
&& !excluded_env_vars.iter().any(|v| **v == *name));
5757
if forward {
5858
let var_ptr = match target_os {
5959
target if target_os_is_unix(target) =>
@@ -65,7 +65,7 @@ impl<'tcx> EnvVars<'tcx> {
6565
unsupported
6666
),
6767
};
68-
ecx.machine.env_vars.map.insert(name, var_ptr);
68+
ecx.machine.env_vars.map.insert(name.clone(), var_ptr);
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)