DynamicLinking: Extend "dylink" section with [] of needed libraries#77
DynamicLinking: Extend "dylink" section with [] of needed libraries#77sbc100 merged 1 commit intoWebAssembly:masterfrom
Conversation
This comes from my work to teach Emscripten dynamic linker to support library -> library linkage: emscripten-core/emscripten#7512 The motivation is that without support for DSO -> DSO linking, it becomes problematic in cases when there are several shared libraries that all need to use another should-be shared functionality, while linking that should-be shared functionality to main module is not an option for size reasons. See above pull-request for more details. In order to support library -> library linkages, we have to store somewhere the information about which other libraries, a library needs. This patch extends "dylink" section with such information, which is similar to how ELF handles the same situation with DT_NEEDED entries. /cc @sbc100
576dff2 to
4cb9313
Compare
|
For the reference: the patch that teaches Emscripten about dylink section extension about DSO -> DSO dependencies had entered Emscripten tree: |
|
Thanks for merging. |
This updates the format of the dylink section in accordance with recent "spec" change: WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D55609 llvm-svn=348989
This updates the format of the dylink section in accordance with recent "spec" change: WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D55609 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348989 91177308-0d34-0410-b5e6-96231b3b80d8
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 llvm-svn: 356102
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@356102 91177308-0d34-0410-b5e6-96231b3b80d8
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356102 91177308-0d34-0410-b5e6-96231b3b80d8
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356102 91177308-0d34-0410-b5e6-96231b3b80d8
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 llvm-svn: 356102
This change adds basic support for shared library dependencies via the dylink section. See WebAssembly/tool-conventions#77 Differential Revision: https://reviews.llvm.org/D59237 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356102 91177308-0d34-0410-b5e6-96231b3b80d8
|
Why not wait for the first call to be made from a recognized function inside the library, then load in asynchronously as needed? I got dlopen working without the use of SIDE_MODULE/MAIN_MODULE making huge files with empty memory space in between. No header necessary if you know a little bit about what it is trying to load. The wiring is already specified with |
|
I think there are a few different points here so I will try to respond them individually. Some of these issues are probably best discussed in emscripten since they talk about emscirpten-specific concepts.
|
|
It looks like I got this working using STANDALONE_WASM and IMPORT_MEMORY, then using the exact same dylink code as what emscripten provides except, I comments out the parseDylinkMetadata since there is none, and I added references to my main program (NOT using MAIN_MODULE) for But as you explain that won't necessarily make a difference transferring a compiled module to someone else's app. I wonder if this is worth patching as a possibly improvement to MAIN_MODULE=2, SIDE_MODULE=2 maybe? Basically, I arrived at this conclusion when looking at the comments on using USE_PTHREADS=1 being the only way to inject our own memory. Maybe this only works because my application (Quake 3) is so well isolated. But my intention was to pretend my module is a pthread, when it is actually a dylink. I also had this idea that dylibs get their own process context and memory space which they can choose to share or not. So I thought it was odd that even if a dylib doesn't want to share memory, that is what is assumed in the library_dylink.js code. Memory sharing must be on, I think. EDIT: Also, I don't know if it's worth mentioning somewhere in examples, but I didn't know ALLOW_MEMORY_GROWTH also should be applied to side_modules. |
The model we are going for is similar to the native idea of dynamic/shared library. So the classic examples would be something like zlib which is shared between apps, where the author of the app the author of zlib are different. As you suggest the module can also be part of app that is split out, such as libGameEngine.so. Either way, I think useful if the modules self describe rather than have the dynamic loader embed knowledge about specific libraries.
I believe that LINKABLE is the flag you want to avoid if you want smaller files, since that ends up including everything and not doing any DCE. This is what If you don't use RELOCTABLE (AKA
Are you saying that
|
|
How about something like this but ported to webassembly? https://www.usenix.org/legacy/publications/library/proceedings/usenix05/tech/general/full_papers/collberg/collberg_html/main.html It's called SLINKY |
|
I just had a revelation. This is going to be used to obfuscate compiled/WebAssembly code and add to mess that is already the entire tech industry. The thing that makes me hate this idea is it promotes this idea that anyone can import functionality, without actually understanding it. No one can see the code anymore, which means they don't have to take responsibility over how well it functions. This happens everywhere already, SourceTree freezes when you copy and paste, all of JetBrains products are terrible at uploading because they imported a library that counts files before it starts uploading. I specifically fell in love with JavaScript when I was 12 years old because I could copy little mouse animations into my Geocities website. Everywhere you look there is free and open source javascript. All the libraries Emscripten imports are free and open source. I've downloaded a dozen libs over the last few months and they all compiled flawlessly on my Mac, including libvpx, libcurl, musl, libopus, RmlUI, SDL, libjpeg, freetype, zlib. All open source, but if they weren't open source, they would be a complete mystery to me. EDIT: If no one is interested in the moral reasons for open-source. Here's just the pragmatic facts. Fact 1) Google/FAANG companies already obfuscate their code. Fact 2) Self-describing libraries make code obfuscation faster and easier. Fact 3) If society wants smarter programmers, every time someone clicks "View Source" it should be an educational experience. Fact 4) This is how I treat my code and development process, and we deserve better. |
This comes from my work to teach Emscripten dynamic linker to support
library -> library linkage:
emscripten-core/emscripten#7512
The motivation is that without support for DSO -> DSO linking, it becomes
problematic in cases when there are several shared libraries that all
need to use another should-be shared functionality, while linking that
should-be shared functionality to main module is not an option for size
reasons. See above pull-request for more details.
In order to support library -> library linkages, we have to store
somewhere the information about which other libraries, a library needs.
This patch extends "dylink" section with such information, which is
similar to how ELF handles the same situation with DT_NEEDED entries.
/cc @sbc100