SIDE_MODULE -> SIDE_MODULE linking with WASM backend

26 views
Skip to first unread message

Manuel Martín de Miguel

unread,
Oct 23, 2019, 6:35:30 AM10/23/19
to emscripten-discuss
Hi,

I need to be able to link several SIDE_MODULEs to each other. more info about the use case here: https://github.com/iodide-project/pyodide/issues/240

"1 level" Dynamic linking seems to be working currently with the WASM backend by using the MAIN_MODULE, SIDE_MODULE and RUNTIME_LINKED_LIBS flags.

At first I though "multi level" dynamic linking was also working. By multi level I mean for example a MAIN_MODULE that links against a SIDE_MODULE which in turn links against another SIDE_MODULE.
This PR and this CHANGELOG entry made me think it should be working:
https://github.com/emscripten-core/emscripten/pull/7512/
CHANGELOG.md version 1.38.22:
Dynamic linker has been taught to handle library -> library dependencies.

However it doesn't seem to be working with the LLVM wasm backend. The way this is supposed to work is by introducing
a new section in the wasm shared objects called "dylink". This section contains references to other .wasm dependencies. The main module
seems to be able to read this section in order to load more .wasm dependencies. (see the loadWebAssembly function on a main module).

The problem is that the section is not being written properly. A dump of a wasm shared object shows that it's just filled with zeros:

emscripten@2502103aaaa0:/home/manuel/devenvironment/projects/mlx/experiments/emscripten-tests/wasm-study/wasm$ llvm-
readobj --sections --section-data libk_so.wasm 

File: libk_so.wasm
Format: WASM
Arch: wasm32
AddressSize: 32bit
Sections [
  Section {
    Type: CUSTOM (0x0)
    Size: 5
    Offset: 8
    Name: dylink
    SectionData (
      0000: 00000000 00                          |.....|
    )
  }

When building a SIDE_MODULE emcc.py should be calling this function: shared.py:WebAssembly.make_shared_library(). This function is the one that builds
the dylink section. The problem is that currently this code seems deactivated for the wasm backend, as we can see in the following code inside emcc.py:

  if shared.Settings.SIDE_MODULE and not shared.Settings.WASM_BACKEND:
    wso = shared.WebAssembly.make_shared_library(final, wasm_binary_target, shared.Settings.RUNTIME_LINKED_LIBS)

This makes me think this is still not supported form WASM, only for asm.js.

I just want to know the state of this functionality and how it fits in the roadmap, if needed I could try to implement the remaining parts since it seems only a few things are needed for it
to work.

Thanks!



Manuel Martín de Miguel

unread,
Oct 23, 2019, 7:26:11 AM10/23/19
to emscripten-discuss
OK, I think perhaps the code I referred to inside tools/shared.py was meant to be used with the fastcomp backend. When using the LLVM backend LLVM is the one that

does this mean we should somehow pass the "needed_dynlibs" array of dependencies to LLVM so that it can correctly fills the dylink section?
Reply all
Reply to author
Forward
0 new messages