This page follows the binary format chapter of the WebAssembly core specification, release 3.0, which includes everything in 1.0 and 2.0. Features added by 2.0 and 3.0 are marked; a 1.0 module uses only the unmarked parts. Type encodings are on the types page and opcodes on instructions.
Values
| Kind | Encoding |
|---|---|
| byte | One byte. |
u32, u64 | Unsigned LEB128: seven bits per byte, lowest group first, top bit set on every byte but the last. At most ⌈N/7⌉ bytes (5 for u32, 10 for u64); unused bits of the last byte must be zero. Trailing zero groups are allowed within that length. |
s32, s33, s64 | Signed LEB128, two’s complement, at most ⌈N/7⌉ bytes; the unused bits of the last byte must be 0 for a positive value and 1 for a negative one. |
i32, i64 | Uninterpreted integers (such as i32.const values) are written as signed LEB128. |
f32, f64 | IEEE 754 bit pattern, 4 or 8 bytes, little-endian. |
| vec(T) | A u32 count, then that many T. |
| name | vec(byte) holding UTF-8 text. |
| index | A u32 (type, function, table, memory, global, tag, element, data, local, label and field indices). |
Examples: u32 624485 is E5 8E 26; s32 −1 is 7F; s32 64 is
C0 00.
Preamble
| Offset | Size | Field | Value |
|---|---|---|---|
0 | 4 | magic | 00 61 73 6D (\0asm) |
4 | 4 | version | 01 00 00 00: version 1, little-endian (still 1 in release 3.0). |
A file with the same magic but bytes 4 to 7 equal to 0D 00 01 00 (version
0x0d, layer 0x01) is a WebAssembly component, a
different format that also uses the .wasm extension, described on the
component pages. Reading the four
version bytes as two 16-bit fields, a core module has layer 0 and version 1. This page
describes core modules only. Source: design/mvp/Binary.md in
github.com/WebAssembly/component-model,
raw file read 2026-11-14.
Sections
After the preamble come sections, each:
| Field | Encoding | Meaning |
|---|---|---|
| id | byte | Section ID, below. |
| size | u32 | Length of the contents in bytes. It must match the contents exactly. |
| contents | size bytes | Depends on the ID. |
| ID | Section | Contents | Since |
|---|---|---|---|
0 | custom | name, then any bytes | 1.0 |
1 | type | vec(rectype) | 1.0 (recursive types 3.0) |
2 | import | vec(import) | 1.0 |
3 | function | vec(typeidx) | 1.0 |
4 | table | vec(table) | 1.0 |
5 | memory | vec(memtype) | 1.0 |
6 | global | vec(global) | 1.0 |
7 | export | vec(export) | 1.0 |
8 | start | funcidx | 1.0 |
9 | element | vec(elem) | 1.0 (flags 1–7 in 2.0) |
10 | code | vec(code) | 1.0 |
11 | data | vec(data) | 1.0 (flags 1–2 in 2.0) |
12 | data count | u32 | 2.0 |
13 | tag | vec(tagtype) | 3.0 |
Every section is optional; a missing one counts as empty. Custom sections may appear anywhere, any number of times. The others appear at most once each and in this order, which differs from the ID order: type, import, function, table, memory, tag, global, export, start, element, data count, code, data. The function and code sections must have the same number of entries.
Section contents
Custom (0)
A name, then bytes to the end of the section. Custom sections do not affect how the
module runs, and errors in them must not make the module invalid. The standard
defines one, the name section. Toolchains add others by
convention (producers, target_features, linking,
reloc.*, dylink.0, sourceMappingURL,
external_debug_info, build_id,
metadata.code.branch_hint), described under
custom sections defined by tool conventions.
Import (2)
| Field | Encoding |
|---|---|
| module | name |
| name | name |
| description | a kind byte and its type: 00 typeidx (function), 01 tabletype, 02 memtype, 03 globaltype, 04 tagtype (3.0) |
Compact imports (compact-import-section proposal, phase 4). Two
further forms replace the single-import encoding. Both begin with the module name and
an empty name, followed by a byte in the place of the kind byte:
7F then a vector of (item name, externtype) pairs, all from that one
module; or 7E then one externtype and a vector of item names, all of that
type. The existing encoding remains valid and encodes one import. Older readers fail on
the unknown kind byte. Source: proposals/compact-import-section/Overview.md
in github.com/WebAssembly/compact-import-section
(“Binary”), raw file read 2026-11-14.
Function (3)
One type index per function the module defines; the bodies are in the code section, in the same order.
Table (4)
| Form | Encoding |
|---|---|
| plain | a tabletype; elements start as ref.null |
| with initialiser (3.0) | 40 00, a tabletype, then an expression giving the initial value |
Memory (5)
One memtype each. Releases 1.0 and 2.0 allow at most one memory (imported or defined); 3.0 allows several, chosen by a memory index in instructions.
Global (6)
A globaltype, then a constant expression for the initial value.
Export (7)
| Field | Encoding |
|---|---|
| name | name |
| kind | 00 function, 01 table, 02 memory, 03 global, 04 tag (3.0) |
| index | u32 into that index space |
Start (8)
The index of the module’s start function.
Element (9)
Element segments initialise tables. Each starts with a u32 flags value:
| Flags | Mode | Encoding after the flags |
|---|---|---|
0 | active, table 0 | offset expr, vec(funcidx) |
1 | passive | elemkind, vec(funcidx) |
2 | active, any table | tableidx, offset expr, elemkind, vec(funcidx) |
3 | declarative | elemkind, vec(funcidx) |
4 | active, table 0 | offset expr, vec(expr); function reference type |
5 | passive | reftype, vec(expr) |
6 | active, any table | tableidx, offset expr, reftype, vec(expr) |
7 | declarative | reftype, vec(expr) |
Bit 0 set: passive or declarative. Bit 1: with bit 0 clear, an explicit table
index; with bit 0 set, declarative rather than passive. Bit 2: the elements are
expressions with a reference type, rather than function indices with an elemkind.
The elemkind byte is 00 (function references); the specification notes
that more kinds may come later.
Code (10)
| Field | Encoding | Meaning |
|---|---|---|
| size | u32 | Bytes of the rest of this entry. |
| locals | vec(u32 count, valtype) | Runs of locals: count locals of each type. Parameters come first in the local index space; the total must stay below 232. |
| body | expr | Instructions ending with 0B. |
Data (11)
| Flags | Mode | Encoding after the flags |
|---|---|---|
0 | active, memory 0 | offset expr, vec(byte) |
1 | passive | vec(byte) |
2 | active, any memory | memidx, offset expr, vec(byte) |
Bit 0 marks a passive segment and bit 1 an explicit memory index.
Data count (12)
The number of data segments, so that code can be validated in one pass. It must
match the data section, and must be present if any code uses a data index
(memory.init, data.drop, array.new_data,
array.init_data).
Tag (13)
Exception tags, each a tagtype: 00 and the index of a function type
whose parameters are the exception’s values.
The name section
A custom section named name, placed after the data section, that gives
names to the module’s items for debuggers. It holds subsections, each a byte ID, a u32
size and the contents, in increasing ID order, each ID at most once.
| ID | Subsection | Contents |
|---|---|---|
0 | module name | name |
1 | function names | namemap by function index |
2 | local names | indirect namemap: by function index, then local index |
3 | label names (extended) | indirect namemap: by function index, then label index |
4 | type names | namemap by type index |
5 | table names (extended) | namemap by table index |
6 | memory names (extended) | namemap by memory index |
7 | global names (extended) | namemap by global index |
8 | element segment names (extended) | namemap by element segment index |
9 | data segment names (extended) | namemap by data segment index |
10 | field names | indirect namemap: by struct type index, then field index |
11 | tag names | namemap by tag index |
12 | parameter names (extended) | indirect namemap: by function type index, then parameter index |
13 | tag parameter names (extended) | indirect namemap: by tag index, then parameter index |
A namemap is vec(index, name), sorted by index with no duplicates. An indirect
namemap is vec(index, namemap). The core specification defines IDs 0, 1, 2, 4, 10 and
11; the rows marked “extended” come from the WebAssembly extended name section
proposal, which closes the gaps for items that have identifiers in the text format.
Label indices in subsection 3 use a new function-wide index space that numbers labels in
the order they appear in the function body, not the scoped indices that branch
instructions use. Subsection 12 names the parameters of function types, not of
type uses (parameters of definitions and imports are already in the local names), and
subsection 13 exists because a tag’s parameter names belong to a type use that has no
function to hold local names. Source:
proposals/extended-name-section/Overview.md in
github.com/WebAssembly/extended-name-section
and document/core/appendix/custom.rst in
github.com/WebAssembly/spec, raw files
read 2026-11-14. As for the core subsections, each occurs at most once, in order of
increasing id.
Custom sections defined by tool conventions
These custom sections are not part of the WebAssembly specification. They are
conventions of the
WebAssembly tool-conventions
repository, implemented by LLVM, lld, Emscripten, Binaryen and wabt, and are found in
real .wasm files and object files. All are custom sections (ID 0), so they
have no effect on how a module runs and may be stripped. Integer types here follow the
conventions’ names: varuint32 is the u32 LEB128 of the
values table.
producers
A record of the tools that produced the module. It may appear only once and only after
the name section. Contents: field_count (varuint32), then that many
fields; each field is a name (field_name), a varuint32
field_value_count and that many versioned names, each a
name and a version (both name values). Each
field_name must be unique, and one of:
language– source languages. Known names:wat,C,C++,Rust,JavaScript.processed-by– tools in the pipeline. Known names:wabt,LLVM,clang,lld,Binaryen,rustc,wasm-bindgen,wasm-pack,webassemblyjs,wasm-snip,Javy.sdk– the top-level toolkit the developer uses. Known names:Emscripten,Webpack.
Unknown names do not invalidate the section. Consumers should not derive optimisation
hints from it. Example: (@producers (processed-by "rustc" "1.78.0 (9b00956e5
2024-04-29)") (language "Rust" "1.78.0")) in the text format. Source:
ProducersSection.md.
target_features
An optional section that must come after producers. Contents: a vector
(varuint32 count) of entries, each a prefix byte and a feature name (name;
unique). Prefix 2B (+): the object uses the feature, and the
link fails if the feature is not in the allowed set. Prefix 2D
(-): the object does not use the feature, and the link fails if it is in
the allowed set. A feature not mentioned is not used by the object but not necessarily
prohibited. The generally accepted features are atomics,
bulk-memory, bulk-memory-opt
(memory.copy and memory.fill, a subset of bulk-memory),
call-indirect-overlong (the table field of call_indirect as a
multibyte LEB, a subset of reference-types), exception-handling,
extended-const, memory64, multimemory,
multivalue, mutable-globals, nontrapping-fptoint,
reference-types, relaxed-simd, sign-ext,
simd128 and tail-call. Source: Linking.md,
“Target Features Section”.
linking and reloc.*
Object files (the input of a static linker) carry a linking custom section
and one or more relocation sections. Object files are valid modules, and the presence of
linking distinguishes them from executables. Every LEB128 value that is to
be relocated must be written maximally padded (function index 3 as
83 80 80 80 00) so it can be rewritten in place.
linking must come after the data section. It holds a varuint32
version (currently 2) and then subsections, each a uint8 type,
a varuint32 payload length and the payload:
| Type | Name | Payload |
|---|---|---|
5 | WASM_SEGMENT_INFO | count, then per data segment: name (len + UTF-8), alignment (varuint32, a power of 2), flags (varuint32): 1 STRINGS (only null-terminated strings, mergeable), 2 TLS (thread-local), 4 RETAIN (keep if the object is linked) |
6 | WASM_INIT_FUNCS | count, then per constructor: priority (varuint32) and symbol index (not function index); called in priority order after memory init; must come after the symbol table |
7 | WASM_COMDAT_INFO | count, then per comdat: name (len + UTF-8), flags (varuint32, must be 0), count and (kind uint8, index varuint32) pairs; kinds 0 data segment, 1 function, 2 global, 3 event, 4 table, 5 section; functions, globals, events and tables must not be imports |
8 | WASM_SYMBOL_TABLE | count, then per symbol a syminfo (below) |
9 | WASM_TARGET_ARCH | a string: wasm32 or wasm64 |
A syminfo starts with a uint8 kind and a varuint32 flags
field. Kinds: 0 function, 1 data, 2 global,
3 section, 4 event, 5 table. Then:
- function, global, event, table:
index(varuint32; an import if and only if the UNDEFINED flag is set), then name length and UTF-8 name, omitted when the index is an import and EXPLICIT_NAME is not set (the name comes from the import); - data: name (length and UTF-8); then, if defined and not common,
index(segment) andoffset(varuint32, at most the segment size); if defined,size(varuint32;offset + sizewithin the segment when not common); and, if defined and common,alignment(uint8, log₂); - section:
section(varuint32), the index of a code, data or custom section.
| Symbol flag | Name | Meaning |
|---|---|---|
0x3 mask | BINDING | 2-bit binding: 0 GLOBAL (strong), 1 WEAK (all weak definitions are dropped if a strong one exists), 2 LOCAL (not exported or linked; names need not be unique; cannot reference an import), 3 COMMON (defined data symbols only: uninitialised data allocated by the linker, the largest size and alignment win) |
0x4 | VISIBILITY_HIDDEN | not exported in the final link, but may be linked to other modules |
0x10 | UNDEFINED | not defined; for non-data symbols it must match whether the symbol is an import; for data it decides whether a segment (or size and alignment) is present |
0x20 | EXPORTED | intended to be exported to the host |
0x40 | EXPLICIT_NAME | uses an explicit name instead of the import’s |
0x80 | NO_STRIP | included in the linker output whether used or not |
0x100 | TLS | lives in thread-local storage |
0x200 | ABSOLUTE | offset is relative to the start of memory, not to a data segment |
reloc.* sections (for example reloc.CODE, reloc.DATA)
must follow the section they relocate and the linking section; the text
after the period is only a convention, the target is encoded in the section. Only code,
data and custom sections can be relocated. Contents: section (varuint32,
index of the target section), count, then entries of type
(uint8), offset (varuint32, relative to the start of the
target section’s contents), index (varuint32: a symbol index, or a type
index for R_WASM_TYPE_INDEX_LEB) and, for the R_WASM_MEMORY_ADDR_*,
R_WASM_FUNCTION_OFFSET_* and R_WASM_SECTION_OFFSET_* types
(and their 64-bit forms), an addend (varint32).
| Type | Name | Value encoded as |
|---|---|---|
| 0 | R_WASM_FUNCTION_INDEX_LEB | 5-byte varuint32: function index (call) |
| 1 | R_WASM_TABLE_INDEX_SLEB | 5-byte varint32: function table index (i32.const, a function address) |
| 2 | R_WASM_TABLE_INDEX_I32 | uint32 function table index (static data) |
| 3 | R_WASM_MEMORY_ADDR_LEB | 5-byte varuint32 memory address (load or store immediate) |
| 4 | R_WASM_MEMORY_ADDR_SLEB | 5-byte varint32 memory address (i32.const) |
| 5 | R_WASM_MEMORY_ADDR_I32 | uint32 memory address (static data) |
| 6 | R_WASM_TYPE_INDEX_LEB | 5-byte varuint32 type index (call_indirect) |
| 7 | R_WASM_GLOBAL_INDEX_LEB | 5-byte varuint32 global index |
| 8 | R_WASM_FUNCTION_OFFSET_I32 | uint32 byte offset within the code section, to a function’s code (excluding its size field) |
| 9 | R_WASM_SECTION_OFFSET_I32 | uint32 byte offset from the start of the section |
| 10 | R_WASM_EVENT_INDEX_LEB | 5-byte varuint32 event (tag) index; used for the immediate argument of a throw and of if_except (Linking.md; if_except is an instruction of an older exception-handling draft) |
| 11 | R_WASM_MEMORY_ADDR_REL_SLEB | varint32 memory address relative to __memory_base (position-independent code) |
| 12 | R_WASM_TABLE_INDEX_REL_SLEB | varint32 table index relative to __table_base |
| 13 | R_WASM_GLOBAL_INDEX_I32 | uint32 global index |
| 14 | R_WASM_MEMORY_ADDR_LEB64 | 10-byte varuint64 memory address |
| 15 | R_WASM_MEMORY_ADDR_SLEB64 | 10-byte varint64 memory address (i64.const) |
| 16 | R_WASM_MEMORY_ADDR_I64 | uint64 memory address |
| 17 | R_WASM_MEMORY_ADDR_REL_SLEB64 | 64-bit form of type 11 |
| 18 | R_WASM_TABLE_INDEX_SLEB64 | 10-byte varint64 table index |
| 19 | R_WASM_TABLE_INDEX_I64 | uint64 table index |
| 20 | R_WASM_TABLE_NUMBER_LEB | 5-byte varuint32 table number (table.* instructions) |
| 21 | R_WASM_MEMORY_ADDR_TLS_SLEB | 5-byte varint32 offset from __tls_base |
| 22 | R_WASM_FUNCTION_OFFSET_I64 | uint64 code-section function offset |
| 23 | R_WASM_MEMORY_ADDR_LOCREL_I32 | uint32 offset between the relocated address and the memory address (pointer-relative) |
| 24 | R_WASM_TABLE_INDEX_REL_SLEB64 | 10-byte varint64 table index, relative |
| 25 | R_WASM_MEMORY_ADDR_TLS_SLEB64 | 64-bit form of type 21 |
| 26 | R_WASM_FUNCTION_INDEX_I32 | uint32 function index (custom-section function annotations) |
| 27 | R_WASM_MEMORY_ADDR_LOCREL_I64 | number and name only: LLVM’s WasmRelocs.def (raw) lists R_WASM_MEMORY_ADDR_LOCREL_I64 as 27, and Linking.md (raw) describes no type 27. By its name it is a 64-bit relative memory address like type 23, but no source read says so, so the encoding is not stated here. |
Type 10 is called R_WASM_EVENT_INDEX_LEB in Linking.md and
R_WASM_TAG_INDEX_LEB in LLVM’s WasmRelocs.def (the event was
renamed tag). Types 0 to 27 are all the numbers in WasmRelocs.def
(llvm/include/llvm/BinaryFormat/ in llvm-project), and the table above
lists each of them. Linking.md lists types 0 to 26 except 11, 12, 17, 21
and 25 (those are in DynamicLinking.md); type 27 appears only in LLVM’s file.
Numbers 11, 12, 17, 21 and 25 are defined in the dynamic-linking document, the rest in
Linking.md; the conventions state that the 64-bit relocations are not yet
stable. The relocated bytes run from offset for 5 (LEB or SLEB), 10 (LEB64 or
SLEB64), 4 (I32) or 8 (I64) bytes and must lie within the section and within one function
(code) or one data element (data); they may not straddle two chunks of the section (two
functions, or the edge of a data element), where the section has such chunks.
Object file validation rules
A module is a valid object file only if these extra rules hold; a tool needs to produce output only for valid object files.
- Every LEB128 value that is to be relocated is maximally padded (5 bytes for 32-bit, 10 for 64-bit values).
- The
offsetof amemargwhose memory has 32-bit addresses may be treated as either a varuint32 or a varuint64. - When a relocation’s
indexnames a symbol, the symbol kind limits the relocation type:
(The names are spelled as inSymbol kind Allowed relocation types function ( SYMTAB_FUNCTION)R_WASM_FUNCTION_IDX_*,R_WASM_TABLE_IDX_*,R_WASM_FUNCTION_OFFSET_*data R_WASM_MEMORY_ADDR_*global R_WASM_GLOBAL_INDEX_*section R_WASM_SECTION_OFFSET_*event R_WASM_EVENT_INDEX_*table R_WASM_TABLE_NUMBER_*Linking.md, which writesIDXin the first row andINDEXin the others.) - The data encoding of the relocated value limits the type: uint32 takes
R_WASM_*_I32, uint64R_WASM_*_I64, varint32R_WASM_*_SLEB, varint64R_WASM_*_SLEB64, varuint32R_WASM_*_LEBand varuint64R_WASM_*_LEB64. Where no grammar construct is known at the offset (an unknown custom section, a data segment) the encoding rule is not applied. - In the code section only certain constructs may be relocated: the constant operand
of an
i*.constinstruction takes onlyR_WASM_TABLE_INDEX_*andR_WASM_MEMORY_ADDR_*; theoffsetof amemargonlyR_WASM_MEMORY_ADDR_*; afuncidxonlyR_WASM_FUNCTION_INDEX_*; aglobalidxonlyR_WASM_GLOBAL_INDEX_*; atagidxonlyR_WASM_EVENT_INDEX_*; atableidxonlyR_WASM_TABLE_NUMBER_*. - For the
R_WASM_*_OFFSET_I*types the addend must be: an instruction boundary ifindexnames the code section; a valid offset into a data segment’s data area if it names the data section; a valid offset into the custom section’s data area if it names a custom section.
Source: Linking.md, “Relocation Sections”, “Object file validation
rules” and “Linking Metadata Section”; DynamicLinking.md; raw files read
2026-11-14 from
github.com/WebAssembly/tool-conventions.
dylink.0
Marks a dynamic library (the module follows the dynamic-linking ABI, which is still a
work in progress) and should be the very first section so a loader can detect it without
scanning the file. Contents: subsections, each a uint8 type, a varuint32
payload length and the payload. A string is a varuint32 length and UTF-8
bytes.
| Type | Name | Payload |
|---|---|---|
1 | WASM_DYLINK_MEM_INFO | memorysize, memoryalignment (power of 2, bytes), tablesize, tablealignment (power of 2, elements): all varuint32; the loader reserves the memory at env.__memory_base and the table at env.__table_base |
2 | WASM_DYLINK_NEEDED | count, then strings: libraries to load first |
3 | WASM_DYLINK_EXPORT_INFO | count, then (name string, flags varuint32) entries; the flags are the linking symbol flags above |
4 | WASM_DYLINK_IMPORT_INFO | count, then (module string, field string, flags varuint32) entries |
5 | WASM_DYLINK_RUNTIME_PATH | count, then strings (like DT_RUNPATH in an ELF .dynamic section) |
6 | WASM_DYLINK_TARGET_ARCH | a string: wasm32 or wasm64 |
A library may import env.memory, env.__indirect_function_table,
env.__stack_pointer (mutable i32), and the immutable i32 globals
env.__memory_base and env.__table_base, provided by the loader.
If it exports __wasm_apply_data_relocs, the loader calls it right after
instantiation. Source: DynamicLinking.md.
Imports and exports of a dynamic library
Conventions from the sections “Imports”, “Exports” and “Note for memory/table exports” of
DynamicLinking.md (tool-conventions, raw, read 2026-11-19).
- Functions are imported directly from the module
env(for exampleenv.enternal_func, as the document spells it) and exported as ordinary function exports. The conventions below do not change the import of functions for a direct call, or exports. - Data and function addresses are imported as WebAssembly globals that hold the
memory offset or table offset of the symbol. Data addresses come from the module
GOT.memand function addresses (table offsets, used withcall_indirect) fromGOT.func. “GOT” is borrowed from ELF’s Global Offset Table; here it is a set of imported globals. The document’s examples are(import "GOT.mem" "foo" (global $foo_addr (mut i32)))and(import "GOT.func" "bar" (global $bar_addr (mut i32))). - These globals must be mutable, because the dynamic linker might need to change the value after instantiation.
- Exported addresses (an exported memory location or table location) are exported
as
i32WebAssembly globals. Exports are static, so a module cannot add__memory_basebefore exporting: the exported value is the address before relocation, and the loader, which knows__memory_base, works out the final address. - Memory and table exports. The common C conventions, WASIp1 included, require a
module to export the memory
memoryand the table__indirect_function_table. For a PIE executable built with this dynamic-linking convention these are not required as exports, because it already imports those resources. Shared libraries do not need to export them either: they should import them, since they share the memory and function table with the main module (a runtime linker can validate this and refuse a module that does not). A non-PIE executable exports them as usual. - Relocations. The same document says code in a dynamic library needs no code-section
relocations; for internal symbols it uses types 11 (
R_WASM_MEMORY_ADDR_REL_SLEB) and 12 (R_WASM_TABLE_INDEX_REL_SLEB), with 17, 21 and 25 for the 64-bit and TLS forms (table above), and rejects the absolute types 4 (R_WASM_MEMORY_ADDR_SLEB) and 1 (R_WASM_TABLE_INDEX_SLEB) in position-independent code. (The type numbers 4 and 1 are from this page’s relocation table; the document names the types, not their numbers.)
sourceMappingURL and external_debug_info
Both contain a varuint32 url_name_len and then that many bytes of
url_name_str. sourceMappingURL is the URL of a Source Map
(an external JSON file; for WebAssembly the line is always 1 and the column is a byte
offset into the binary). external_debug_info is the URL of a Wasm container
file holding DWARF in .debug_* custom sections (it may also hold the code
and data sections), used when the main file carries no debug information. Embedded DWARF
lives in custom sections named .debug_* with the raw DWARF bytes. Source:
Debugging.md.
DWARF conventions (Dwarf.md)
- Section names. Each DWARF section is one custom section whose
name is the DWARF section name, for example
.debug_info,.debug_line,.debug_abbrev,.debug_str,.debug_ranges,.debug_loc,.debug_pubnames,.debug_pubtypes,.debug_macinfo(the DWARF standard’s Appendix B lists the full set); the contents are the raw DWARF data. (ELF does the same; Mach-O writes__for the dot.) - One kind only. A file should not carry both embedded and external DWARF; if it does, a consumer may use either, or may treat the file as having no DWARF.
- external_debug_info. Its contents are a UTF-8 URL (preferably
relative to the Wasm file), written as
namethen a vector of bytes:section_0(n:name b*:vec(byte))withn=external_debug_info. A tool that needs a file path decodes it by the “file” URI scheme rules. When the section is present, any embedded DWARF sections are ignored, and a producer should remove them. If several validexternal_debug_infosections are present, consumers use the last. The external file must be a Wasm file with embedded DWARF; a consumer ignores its non-DWARF sections, including anyexternal_debug_infosection in it. Relocation sections for the DWARF sections may be kept in the external file. - Address space: code addresses. Wherever DWARF uses a code address
(
DW_AT_low_pc,DW_AT_high_pc,.debug_lineaddresses,.debug_ranges), it is the offset of an instruction relative to the code section of the file; DWARF is malformed if a PC falls between instruction boundaries. That is the rule in the text ofDwarf.md. A separate note in the same document says the instruction pointer “is selected as the offset in the binary file of the first byte of the instruction”, and that this is consistent with the WebAssembly Web API’s definition of the code location. The two statements give different numbers for the same instruction (a section-relative offset against a file offset, which differ by the size of the file bytes before the code section’s contents), and the document does not say how they fit together, so this page does not say which one tools use. The examples in the document (.debug_line,DW_AT_low_pc) say “Codesection-relative instruction offsets”. - Location descriptions. A value held in a local, a global or on the
operand stack uses the extension operator
DW_OP_WASM_location(0xED) followed by a sub-operator:00uleb128 i (local i of the running function);01uleb128 i (global i);03i:u32(global i: the grammar writesi:u32and the text calls it the “U32-encoded operand”; the source does not say how that is encoded, so no width is stated here);02uleb128 i (operand-stack entry i, where 0 is the bottom of the stack). Empty, memory and implicit location descriptions are used as in DWARF; register location descriptions are not used.
Source: Dwarf.md and Debugging.md, raw files read 2026-11-14.
metadata.code.branch_hint
Branch hints tell a compiler that a conditional branch is likely or unlikely. The
section appears at most once and only before the code section. It is a
custom section named metadata.code.branch_hint, and removing it does not
change what the module does. Contents: a vector of function entries, each a function
index (u32) and a vector of hints. Function indices increase, with no repeats. Each hint is:
| Field | Encoding | Meaning |
|---|---|---|
| offset | u32 | byte offset of the hinted instruction, from the start of the function’s locals declaration |
| size | u32 = 1 | length of the hint value |
| hint | u32 | 0 condition likely false, 1 likely true |
Offsets increase within a function, with no repeats, and an if or
br_if instruction must be at the offset. This is the first of the
“code metadata” sections of CodeMetadata.md, which share the layout
name, vec(funcidx, vec(funcpos u32, size u32, data)); the same file also
defines metadata.code.trace_inst (a u32 mark id on any instruction; its proposal,
Instrument and Tracing Technology, is in the inactive-proposals list, so it is not
described here). Branch hinting is phase 4 and part of release 3.0. Sources:
proposals/branch-hinting/Overview.md in
github.com/WebAssembly/branch-hinting
and CodeMetadata.md in tool-conventions, raw files read 2026-11-14.
build_id
A varuint32 byte count and that many bytes of identifier (arbitrary binary data, not
UTF-8), anywhere in the file; the method of generation is unspecified. Source:
BuildId.md.
Example
A module exporting a function f that returns 42:
00 61 73 6D 01 00 00 00 preamble
01 05 01 60 00 01 7F type section: 1 type, func () -> (i32)
03 02 01 00 function section: 1 function, type 0
07 05 01 01 66 00 00 export section: "f", function 0
0A 06 01 04 00 41 2A 0B code section: 1 body of 4 bytes:
no locals, i32.const 42, end
Sources
The WebAssembly core
specification, release 3.0: binary format chapters “Conventions” (lists),
“Values” (LEB128, floats, names), “Modules” (preamble, sections, every section’s
contents, order) and “Instructions” (i32.const, used in the example);
appendix “Custom Sections” (name section); appendix “Change History” (what 2.0 and
3.0 added). The LEB128 examples and the module bytes are worked out from those
rules. Beyond the core release: the WebAssembly tool-conventions
(Linking.md, DynamicLinking.md, Debugging.md,
Dwarf.md, BuildId.md, CodeMetadata.md,
ProducersSection.md), LLVM’s WasmRelocs.def, the branch-hinting,
compact-import-section and component-model Binary.md files, and the
proposals phase table (proposals/README.md,
finished-proposals.md), all fetched as raw files on 2026-11-14.