-
Notifications
You must be signed in to change notification settings - Fork 3.4k
"local count too large" with large generated C++ function in debug mode #19346
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Does the problem go away when you run with Can you try also with |
Thanks, yes, it is only reproducible in debug mode. If I add I've already broken up the generated function, and that has solved the problem for me. As you say though, this could still be a llvm bug. |
I got the same error when I enabled Asan via build parameter |
@mike-lischke, does adding |
I'm on travel with limited internet connection. Will check when I return in 2 weeks. |
@sbc100 I have now tested your suggestion and get this error:
Unclear why a change to the wasm file would be necessary. The full command line is:
|
Can you try without |
Also without source maps the same error comes up (failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Compiling function #77:"embind_init_main()" failed: local count too large @+51266). |
And this was with What other flags are you using? I know |
Yes, I could link without
Using |
I see, so this seems like an issue with BTW, do you have any information about the function in question (the one with too many locals): embind_init_main? Is it a particularly long or complex function? One possible workaround here would be to split this function up at the source level into several smaller functions. In the case of EMSCRIPTEN_BINDINGS (which it looks like this is) you could create several blocks such as :
|
Somehow I anticipated this question :-) But no, this is not from my code. I searched my entire project and could not find it, not even in generated code. How much are "to many locals"? However, since I want to make all public classes available in JS/TS, I have bound many classes already. If the What are those names in that macro call actually? The documentation doesn't really explain them. Do they matter in some way? Update: That was it! I split the main bindings (around 2000 lines, 53 classes) into 6 separated binding functions and now I can execute the code and get an error report:
That's great! Many thanks for your help Sam! |
The name passed as the first argument to EMSCRIPTEN_BINDINGS doesn't really mean anything.. it just gives the generated function a unique name. So you can use whatever name you want as long as don't repeat names (since that will result in multiple symbols with the same name. |
@sbc100 I have the same problem when compiling a huge 300k lines SWIG-generated C++ file. In my case the problem is very real - it happens in a function which registers all the exported classes which has 768 blocks of this type: do {
// register class and methods
} while(0); Every block contains 4 local variables. When I use |
I believe the We could perhaps have binaryen (wasm-opt) and/or llvm try to limit the number of locals they allow themselves to use. It might be easier on the binaryen side but I'm not sure. @tlively @kripken WDTY? In the short term I'm afraid that your best best is probably to attempt to break up your large function into smaller ones. |
Binaryen does do this when it optimizes. I think that's why as reported above this works with As a workaround, you can do some manual optimization of the wasm like this: |
@kripken Alas, Finally, building just that one source file with |
I notice that llvm geps where the offset is a constant produce a local in the wat which is unneeded and optimised away with O1 . It would seem possible to eliminate that. |
* build, callbacks: fix/clarify wasm building * build: wasm building requires -O3 to be set in EMCC_CFLAGS, apperently. see emscripten-core/emscripten#19346 * bindings: moved functions for handling log callbacks over to c code * bindings: use our own raylib.h in the c code * audio: rename the 'ready' functions to match their function names * test: updated test to match AsRef PR * audio: brought back PhantomData for RaylibAudio so that the struct is and !Send and !Sync * audio: AsRef for more functions * raylib/cargo, raylib-sys/cargo: realized i had left in some unused imports * callbacks: make custom_trace_log_callback public as a stab in the dark to see if that fixes the windows issue * callbacks,tests: realized that since rust marks our external function as having 'char *' as the first argument on windows-gnu * callbacks: realized the c code wasn't wrapped in extern 'c' when compiling in c++ * callbacks: have windows compile a cpp file instead of a c file for utils_log * fixed the windows link error but now it complains about the char fix i did * log: vsprintf -> vsnprintf * log: use the result of vsnprintf instead of strlen * build: removed some flags i forgot i added. * log: actually, just use from_ptr, because what raylib gives us is always going to end in \0 * tests: disable callbacks test under windows after confirming that the issue literally only happens when we use cargo test * tests: disable callbacks test under windows after confirming that the issue literally only happens when we use cargo test * ci: remove windows test after confirming it only fails under CI. ran cargo clippy --fix
I'm getting the same issue, the difference is that, if I enable your suggested flag @sbc100 Also, I notice I get this error when addind the |
@kohakukun can you remove share the original link command that caused the failure? Along with the failure message itself? Does it happen if you add |
I also have the problem with the ASYNCIFY flag |
I met same issue with ASYNCIFY too. |
I'm having the same issue after compiling including FFmpeg for debug. If I exclude the decoders, it works, but that is far from optimal.
|
Does the workaround of manually optimizing the wasm not work for anyone? I see a comment about a "segfault on instantiateStreaming" in that case, but that sounds like a separate browser issue. If we can get a testcase for it, we can file a bug on the relevant browser. Otherwise, there isn't anything more we can do: reducing the amount of locals is something optimizations do, so this browser limit on locals can be hit in debug builds, unfortunately. Always running |
@kripken |
I can compile with edit: link to the chromium issue |
Uh oh!
There was an error while loading. Please reload this page.
Please include the following in your bug report:
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.34 (57b21b8)
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
Target: wasm32-unknown-emscripten
Thread model: posix
Using this python script to generate the code:
and this command line:
Chrome fails with something like
Firefox fails with something like
I don't really know what is meant by
locals
here, because there are not many local variables.The text was updated successfully, but these errors were encountered: