-
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
Add support for simultaneously using dynamic linking + pthreads. #3494
Comments
I would hope that this would just work. Did you see a problem when trying it? |
I did not try, this was motivated by your comment in the pull, will need a bit of an audit and testing. |
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
Any update on this? |
I don't believe anyone is working on it. It would require some design thinking, as say dlopen on one thread would require adding to the Table on all other threads. However, non-dlopen dynamic linking may be a lot easier. |
What about dlopening all from the "main-thread"? |
That would mean to have all the .so (is it really .so?) modules loaded all the time, no? |
@sbc100 talked about a shared table instead, would it be feasible? the SIDE_MODULE would still expose its native table to JS (like a normal wasm module does). I don't see how emscripten reads the native table? is it here? For now, "agressively" disabling the errors when we USE_PTHREADS+SIDE_MODULE lands into a wasm-ld assert:
Makes me think there's another write. Is it like that? :
Dynamic linking in our case would be to be able to feed the JS table from SIDE_MODULES and read from it from the MAIN_MODULE. |
Current there is no concept of a shared wasm table in the spec, so each thread necessarily has its own table. And the tables need to stay in sync because C/C++ code expects to be able the share function pointer between threads. Right now we really on the startup code on each thread insantiating the wasm module and the local table such that local table on each thread ends up with the same content. Each time you load a DLL new table entries get add, so these table entries (and the DLL itself) need to propagated to each thread). If it can be done deterministicly then as perhaps just loading the DLL on each thread would be enough to guarantee the same table contents? |
I'm curious to know that your use cases for dynamic linking are there? Are you sure you need it? If its all happening at startup for example then its almost always better to produce a single module (at least today). |
For vlc.js I believe the requirement is to avoid pre-downloading megabytes of code for supporting file formats and codecs that mostly won't be used on any given run. Otherwise you either have a large initial download that's wasted by bundling all code together, or you have to make custom builds targeting just the formats that will be used on a given data set. With dynamic linking you get the flexibility of supporting many formats without having to ship unused code over the wire. |
We are trying to port VLC, which is built around the idea that modules can be loaded at runtime. As long as this is not implemented, it will always be less performant with this target. I am very interested in trying to make it work as is. |
I see. Loading plugins dynamically is indeed a valid use case :) In fact I think its pretty much the only one that exists on the web today. Presumably if you know the content type of the thing you wanted to play you could be a static build with just say, mpeg4+aac support? But then you wouldn't have a universal player. However I imagine it might be useful for a given site if they know the format of all their content. I might be worth the refactoring effort in your build system to be able to produce such tailored binaries? |
Yes. That will avoid using 30MB of binary (or more)
De facto, you never know. There is no such thing as AAC, for example. For example, I have a build for DVD, but we want something universal, but more importantly, extensible, from the webpage. So, I think we have a usecase here :D However, we don't need to dlopen from any thread. It could be done always from the same one. |
I was thinking if you were running a website the hosted videos one could imagine that they all might be in a known format. Maybe not a common use case, but perhaps this is true for someone like wikipedia? I don't know why hw codecs have any bearing here since wasm by definition can't access such things. That said, I do understand and sympathize with your use case now. |
Usually, people think they do know. And they don't :D
WebCodec is being discussed right now. I do not see why wasm couldn't access to such things.
Thanks :) |
+1 |
pyodide is another one. If there are multiple python modules available with C-extensions we don't want to load all of them at the same time, and threading is used quite a bit in Python. Though a blocker for threading is currently the lack of Firefox support by default in any case pyodide/pyodide#237 |
Mostly convert to C to match the other tests here. See #3494
Mostly convert to C to match the other tests here. See #3494
Mostly convert to C to match the other tests here. See #3494
Mostly convert to C to match the other tests here. See #3494
The conditional guarding createInitMemoryFunction was incorrect and didn't match that guarding the creation of the associated symbol. Rather that reproduce the same conditions in multiple places we can simply use the presence of the associated symbol. Also, add an assertion that would have caught this bug. Also, add a new test for this flag combination. This is part of an ongoing effort to enable dynamic linking with threads in emscripten. See emscripten-core/emscripten#3494 Differential Revision: https://reviews.llvm.org/D92520
Don't early return from layoutMemory in PIC mode before we have set the memory limits. This matters in particular with shared-memory + PIC because shared memories require maximum size. Secondly, when we need a maximum, but the user does not supply one, default to MAX_INT rather than 0 (defaulting to zero is completely useless and means that building with -shared didn't previously work at all without --maximum-memory, because zero is never big enough). This is part of an ongoing effort to enable dynamic linking with threads in emscripten. See emscripten-core/emscripten#3494 Differential Revision: https://reviews.llvm.org/D92528
This support is still experimental and has some major caveats: - Only supports load-time dynamic linking - No support for sharing TLS data between dylibs. The major change is that workers now also call the module `run` function although they exit early, once dynamic libraries have all been loaded. See: #3494
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. |
I don't think this should be closed as wontfix, it's a major issue. |
I think this is is largely complete. We still warn about it being experimental, but it should work % bugs. We can open specific bugs if/when they are found. |
Mostly convert to C to match the other tests here. See #3494
Mostly convert to C to match the other tests here. See emscripten-core#3494
Mostly convert to C to match the other tests here. See #3494
Current pthreads implementation has a limitation that the dynamic linking feature cannot be used with it. Investigate what is needed to enable this.
The text was updated successfully, but these errors were encountered: