emscripten-core / emscripten-core/emscripten

setTempRet0 and getTempRet0 are inconsistent in their implementation.

Open
#7,273 8 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

There are several places there the need to some kind of temporary is need is needed / used in emscripten.

1. When returning 64-bit values to emscripten:

Under wasm this is handled in either asm2wasm or emscripten-wasm-finalize which both run the legalize-js-interface pass: https://github.com/WebAssembly/binaryen/blob/master/src/passes/LegalizeJSInterface.cpp#L256

In this case the temporary uses is a wasm global and is only ever set via inline calls to set_global in the wrapper functions. `getTempRet0` in synthesized here then exported so that JS can call it. For an example of this run the `other.test_sixtyfour_bit_return_value` test.

2. setjmp/longjmp + exception handling in fastcmp and llvm upstream:

See lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp in both fastcmp and upstream.
Here we have a global variable in linear memory and a helper function called `setTempRet0` that JS can use to set it.

So we have two different globals being used, which happens to work because JS code only need to set one of them an get the other.

This is somewhat confusing and should probably be fixed. There is more complexity that I'm also missing. Continuing to investigate. My current feeling is that the codegen in both llvm and binaryen should always use the getters and setters, and then the implementations can be up the linker/LTO.

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.