With the latest release, shared libraries work, but not with -flto. I managed to make static libraries work for me anyways.
Thanks Sam! Dan On Tuesday, May 4, 2021 at 6:23:14 PM UTC-7 [email protected] wrote: > On Tue, May 4, 2021 at 4:32 PM Dan C <[email protected]> wrote: > >> Hi All, >> >> We are currently building a library with 50 other libraries, and need >> expose over a thousand functions. With fastcomp backend, we currently >> create a shared lib with all these libs, and another shared lib worker.so >> which was linked against the previous shared lib. We then create >> WebAssembly binaries with these two shared libraries. >> >> When trying to use the latest upstream backend, we encountered this issue >> https://github.com/emscripten-core/emscripten/issues/9726 for creating >> the shared libs. We then tried to create WebAssembly binaries with static >> libs. First difficulty is that we need to list all the 50 static lib names >> in the cmake file, and we also need list all the 2000 functions for >> EXPORTED_FUNCTIONS because EMSCRIPTEN_KEEPALIVE doesn't keep the functions >> alive. >> >> Is there an equivalent of EMSCRIPTEN_KEEPALIVE for static libraries or a >> way to make it work with them? Is there any alternative approach to group >> the libraries, so that we don't need to list all the libraries and >> functions? >> >> > EMSCRIPTEN_KEEPALIVE does work on static libraries, but you need to > understand how object files in static libraries are included by the > linker. By default only object files that are needed via some symbol > dependency will be included. You can override this behavior using > `-Wl,-whole-archive -lmylib `-Wl,-no-whole-archive` which causes the linker > to include all the object files as if you have listed them on the command > line individually (which in turn will honor all of the > `EMSCRIPTEN_KEEPALIVE` statements in those objects). > > If you want to continue using shared libraries can also do that instead. > https://github.com/emscripten-core/emscripten/issues/9726 is now fixed > and we released a new version of emsdk today which should include that fix > (2.0.19). > > Bear in mind that the "shared library" support you are referring to is > kind of fake. What emscripten does today when you pass `-shared` is > create an intermediate object file (basically combines the input objects > into one big object). The result works like shared libraries but actually > you are still statically linking. If this works for you and you prefer > it to using more traditional static libraries you should be able to > continue to do that. > > cheers, > sam > > Thanks in advance for any suggestions, >> Dan >> >> -- >> You received this message because you are subscribed to the Google Groups >> "emscripten-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/emscripten-discuss/eccc3847-0ac2-4a88-89a7-51a89e63ea61n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/emscripten-discuss/eccc3847-0ac2-4a88-89a7-51a89e63ea61n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/191df11e-91a3-49f7-8323-87b6b93a7008n%40googlegroups.com.
