@@ -84,22 +84,23 @@ In these cases, the empty result :math:`\epsilon` is interpreted as the empty ve
84
84
85
85
The following section ids are used:
86
86
87
- == ========================================
88
- Id Section
89
- == ========================================
90
- 0 :ref: `custom section <binary-customsec >`
91
- 1 :ref: `type section <binary-typesec >`
92
- 2 :ref: `import section <binary-importsec >`
93
- 3 :ref: `function section <binary-funcsec >`
94
- 4 :ref: `table section <binary-tablesec >`
95
- 5 :ref: `memory section <binary-memsec >`
96
- 6 :ref: `global section <binary-globalsec >`
97
- 7 :ref: `export section <binary-exportsec >`
98
- 8 :ref: `start section <binary-startsec >`
99
- 9 :ref: `element section <binary-elemsec >`
100
- 10 :ref: `code section <binary-codesec >`
101
- 11 :ref: `data section <binary-datasec >`
102
- == ========================================
87
+ == ===============================================
88
+ Id Section
89
+ == ===============================================
90
+ 0 :ref: `custom section <binary-customsec >`
91
+ 1 :ref: `type section <binary-typesec >`
92
+ 2 :ref: `import section <binary-importsec >`
93
+ 3 :ref: `function section <binary-funcsec >`
94
+ 4 :ref: `table section <binary-tablesec >`
95
+ 5 :ref: `memory section <binary-memsec >`
96
+ 6 :ref: `global section <binary-globalsec >`
97
+ 7 :ref: `export section <binary-exportsec >`
98
+ 8 :ref: `start section <binary-startsec >`
99
+ 9 :ref: `element section <binary-elemsec >`
100
+ 10 :ref: `code section <binary-codesec >`
101
+ 11 :ref: `data section <binary-datasec >`
102
+ 12 :ref: `data count section <binary-datacountsec >`
103
+ == ===============================================
103
104
104
105
105
106
.. index :: ! custom section
@@ -433,6 +434,32 @@ It decodes into a vector of :ref:`data segments <syntax-data>` that represent th
433
434
segments have a |DMEM | value of :math: `0 `.
434
435
435
436
437
+ .. index :: ! data count section, data count, data segment
438
+ pair: binary format; data count
439
+ pair: section; data count
440
+ .. _binary-datacountsec :
441
+
442
+ Data Count Section
443
+ ~~~~~~~~~~~~~~~~~~
444
+
445
+ The *data count section * has the id 12.
446
+ It decodes into an optional :ref: `u32 <syntax-uint >` that represents the number of :ref: `data segments <syntax-data >` in the :ref: `data section <binary-datasec >`. If this count does not match the length of the data segment vector, the module is malformed.
447
+
448
+ .. math ::
449
+ \begin {array}{llclll}
450
+ \production {data count section} & \Bdatacountsec &::=&
451
+ \X {n}^?{:}\Bsection _{12 }(\Bu32 ) &\Rightarrow & \X {n}^? \\
452
+ \end {array}
453
+
454
+ .. note ::
455
+ The data count section is used to simplify single-pass validation. Since the
456
+ data section occurs after the code section, the :math: `\MEMORYINIT ` and
457
+ :math: `\DATADROP ` instructions would not be able to check whether the data
458
+ segment index is valid until the data section is read. The data count section
459
+ occurs before the code section, so a single-pass validator can use this count
460
+ instead of deferring validation.
461
+
462
+
436
463
.. index :: module, section, type definition, function type, function, table, memory, global, element, data, start function, import, export, context, version
437
464
pair: binary format; module
438
465
.. _binary-magic :
@@ -450,6 +477,8 @@ The preamble is followed by a sequence of :ref:`sections <binary-section>`.
450
477
while other sections must occur at most once and in the prescribed order.
451
478
All sections can be empty.
452
479
The lengths of vectors produced by the (possibly empty) :ref: `function <binary-funcsec >` and :ref: `code <binary-codesec >` section must match up.
480
+ Similarly, the data count must match the length of the :ref: `data segment <binary-datasec >` vector.
481
+ The :math: `\MEMORYINIT ` and :math: `\DATADROP ` instructions can only be used if the data count section is present.
453
482
454
483
.. math ::
455
484
\begin {array}{llcllll}
@@ -479,9 +508,11 @@ The lengths of vectors produced by the (possibly empty) :ref:`function <binary-f
479
508
\Bcustomsec ^\ast \\ &&&
480
509
\elem ^\ast {:\, }\Belemsec \\ &&&
481
510
\Bcustomsec ^\ast \\ &&&
511
+ m^?{:\, }\Bdatacountsec \\ &&&
512
+ \Bcustomsec ^\ast \\ &&&
482
513
\X {code}^n{:\, }\Bcodesec \\ &&&
483
514
\Bcustomsec ^\ast \\ &&&
484
- \data ^\ast {:\, }\Bdatasec \\ &&&
515
+ \data ^{ \X {m'}} {:\, }\Bdatasec \\ &&&
485
516
\Bcustomsec ^\ast
486
517
\quad \Rightarrow \quad \{~
487
518
\begin {array}[t]{@{}l@{}}
@@ -491,10 +522,14 @@ The lengths of vectors produced by the (possibly empty) :ref:`function <binary-f
491
522
\MMEMS ~\mem ^\ast , \\
492
523
\MGLOBALS ~\global ^\ast , \\
493
524
\MELEM ~\elem ^\ast , \\
494
- \MDATA ~\data ^\ast , \\
525
+ \MDATA ~\data ^{ \X {m'}} , \\
495
526
\MSTART ~\start ^?, \\
496
527
\MIMPORTS ~\import ^\ast , \\
497
528
\MEXPORTS ~\export ^\ast ~\} \\
529
+ \end {array} \\ &&&
530
+ (\begin {array}[t]{@{}c@{~}l@{}}
531
+ \iff & m^? \neq \epsilon \\
532
+ \vee & \forall (t^\ast , e) \in \X {code}^n, \MEMORYINIT \notin e \wedge \DATADROP \notin e) \\
498
533
\end {array} \\
499
534
\end {array}
500
535
@@ -503,6 +538,14 @@ where for each :math:`t_i^\ast, e_i` in :math:`\X{code}^n`,
503
538
.. math ::
504
539
\func ^n[i] = \{ \FTYPE ~\typeidx ^n[i], \FLOCALS ~t_i^\ast , \FBODY ~e_i \} ) \\
505
540
541
+ and where,
542
+
543
+ .. math ::
544
+ \begin {array}{lcl@{\qquad }l}
545
+ \X {m'} &=& m & (\iff m^? \neq \epsilon ) \\
546
+ \X {m'} &=& 0 & (\otherwise )
547
+ \end {array}
548
+
506
549
.. note ::
507
550
The version of the WebAssembly binary format may increase in the future
508
551
if backward-incompatible changes have to be made to the format.
0 commit comments