On Sat, Mar 9, 2019 at 1:51 PM Philipp Gloor <[email protected]> wrote:
>
> I have spent some time to explore the dynamic linking in emscripten/wasm and 
> I have a couple of questions for my understanding.
>
> As I see I have following options to load dynamically:
>
> Use `Module.dynamicLibraries` and provide a list of side modules that are 
> being loaded and linked during the start up of the main module. So if one of 
> the side modules is big, the start up takes longer.
> `dlopen` and `dlsym`: this needs the modules to be available in the file 
> system.
> `loadDynamicLibrary` during run time. Can asynchronously fetch another 
> side_module a link during run time
>
>
> So the questions:
>
> Is `3` the only way to prevent loading the side modules only when needed?

Do you mean the only way to *allow" loading when needed?   Yes, my
understanding is that because dlopen is synchronous its can't be used
to compile/instantiate wasm modules dynamically (at least not on the
main thread).

> For `2`: Do I need to expose all my side module functions with `extern "C"` 
> so that `dlsym` finds them?

No, you can lookup C++ mangled names with dlsym() too.  The key is
that each symbol needs to be looked up individually by name.  In
practice though it does normally make sense to use C symbols when
using dlsym().

> To me, `3` seems to win by far: I only load the modules when I need them, and 
> I don't have to worry about `extern "C"` and the function signatures/returns
>

Yes, it looks like if you call loadDynamicLibrary() directly then you
can have first class references to functions in the library, then will
abort() if called before the library is loaded.

The `test_dylink_funcpointers2` looks like it does just that.

> --
> 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].
> For more options, visit https://groups.google.com/d/optout.

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to