emscripten-core / emscripten-core/emscripten
Exporting mutable globals / externref globals from `.s` files
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Suppose I make a `.s` file with the following:
```
.globl myGlobal
.globaltype myGlobal, externref
myGlobal:
```
This causes trouble in many places in the code. At compile time, it crashes in `extract_metadata.py` in `get_const_expr_value` because it is surprised to see `ref.null` as the expression. But also `create_named_globals` is troublesome. Ideally we'd want to export the global itself and not the `value` of the global for mutable ones because then it would be possible to change the global from JavaScript or pass it as an import to a second wasm module.
If we use an `externref` global, there's more troubles at runtime in `relocateExports` and `updateGOT` in `library_dylink.js` because both of these methods get surprised that `typeof value.value === "object"`.
So
1. ideally, for exported mutable globals the whole global object should be exported not just the value
2. it would be nice if `externref`-valued globals were supported
I am willing to contribute code for this.
Contributor guide
Assessment
This issue has not been assessed yet.