Skip to content

Commit 5425338

Browse files
Suggest using RUST_MIN_STACK if rustc overflowed
1 parent 60891ca commit 5425338

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_driver_impl/src/signal_handler.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Signal handler for rustc
22
//! Primarily used to extract a backtrace from stack overflow
33
4+
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
45
use std::alloc::{alloc, Layout};
56
use std::{fmt, mem, ptr};
67

@@ -100,7 +101,10 @@ extern "C" fn print_stack_trace(_: libc::c_int) {
100101
written += 1;
101102
}
102103
raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust");
103-
written += 1;
104+
// get the current stack size WITHOUT blocking and double it
105+
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
106+
raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}");
107+
written += 2;
104108
if written > 24 {
105109
// We probably just scrolled the earlier "we got SIGSEGV" message off the terminal
106110
raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal");

compiler/rustc_interface/src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub fn add_configuration(cfg: &mut Cfg, sess: &mut Session, codegen_backend: &dy
4848
}
4949
}
5050

51-
static STACK_SIZE: OnceLock<usize> = OnceLock::new();
52-
const DEFAULT_STACK_SIZE: usize = 8 * 1024 * 1024;
51+
pub static STACK_SIZE: OnceLock<usize> = OnceLock::new();
52+
pub const DEFAULT_STACK_SIZE: usize = 8 * 1024 * 1024;
5353

5454
fn init_stack_size() -> usize {
5555
// Obey the environment setting or default

0 commit comments

Comments
 (0)