From e24cbe2da07f1a713bd50a8f30792b145633795e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 8 Apr 2018 13:44:29 +0200 Subject: [PATCH] Misc tweaks --- config.toml.example | 3 +++ src/Cargo.lock | 1 + src/bootstrap/bin/rustc.rs | 7 ++++++ src/bootstrap/builder.rs | 4 ++++ src/bootstrap/config.rs | 3 +++ src/bootstrap/job.rs | 10 ++++---- src/librustc/util/common.rs | 11 +++++++++ src/librustc_plugin/lib.rs | 1 - src/librustc_plugin/registry.rs | 2 -- src/tools/compiletest/Cargo.toml | 1 + src/tools/compiletest/src/main.rs | 3 +++ src/tools/compiletest/src/runtest.rs | 36 ++++++++++++++++++++++++++-- src/tools/tidy/src/deps.rs | 1 + 13 files changed, 72 insertions(+), 11 deletions(-) diff --git a/config.toml.example b/config.toml.example index effe0084381..34fcc755b3a 100644 --- a/config.toml.example +++ b/config.toml.example @@ -346,6 +346,9 @@ # Whether to deny warnings in crates #deny-warnings = true +# Print backtrace on internal compiler errors during bootstrap +#backtrace-on-ice = false + # ============================================================================= # Options for specific targets # diff --git a/src/Cargo.lock b/src/Cargo.lock index 0f08eaf596a..a2767bd290d 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -390,6 +390,7 @@ dependencies = [ "env_logger 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index b6ae824c376..3f97accaa4d 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -107,6 +107,13 @@ fn main() { env::join_paths(&dylib_path).unwrap()); let mut maybe_crate = None; + // Print backtrace in case of ICE + if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() { + cmd.env("RUST_BACKTRACE", "1"); + } + + cmd.env("RUSTC_BREAK_ON_ICE", "1"); + if let Some(target) = target { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option. diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 08bb8ab4815..43387e28565 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -706,6 +706,10 @@ impl<'a> Builder<'a> { cargo.env("RUSTC_PRINT_STEP_TIMINGS", "1"); } + if self.config.backtrace_on_ice { + cargo.env("RUSTC_BACKTRACE_ON_ICE", "1"); + } + cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity)); // in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful. diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 7175f6a6764..6dd6291be23 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -72,6 +72,7 @@ pub struct Config { pub dry_run: bool, pub deny_warnings: bool, + pub backtrace_on_ice: bool, // llvm codegen options pub llvm_enabled: bool, @@ -306,6 +307,7 @@ struct Rust { wasm_syscall: Option, lld: Option, deny_warnings: Option, + backtrace_on_ice: Option, } /// TOML representation of how each build target is configured. @@ -531,6 +533,7 @@ impl Config { config.musl_root = rust.musl_root.clone().map(PathBuf::from); config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from); set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings)); + set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); if let Some(ref backends) = rust.codegen_backends { config.rust_codegen_backends = backends.iter() diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index fa3ba02482f..6445ce8da33 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -122,12 +122,10 @@ struct JOBOBJECT_BASIC_LIMIT_INFORMATION { } pub unsafe fn setup(build: &mut Build) { - // Tell Windows to not show any UI on errors (such as not finding a required dll - // during startup or terminating abnormally). This is important for running tests, - // since some of them use abnormal termination by design. - // This mode is inherited by all child processes. - let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags - SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + // Enable the Windows Error Reporting dialog which msys disables, + // so we can JIT debug rustc + let mode = SetErrorMode(0); + SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX); // Create a new job object for us to use let job = CreateJobObjectW(0 as *mut _, 0 as *const _); diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index c74e42263ef..85533caffce 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -58,6 +58,17 @@ fn panic_hook(info: &panic::PanicInfo) { if backtrace { TyCtxt::try_print_query_stack(); } + + #[cfg(windows)] + unsafe { + if env::var("RUSTC_BREAK_ON_ICE").is_ok() { + extern "system" { + fn DebugBreak(); + } + // Trigger a debugger if we crashed during bootstrap + DebugBreak(); + } + } } } diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index 622d8e51a6c..348aa6a7cef 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -65,7 +65,6 @@ html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(rustc_diagnostic_macros)] -#![feature(staged_api)] #[macro_use] extern crate syntax; diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index ebfd8785a0a..7e3c411c1d2 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -128,8 +128,6 @@ impl<'a> Registry<'a> { /// This can be used in place of `register_syntax_extension` to register legacy custom derives /// (i.e. attribute syntax extensions whose name begins with `derive_`). Legacy custom /// derives defined by this function do not trigger deprecation warnings when used. - #[unstable(feature = "rustc_private", issue = "27812")] - #[rustc_deprecated(since = "1.15.0", reason = "replaced by macros 1.1 (RFC 1861)")] pub fn register_custom_derive(&mut self, name: ast::Name, extension: SyntaxExtension) { assert!(name.as_str().starts_with("derive_")); self.whitelisted_custom_derives.push(name); diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index 77554f244c8..45cb147fbbc 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -19,5 +19,6 @@ rustfix = "0.2" libc = "0.2" [target.'cfg(windows)'.dependencies] +lazy_static = "1.0" miow = "0.3" winapi = { version = "0.3", features = ["winerror"] } diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index a7849d53c3d..e2b446c99dc 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -23,6 +23,9 @@ extern crate libc; extern crate log; extern crate regex; #[macro_use] +#[cfg(windows)] +extern crate lazy_static; +#[macro_use] extern crate serde_derive; extern crate serde_json; extern crate test; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index fae75c352da..1bac9ef66bb 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -38,6 +38,39 @@ use std::str; use extract_gdb_version; +#[cfg(windows)] +fn disable_error_reporting R, R>(f: F) -> R { + use std::sync::Mutex; + const SEM_NOGPFAULTERRORBOX: u32 = 0x0002; + extern "system" { + fn SetErrorMode(mode: u32) -> u32; + } + + lazy_static! { + static ref LOCK: Mutex<()> = { + Mutex::new(()) + }; + } + // Error mode is a global variable, so lock it so only one thread will change it + let _lock = LOCK.lock().unwrap(); + + // Tell Windows to not show any UI on errors (such as terminating abnormally). + // This is important for running tests, since some of them use abnormal + // termination by design. This mode is inherited by all child processes. + unsafe { + let old_mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags + SetErrorMode(old_mode | SEM_NOGPFAULTERRORBOX); + let r = f(); + SetErrorMode(old_mode); + r + } +} + +#[cfg(not(windows))] +fn disable_error_reporting R, R>(f: F) -> R { + f() +} + /// The name of the environment variable that holds dynamic library locations. pub fn dylib_env_var() -> &'static str { if cfg!(windows) { @@ -1578,8 +1611,7 @@ impl<'test> TestCx<'test> { let newpath = env::join_paths(&path).unwrap(); command.env(dylib_env_var(), newpath); - let mut child = command - .spawn() + let mut child = disable_error_reporting(|| command.spawn()) .expect(&format!("failed to exec `{:?}`", &command)); if let Some(input) = input { child diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 8caf39fc27b..9a87fcb00d5 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -73,6 +73,7 @@ static WHITELIST: &'static [Crate] = &[ Crate("flate2"), Crate("fuchsia-zircon"), Crate("fuchsia-zircon-sys"), + Crate("getopts"), Crate("humantime"), Crate("jobserver"), Crate("kernel32-sys"),