【问题标题】:Building libsoxr to Webassembly leads to function signature mismatch error将 libsoxr 构建到 Webassembly 会导致函数签名不匹配错误
【发布时间】:2020-07-19 16:44:56
【问题描述】:

我正在尝试使用 emscripten 将 libsoxr 构建到 WebAssembly。在调用soxr_create 函数时,我尝试的所有操作都会导致RuntimeError: function signature mismatch 错误。我正在使用 emscripten 的 latest 标签。我还尝试了提供的示例,并且行为是相同的。我尝试使用 NodeJS 和 Chromium。

复制方法如下:

git clone https://git.code.sf.net/p/soxr/code
cd soxr
emcmake cmake -DBUILD_EXAMPLES=ON .
emmake make
node examples/2-stream.js

堆栈跟踪是:

exception thrown: RuntimeError: function signature mismatch,RuntimeError: function signature mismatch
    at wasm-function[50]:0xf72e
    at wasm-function[49]:0xe90d
    at wasm-function[60]:0x1057f
    at wasm-function[14]:0xcac
    at wasm-function[13]:0xb53
    at wasm-function[11]:0x699
...

当构建一个只有 main 函数调用 soxr_create 并使用 -g --profiling 构建的文件时,这是我得到的堆栈跟踪:

exception thrown: RuntimeError: function signature mismatch,RuntimeError: function signature mismatch
    at dft_stage_init (wasm-function[68]:0x1b8e2)
    at _soxr_init (wasm-function[66]:0x190be)
    at rate_create (wasm-function[88]:0x1f8fa)
    at initialise (wasm-function[124]:0x43c90)
    at soxr_set_io_ratio (wasm-function[122]:0x4373f)
    at soxr_create (wasm-function[119]:0x43213)
    at __original_main (wasm-function[135]:0x45646)
    at main (wasm-function[136]:0x45684)
    at /home/geekuillaume/code/wasm-audio-resampler/soxr_wasm.js:1635:22
    at callMain (/home/geekuillaume/code/wasm-audio-resampler/soxr_wasm.js:2377:15)

我尝试过使用 emscripten sanitizer,但它什么也没做。

【问题讨论】:

  • 这通常发生在 C 中的函数指针与错误的签名一起使用时。如果您在 wasm binaryen 上使用 wasm-objdump -d,您应该会在 dft_stage_init 函数 (0x1b8e2) 中给出的偏移处看到一条 call_indirect 指令。这应该可以让您找出对应的源代码行。我在该源代码中没有看到任何明显的间接调用,但您应该能够弄清楚。希望这是可以在源代码中修复的东西,而不是编译器错误。
  • 感谢您的帮助!你是对的,它来自 call_indirect 指令。我发现它是由文件cr.c 中的rdft_forward_setup 调用生成的。该函数来自具有多个函数签名的函数表RDFT_CB。会不会是因为这个?我不知道该怎么做才能尝试调试它。

标签: webassembly emscripten


【解决方案1】:

发现问题。 Soxr 库错误地转换了函数指针。指向的函数不期望任何参数,但被强制转换为接收一个 int 作为参数的函数。我写了一个补丁来解决这个问题,一切正常!在Emscripten documentation 中有更多相关信息。

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多