-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Unexpected arg0 type (select)" for EM_ASM call #11539
Comments
Further intrigue on this. The broader context is that the code looks like:
As mentioned, I can change that second from Strangely, rewriting it to not use an
I'll point out that strange compiler errors arose in similarly-patterned code before from the same routine: I tried using |
This looks like a bug/limitation in binaryen: https://github.com/WebAssembly/binaryen/blob/cd0cc95e2794375c463a69833b1ccc9cc96d597c/src/wasm/wasm-emscripten.cpp#L774 I imagine what happens is that llvm is performing optimizations and then binaryen tries to essentially decompile to find the pointer to the JS code which you embed. Perhaps the quickest and most robust solution would be to switch to EM_JS which puts each JS function on its own C function and I don't think suffers from this problem. |
I wonder what the difference would be between EM_ASM and EM_ASM_MAIN_THREAD, from an optimization point of view...as the definitions look very similar:
If the functions aren't inlined, why would one of these trigger the problem and the other not? Might there be some accommodation in a process that is looking for |
To debug the issue fully you would need to look a the compiled code by decompiling the resulting wasm object file, then look at the code in binaryen(in wasm-emscripten.cpp) to figure out why failing to find what it needs. Switching to EM_JS seems like it might be an easier option. |
I need to synchronously run on the main thread, and there doesn't seem to be a MAIN_THREAD_EM_JS: For now I'll go with the workaround of |
Ah yes I guess maybe EM_JS has no support for threading yet? @jgravelle-google ? |
I came across the same error, fortunately I was prototyping and didn't have much code, so I reduced it to a minimal example showing this error.
cmake_minimum_required(VERSION 2.8)
add_executable(test main.cpp) #include <cstdlib> // rand
#include <emscripten/emscripten.h>
int main() {
int test = rand() % 2;
if (test == 0) {
EM_ASM(alert('a'));
} else {
EM_ASM(alert('b'));
}
return 0;
} cmake -GNinja -DCMAKE_TOOLCHAIN_FILE="(...)/cmake/Modules/Platform/Emscripten.cmake"
ninja Note that compiling if (test == 0) {
//EM_ASM(alert('a'));
} else {
EM_ASM(alert('b'));
} or if (test == 0) {
EM_ASM(alert('a'));
} else {
//EM_ASM(alert('b'));
} both works and compile fine. if (test == 0) {
EM_ASM(alert('a'));
} else {
EM_ASM(alert('b'));
} results in:
|
Thanks for the testcase @mlomb ! Looks like the issue is that binaryen wants to see a constant there, so we can tell the ID for each EM_ASM statically (we use that to find the text of the EM_ASM JS code). But LLVM optimizes here and passes a dynamic value (here, a select of two constant values). It may be interesting to look into handling such a select, but in more complicated cases the instruction could be much more complex. So it may be better to look into emitting a better error message + suggestion for how to work around this. In general the workaround would be to avoid almost-identical EM_ASMs in the same function. Alternatively, if we can implement EM_ASM not using a pointer to JS as text in the data section, this problem could go away. |
I couldn't track down precisely which
|
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
This may (?) still be a problem when using PTHREAD features: emscripten-core/emscripten#11539 But the pthreads build is unlikely to be relevant again in this particular lifetime. It does not seem to be a problem with the stackless build.
I have previously compiling code not working after
git pull
and activating thelatest
emsdk (1.39.18). The error is:There are several EM_ASM calls, some returning an int and not. Commenting them out one by one revealed the call it was complaining about was this one (where
utf8
is aconst char *
):Changing this to simply
{ eval(UTF8ToString($0)) }
gets it to compile. However, that doesn't achieve the purpose... which was to achieve an "indirect eval call".Changing it to a plain EM_ASM (no MAIN_THREAD) also seems to work, but also does not accomplish the intent.
Command line
The text was updated successfully, but these errors were encountered: