Skip to content

Commit 04894f5

Browse files
committed
Deprecate DISABLE_EXCEPTION_CATCHING=2
We can instead imply this mode by the presence of the EXCEPTION_CATCHING_ALLOWED` list. This turns DISABLE_EXCEPTION_CATCHING into a binary option which is easier to deal with both internally and externally.
1 parent 168149f commit 04894f5

File tree

7 files changed

+40
-30
lines changed

7 files changed

+40
-30
lines changed

ChangeLog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ See docs/process.md for more on how version tagging works.
2020

2121
Current Trunk
2222
-------------
23-
- values returns from `pathconf` now match the defintions found in header files
23+
- `DISABLE_EXCEPTION_CATCHING=2` is now deprecated since it can be inferred from
24+
the presence of the `EXCEPTION_CATCHING_ALLOWED` list. This makes
25+
`DISABLE_EXCEPTION_CATCHING` a simple binary option (0 or 1) which defaults to
26+
0 which will be set to 1 internally if `EXCEPTION_CATCHING_ALLOWED` list is
27+
specified.
28+
- Values returned from `pathconf` now match the definitions found in header files
2429
and/or upstream musl:
2530
_PC_LINK_MAX 3200 -> 8
2631
_PC_SYNC_IO -1 -> 1

emcc.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def get_cflags(options, user_args):
751751

752752
# if exception catching is disabled, we can prevent that code from being
753753
# generated in the frontend
754-
if shared.Settings.DISABLE_EXCEPTION_CATCHING == 1 and not shared.Settings.EXCEPTION_HANDLING:
754+
if shared.Settings.DISABLE_EXCEPTION_CATCHING and not shared.Settings.EXCEPTION_HANDLING:
755755
cflags.append('-fignore-exceptions')
756756

757757
if shared.Settings.INLINING_LIMIT:
@@ -1578,6 +1578,14 @@ def default_setting(name, new_default):
15781578
default_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)
15791579
default_setting('WARN_ON_UNDEFINED_SYMBOLS', 0)
15801580

1581+
if shared.Settings.EXCEPTION_CATCHING_ALLOWED:
1582+
if 'DISABLE_EXCEPTION_CATCHING' in settings_key_changes:
1583+
if settings_key_changes['DISABLE_EXCEPTION_CATCHING'] == '2':
1584+
diagnostics.warning('deprecated', 'DISABLE_EXCEPTION_CATCHING is no longer needed when specifying EXCEPTION_CATCHING_ALLOWED')
1585+
else:
1586+
exit_with_error('DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED are mutually exclusive')
1587+
shared.Settings.DISABLE_EXCEPTION_CATCHING = 0
1588+
15811589
if shared.Settings.DISABLE_EXCEPTION_THROWING and not shared.Settings.DISABLE_EXCEPTION_CATCHING:
15821590
exit_with_error("DISABLE_EXCEPTION_THROWING was set (probably from -fno-exceptions) but is not compatible with enabling exception catching (DISABLE_EXCEPTION_CATCHING=0). If you don't want exceptions, set DISABLE_EXCEPTION_CATCHING to 1; if you do want exceptions, don't link with -fno-exceptions")
15831591

@@ -1630,7 +1638,7 @@ def default_setting(name, new_default):
16301638

16311639
if shared.Settings.USE_PTHREADS:
16321640
if shared.Settings.USE_PTHREADS == 2:
1633-
exit_with_error('USE_PTHREADS=2 is not longer supported')
1641+
exit_with_error('USE_PTHREADS=2 is no longer supported')
16341642
if shared.Settings.ALLOW_MEMORY_GROWTH:
16351643
diagnostics.warning('pthreads-mem-growth', 'USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271')
16361644
# UTF8Decoder.decode may not work with a view of a SharedArrayBuffer, see https://github.com/whatwg/encoding/issues/172
@@ -1955,7 +1963,7 @@ def check_memory_setting(setting):
19551963
shared.Settings.USE_PTHREADS or \
19561964
shared.Settings.OFFSCREENCANVAS_SUPPORT or \
19571965
shared.Settings.LEGACY_GL_EMULATION or \
1958-
shared.Settings.DISABLE_EXCEPTION_CATCHING != 1 or \
1966+
not shared.Settings.DISABLE_EXCEPTION_CATCHING or \
19591967
shared.Settings.ASYNCIFY or \
19601968
shared.Settings.ASMFS or \
19611969
shared.Settings.DEMANGLE_SUPPORT or \
@@ -1968,7 +1976,7 @@ def check_memory_setting(setting):
19681976
sanitize:
19691977
shared.Settings.EXPORTED_FUNCTIONS += ['_malloc', '_free']
19701978

1971-
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
1979+
if not shared.Settings.DISABLE_EXCEPTION_CATCHING:
19721980
# If not for LTO builds, we could handle these by adding deps_info.py
19731981
# entries for __cxa_find_matching_catch_* functions. However, under
19741982
# LTO these symbols don't exist prior the linking.

src/parseTools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ function makeStructuralReturn(values) {
873873
}
874874

875875
function makeThrow(what) {
876-
if (ASSERTIONS && DISABLE_EXCEPTION_CATCHING == 1) {
877-
what += ' + " - Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch."';
876+
if (ASSERTIONS && DISABLE_EXCEPTION_CATCHING) {
877+
what += ' + " - Exception catching is disabled, this exception cannot be caught. Compile with -s NO_DISABLE_EXCEPTION_CATCHING or -s EXCEPTION_CATCHING_ALLOWED=[..] to catch."';
878878
if (MAIN_MODULE) {
879879
what += ' + " (note: in dynamic linking, if a side module wants exceptions, the main module must be built with that support)"';
880880
}

src/preamble.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,12 @@ function createExportWrapper(name, fixedasm) {
658658
#endif
659659

660660
#if ABORT_ON_WASM_EXCEPTIONS
661-
// When DISABLE_EXCEPTION_CATCHING != 1 `abortWrapperDepth` counts the recursion
662-
// level of the wrapper function so that we only handle exceptions at the top level
663-
// letting the exception mechanics work uninterrupted at the inner level.
664-
// Additionally, `abortWrapperDepth` is also manually incremented in callMain so that
665-
// we know to ignore exceptions from there since they're handled by callMain directly.
661+
// When exception catching is enabled (!DISABLE_EXCEPTION_CATCHING)
662+
// `abortWrapperDepth` counts the recursion level of the wrapper function so
663+
// that we only handle exceptions at the top level letting the exception
664+
// mechanics work uninterrupted at the inner level. Additionally,
665+
// `abortWrapperDepth` is also manually incremented in callMain so that we know
666+
// to ignore exceptions from there since they're handled by callMain directly.
666667
var abortWrapperDepth = 0;
667668

668669
// Creates a wrapper in a closure so that each wrapper gets it's own copy of 'original'
@@ -673,7 +674,7 @@ function makeAbortWrapper(original) {
673674
throw "program has already aborted!";
674675
}
675676

676-
#if DISABLE_EXCEPTION_CATCHING != 1
677+
#if !DISABLE_EXCEPTION_CATCHING
677678
abortWrapperDepth += 1;
678679
#endif
679680
try {
@@ -692,7 +693,7 @@ function makeAbortWrapper(original) {
692693

693694
abort("unhandled exception: " + [e, e.stack]);
694695
}
695-
#if DISABLE_EXCEPTION_CATCHING != 1
696+
#if !DISABLE_EXCEPTION_CATCHING
696697
finally {
697698
abortWrapperDepth -= 1;
698699
}

src/settings.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,25 +640,23 @@ var LZ4 = 0;
640640

641641
// Disables generating code to actually catch exceptions. This disabling is on
642642
// by default as the overhead of exceptions is quite high in size and speed
643-
// currently (in the future, wasm should improve that). When exceptions are
643+
// currently (in the future, wasm should improve that). When exceptions are
644644
// disabled, if an exception actually happens then it will not be caught
645645
// and the program will halt (so this will not introduce silent failures).
646-
// There are 3 specific modes here:
647-
// DISABLE_EXCEPTION_CATCHING = 0 - generate code to actually catch exceptions
648-
// DISABLE_EXCEPTION_CATCHING = 1 - disable exception catching at all
649-
// DISABLE_EXCEPTION_CATCHING = 2 - disable exception catching, but enables
650-
// catching in list of allowed functions
646+
//
651647
// XXX note that this removes *catching* of exceptions, which is the main
652648
// issue for speed, but you should build source files with
653649
// -fno-exceptions to really get rid of all exceptions code overhead,
654650
// as it may contain thrown exceptions that are never caught (e.g.
655651
// just using std::vector can have that). -fno-rtti may help as well.
656652
//
653+
// This option is ignoed if EXCEPTION_CATCHING_ALLOWED is specified.
654+
//
657655
// [compile+link] - affects user code at compile and system libraries at link
658656
var DISABLE_EXCEPTION_CATCHING = 1;
659657

660-
// Enables catching exception in the listed functions only, if
661-
// DISABLE_EXCEPTION_CATCHING = 2 is set
658+
// Enables catching exception but only in the listed functions. This
659+
// option acts like a more precise version of `DISABLE_EXCEPTION_CATCHING=0`.
662660
// [compile+link] - affects user code at compile and system libraries at link
663661
var EXCEPTION_CATCHING_ALLOWED = [];
664662

tests/test_core.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,6 @@ def test_exceptions_3(self):
12361236
self.do_run('src.js', 'Caught exception: Hello\nDone.', args=['2'], no_build=True)
12371237

12381238
def test_exceptions_allowed(self):
1239-
self.set_setting('DISABLE_EXCEPTION_CATCHING', 2)
12401239
# Wasm does not add an underscore to function names. For wasm, the
12411240
# mismatches are fixed in fixImports() function in JS glue code.
12421241
self.set_setting('EXCEPTION_CATCHING_ALLOWED', ["_Z12somefunctionv"])
@@ -1267,7 +1266,7 @@ def test_exceptions_allowed(self):
12671266
fake_size += os.path.getsize('test_exceptions_allowed.wasm')
12681267
shutil.copyfile('test_exceptions_allowed.js', 'fake.js')
12691268

1270-
self.set_setting('DISABLE_EXCEPTION_CATCHING')
1269+
self.clear_setting('EXCEPTION_CATCHING_ALLOWED')
12711270
self.do_run_from_file(src, empty_output, assert_returncode=NON_ZERO)
12721271
disabled_size = os.path.getsize('test_exceptions_allowed.js')
12731272
if self.is_wasm():
@@ -1278,14 +1277,14 @@ def test_exceptions_allowed(self):
12781277
print('empty_size: %d' % empty_size)
12791278
print('fake_size: %d' % fake_size)
12801279
print('disabled_size: %d' % disabled_size)
1281-
self.assertEqual(empty_size, fake_size)
1280+
# empty list acts the same a full disable
1281+
self.assertEqual(empty_size, disabled_size)
12821282
# big change when we disable exception catching of the function
12831283
self.assertGreater(size - empty_size, 0.01 * size)
12841284
# full disable can remove a little bit more
1285-
self.assertLess(disabled_size, empty_size)
1285+
self.assertLess(disabled_size, fake_size)
12861286

12871287
def test_exceptions_allowed_2(self):
1288-
self.set_setting('DISABLE_EXCEPTION_CATCHING', 2)
12891288
# Wasm does not add an underscore to function names. For wasm, the
12901289
# mismatches are fixed in fixImports() function in JS glue code.
12911290
self.set_setting('EXCEPTION_CATCHING_ALLOWED', ["main"])
@@ -1296,7 +1295,6 @@ def test_exceptions_allowed_2(self):
12961295

12971296
def test_exceptions_allowed_uncaught(self):
12981297
self.emcc_args += ['-std=c++11']
1299-
self.set_setting('DISABLE_EXCEPTION_CATCHING', 2)
13001298
# Wasm does not add an underscore to function names. For wasm, the
13011299
# mismatches are fixed in fixImports() function in JS glue code.
13021300
self.set_setting('EXCEPTION_CATCHING_ALLOWED', ["_Z4testv"])

tools/building.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,9 @@ def llvm_backend_args():
483483
args = ['-combiner-global-alias-analysis=false']
484484

485485
# asm.js-style exception handling
486-
if Settings.DISABLE_EXCEPTION_CATCHING != 1:
486+
if not Settings.DISABLE_EXCEPTION_CATCHING:
487487
args += ['-enable-emscripten-cxx-exceptions']
488-
if Settings.DISABLE_EXCEPTION_CATCHING == 2:
488+
if Settings.EXCEPTION_CATCHING_ALLOWED:
489489
allowed = ','.join(Settings.EXCEPTION_CATCHING_ALLOWED or ['__fake'])
490490
args += ['-emscripten-cxx-exceptions-allowed=' + allowed]
491491

0 commit comments

Comments
 (0)