emscripten-core / emscripten-core/emscripten

Problem when compiling code that has symbol collision with WASI API

Open
#22,205 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 16h
Merged PRs (30d)
117

Description

**Version of emscripten/emsdk:**
`3.1.62`

**Issue Description**

Hi, I am trying to compile a project into wasm that has a function with name `proc_exit`
It seems that `proc_exit` is a special WASI name that is part of the WASM POSIX API. Usually emscripten generates a JS wrapper for this function and exposes it to the underlying WASM that could have been compiled from C sources, for example. Then, both js and C code can call this `proc_exit` to exit the process.
However, I run into a runtime error when my C code contains an unrelated function with name `proc_exit`. It seems emscripten sees the presence of my function with the same name and decides to not create the special `proc_exit` function to act as js-wasm/WASI bridge.

I ran into this problem when compiling postgres, which has a function named `proc_exit`.

My understanding is that emscripted could expose its WASI API function, regardless of existence of homonymous functions in the source project. To avoid name collisions, emscripten could generate special attributes to expose the WASI api functions under special prefix.

Please find minimal reproducing example of the issue below to compile and run make all .
I would expect to open `index.html` in the browser and not see any error, but I see an error:

`Import #15 "wasi_snapshot_preview1" "proc_exit": function import requires a callable`

Does the issue make sense?
Is it a real problem or am I misunderstanding something?
What are your thoughts on the proposed solution?

### Code

`main.c`
```c
void proc_exit(int status) { (void)status; }
```

`Makefile`
```
all:
emcc main.c -sMAIN_MODULE -s EXPORT_ALL -o index.html
python -m http.server 8888 -d .
```

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.