Skip to content

Commit b802c8a

Browse files
committed
Default to STACK_OVERFLOW_CHECK=2 in debug builds
Previously we defaulted to 1 in this case, but we want to improve the error reporting around stack overflow in preparation for lowering the default stack size. See #14177
1 parent deb5d86 commit b802c8a

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.25 (in development)
2222
-----------------------
23+
- `STACK_OVERFLOW_CHECK` now defaults 2 in debug builds (when `ASSERTIONS` are
24+
enabled). This is because we are planning on lowering the default stack size
25+
and we want good reporting of stack overflow in debug builds. See #14177.
26+
This can be set of 1 or 0 if the performance overhead is a problem.
2327

2428
3.1.24 - 10/11/22
2529
-----------------

emcc.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,14 +1774,12 @@ def phase_linker_setup(options, state, newargs, user_settings):
17741774
if '_main' in settings.EXPORTED_FUNCTIONS:
17751775
settings.EXPORT_IF_DEFINED.append('__main_argc_argv')
17761776

1777-
# -sASSERTIONS implies basic stack overflow checks, and ASSERTIONS=2
1778-
# implies full stack overflow checks.
1779-
if settings.ASSERTIONS:
1780-
# However, we don't set this default in PURE_WASI, or when we are linking without standard
1781-
# libraries because STACK_OVERFLOW_CHECK depends on emscripten_stack_get_end which is defined
1782-
# in libcompiler-rt.
1783-
if not settings.PURE_WASI and '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs:
1784-
default_setting(user_settings, 'STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK))
1777+
# -sASSERTIONS implies stack overflow checks
1778+
# However, we don't set this default in PURE_WASI, or when we are linking without standard
1779+
# libraries (because STACK_OVERFLOW_CHECK depends on emscripten_stack_get_end which is defined
1780+
# in compiler-rt).
1781+
if settings.ASSERTIONS and not settings.PURE_WASI and '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs:
1782+
default_setting(user_settings, 'STACK_OVERFLOW_CHECK', 2)
17851783

17861784
if settings.LLD_REPORT_UNDEFINED or settings.STANDALONE_WASM:
17871785
# Reporting undefined symbols at wasm-ld time requires us to know if we have a `main` function

src/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ var ASSERTIONS = 1;
6363
var RUNTIME_LOGGING = false;
6464

6565
// Chooses what kind of stack smash checks to emit to generated code:
66-
// Building with ASSERTIONS=1 causes STACK_OVERFLOW_CHECK default to 1.
66+
// Building with ASSERTIONS=1 causes STACK_OVERFLOW_CHECK default to 2.
6767
// Since ASSERTIONS=1 is the default at -O0, which itself is the default
6868
// optimization level this means that this setting also effectively
69-
// defaults 1, absent any other settings.
69+
// defaults 2, absent any other settings.
7070
// 0: Stack overflows are not checked.
7171
// 1: Adds a security cookie at the top of the stack, which is checked at end of
7272
// each tick and at exit (practically zero performance overhead)

0 commit comments

Comments
 (0)