WebAssembly / WebAssembly/binaryen
Handling of exported _GLOBAL__sub_I_* functions
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
Description
First off, I'm not sure if binaryen is the right place to raise this as this may go further up to llc or llvm/clang, or if it's an issue further down with wabt, but I'm trying here first as this issue is specific to WebAssembly.
Additionally this is not an Emscripten issue, I'm manually passing my code through clang->llvm-link (if there are multiple code files)->llc->s2wasm->wat2wasm->wasm-opt to get my binaries.
I noticed in the wat file produced by s2wasm that it was exporting a function called _GLOBAL__sub_I_main.withinternalfloatarr.cpp, and can trace it back to the .s file produced by llc (which means it's also part of the .bc file produced by clang/clang++) which places it in a section called __startup
.section .text.__startup,"ax",@progbits
.type _GLOBAL__sub_I_main.withinternalfloatarr.cpp,@function
_GLOBAL__sub_I_main.withinternalfloatarr.cpp:
...
However since this function contains full-stops because of the filename in it when it finally reached the compiled module's exports it was both there (console.log(module.exports)) and not there (trying to actually access it at module.exports._GLOBAL__sub_I_main.withinternalfloatarr.cpp).
These _GLOBAL__sub_I_ functions from what I can tell do all the setting up in the background that you take for granted in a normal C/C++ application, however since this function doesn't seem to be getting called when the module is instanced or even callable manually is a bit problematic.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue through clang, llvm-link, llc, s2wasm, wat2wasm, and wasm-opt, then inspect the generated .s and .wat around the __startup section and GLOBAL__sub_I export. Check whether the behavior belongs in Binaryen or an upstream tool; done means the startup function's export and invocation behavior are defined consistently for the compiled module.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100