Skip to content

[docs] Document passing side modules on command line with -sMAIN_MODULE=2 - #27592

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:docs-main-module-autoload
Open

[docs] Document passing side modules on command line with -sMAIN_MODULE=2#27592
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:docs-main-module-autoload

Conversation

@sbc100

@sbc100 sbc100 commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Explain how passing side modules on the command line automatically preserves their required symbols in -sMAIN_MODULE=2 mode, and how passing them together with -sAUTOLOAD_DYLIBS=0 avoids startup loading when modules are loaded dynamically via dlopen().

See #27588

…LE=2

Explain how passing side modules on the command line automatically
preserves their required symbols in `-sMAIN_MODULE=2` mode, and how
passing them together with `-sAUTOLOAD_DYLIBS=0` avoids startup
loading when modules are loaded dynamically via `dlopen()`.

See emscripten-core#27588
@sbc100 sbc100 changed the title [docs] Document passing side modules on command line with -sMAIN_MODU… [docs] Document passing side modules on command line with -sMAIN_MODULE=2 Aug 22, 2026
@sbc100
sbc100 requested review from dschuff and kripken August 22, 2026 00:59
symbols and JS library functions) are preserved and exported from the main
module.

- **Load-time dynamic linking**: Side modules are passed on the command line,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, is this always the case? You must pass side modules on the command line?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For load-time dynamic linking yes. I suppose its not always true since you might also specify the load time libraries by directly modifying Module.dynamicLibraries? Is that what you were thinking of? I'd like of forgotten one could do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the Module stuff is what I was thinking of.

If side modules are not passed on the command line (e.g. loaded later via
``dlopen``), you must either keep symbols alive manually (via
``EXPORTED_FUNCTIONS`` or ``EMSCRIPTEN_KEEPALIVE``) or pass the side
modules on the command line along with ``-sAUTOLOAD_DYLIBS=0``.

@kripken kripken Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sentences say this:

  1. Symbols needed by side modules passed on the command line will be kept alive automatically
  2. If side modules are not passed, you must either
    2.1. keep symbols alive manually
    2.2. pass side modules on the command line (with a flag)

Is 2.2 not redundant with 1? Both talk about passing the side modules on the command line.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I want to call out the second cases specificity because one doesn't normally pass dlopen'ed side modules on the command line. I will try to rephrase to avoid the seeming repetition.

in the same way, with the same flags used to build the main and side modules.

Side modules loaded dynamically at runtime must be placed in the virtual
filesystem so that ``dlopen()`` (or ``fopen()``, etc.) can access them (except

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we also had support for dlopen on URLs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants