emscripten-core / emscripten-core/emscripten

Optimization O3 fails when importing Wasi functions

Open
#16,294 4 comments 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

The implementation of PThreadFS imports Wasi functions such as `fd_write()`. Unfortunately, this fails under optimization level `-O3`. Under optimization level `-O2`, everything works well. Is there a way to avoid this issue?

Minimal example
```
#include
#include

EM_IMPORT(fd_close) __wasi_errno_t env_fd_close(__wasi_fd_t fd);

int main() {
env_fd_close(1);
return 0;
}
```
Compile with `emcc -o o3bug.html o3bug.cpp -O3`, then instantiation fails with
```
RuntimeError: Aborted(LinkError: WebAssembly.instantiate(): Import #0 module="a" function="a" error: function import requires a callable). Build with -s ASSERTIONS=1 for more info.
```
Using Emsdk 3.1.3, Chrome 98.

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.