emscripten-core / emscripten-core/emscripten

Recommended updates to dynamic linking documentation

Open
#14,426 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The documentation at https://github.com/emscripten-core/emscripten/wiki/Linking gives the impression that dynamic linking is straight forward. For real world apps, it is more complicated. To help others in the future, I'd recommend updating the documentation to:

- give more emphasis on complications related to +4K modules and steps to solve them
- mention and explain why dlopen cannot be used in a thread to overcome that problem
- mention the drawbacks of preloading (not ideal when there are many large modules/plug-ins that may not be needed until later or at all)
- mention and document loadDynamicLibrary (with "fs: FS" for preloaded), which seems to be the only way to truly load larger modules dynamically.
- use RTLD_DEFAULT in dlsym and add leading underscore as required?
- or for non-global, use handle returned by loadDynamicLibrary in dlsym, but no leading underscore?
- mention that the pointer returned from dlsym cannot be used in a thread to call a function

I see a warning that -s MAIN_MODULE + pthreads is experimental. Is there a way to call a dynamically loaded function from a pthread now?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.