Skip to content
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

Stack overflow when js_name = "sin" #3462

Closed
samestep opened this issue Jun 5, 2023 · 1 comment
Closed

Stack overflow when js_name = "sin" #3462

samestep opened this issue Jun 5, 2023 · 1 comment
Labels

Comments

@samestep
Copy link
Contributor

samestep commented Jun 5, 2023

Describe the Bug

The Rust compiler generates Wasm trigonometry functions with unmangled names. Trying to export a wasm-bindgen function with one of those names causes a symbol conflict where the exported function just calls itself, resulting in a stack overflow.

Steps to Reproduce

https://github.com/samestep/wbg-sin

  1. gh repo clone samestep/wbg-sin
  2. cd wbg-sin
  3. ./run.sh

Expected Behavior

   Compiling wbg-sin v0.0.0
    Finished release [optimized] target(s) in 0.24s
-0.9165215479156338

Actual Behavior

   Compiling wbg-sin v0.0.0
    Finished release [optimized] target(s) in 0.51s
wasm://wasm/cc173f36:1


RangeError: Maximum call stack size exceeded
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x52)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)
    at sin (wasm://wasm/cc173f36:wasm-function[0]:0x55)

Node.js v18.15.0

Additional Context

See also #2338 and #2806.

Importantly, note that changing the exported function name from sin to sine yields the Expected Behavior described above. But with the function named sin, the actual implementation of sine becomes dead code and gets optimized away, yielding this very tiny disassembled Wasm as can be seen by running wasm2wat wbg/wbg_sin_bg.wasm:

(module
  (type (;0;) (func (param f64) (result f64)))
  (func $sin (type 0) (param f64) (result f64)
    local.get 0
    call $sin)
  (memory (;0;) 17)
  (global (;0;) (mut i32) (i32.const 1048576))
  (export "memory" (memory 0))
  (export "sin" (func $sin)))
@samestep samestep added the bug label Jun 5, 2023
@daxpedda
Copy link
Collaborator

daxpedda commented Jun 5, 2023

Duplicate of #2338.

@daxpedda daxpedda closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants