emscripten-core / emscripten-core/emscripten

EMULATE_FUNCTION_POINTER_CASTS + dlsym breaks

Open
#13,076 7 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Sample code:
```c
// main.c
#include
int main() {
void *handle = dlopen("library.wasm", RTLD_NOW);
typedef void (*fp)();
fp g = (fp) dlsym(handle, "foo");
g();
return 0;
}
```
```c
// library.c
void foo() {}
```
Build script:
```shell
$ emcc library.c -o library.wasm -s SIDE_MODULE=1 -s EXPORT_ALL=1 -s EMULATE_FUNCTION_POINTER_CASTS=1
$ emcc main.c -s MAIN_MODULE=1 -s EXPORT_ALL=1 --embed-file library.wasm -s EMULATE_FUNCTION_POINTER_CASTS=1
$ node a.out.js
```
Error message:
```
exception thrown: RuntimeError: function signature mismatch,RuntimeError: function signature mismatch
at __original_main (:wasm-function[145]:0x6dc93)
at main (:wasm-function[146]:0x6dcae)
at /tmp/dyncall/a.out.js:1506:22
at callMain (/tmp/dyncall/a.out.js:49544:15)
at doRun (/tmp/dyncall/a.out.js:49608:23)
at run (/tmp/dyncall/a.out.js:49623:5)
at runCaller (/tmp/dyncall/a.out.js:49518:19)
at removeRunDependency (/tmp/dyncall/a.out.js:1427:7)
at receiveInstance (/tmp/dyncall/a.out.js:1573:5)
at receiveInstantiatedSource (/tmp/dyncall/a.out.js:1589:5)
```
emcc version: 2.0.10
wasm-opt version: version 91

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.