wasm3 / wasm3

🚀 A fast WebAssembly interpreter and the most universal WASM runtime
https://twitter.com/wasm3_engine
MIT License
7.28k stars 458 forks source link

FindFunction is confused with import and export having same name #143

Closed axic closed 3 years ago

axic commented 4 years ago

In this example env:adler32 is imported and adler32 is exported:

(module
  (type (;0;) (func (param i32 i32) (result i32)))
  (type (;1;) (func (param i32) (result i32)))
  (import "env" "adler32" (func (;0;) (type 0)))
  (func (;1;) (type 1) (param i32) (result i32)
    (local i32)
    loop  ;; label = @1
      local.get 1
      i32.const 0
      i32.const 4
      call 0
      i32.add
      local.set 1
      local.get 0
      i32.const 1
      i32.sub
      local.tee 0
      br_if 0 (;@1;)
    end
    local.get 1)
  (memory (;0;) 1)
  (export "memory" (memory 0))
  (export "adler32" (func 1))
  (data (;0;) (i32.const 0) "11223344"))

m3_FindFunction seems to return the function index of the import. I think that is because Module_AddFunction is used both in ParseSection_Function and ParseSection_Import and the underlying function list doesn't differentiate.

axic commented 3 years ago

This seems to be still not working for me on dee9389d831a6ed5101155f31d217e47c4ad8175. m3_FindFunction seemingly finds the import.

vshymanskyy commented 3 years ago

@axic verified on https://github.com/wasm3/wasm3/commit/097da3c788e4db3c5972c156853ee73f01040a50 Simple pywasm3-based test:

import wasm3

env = wasm3.Environment()
rt = env.new_runtime(1024)
with open("./adler.wasm", "rb") as f:
    mod = env.parse_module(f.read())
    rt.load(mod)
    mod.link_function("env", "adler32", "i(ii)", lambda x, y: 42)

wasm_run = rt.find_function("adler32")
res = wasm_run(100)
print(res)

Output:

4200
axic commented 3 years ago

Thank you, just confirmed in our benchmarking tool too. That makes sure our integration wasn't broken either.

axic commented 3 years ago

@vshymanskyy a random question, do you plan to make a release soon (this month)?

vshymanskyy commented 3 years ago

@axic , there are several things (technical, mostly) that hold us back. But the intent is to have a release really soon.