Search code examples
binarywebassemblywasmtime

What is the size of the Section vector of certain data type in wasm binary?


I am reading this docs. I have doubt about the content of the vector of the sections in binary. For eg Table Section here. How many items of type tabletype can be present in that vector<tabletype>. Is it 0,1 and more or 0(not present) and 1 (only one present)?


Solution

  • The table section is made of vector of tables: vec(table). Each table has one tabletype. From here:

    Vectors are encoded with their u32 length followed 
    by the encoding of their element sequence.
    

    This means that a module might have [0..2^32) tables, each with its owntabletype. That said, it is expected, that some "reasonable" limitation is placed on the number of tables (and other objects) that a program is willing to load.

    If there are no tables, the section might be omitted:

    Every section is optional; an omitted section is equivalent 
    to the section being present with empty contents.
    

    This makes a total of three ways to have no tables: no section; empty section; section with a zero length tables vector.

    As usual, when de-serializing (parse) one might expect all cases, but the when serializing (generate) it is better to have the minimum number of bytes.