emscripten-core / emscripten-core/emscripten
Strange behavior when mixing -fexceptions with -fwasm-exceptions
- Lingua principale
- C++
- Stelle
- 27.6k
- Fork
- 3.6k
- Merge medio
- 1g 14h
- PR unite (30g)
- 125
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia dal codice di analisi degli argomenti in emcc.py alle righe 3610-3627 e traccia come -fno-exceptions, -fexceptions, -fignore-exceptions e -fwasm-exceptions aggiornano i flag interni. Prova combinazioni di queste opzioni al di fuori dei file di risposta generati da CMake non disponibili, quindi determina come dovrebbero essere segnalate le combinazioni incoerenti. Il lavoro è completato quando flag delle eccezioni in conflitto producono un avviso o un errore chiaro invece di una configurazione dipendente dall’ordine.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cmake, cpp, python, wasm
- Ambito
- build-system, compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100