Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Import Table #170

Open
Open
@sampaioletti

Description

Related to work for #163

In a pretty standard (from what i can tell) wasm generated with emscripten it has the following imports

  (import "env" "memory" (memory (;0;) 256 256))
  (import "env" "table" (table (;0;) 14 14 funcref))
  ;;with table def further down the file
  (elem (;0;) (global.get 1) 50 22 51 51 28 51 23 51 51 51 52 52 52 24) ;;global 1 is just the mem base

and has no memory/table statement for the root module

This results in

  • The Root Module is decoded correctly
  • The Root Module has no Memory Sections or Table Sections

the LinearMemory space gets instantiated automatically

m.LinearMemoryIndexSpace = make([][]byte, 1)

while the TableIndexSpace does not (as there is no Table Section)

wagon/wasm/module.go

Lines 141 to 143 in 3fd3653

if m.Table != nil {
m.TableIndexSpace = make([][]uint32, int(len(m.Table.Entries)))
}

Which causes a fault when importing the "env" modules table definition (line 213) as module.TableIndexSpace is undefnied

wagon/wasm/imports.go

Lines 209 to 214 in 3fd3653

case ExternalTable:
if int(index) >= len(importedModule.TableIndexSpace) {
return InvalidTableIndexError(index)
}
module.TableIndexSpace[0] = importedModule.TableIndexSpace[0]
module.imports.Tables++

I can't seem to find much info on if this is per MVP spec or if its a hack for emscripten but should a root module instantiate its own table/memory when an imported module has these entries? Or am I missing something. I've played with various hacks..like inserting

 //while resolving imports wasm/imports.go 209
case ExternalTable:
    if int(index) >= len(importedModule.TableIndexSpace) {
        return InvalidTableIndexError(index)
    }
    //Inserted to setup module.Table if not already setup since import requires it
    if module.Table==nil{
        module.Table=importedModule.Table
        moudile.TableIndexSpace=importedModule.TableIndexSpace
    }
    //end insert
    module.TableIndexSpace[0] = importedModule.TableIndexSpace[0]
    module.imports.Tables++

which seems to give me the correct functionality.

If I'm on the right path I can prep a PR...if I'm way off base I can accept that also (:

Looking for insight. Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions