Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
canislupaster opened this issue Apr 10, 2025 · 1 comment
Open

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

canislupaster opened this issue Apr 10, 2025 · 1 comment

Comments

@canislupaster
Copy link

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.

@sbc100
Copy link
Collaborator

sbc100 commented Apr 10, 2025

The fact that getExceptionMessage is included in unexportedSymbols looks like a bug to me. I can take a look at that part

The fact that getExceptionMessage is crashing seems like when ASSERTIONS are enabled looks separate. Perhaps @aheejin knows about that one.

sbc100 added a commit to sbc100/emscripten that referenced this issue Apr 10, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue Apr 14, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue Apr 14, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue Apr 14, 2025
sbc100 added a commit to sbc100/emscripten that referenced this issue Apr 15, 2025
sbc100 added a commit that referenced this issue Apr 15, 2025
…D_FUNCTIONS (#24091)

This bug meant that library symbol exported via `EXPORTED_FUNCTIONS`
were incorrectly being reported as not exported using
unexportedRuntimeSymbol

See #24086
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants