Skip to content

Commit

Permalink
Suggest using RUST_MIN_STACK if rustc overflowed
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Mar 21, 2024
1 parent 60891ca commit 5425338
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_driver_impl/src/signal_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Signal handler for rustc
//! Primarily used to extract a backtrace from stack overflow
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
use std::alloc::{alloc, Layout};
use std::{fmt, mem, ptr};

Expand Down Expand Up @@ -100,7 +101,10 @@ extern "C" fn print_stack_trace(_: libc::c_int) {
written += 1;
}
raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust");
written += 1;
// get the current stack size WITHOUT blocking and double it
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}");
written += 2;
if written > 24 {
// We probably just scrolled the earlier "we got SIGSEGV" message off the terminal
raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dy
}
}

static STACK_SIZE: OnceLock<usize> = OnceLock::new();
const DEFAULT_STACK_SIZE: usize = 8 * 1024 * 1024;
pub static STACK_SIZE: OnceLock<usize> = OnceLock::new();
pub const DEFAULT_STACK_SIZE: usize = 8 * 1024 * 1024;

fn init_stack_size() -> usize {
// Obey the environment setting or default
Expand Down

0 comments on commit 5425338

Please sign in to comment.