emscripten-core / emscripten-core/emscripten
postRun hooks not run when exit runtime is enabled
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
This issue can be reproduced with the following files.
**pre-js.js**
```js
Module = {};
Module['postRun'] = function() {
console.log('Hello, this is postRun.');
}
```
**main.c**
```C
main() {}
```
And the commands:
1. `emcc main.c --pre-js pre-js.js -o no-exit.js`
2. `emcc main.c --pre-js pre-js.js -o exit.js -s EXIT_RUNTIME=1`
`no-exit.js` runs the hook, but `exit.js` does not, which is extremely counterintuitive.
The reason is that postRun hooks are run after `callMain` has returned and `callMain` calls `exit`, which returns if the exit runtime is disabled but kills the interpreter otherwise. One potential solution is to move the postRun hook execution into `exit`, but I don't know if that would break anything. A better solution would be to remove the postRun hooks entirely, but idk if anyone depends on them.
Contributor guide
Assessment
This issue has not been assessed yet.