-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
--shared-memory is disallowed when using -sSHARED_MEMORY=1 compiling C++ code #17213
Comments
@juj it looks like emscripten/tools/system_libs.py Line 497 in 17ea9f0
SHARED_MEMORY builds that object with atomics + bulk memory, but we link with non-atomic-supporting libc++ for example, which fails to link.
What should // [compile+link] - affects user code at compile and system libraries at link. Should it affect system libraries? If so, however, wouldn't it end up linking in pthreads dependencies? (libc++ might use pthreads when atomics are enabled) I'm not sure how this fits together... |
This does certainly look like a bug. The way I understood the requested use case of However implementing that is tricky, since to enable shared codegen for LLVM means to pass Building libc with multithreading enabled also makes it assume that pthreads is available, so I think libc-mt will have spots that depend on pthreads. I think we are probably missing an implementation of a "libc-mt-without-pthreads" and possibly a LLVM "-shared-mem-without-pthread" build flags here which would enable targeting such cases. In the original PR, since we don't have such an adapted "libc-mt-without-pthreads", I configured system_libs.py to build libc singlethreaded, thinking that it would be linked to the final app (and that apps won't care/observe that anyway since all they want is a shared SAB) - but now I see with that error message that this won't work because WebAssembly linker is strict and disallows linking singlethreaded object files against multithreading enabled object files. |
It seems that I understand correctly. I'm not familiar with how the underlying toolchain works. I just wanted to try to write my custom Worker in JavaScript and do something in worker with |
|
Yes.
Yes. Running the same wasm code and custom JS.
Maybe
I'm not sure. I am the author of emnapi which is a library implemented a subset of Node-API in JavaScript for Emscripten platform. All APIs declared in js_native_api.h has been implemented. Recently I'm thinking how to implement the simple asynchronous operation APIs declared in node_api.h: I plan to invoke the C side |
Is there some reason why you can't use the existing pthread support? ( |
I need to do these things in JavaScript, using dynCalls, and listen worker message myself to interact with my emnapi JS runtime code. Maybe using existing pthread support can also achieve this, but if user don't need to use pthread, they still need to use |
@juj Thanks, makes sense. There isn't an obvious solution, then, and we'd need to do more work to support use cases here. Maybe we need to figure those out more first. |
IIRC, pthreads can call JS code in the all the same ways that the main thread can. If your main goal is to proxy async work then we have specific API that can be used for this purpose: /~https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/proxying.h In terms of listen for worker messages I believe you can do that to. See the discussion here: #16239 |
Same error here:
Just to know how to resolve here? |
This is because nanodet.cpp was not compiled with |
If you want to build a multithreaded program you need to apply |
Hitting a similar issue while compiling a recent fontconfig (was not the case before one year ago) |
Looks like this issue becomes pretty much inevitable with a sufficiently large dependency tree. Building It would at least be useful to have a standard library that is either thread-safe, or maybe unsafe but at least it should be possible to link it with thearding-enabled code. Maybe then it is UB to concurrently call those standard library methods, but well-behaved apps would hopefully not do that. |
When linking fails in this way its because thread-safety has been stripped/removed from a given object file. This means the resulting code is guarantees to unsafe to use from multiple threads (i.e. the specific object in question had usages of atomics or TLS that were lowered away by the compiler). It true that you could take that guaranteed thread-unsafe code and link it into a multithreaded program if you are sure that all the usage of that library will come from just one thread. I can imagine that could be useful in a few application but one would need to be extremely careful and aware of the risks involved. Is that really what you are asking for? How common is this case? How hard would it be to instead just rebuild everything with the Being able to rebuild your entire project, including all object files from scratch (for example when updating from one version of emscripten to the next) is already something that folks kind of need to be able to do. Certainly if you were going to try to distribute a version libffmpeg.a to a wide audience you would want to distrubute two flavors of it ( |
To be clear here, I would much rather recompile everything down to the standard library, rather than link against thread-unsafe code. I am however, currently unsure how to do that. (Namely, how to recompile the standard library — or, are there already Indeed, building a Maybe those dependencies are not correctly passing And to add to all that, I'm only interested in a multithreaded version at the moment, since we will need to use the Thanks for the quick response btw! |
Emscripten already takes care of linking the correct version of the standard libraries yes. |
I'm not sure what you mean by this, perhaps you could give and example of elaborate? |
While I got it working now, the issue I gat was while trying to build, of all things, |
Version of emscripten/emsdk:
Failing command line in full:
Full link command and output with
-v
appended:Repro:
/~https://github.com/toyobayashi/emxx-shared-memory-repro
C++ hello world is also failed to compile with
-sSHARED_MEMORY=1
main.cc
But C is all OK.
main.c
Forgive my stupidity if this is not a bug.
The text was updated successfully, but these errors were encountered: