emscripten-core / emscripten-core/emscripten

Met `function signature mismatch` warning and got `RuntimeError: unreachable` in execution

Open
#22,254 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

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.
```shell
# 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
```c++
int test_func(); // defined as void test(); in test_mismatch.c

int main() {
test_func();
}
```
#### test_mismatch.c
```c++
#include
void test_func() {
printf("test\n");
}
```

### Execution
```shell
# 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
```

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.