Chapter 3. WebAssembly Modules

A place for everything and everything in its place.

Seventeenth-century proverb

An operating system runs a program usually contained in a compiled form.1 Each operating system has its own format that defines where to start, what data is necessary, and what the instructions are for the different advertised bits of functionality. WebAssembly is no different. In this chapter, we are going to look at how the behavior is packaged up and how a host will know what to do with it.

It is possible that software engineers can spend their entire careers ignoring how programs are loaded and executed through this process. Their world starts and stops at int main(int argc, char **argv) or static void main(String []args) or even if __name__ == "__main__":. These are well-known entry points to programs in C, Java, and Python, thus this is where programmers assume responsibility for the control flow. Prior to programs being launched and after they exit, however, the operating system or programmatic runtime needs to set up and tear down the executable structure. The loader process needs to know where the instructions begin, how data elements are initialized, what other modules or libraries need to be loaded, and more.

These details are generally defined by the nature of the executable. On Linux, this is defined by the Executable and Linkable Format (ELF); on Windows, it’s the Portable Executable (PE) format; and on macOS, it is the Mach-O format. These are obviously ...

Get WebAssembly: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.