Skip to content

Exception handling helpers do not work with ASSERTIONS=1 #24086

Open
@canislupaster

Description

@canislupaster

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.7-git (a53b1a34f0b31f05f2045f2d4aa1343f75180693)
Copyright (C) 2025 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Failing command line in full:

em++ ./main.cpp -o main.js -fwasm-exceptions -sEXPORT_EXCEPTION_HANDLING_HELPERS=1

(Any C++ source file will work.)

This outputs a main.js where getExceptionMessage is in unexportedSymbols due to the implicit -sASSERTIONS=1. Importing main.js always causes an error since ASSERTIONS overrides the getter of anything in unexportedSymbols to throw an error:

// in ASSERTIONS mode we show a useful error if it is used without being

The test in test_core.py, however, explicitly disables ASSERTIONS:

self.set_setting('ASSERTIONS', 0)

I don't think disabling ASSERTIONS should be required to use exception helpers? If it needs to be, then you can probably dismiss this.

This stems from

settings.EXPORTED_FUNCTIONS += ['getExceptionMessage', 'incrementExceptionRefcount', 'decrementExceptionRefcount']
where the helper functions are added to EXPORTED_FUNCTIONS instead of EXPORTED_RUNTIME_METHODS, and changing this lets me import the file.

However, now getExceptionMessage with ASSERTIONS and Emscripten exceptions somehow triggers a WebAssembly.RuntimeError for memory access out of bounds. The __get_exception_message in system/lib/libcxxabi/src/cxa_exception_js_utils.cpp used from src/lib/libcore.js apparently dies while returning. I have no idea when this error is emitted or how ASSERTIONS could impact that.

Please let me know if I'm missing anything. Thanks for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions