Skip to content

Commit bbd4223

Browse files
authored
Update dynamic linking docs. NFC (#25682)
- Add more cross referencing - Update note about 4kb limit of sync loading of wasm files.
1 parent d0465ad commit bbd4223

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

site/source/docs/compiling/Dynamic-Linking.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ along with the main module, during startup and they are linked together
109109
before your application starts to run.
110110

111111
- Build one part of your code as the main module, linking it using
112-
``-sMAIN_MODULE``.
112+
``-sMAIN_MODULE`` (See :ref:`MAIN_MODULE`).
113113
- Build other parts of your code as side modules, linking it using
114-
``-sSIDE_MODULE``.
114+
``-sSIDE_MODULE`` (See :ref:`SIDE_MODULE`).
115115

116116
For the main module the output suffix should be ``.js`` (the WebAssembly
117117
file will be generated alongside it just like normal). For the side
@@ -152,14 +152,14 @@ By default, main modules disable dead code elimination. That means that
152152
all the code compiled remains in the output, including all system
153153
libraries linked in, and also all the JS library code.
154154

155-
That is the default behavior since it is the least surprising. But it is
156-
also possible to use normal dead code elimination, by building with
157-
``-sMAIN_MODULE=2`` (instead of 1). In that mode, the main module is
158-
built normally, with no special behavior for keeping code alive. It is
159-
then your responsibility to make sure that code that side modules need
160-
is kept alive. You can do this either by adding to ``EXPORTED_FUNCTIONS`` or
161-
tagging the symbol ``EMSCRIPTEN_KEEPALIVE`` in the source code.
162-
See ``other.test_minimal_dynamic`` for an example of this in action.
155+
That is the default behavior since it is the least surprising. But it is also
156+
possible to use normal dead code elimination, by building with
157+
``-sMAIN_MODULE=2`` (instead of 1). In that mode, the main module is built
158+
normally, with no special behavior for keeping code alive. It is then your
159+
responsibility to make sure that code that side modules need is kept alive. You
160+
can do this either by adding to :ref:`EXPORTED_FUNCTIONS` or tagging the symbol
161+
``EMSCRIPTEN_KEEPALIVE`` in the source code. See ``other.test_minimal_dynamic``
162+
for an example of this in action.
163163

164164
If you are doing load time dynamic linking then any symbols needed by
165165
the side modules specified on the command line will be kept alive
@@ -201,25 +201,25 @@ symbols remain unresolved, and code can start to run even if there are.
201201
It will run successfully if they are not called in practice. If they
202202
are, you will get a runtime error. What went wrong should be clear from
203203
the stack trace (in an unminified build); building with
204-
``-sASSERTIONS`` can help some more.
204+
:ref:`ASSERTIONS` can help some more.
205205

206206
Limitations
207207
-----------
208208

209-
- Chromium does not support compiling >4kB WASM on the main thread, and that
210-
includes side modules; you can use ``--use-preload-plugins`` (in ``emcc`` or
211-
``file_packager.py``) to make Emscripten compile them on startup
212-
`[doc] <https://emscripten.org/docs/porting/files/packaging_files.html#preloading-files>`__
213-
`[discuss] <https://groups.google.com/forum/#!topic/emscripten-discuss/cE3hUV3fDSw>`__.
209+
- Chromium does not support synchronous compiling of Wasm modules over 8Mb on
210+
the main thread. You could run into this limit when using the synchronous
211+
``dlopen`` API to load large side modules. Emscripten has async versions of
212+
``dlopen`` that can work around this issue (See :c:func:`emscripten_dlopen`).
214213
- ``EM_ASM`` and ``EM_JS`` code defined within side modules depends on ``eval``
215-
support and are therefore incompatible with ``-sDYNAMIC_EXECUTION=0``.
214+
support and are therefore incompatible with ``-sDYNAMIC_EXECUTION=0`` (See
215+
:ref:`DYNAMIC_EXECUTION`).
216216

217217

218218
Pthreads support
219219
----------------
220220

221221
Dynamic linking + pthreads is is still experimental. As such, linking with both
222-
``MAIN_MODULE`` and ``-pthread`` will produce a warning.
222+
:ref:`MAIN_MODULE` and ``-pthread`` will produce a warning.
223223

224224
While load-time dynamic linking works without any complications, runtime dynamic
225225
linking via ``dlopen``/``dlsym`` can require some extra consideration. The

0 commit comments

Comments
 (0)