Skip to content

Commit d60d66c

Browse files
authored
Add support for the event section (#70)
1 parent ae811fe commit d60d66c

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

Linking.md

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ be performed:
2020

2121
- Merging of function sections (re-numbering functions)
2222
- Merging of globals sections (re-numbering globals)
23+
- Merging of event sections (re-numbering events)
2324
- Merging of data segments (re-positioning data)
2425
- Resolving undefined external references
2526

@@ -84,6 +85,9 @@ A relocation type can be one of the following:
8485
The offsets start at the actual function code excluding its size field.
8586
- `9 / R_WEBASSEMBLY_SECTION_OFFSET_I32` - an byte offset from start of the
8687
specified section encoded as a [uint32].
88+
- `10 / R_WEBASSEMBLY_EVENT_INDEX_LEB` - an event index encoded as a 5-byte
89+
[varuint32]. Used for the immediate argument of a `throw` and `if_except`
90+
instruction.
8791

8892
[varuint32]: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#varuintn
8993
[varint32]: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#varintn
@@ -188,15 +192,16 @@ where a `syminfo` is encoded as:
188192
| | | `1 / SYMTAB_DATA` |
189193
| | | `2 / SYMTAB_GLOBAL` |
190194
| | | `3 / SYMTAB_SECTION` |
195+
| | | `4 / SYMTAB_EVENT` |
191196
| flags | `varuint32` | a bitfield containing flags for this symbol |
192197

193-
For functions and globals, we reference an existing Wasm object, which is either
194-
an import or a defined function/global (recall that the operand of a Wasm
195-
`call` instruction uses an index space consisting of the function imports
198+
For functions, globals and events, we reference an existing Wasm object, which
199+
is either an import or a defined function/global/event (recall that the operand of a
200+
Wasm `call` instruction uses an index space consisting of the function imports
196201
followed by the defined functions, and similarly `get_global` for global imports
197-
and definitions). If a function or global symbol references an import, then the
198-
name is taken from the import; otherwise the `syminfo` specifies the symbol's
199-
name.
202+
and definitions and `throw` for event imports and definitions). If a function,
203+
global, or event symbol references an import, then the name is taken from the
204+
import; otherwise the `syminfo` specifies the symbol's name.
200205

201206
| Field | Type | Description |
202207
| ------------ | -------------- | ------------------------------------------- |
@@ -236,8 +241,8 @@ The current set of valid flags for symbols are:
236241
Hidden symbols are not to be exported when performing the final link, but
237242
may be linked to other modules.
238243
- `0x10 / WASM_SYM_UNDEFINED` - Indicating that this symbol is not defined.
239-
For function/global symbols, must match whether the symbol is an import or
240-
is defined; for data symbols, determines whether a segment is specified.
244+
For function/global/event symbols, must match whether the symbol is an import
245+
or is defined; for data symbols, determines whether a segment is specified.
241246

242247
For `WASM_COMDAT_INFO` the following fields are present in the
243248
subsection:
@@ -262,10 +267,11 @@ and where a `comdat_sym` is encoded as:
262267
| Field | Type | Description |
263268
| -------- | -------------- | ------------------------------------------- |
264269
| kind | `uint8` | Type of symbol, one of: |
265-
| | | * `0 / WASM_COMDATA_DATA`, a data segment |
266-
| | | * `1 / WASM_COMDATA_FUNCTION` |
267-
| | | * `2 / WASM_COMDATA_GLOBAL` |
268-
| index | `varuint32` | Index of the data segment/function/global in the Wasm module (depending on kind). The function/global must not be an import. |
270+
| | | * `0 / WASM_COMDAT_DATA`, a data segment |
271+
| | | * `1 / WASM_COMDAT_FUNCTION` |
272+
| | | * `2 / WASM_COMDAT_GLOBAL` |
273+
| | | * `3 / WASM_COMDAT_EVENT` |
274+
| index | `varuint32` | Index of the data segment/function/global/event in the Wasm module (depending on kind). The function/global/event must not be an import. |
269275

270276

271277
Merging Global Sections
@@ -285,6 +291,26 @@ object file. For example, the `__stack_pointer` symbol may be provided at
285291
link-time.
286292

287293

294+
Merging Event Sections
295+
-----------------------
296+
297+
Events are meant to represent various control-flow changing constructs of wasm.
298+
Currently we have a
299+
[proposal](https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
300+
for one kind of events: exceptions, but the event section can be used to support
301+
other kinds of events in future as well. The event section is a list of declared
302+
events associated with the module.
303+
304+
Merging of the event sections requires the re-numbering of events. This follows
305+
the normal rules for defining symbols: if two object files provide the same
306+
event symbol strongly, there is a link error; if two object files provide the
307+
symbol weakly, one is chosen.
308+
309+
When creating non-relocatable output, the Wasm output shall have an import for
310+
each undefined strong symbol, and an export for each defined symbol with
311+
non-local linkage and non-hidden visibility.
312+
313+
288314
Merging Function Sections
289315
-------------------------
290316

@@ -369,9 +395,9 @@ symbols via a `call_indirect` instruction.
369395
`R_WEBASSEMBLY_GLOBAL_INDEX_LEB` relocations may fail to be processed, in which
370396
case linking fails. This occurs if there is a weakly-undefined global symbol,
371397
in which case there is no legal value that can be written as the target of any
372-
`get_global` or `set_global` instruction. The frontend must not weak globals
373-
which may not be defined; a definition or import must exist for all global
374-
symbols in the linked output.
398+
`get_global` or `set_global` instruction. (This means the frontend must not
399+
generate weak globals which may not be defined; a definition or import must
400+
exist for all global symbols in the linked output.)
375401

376402
`R_WEBASSEMBLY_MEMORY_ADDR_LEB`, `R_WEBASSEMBLY_MEMORY_ADDR_SLEB` and
377403
`R_WEBASSEMBLY_MEMORY_ADDR_I32` relocations cannot fail. The relocation's value
@@ -385,4 +411,11 @@ adjusted to reflect new offsets in the code section.
385411
`R_WEBASSEMBLY_SECTION_OFFSET_I32` relocation cannot fail. The values shall be
386412
adjusted to reflect new offsets in the combined sections.
387413

414+
`R_WEBASSEMBLY_EVENT_INDEX_LEB` relocations may fail to be processed, in which
415+
case linking fails. This occurs if there is a weakly-undefined event symbol, in
416+
which case there is no legal value that can be written as the target of any
417+
`throw` and `if_except` instruction. (This means the frontend must not generate
418+
weak events which may not be defined; a definition or import must exist for all
419+
event symbols in the linked output.)
420+
388421
[names_sec]: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section

0 commit comments

Comments
 (0)