emscripten-core / emscripten-core/emscripten

Strange behavior when mixing -fexceptions with -fwasm-exceptions

Open
#20,165 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

We have a nightmare build system that uses a mix of cmake and direct emcc invocations to first compile a bunch of static libraries, then link them together into a wasm file in a configurable way. I'm working on utilizing `EXPORT_EXCEPTION_HANDLING_HELPERS` so that our JIT can interop with the code emscripten produces for C++ exception handling. I have been getting lots of baffling failures in the process, and I think I finally tracked the problem down to this:

The configuration parser sets internal flags when parsing `-fno-exceptions`, `-fexceptions`, `-fignore-exceptions` and `-fwasm-exceptions`. However, each of those flags does not set all of the internal flags, only some of them. Our build system had some `-fexceptions` flags buried deep in the configuration, so when I added `-fwasm-exceptions` I got a weird unique configuration different from if I only had set the latter. (This was hard to diagnose because it seems like cmake and/or emcmake delete the .json file passed to the compiler upon build failure, and i couldn't get `-v` to flow through to the compiler either, so I couldn't inspect the compiler arguments...)

See https://github.com/emscripten-core/emscripten/blob/c47ab8d7f644c6a501a0fc0eeb91f60c5b6682cb/emcc.py#L3610-L3627

Based on my reading of this, the configuration `-fexceptions -fwasm-exceptions` would result in the internal flags `{ WASM_EXCEPTIONS: 1, DISABLE_EXCEPTION_THROWING: 0, DISABLE_EXCEPTION_CATCHING: 0 }` while `-fwasm-exceptions` would only produce `{ WASM_EXCEPTIONS: 1 }`. Depending on parsing order some of the other ones could also produce a weird configuration and it seems like using mutually exclusive flags would not spit out any sort of error or warning, you'd just get a weird compile configuration.

In the process of troubleshooting everything I was getting confusing errors like `emcc : error : DISABLE_EXCEPTION_CATCHING=0 is not compatible with -fwasm-exceptions` (why would disabling catching be mandatory if I enabled EH? it turns out this switch means something other than what its name implies) and `EXPORT_EXCEPTION_HANDLING_HELPERS requires either of -fexceptions or -fwasm-exceptions` even though I was definitely passing through `-fwasm-exceptions`. I also saw `DISABLE_EXCEPTION_THROWING was set (probably from -fno-exceptions)` a lot even though I was trying to enable exceptions, presumably because some other flag was overwriting `-fwasm-exceptions`.

I don't have a reliable repro for this because I was never able to actually capture the .rsp or .json files due to some part of the emcmake pipeline deleting them :( Just wanted to describe this situation I ran into and suggest that maybe the argument/switch parsing for this set of flags be cleaned up so that incoherent combinations of switches produce a warning or error.

My suggestion would be that `-fno-exceptions`, `-fexceptions`, and `-fwasm-exceptions` should be mutually exclusive, or at least produce a warning if you use more than one of them, because setting two or more of them is not equivalent to only setting the last one. Including `-fignore-exceptions` in the list would complicate things further so maybe it should be required to only come after the other three have been set.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.