Modules

The binary encoding of modules is organized into sections. Most sections correspond to one component of a module record, except that function definitions are split into two sections, separating their type declarations in the function section from their bodies in the code section.

Note

This separation enables parallel and streaming compilation of the functions in a module.

Indices

All indices are encoded with their respective value.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{type index} & \href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{function index} & \href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{table index} & \href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{memory index} & \href{../binary/modules.html#binary-memidx}{\mathtt{memidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{global index} & \href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{local index} & \href{../binary/modules.html#binary-localidx}{\mathtt{localidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef659#1{{}}\mathdef659{label index} & \href{../binary/modules.html#binary-labelidx}{\mathtt{labelidx}} &::=& l{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}} &\Rightarrow& l \\ \end{array}\end{split}\]

Sections

Each section consists of

  • a one-byte section id,
  • the \(\href{../syntax/values.html#syntax-int}{\def\mathdef665#1{{\mathit{u}#1}}\mathdef665{\mathit{32}}}\) size of the contents, in bytes,
  • the actual contents, whose structure is depended on the section id.

Every section is optional; an omitted section is equivalent to the section being present with empty contents.

The following parameterized grammar rule defines the generic structure of a section with id \(N\) and contents described by the grammar \(\mathtt{B}\).

\[\begin{split}\begin{array}{llclll@{\qquad}l} \def\mathdef659#1{{}}\mathdef659{section} & \href{../binary/modules.html#binary-module}{\mathtt{section}}_N(\mathtt{B}) &::=& N{:}\href{../binary/values.html#binary-byte}{\mathtt{byte}}~~\mathit{size}{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}}~~\mathit{cont}{:}\mathtt{B} &\Rightarrow& \mathit{cont} & (\mathrel{\mbox{if}} \mathit{size} = ||\mathtt{B}||) \\ &&|& \epsilon &\Rightarrow& \epsilon \end{array}\end{split}\]

For most sections, the contents \(\mathtt{B}\) encodes a vector. In these cases, the empty result \(\epsilon\) is interpreted as the empty vector.

Note

Other than for unknown custom sections, the \(\mathit{size}\) is not required for decoding, but can be used to skip sections when navigating through a binary. The module is malformed if the size does not match the length of the binary contents \(\mathtt{B}\).

The following section ids are used:

Id Section
0 custom section
1 type section
2 import section
3 function section
4 table section
5 memory section
6 global section
7 export section
8 start section
9 element section
10 code section
11 data section

Custom Section

Custom sections have the id 0. They are intended to be used for debugging information or third-party extensions, and are ignored by the WebAssembly semantics. Their contents consist of a name further identifying the custom section, followed by an uninterpreted sequence of bytes for custom use.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{custom section} & \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}} &::=& \href{../binary/modules.html#binary-module}{\mathtt{section}}_0(\href{../binary/modules.html#binary-customsec}{\mathtt{custom}}) \\ \def\mathdef659#1{{}}\mathdef659{custom data} & \href{../binary/modules.html#binary-customsec}{\mathtt{custom}} &::=& \href{../binary/values.html#binary-name}{\mathtt{name}}~~\href{../binary/values.html#binary-byte}{\mathtt{byte}}^\ast \\ \end{array}\end{split}\]

Note

If an implementation interprets the contents of a custom section, then errors in that contents, or the placement of the section, must not invalidate the module.

Type Section

The type section has the id 1. It decodes into a vector of function types that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{types}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{type section} & \href{../binary/modules.html#binary-typesec}{\mathtt{typesec}} &::=& \mathit{ft}^\ast{:\,}\href{../binary/modules.html#binary-module}{\mathtt{section}}_1(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-functype}{\mathtt{functype}})) &\Rightarrow& \mathit{ft}^\ast \\ \end{array}\end{split}\]

Import Section

The import section has the id 2. It decodes into a vector of imports that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{imports}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{import section} & \href{../binary/modules.html#binary-importsec}{\mathtt{importsec}} &::=& \mathit{im}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_2(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-import}{\mathtt{import}})) &\Rightarrow& \mathit{im}^\ast \\ \def\mathdef659#1{{}}\mathdef659{import} & \href{../binary/modules.html#binary-import}{\mathtt{import}} &::=& \mathit{mod}{:}\href{../binary/values.html#binary-name}{\mathtt{name}}~~\mathit{nm}{:}\href{../binary/values.html#binary-name}{\mathtt{name}}~~d{:}\href{../binary/modules.html#binary-importdesc}{\mathtt{importdesc}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-import}{\mathsf{module}}~\mathit{mod}, \href{../syntax/modules.html#syntax-import}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-import}{\mathsf{desc}}~d \} \\ \def\mathdef659#1{{}}\mathdef659{import description} & \href{../binary/modules.html#binary-importdesc}{\mathtt{importdesc}} &::=& \def\mathdef717#1{\mathtt{0x#1}}\mathdef717{00}~~x{:}\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef718#1{\mathtt{0x#1}}\mathdef718{01}~~\mathit{tt}{:}\href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{table}}~\mathit{tt} \\ &&|& \def\mathdef719#1{\mathtt{0x#1}}\mathdef719{02}~~\mathit{mt}{:}\href{../binary/types.html#binary-memtype}{\mathtt{memtype}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{mem}}~\mathit{mt} \\ &&|& \def\mathdef720#1{\mathtt{0x#1}}\mathdef720{03}~~\mathit{gt}{:}\href{../binary/types.html#binary-globaltype}{\mathtt{globaltype}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{global}}~\mathit{gt} \\ \end{array}\end{split}\]

Function Section

The function section has the id 3. It decodes into a vector of type indices that represent the \(\href{../syntax/modules.html#syntax-func}{\mathsf{type}}\) fields of the functions in the \(\href{../syntax/modules.html#syntax-module}{\mathsf{funcs}}\) component of a module. The \(\href{../syntax/modules.html#syntax-func}{\mathsf{locals}}\) and \(\href{../syntax/modules.html#syntax-func}{\mathsf{body}}\) fields of the respective functions are encoded separately in the code section.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{function section} & \href{../binary/modules.html#binary-funcsec}{\mathtt{funcsec}} &::=& x^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_3(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}})) &\Rightarrow& x^\ast \\ \end{array}\end{split}\]

Table Section

The table section has the id 4. It decodes into a vector of tables that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{tables}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{table section} & \href{../binary/modules.html#binary-tablesec}{\mathtt{tablesec}} &::=& \mathit{tab}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_4(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-table}{\mathtt{table}})) &\Rightarrow& \mathit{tab}^\ast \\ \def\mathdef659#1{{}}\mathdef659{table} & \href{../binary/modules.html#binary-table}{\mathtt{table}} &::=& \mathit{tt}{:}\href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-table}{\mathsf{type}}~\mathit{tt} \} \\ \end{array}\end{split}\]

Memory Section

The memory section has the id 5. It decodes into a vector of memories that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{mems}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{memory section} & \href{../binary/modules.html#binary-memsec}{\mathtt{memsec}} &::=& \mathit{mem}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_5(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-mem}{\mathtt{mem}})) &\Rightarrow& \mathit{mem}^\ast \\ \def\mathdef659#1{{}}\mathdef659{memory} & \href{../binary/modules.html#binary-mem}{\mathtt{mem}} &::=& \mathit{mt}{:}\href{../binary/types.html#binary-memtype}{\mathtt{memtype}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-mem}{\mathsf{type}}~\mathit{mt} \} \\ \end{array}\end{split}\]

Global Section

The global section has the id 6. It decodes into a vector of globals that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{globals}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{global section} & \href{../binary/modules.html#binary-globalsec}{\mathtt{globalsec}} &::=& \mathit{glob}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_6(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-global}{\mathtt{global}})) &\Rightarrow& \mathit{glob}^\ast \\ \def\mathdef659#1{{}}\mathdef659{global} & \href{../binary/modules.html#binary-global}{\mathtt{global}} &::=& \mathit{gt}{:}\href{../binary/types.html#binary-globaltype}{\mathtt{globaltype}}~~e{:}\href{../binary/instructions.html#binary-expr}{\mathtt{expr}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-global}{\mathsf{type}}~\mathit{gt}, \href{../syntax/modules.html#syntax-global}{\mathsf{init}}~e \} \\ \end{array}\end{split}\]

Export Section

The export section has the id 7. It decodes into a vector of exports that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{exports}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{export section} & \href{../binary/modules.html#binary-exportsec}{\mathtt{exportsec}} &::=& \mathit{ex}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_7(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-export}{\mathtt{export}})) &\Rightarrow& \mathit{ex}^\ast \\ \def\mathdef659#1{{}}\mathdef659{export} & \href{../binary/modules.html#binary-export}{\mathtt{export}} &::=& \mathit{nm}{:}\href{../binary/values.html#binary-name}{\mathtt{name}}~~d{:}\href{../binary/modules.html#binary-exportdesc}{\mathtt{exportdesc}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-export}{\mathsf{name}}~\mathit{nm}, \href{../syntax/modules.html#syntax-export}{\mathsf{desc}}~d \} \\ \def\mathdef659#1{{}}\mathdef659{export description} & \href{../binary/modules.html#binary-exportdesc}{\mathtt{exportdesc}} &::=& \def\mathdef721#1{\mathtt{0x#1}}\mathdef721{00}~~x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef722#1{\mathtt{0x#1}}\mathdef722{01}~~x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x \\ &&|& \def\mathdef723#1{\mathtt{0x#1}}\mathdef723{02}~~x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x \\ &&|& \def\mathdef724#1{\mathtt{0x#1}}\mathdef724{03}~~x{:}\href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{global}}~x \\ \end{array}\end{split}\]

Start Section

The start section has the id 8. It decodes into an optional start function that represents the \(\href{../syntax/modules.html#syntax-module}{\mathsf{start}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{start section} & \href{../binary/modules.html#binary-startsec}{\mathtt{startsec}} &::=& \mathit{st}^?{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_8(\href{../binary/modules.html#binary-start}{\mathtt{start}}) &\Rightarrow& \mathit{st}^? \\ \def\mathdef659#1{{}}\mathdef659{start function} & \href{../binary/modules.html#binary-start}{\mathtt{start}} &::=& x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}} &\Rightarrow& \{ \href{../syntax/modules.html#syntax-start}{\mathsf{func}}~x \} \\ \end{array}\end{split}\]

Element Section

The element section has the id 9. It decodes into a vector of element segments that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{elem}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{element section} & \href{../binary/modules.html#binary-elemsec}{\mathtt{elemsec}} &::=& \mathit{seg}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_9(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-elem}{\mathtt{elem}})) &\Rightarrow& \mathit{seg} \\ \def\mathdef659#1{{}}\mathdef659{element segment} & \href{../binary/modules.html#binary-elem}{\mathtt{elem}} &::=& x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}}~~e{:}\href{../binary/instructions.html#binary-expr}{\mathtt{expr}}~~y^\ast{:}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}}) &\Rightarrow& \{ \href{../syntax/modules.html#syntax-elem}{\mathsf{table}}~x, \href{../syntax/modules.html#syntax-elem}{\mathsf{offset}}~e, \href{../syntax/modules.html#syntax-elem}{\mathsf{init}}~y^\ast \} \\ \end{array}\end{split}\]

Code Section

The code section has the id 10. It decodes into a vector of code entries that are pairs of value type vectors and expressions. They represent the \(\href{../syntax/modules.html#syntax-func}{\mathsf{locals}}\) and \(\href{../syntax/modules.html#syntax-func}{\mathsf{body}}\) field of the functions in the \(\href{../syntax/modules.html#syntax-module}{\mathsf{funcs}}\) component of a module. The \(\href{../syntax/modules.html#syntax-func}{\mathsf{type}}\) fields of the respective functions are encoded separately in the function section.

The encoding of each code entry consists of

  • the \(\href{../syntax/values.html#syntax-int}{\def\mathdef665#1{{\mathit{u}#1}}\mathdef665{\mathit{32}}}\) size of the function code in bytes,
  • the actual function code, which in turn consists of
    • the declaration of locals,
    • the function body as an expression.

Local declarations are compressed into a vector whose entries consist of

  • a \(\href{../syntax/values.html#syntax-int}{\def\mathdef665#1{{\mathit{u}#1}}\mathdef665{\mathit{32}}}\) count,
  • a value type,

denoting count locals of the same value type.

\[\begin{split}\begin{array}{llclll@{\qquad}l} \def\mathdef659#1{{}}\mathdef659{code section} & \href{../binary/modules.html#binary-codesec}{\mathtt{codesec}} &::=& \mathit{code}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_{10}(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-code}{\mathtt{code}})) &\Rightarrow& \mathit{code}^\ast \\ \def\mathdef659#1{{}}\mathdef659{code} & \href{../binary/modules.html#binary-code}{\mathtt{code}} &::=& \mathit{size}{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}}~~\mathit{code}{:}\href{../binary/modules.html#binary-func}{\mathtt{func}} &\Rightarrow& \mathit{code} & (\mathrel{\mbox{if}} \mathit{size} = ||\href{../binary/modules.html#binary-func}{\mathtt{func}}||) \\ \def\mathdef659#1{{}}\mathdef659{function} & \href{../binary/modules.html#binary-func}{\mathtt{func}} &::=& (t^\ast)^\ast{:}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-local}{\mathtt{locals}})~~e{:}\href{../binary/instructions.html#binary-expr}{\mathtt{expr}} &\Rightarrow& \href{../syntax/conventions.html#notation-concat}{\mathrm{concat}}((t^\ast)^\ast), e^\ast & (\mathrel{\mbox{if}} |\href{../syntax/conventions.html#notation-concat}{\mathrm{concat}}((t^\ast)^\ast)| < 2^{32}) \\ \def\mathdef659#1{{}}\mathdef659{locals} & \href{../binary/modules.html#binary-local}{\mathtt{locals}} &::=& n{:}\href{../binary/values.html#binary-int}{\def\mathdef686#1{{\mathtt{u}#1}}\mathdef686{\mathtt{32}}}~~t{:}\href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &\Rightarrow& t^n \\ \end{array}\end{split}\]

Here, \(\mathit{code}\) ranges over pairs \((\href{../syntax/types.html#syntax-valtype}{\mathit{valtype}}^\ast, \href{../syntax/instructions.html#syntax-expr}{\mathit{expr}})\). The meta function \(\href{../syntax/conventions.html#notation-concat}{\mathrm{concat}}((t^\ast)^\ast)\) concatenates all sequences \(t_i^\ast\) in \((t^\ast)^\ast\). Any code for which the length of the resulting sequence is out of bounds of the maximum size of a vector is malformed.

Note

Like with sections, the code \(\mathit{size}\) is not needed for decoding, but can be used to skip functions when navigating through a binary. The module is malformed if a size does not match the length of the respective function code.

Data Section

The data section has the id 11. It decodes into a vector of data segments that represent the \(\href{../syntax/modules.html#syntax-module}{\mathsf{data}}\) component of a module.

\[\begin{split}\begin{array}{llclll} \def\mathdef659#1{{}}\mathdef659{data section} & \href{../binary/modules.html#binary-datasec}{\mathtt{datasec}} &::=& \mathit{seg}^\ast{:}\href{../binary/modules.html#binary-module}{\mathtt{section}}_{11}(\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/modules.html#binary-data}{\mathtt{data}})) &\Rightarrow& \mathit{seg} \\ \def\mathdef659#1{{}}\mathdef659{data segment} & \href{../binary/modules.html#binary-data}{\mathtt{data}} &::=& x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}}~~e{:}\href{../binary/instructions.html#binary-expr}{\mathtt{expr}}~~b^\ast{:}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/values.html#binary-byte}{\mathtt{byte}}) &\Rightarrow& \{ \href{../syntax/modules.html#syntax-data}{\mathsf{data}}~x, \href{../syntax/modules.html#syntax-data}{\mathsf{offset}}~e, \href{../syntax/modules.html#syntax-data}{\mathsf{init}}~b^\ast \} \\ \end{array}\end{split}\]

Modules

The encoding of a module starts with a preamble containing a 4-byte magic number and a version field. The current version of the WebAssembly binary format is 1.

The preamble is followed by a sequence of sections. Custom sections may be inserted at any place in this sequence, while other sections must occur at most once and in the prescribed order. All sections can be empty. The lengths of vectors produced by the (possibly empty) function and code section must match up.

\[\begin{split}\begin{array}{llcllll} \def\mathdef659#1{{}}\mathdef659{magic} & \href{../binary/modules.html#binary-magic}{\mathtt{magic}} &::=& \def\mathdef725#1{\mathtt{0x#1}}\mathdef725{00}~\def\mathdef726#1{\mathtt{0x#1}}\mathdef726{61}~\def\mathdef727#1{\mathtt{0x#1}}\mathdef727{73}~\def\mathdef728#1{\mathtt{0x#1}}\mathdef728{6D} \\ \def\mathdef659#1{{}}\mathdef659{version} & \href{../binary/modules.html#binary-version}{\mathtt{version}} &::=& \def\mathdef729#1{\mathtt{0x#1}}\mathdef729{01}~\def\mathdef730#1{\mathtt{0x#1}}\mathdef730{00}~\def\mathdef731#1{\mathtt{0x#1}}\mathdef731{00}~\def\mathdef732#1{\mathtt{0x#1}}\mathdef732{00} \\ \def\mathdef659#1{{}}\mathdef659{module} & \href{../binary/modules.html#binary-module}{\mathtt{module}} &::=& \href{../binary/modules.html#binary-magic}{\mathtt{magic}} \\ &&& \href{../binary/modules.html#binary-version}{\mathtt{version}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/types.html#syntax-functype}{\mathit{functype}}^\ast{:\,}\href{../binary/modules.html#binary-typesec}{\mathtt{typesec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-import}{\mathit{import}}^\ast{:\,}\href{../binary/modules.html#binary-importsec}{\mathtt{importsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}^n{:\,}\href{../binary/modules.html#binary-funcsec}{\mathtt{funcsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-table}{\mathit{table}}^\ast{:\,}\href{../binary/modules.html#binary-tablesec}{\mathtt{tablesec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-mem}{\mathit{mem}}^\ast{:\,}\href{../binary/modules.html#binary-memsec}{\mathtt{memsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-global}{\mathit{global}}^\ast{:\,}\href{../binary/modules.html#binary-globalsec}{\mathtt{globalsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-export}{\mathit{export}}^\ast{:\,}\href{../binary/modules.html#binary-exportsec}{\mathtt{exportsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-start}{\mathit{start}}^?{:\,}\href{../binary/modules.html#binary-startsec}{\mathtt{startsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-elem}{\mathit{elem}}^\ast{:\,}\href{../binary/modules.html#binary-elemsec}{\mathtt{elemsec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \mathit{code}^n{:\,}\href{../binary/modules.html#binary-codesec}{\mathtt{codesec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \\ &&& \href{../syntax/modules.html#syntax-data}{\mathit{data}}^\ast{:\,}\href{../binary/modules.html#binary-datasec}{\mathtt{datasec}} \\ &&& \href{../binary/modules.html#binary-customsec}{\mathtt{customsec}}^\ast \quad\Rightarrow\quad \{~ \begin{array}[t]{@{}l@{}} \href{../syntax/modules.html#syntax-module}{\mathsf{types}}~\href{../syntax/types.html#syntax-functype}{\mathit{functype}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{funcs}}~\href{../syntax/modules.html#syntax-func}{\mathit{func}}^n, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{tables}}~\href{../syntax/modules.html#syntax-table}{\mathit{table}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{mems}}~\href{../syntax/modules.html#syntax-mem}{\mathit{mem}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{globals}}~\href{../syntax/modules.html#syntax-global}{\mathit{global}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{elem}}~\href{../syntax/modules.html#syntax-elem}{\mathit{elem}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{data}}~\href{../syntax/modules.html#syntax-data}{\mathit{data}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{start}}~\href{../syntax/modules.html#syntax-start}{\mathit{start}}^?, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{imports}}~\href{../syntax/modules.html#syntax-import}{\mathit{import}}^\ast, \\ \href{../syntax/modules.html#syntax-module}{\mathsf{exports}}~\href{../syntax/modules.html#syntax-export}{\mathit{export}}^\ast ~\} \\ \end{array} \\ \end{array}\end{split}\]

where for each \(t_i^\ast, e_i\) in \(\mathit{code}^n\),

\[\begin{split}\href{../syntax/modules.html#syntax-func}{\mathit{func}}^n[i] = \{ \href{../syntax/modules.html#syntax-func}{\mathsf{type}}~\href{../syntax/modules.html#syntax-typeidx}{\mathit{typeidx}}^n[i], \href{../syntax/modules.html#syntax-func}{\mathsf{locals}}~t_i^\ast, \href{../syntax/modules.html#syntax-func}{\mathsf{body}}~e_i \} ) \\\end{split}\]

Note

The version of the WebAssembly binary format may increase in the future if backward-incompatible changes have to be made to the format. However, such changes are expected to occur very infrequently, if ever. The binary format is intended to be forward-compatible, such that future extensions can be made without incrementing its version.