@@ -20,6 +20,7 @@ be performed:
20
20
21
21
- Merging of function sections (re-numbering functions)
22
22
- Merging of globals sections (re-numbering globals)
23
+ - Merging of event sections (re-numbering events)
23
24
- Merging of data segments (re-positioning data)
24
25
- Resolving undefined external references
25
26
@@ -84,6 +85,9 @@ A relocation type can be one of the following:
84
85
The offsets start at the actual function code excluding its size field.
85
86
- ` 9 / R_WEBASSEMBLY_SECTION_OFFSET_I32 ` - an byte offset from start of the
86
87
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.
87
91
88
92
[ varuint32 ] : https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#varuintn
89
93
[ varint32 ] : https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#varintn
@@ -188,15 +192,16 @@ where a `syminfo` is encoded as:
188
192
| | | ` 1 / SYMTAB_DATA ` |
189
193
| | | ` 2 / SYMTAB_GLOBAL ` |
190
194
| | | ` 3 / SYMTAB_SECTION ` |
195
+ | | | ` 4 / SYMTAB_EVENT ` |
191
196
| flags | ` varuint32 ` | a bitfield containing flags for this symbol |
192
197
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
196
201
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.
200
205
201
206
| Field | Type | Description |
202
207
| ------------ | -------------- | ------------------------------------------- |
@@ -236,8 +241,8 @@ The current set of valid flags for symbols are:
236
241
Hidden symbols are not to be exported when performing the final link, but
237
242
may be linked to other modules.
238
243
- ` 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.
241
246
242
247
For ` WASM_COMDAT_INFO ` the following fields are present in the
243
248
subsection:
@@ -262,10 +267,11 @@ and where a `comdat_sym` is encoded as:
262
267
| Field | Type | Description |
263
268
| -------- | -------------- | ------------------------------------------- |
264
269
| 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. |
269
275
270
276
271
277
Merging Global Sections
@@ -285,6 +291,26 @@ object file. For example, the `__stack_pointer` symbol may be provided at
285
291
link-time.
286
292
287
293
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
+
288
314
Merging Function Sections
289
315
-------------------------
290
316
@@ -369,9 +395,9 @@ symbols via a `call_indirect` instruction.
369
395
` R_WEBASSEMBLY_GLOBAL_INDEX_LEB ` relocations may fail to be processed, in which
370
396
case linking fails. This occurs if there is a weakly-undefined global symbol,
371
397
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.)
375
401
376
402
` R_WEBASSEMBLY_MEMORY_ADDR_LEB ` , ` R_WEBASSEMBLY_MEMORY_ADDR_SLEB ` and
377
403
` 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.
385
411
` R_WEBASSEMBLY_SECTION_OFFSET_I32 ` relocation cannot fail. The values shall be
386
412
adjusted to reflect new offsets in the combined sections.
387
413
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
+
388
421
[ names_sec ] : https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section
0 commit comments