emscripten
emscripten copied to clipboard
Met `function signature mismatch` warning and got `RuntimeError: unreachable` in execution
Please include the following in your bug report:
Version of emscripten/emsdk: 3.1.54
Failing command line in full:
Hi, I got an issue with function signature mismatch warning when compiling with emscripten, and when running the compiled wasm binary, I also got RuntimeError: unreachable. I summarized the case I met as the code example shown below. (Also it just works fine in native.) May I ask if there is any particular way to solve this?
Thank you very much!
Compilation
Compiled with 2 files, test_mismatch.c and use_mismatch.c, and you can check the code below.
# with emcc
$ emcc test_mismatch.c use_mismatch.c -o main.js -g
wasm-ld: warning: function signature mismatch: test_func
>>> defined as () -> i32 in /tmp/emscripten_temp_odw_3j7b/use_mismatch_1.o
>>> defined as () -> void in /tmp/emscripten_temp_odw_3j7b/test_mismatch_0.o
# with gcc
$ gcc test_mismatch.c use_mismatch.c -o main -g
Code
use_mismatch.c
int test_func(); // defined as void test(); in test_mismatch.c
int main() {
test_func();
}
test_mismatch.c
#include <stdio.h>
void test_func() {
printf("test\n");
}
Execution
# wasm
$ node main.js
/data/main.js:128
throw ex;
^
RuntimeError: unreachable
at main.wasm.signature_mismatch:test_func (wasm://wasm/main.wasm-0004140a:wasm-function[2]:0x1d8)
at main.wasm.__original_main (wasm://wasm/main.wasm-0004140a:wasm-function[3]:0x1de)
at main.wasm.main (wasm://wasm/main.wasm-0004140a:wasm-function[4]:0x1ed)
...
# native
$ ./main
test