emscripten-core / emscripten-core/emscripten
Crash when object file was compiled with -fexceptions but linking with -fwasm-exceptions
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Minimal example:
```cpp
#include
int main() {
try {
throw std::runtime_error("foo");
} catch (std::exception e) {
}
}
```
Compiling & linking with mismatched exception modes results in a crash and core dump:
```
$ emcc -c temp.cpp -o temp.o -fexceptions -flto
$ emcc temp.o -o temp.js -fwasm-exceptions -flto
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld -o temp.wasm temp.o -L/usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto -lGL -lal -lhtml5 -lstubs-debug -lc -lcompiler_rt -lc++-except -lc++abi-except -lunwind-except -ldlmalloc -lc_rt -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -exception-model=wasm --import-undefined --strip-debug --export-if-defined=main --export-if-defined=emscripten_stack_get_end --export-if-defined=emscripten_stack_get_free --export-if-defined=emscripten_stack_init --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__wasm_call_ctors --export-if-defined=fflush --export-if-defined=__errno_location --export-if-defined=malloc --export-if-defined=setThrew --export-if-defined=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024
1. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2. Running pass 'WebAssembly Instruction Selection' on function '@__original_main'
#0 0x0000000001119b5c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld+0x1119b5c)
#1 0x00000000011174ae llvm::sys::RunSignalHandlers() (/usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld+0x11174ae)
#2 0x000000000111a43f SignalHandler(int) Signals.cpp:0:0
#3 0x00007f9f71c938e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x138e0)
#4 0x0000000001c6610d (/usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld+0x1c6610d)
emcc: error: '/usr/local/google/home/rreverser/emsdk/upstream/bin/wasm-ld -o temp.wasm temp.o -L/usr/local/google/home/rreverser/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto -lGL -lal -lhtml5 -lstubs-debug -lc -lcompiler_rt -lc++-except -lc++abi-except -lunwind-except -ldlmalloc -lc_rt -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -mllvm -wasm-enable-eh -mllvm -exception-model=wasm --import-undefined --strip-debug --export-if-defined=main --export-if-defined=emscripten_stack_get_end --export-if-defined=emscripten_stack_get_free --export-if-defined=emscripten_stack_init --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__wasm_call_ctors --export-if-defined=fflush --export-if-defined=__errno_location --export-if-defined=malloc --export-if-defined=setThrew --export-if-defined=free --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (received SIGTRAP (-5))
```
It seems to happen only in combination with `-flto`, otherwise getting a more reasonable, although still a bit misleading error:
```
$ emcc -c temp.cpp -o temp.o -fexceptions
$ emcc temp.o -o temp.js -fwasm-exceptions
error: DISABLE_EXCEPTION_THROWING was set (likely due to -fno-exceptions), which means no C++ exception throwing support code is linked in, but exception catching code appears. Either do not set DISABLE_EXCEPTION_THROWING (if you do want exception throwing) or compile all source files with -fno-except (so that no exceptions support code is required); also make sure DISABLE_EXCEPTION_CATCHING is set to the right value - if you want exceptions, it should be off, and vice versa.
error: undefined symbol: __resumeException (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: ___resumeException may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: llvm_eh_typeid_for (referenced by top-level compiled C/C++ code)
warning: _llvm_eh_typeid_for may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '/usr/local/google/home/rreverser/emsdk/node/14.15.5_64bit/bin/node /usr/local/google/home/rreverser/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpss3e4tlf.txt' failed (returned 1)
```
Contributor guide
Assessment
This issue has not been assessed yet.