Skip to content

Unexpected lifting of direct call to $legalfunc$invoke_i* #8119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexAltea opened this issue Feb 18, 2019 · 1 comment
Closed

Unexpected lifting of direct call to $legalfunc$invoke_i* #8119

AlexAltea opened this issue Feb 18, 2019 · 1 comment

Comments

@AlexAltea
Copy link

AlexAltea commented Feb 18, 2019

I'm building my project using the latest sdk-incoming-64bit with the following flags:

emcc -O3
 -s WASM=1
 -s ALLOW_TABLE_GROWTH=1 
 -s EXPORTED_FUNCTIONS="$EXP_FUNCTIONS"
 -s EXTRA_EXPORTED_RUNTIME_METHODS="$EXP_METHODS"
 -s RESERVED_FUNCTION_POINTERS=256
 -s EMULATED_FUNCTION_POINTERS=1
 -s ALLOW_MEMORY_GROWTH=1
 -s MODULARIZE=1
 -s EXPORT_NAME="MEmu"
 $BINARYEN_DIR/lib/libbinaryen.so path/to/libemu.a

One function, test1, direct-calls test2, which direct-calls test3, which direct-calls test4. The functions test2 and test3 disappear do to inlining, leaving us just with the direct call to test4 which looks like:

// uintptr_t test4(void *arg1, uint64_t arg2);

res = test4(arg1, arg2);

which gets converted to this:

(func $_test1 (; 370 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32)
  [...]
  (local.set $2
    (call $legalfunc$invoke_iij   ;; This should have been $_test4
      (local.get $12)
      (local.get $42)
    )
  )
  [...]
)

(func $legalfunc$invoke_iij (; 8921 ;) (; has Stack IR ;) (param $0 i32) (param $1 i64) (result i32)
  (call $legalimport$invoke_iij
    (i32.const 2125)              ;; This is the pointer to $_test4
    [...]
  )
)

My main issue with this unexpected conversion is that invoke_iij (JavaScript!) will try to call a function expecting i64 arguments, which results in the following issue:

Uncaught (in promise) TypeError: wasm function signature contains illegal type
    at ftCall_iij (emu.min.js:6240)
    at invoke_iij (emu.min.js:6023)
    at legalfunc$invoke_iij (wasm-function[8921]:15)
    at _test1 (wasm-function[370]:2885)

What's really weird is that there's other functions that do direct calls to test4 just fine. So my question is:

  • Do anyone know any possible reason why $legalimport$invoke_iij has been emitted here? (@kripken?)

I suspect this could have some connection with #8065, since I'm mixing -s WASM=1 and -s EMULATED_FUNCTION_POINTERS=1 (which I need, since I'm running a WASM JIT compiler in WASM see #7082).

@AlexAltea
Copy link
Author

AlexAltea commented Feb 19, 2019

This turned out to be caused by a setjmp call, this issue matches exactly #7399, so I'll close this as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant