7 Dynamic linking: the basics

 

This chapter covers:

  • How dynamic linking works for WebAssembly modules
  • Why you might want to use dynamic linking and why you might not
  • How to create WebAssembly modules as main or side modules
  • What the different options are for dynamic linking and how to use each approach

When it comes to WebAssembly modules, dynamic linking is the process of joining two or more modules together at runtime where the unresolved symbols from one module (functions for example) resolve to symbols existing in another module. You’ll still have the original number of WebAssembly modules but now they’re linked together and able to access each other’s functionality, as shown in figure 7.1.

Figure 7.1 At runtime, the logic from one module (Module 2 in this case) is linked to another module (Module 1 in this case) allowing the two to communicate and act as one.

There are several different ways that dynamic linking can be implemented for WebAssembly modules, making this a large topic. Before you learn how to build a website that uses dynamic linking in chapter 8, you’ll need to learn what your options are.

7.1   Dynamic linking: pros and cons

 

Why would you want to use dynamic linking instead of just using the single WebAssembly module approach that you’ve used so far in this book?

You might consider using dynamic linking for several reasons, including the following:

7.2   Dynamic linking options

7.2.1   Side modules and main modules

7.2.2   Dynamic linking: dlopen

7.2.3   Dynamic linking: dynamicLibraries

7.2.4   Dynamic linking: WebAssembly JavaScript API

7.3   Dynamic linking review

7.4   Exercises

7.5   Summary