Import Table #170
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
Line 140 in 3fd3653
while the TableIndexSpace does not (as there is no Table Section)
Lines 141 to 143 in 3fd3653
Which causes a fault when importing the "env" modules table definition (line 213) as module.TableIndexSpace is undefnied
Lines 209 to 214 in 3fd3653
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