diff options
| author | bors <bors@rust-lang.org> | 2015-08-10 23:40:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-08-10 23:40:54 +0000 |
| commit | 5aca49c693c9be3064d9e6db9473b1fa76834b79 (patch) | |
| tree | a3ed497baf27e7c8401b916d26fb63678edb91f7 /src/libstd/rt | |
| parent | 75383ea7d7b1a4dff104be737830c1a31a6c0a73 (diff) | |
| parent | 7a3fdfbf674a08b7f6fd32c9124e52924a2f9a1c (diff) | |
| download | rust-5aca49c693c9be3064d9e6db9473b1fa76834b79.tar.gz rust-5aca49c693c9be3064d9e6db9473b1fa76834b79.zip | |
Auto merge of #27338 - alexcrichton:remove-morestack, r=brson
This commit removes all morestack support from the compiler which entails: * Segmented stacks are no longer emitted in codegen. * We no longer build or distribute libmorestack.a * The `stack_exhausted` lang item is no longer required The only current use of the segmented stack support in LLVM is to detect stack overflow. This is no longer really required, however, because we already have guard pages for all threads and registered signal handlers watching for a segfault on those pages (to print out a stack overflow message). Additionally, major platforms (aka Windows) already don't use morestack. This means that Rust is by default less likely to catch stack overflows because if a function takes up more than one page of stack space it won't hit the guard page. This is what the purpose of morestack was (to catch this case), but it's better served with stack probes which have more cross platform support and no runtime support necessary. Until LLVM supports this for all platform it looks like morestack isn't really buying us much. cc #16012 (still need stack probes) Closes #26458 (a drive-by fix to help diagnostics on stack overflow) r? @brson
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/mod.rs | 40 | ||||
| -rw-r--r-- | src/libstd/rt/unwind/mod.rs | 4 |
2 files changed, 2 insertions, 42 deletions
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 56bf73db399..24a4575aa54 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -23,7 +23,7 @@ use prelude::v1::*; use sys; -use usize; +use thread; // Reexport some of our utilities which are expected by other crates. pub use self::util::min_stack; @@ -53,11 +53,6 @@ mod dwarf; /// of exiting cleanly. pub const DEFAULT_ERROR_CODE: isize = 101; -#[cfg(any(windows, android))] -const OS_DEFAULT_STACK_ESTIMATE: usize = 1 << 20; -#[cfg(all(unix, not(android)))] -const OS_DEFAULT_STACK_ESTIMATE: usize = 2 * (1 << 20); - #[cfg(not(test))] #[lang = "start"] fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { @@ -67,37 +62,9 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use env; use rt; use sys_common::thread_info::{self, NewThread}; - use sys_common; use thread::Thread; - let something_around_the_top_of_the_stack = 1; - let addr = &something_around_the_top_of_the_stack as *const _ as *const isize; - let my_stack_top = addr as usize; - - // FIXME #11359 we just assume that this thread has a stack of a - // certain size, and estimate that there's at most 20KB of stack - // frames above our current position. - const TWENTY_KB: usize = 20000; - - // saturating-add to sidestep overflow - let top_plus_spill = if usize::MAX - TWENTY_KB < my_stack_top { - usize::MAX - } else { - my_stack_top + TWENTY_KB - }; - // saturating-sub to sidestep underflow - let my_stack_bottom = if top_plus_spill < OS_DEFAULT_STACK_ESTIMATE { - 0 - } else { - top_plus_spill - OS_DEFAULT_STACK_ESTIMATE - }; - let failed = unsafe { - // First, make sure we don't trigger any __morestack overflow checks, - // and next set up our stack to have a guard page and run through our - // own fault handlers if we hit it. - sys_common::stack::record_os_managed_stack_bounds(my_stack_bottom, - my_stack_top); let main_guard = sys::thread::guard::init(); sys::stack_overflow::init(); @@ -129,10 +96,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { args::init(argc, argv); // And finally, let's run some code! - let res = unwind::try(|| { - let main: fn() = mem::transmute(main); - main(); - }); + let res = thread::catch_panic(mem::transmute::<_, fn()>(main)); cleanup(); res.is_err() }; diff --git a/src/libstd/rt/unwind/mod.rs b/src/libstd/rt/unwind/mod.rs index 59b2e14643d..bb43eec8db1 100644 --- a/src/libstd/rt/unwind/mod.rs +++ b/src/libstd/rt/unwind/mod.rs @@ -111,10 +111,6 @@ static CALLBACK_CNT: atomic::AtomicUsize = atomic::AtomicUsize::new(0); thread_local! { static PANICKING: Cell<bool> = Cell::new(false) } -#[link(name = "rustrt_native", kind = "static")] -#[cfg(not(test))] -extern {} - /// Invoke a closure, capturing the cause of panic if one occurs. /// /// This function will return `Ok(())` if the closure did not panic, and will |
