Skip to content

Commit 5aca49c

Browse files
committed
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
2 parents 75383ea + 7a3fdfb commit 5aca49c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+147
-1673
lines changed

mk/clean.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ define CLEAN_TARGET_STAGE_N
101101
clean$(1)_T_$(2)_H_$(3): \
102102
$$(foreach crate,$$(CRATES),clean$(1)_T_$(2)_H_$(3)-lib-$$(crate)) \
103103
$$(foreach tool,$$(TOOLS) $$(DEBUGGER_BIN_SCRIPTS_ALL),clean$(1)_T_$(2)_H_$(3)-tool-$$(tool))
104-
$$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
105104
$$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
106105
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/librun_pass_stage* # For unix
107106
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/run_pass_stage* # For windows

mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ DEPS_libc := core
6565
DEPS_rustc_unicode := core
6666
DEPS_alloc := core libc native:jemalloc
6767
DEPS_std := core libc rand alloc collections rustc_unicode \
68-
native:rust_builtin native:backtrace native:rustrt_native \
68+
native:rust_builtin native:backtrace \
6969
rustc_bitflags
7070
DEPS_graphviz := std
7171
DEPS_syntax := std term serialize log fmt_macros arena libc

mk/main.mk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ endif
163163
# that the snapshot will be generated with a statically linked rustc so we only
164164
# have to worry about the distribution of one file (with its native dynamic
165165
# dependencies)
166-
RUSTFLAGS_STAGE0 += -C prefer-dynamic
166+
RUSTFLAGS_STAGE0 += -C prefer-dynamic -C no-stack-check
167167
RUSTFLAGS_STAGE1 += -C prefer-dynamic
168168
RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
169169
RUST_LIB_FLAGS_ST3 += -C prefer-dynamic
@@ -400,6 +400,11 @@ TSREQ$(1)_T_$(2)_H_$(3) = \
400400
$$(foreach obj,$$(INSTALLED_OBJECTS_$(2)),\
401401
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(obj))
402402

403+
ifeq ($(1),0)
404+
TSREQ$(1)_T_$(2)_H_$(3) += \
405+
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(call CFG_STATIC_LIB_NAME_$(2),morestack)
406+
endif
407+
403408
# Prerequisites for a working stageN compiler and libraries, for a specific
404409
# target
405410
SREQ$(1)_T_$(2)_H_$(3) = \

mk/platform.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ CFG_RLIB_GLOB=lib$(1)-*.rlib
113113
include $(wildcard $(CFG_SRC_DIR)mk/cfg/*.mk)
114114

115115
define ADD_INSTALLED_OBJECTS
116-
INSTALLED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),morestack) \
117-
$$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
116+
INSTALLED_OBJECTS_$(1) += $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
118117
endef
119118

120119
$(foreach target,$(CFG_TARGET), \

mk/rt.mk

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
# that's per-target so you're allowed to conditionally add files based on the
3636
# target.
3737
################################################################################
38-
NATIVE_LIBS := rust_builtin hoedown morestack miniz \
39-
rustrt_native rust_test_helpers
38+
NATIVE_LIBS := rust_builtin hoedown miniz \
39+
rust_test_helpers morestack
4040

4141
# $(1) is the target triple
4242
define NATIVE_LIBRARIES
@@ -53,10 +53,8 @@ NATIVE_DEPS_hoedown_$(1) := hoedown/src/autolink.c \
5353
NATIVE_DEPS_miniz_$(1) = miniz.c
5454
NATIVE_DEPS_rust_builtin_$(1) := rust_builtin.c \
5555
rust_android_dummy.c
56-
NATIVE_DEPS_rustrt_native_$(1) := arch/$$(HOST_$(1))/record_sp.S
5756
NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c
58-
NATIVE_DEPS_morestack_$(1) := arch/$$(HOST_$(1))/morestack.S
59-
57+
NATIVE_DEPS_morestack_$(1) := empty.c
6058

6159
################################################################################
6260
# You shouldn't find it that necessary to edit anything below this line.

mk/target.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ $(foreach host,$(CFG_HOST), \
5656
# 1. The immediate dependencies are the rust source files
5757
# 2. Each rust crate dependency is listed (based on their stamp files),
5858
# as well as all native dependencies (listed in RT_OUTPUT_DIR)
59-
# 3. The stage (n-1) compiler is required through the TSREQ dependency, along
60-
# with the morestack library
59+
# 3. The stage (n-1) compiler is required through the TSREQ dependency
6160
# 4. When actually executing the rule, the first thing we do is to clean out
6261
# old libs and rlibs via the REMOVE_ALL_OLD_GLOB_MATCHES macro
6362
# 5. Finally, we get around to building the actual crate. It's just one

src/doc/trpl/lang-items.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fn main(argc: isize, argv: *const *const u8) -> isize {
5151
0
5252
}
5353

54-
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
5554
#[lang = "eh_personality"] extern fn eh_personality() {}
5655
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
5756
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}

src/doc/trpl/no-stdlib.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
3636
// These functions and traits are used by the compiler, but not
3737
// for a bare-bones hello world. These are normally
3838
// provided by libstd.
39-
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
4039
#[lang = "eh_personality"] extern fn eh_personality() {}
4140
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
4241
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
@@ -61,7 +60,6 @@ pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {
6160
0
6261
}
6362
64-
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
6563
#[lang = "eh_personality"] extern fn eh_personality() {}
6664
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
6765
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
@@ -73,18 +71,12 @@ The compiler currently makes a few assumptions about symbols which are available
7371
in the executable to call. Normally these functions are provided by the standard
7472
library, but without it you must define your own.
7573

76-
The first of these three functions, `stack_exhausted`, is invoked whenever stack
77-
overflow is detected. This function has a number of restrictions about how it
78-
can be called and what it must do, but if the stack limit register is not being
79-
maintained then a thread always has an "infinite stack" and this function
80-
shouldn't get triggered.
81-
82-
The second of these three functions, `eh_personality`, is used by the
74+
The first of these two functions, `eh_personality`, is used by the
8375
failure mechanisms of the compiler. This is often mapped to GCC's
8476
personality function (see the
8577
[libstd implementation](../std/rt/unwind/index.html) for more
8678
information), but crates which do not trigger a panic can be assured
87-
that this function is never called. The final function, `panic_fmt`, is
79+
that this function is never called. The second function, `panic_fmt`, is
8880
also used by the failure mechanisms of the compiler.
8981

9082
## Using libcore
@@ -150,7 +142,6 @@ extern fn panic_fmt(args: &core::fmt::Arguments,
150142
loop {}
151143
}
152144
153-
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
154145
#[lang = "eh_personality"] extern fn eh_personality() {}
155146
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
156147
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }

src/librustc/middle/lang_items.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,5 @@ lets_do_this! {
347347

348348
NonZeroItem, "non_zero", non_zero;
349349

350-
StackExhaustedLangItem, "stack_exhausted", stack_exhausted;
351-
352350
DebugTraitLangItem, "debug_trait", debug_trait;
353351
}

src/librustc/middle/weak_lang_items.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ pub fn check_crate(krate: &ast::Crate,
3939
// These are never called by user code, they're generated by the compiler.
4040
// They will never implicitly be added to the `missing` array unless we do
4141
// so here.
42-
if items.stack_exhausted().is_none() {
43-
items.missing.push(lang_items::StackExhaustedLangItem);
44-
}
4542
if items.eh_personality().is_none() {
4643
items.missing.push(lang_items::EhPersonalityLangItem);
4744
}
@@ -124,7 +121,6 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
124121

125122
weak_lang_items! {
126123
panic_fmt, PanicFmtLangItem, rust_begin_unwind;
127-
stack_exhausted, StackExhaustedLangItem, rust_stack_exhausted;
128124
eh_personality, EhPersonalityLangItem, rust_eh_personality;
129125
eh_unwind_resume, EhUnwindResumeLangItem, rust_eh_unwind_resume;
130126
}

0 commit comments

Comments
 (0)