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\mathdef1095#1{{}}\mathdef1095{type index} & \href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{function index} & \href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{table index} & \href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{memory index} & \href{../binary/modules.html#binary-memidx}{\mathtt{memidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{global index} & \href{../binary/modules.html#binary-globalidx}{\mathtt{globalidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{local index} & \href{../binary/modules.html#binary-localidx}{\mathtt{localidx}} &::=& x{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\mathtt{32}}} &\Rightarrow& x \\ \def\mathdef1095#1{{}}\mathdef1095{label index} & \href{../binary/modules.html#binary-labelidx}{\mathtt{labelidx}} &::=& l{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\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\mathdef1101#1{{\mathit{u}#1}}\mathdef1101{\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\mathdef1095#1{{}}\mathdef1095{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\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{import description} & \href{../binary/modules.html#binary-importdesc}{\mathtt{importdesc}} &::=& \def\mathdef1152#1{\mathtt{0x#1}}\mathdef1152{00}~~x{:}\href{../binary/modules.html#binary-typeidx}{\mathtt{typeidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef1153#1{\mathtt{0x#1}}\mathdef1153{01}~~\mathit{tt}{:}\href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{table}}~\mathit{tt} \\ &&|& \def\mathdef1154#1{\mathtt{0x#1}}\mathdef1154{02}~~\mathit{mt}{:}\href{../binary/types.html#binary-memtype}{\mathtt{memtype}} &\Rightarrow& \href{../syntax/modules.html#syntax-importdesc}{\mathsf{mem}}~\mathit{mt} \\ &&|& \def\mathdef1155#1{\mathtt{0x#1}}\mathdef1155{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{export description} & \href{../binary/modules.html#binary-exportdesc}{\mathtt{exportdesc}} &::=& \def\mathdef1156#1{\mathtt{0x#1}}\mathdef1156{00}~~x{:}\href{../binary/modules.html#binary-funcidx}{\mathtt{funcidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{func}}~x \\ &&|& \def\mathdef1157#1{\mathtt{0x#1}}\mathdef1157{01}~~x{:}\href{../binary/modules.html#binary-tableidx}{\mathtt{tableidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{table}}~x \\ &&|& \def\mathdef1158#1{\mathtt{0x#1}}\mathdef1158{02}~~x{:}\href{../binary/modules.html#binary-memidx}{\mathtt{memidx}} &\Rightarrow& \href{../syntax/modules.html#syntax-exportdesc}{\mathsf{mem}}~x \\ &&|& \def\mathdef1159#1{\mathtt{0x#1}}\mathdef1159{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1101#1{{\mathit{u}#1}}\mathdef1101{\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\mathdef1101#1{{\mathit{u}#1}}\mathdef1101{\mathit{32}}}\) count,
  • a value type,

denoting count locals of the same value type.

\[\begin{split}\begin{array}{llclll@{\qquad}l} \def\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{code} & \href{../binary/modules.html#binary-code}{\mathtt{code}} &::=& \mathit{size}{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{locals} & \href{../binary/modules.html#binary-local}{\mathtt{locals}} &::=& n{:}\href{../binary/values.html#binary-int}{\def\mathdef1121#1{{\mathtt{u}#1}}\mathdef1121{\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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{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\mathdef1095#1{{}}\mathdef1095{magic} & \href{../binary/modules.html#binary-magic}{\mathtt{magic}} &::=& \def\mathdef1160#1{\mathtt{0x#1}}\mathdef1160{00}~\def\mathdef1161#1{\mathtt{0x#1}}\mathdef1161{61}~\def\mathdef1162#1{\mathtt{0x#1}}\mathdef1162{73}~\def\mathdef1163#1{\mathtt{0x#1}}\mathdef1163{6D} \\ \def\mathdef1095#1{{}}\mathdef1095{version} & \href{../binary/modules.html#binary-version}{\mathtt{version}} &::=& \def\mathdef1164#1{\mathtt{0x#1}}\mathdef1164{01}~\def\mathdef1165#1{\mathtt{0x#1}}\mathdef1165{00}~\def\mathdef1166#1{\mathtt{0x#1}}\mathdef1166{00}~\def\mathdef1167#1{\mathtt{0x#1}}\mathdef1167{00} \\ \def\mathdef1095#1{{}}\mathdef1095{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.