How to debug "RuntimeError: function signature mismatch"

65 views
Skip to first unread message

Shi Yan

unread,
Nov 1, 2019, 1:21:08 PM11/1/19
to emscripten-discuss
I'm trying to compile llvm into wasm, so that I can compile and run c++ code directly from the browser.

I'm using another project as a reference: https://github.com/tbfleming/cib

This project worked well, but haven't been updated for 2 years.

I'm basically repeating the same, but with llvm9.



I got llvm compiled into wasm, and I made a simple program to test it. (similar to https://github.com/tbfleming/cib/blob/master/src/clang.cpp)

But as soon as I include a clang header:

#include "clang/CodeGen/CodeGenAction.h"

I will see a runtime error 

RuntimeError: function signature mismatch
RuntimeError: function signature mismatch

/home/shiy/cib/cib/src/build/clang.js:1
var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var arguments_=[];var thisProgram="./this.program";var quit_=function(status,toThrow){throw toThrow};var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(Module["ENVIRONMENT"]){throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s E
abort(RuntimeError: function signature mismatch) at Error
    at jsStackTrace (/home/shiy/cib/cib/src/build/clang.js:1:25243)
    at stackTrace (/home/shiy/cib/cib/src/build/clang.js:1:25414)
    at process.abort (/home/shiy/cib/cib/src/build/clang.js:1:22376)
    at process.emit (events.js:209:13)
    at processPromiseRejections (internal/process/promises.js:201:33)
    at processTicksAndRejections (internal/process/task_queues.js:86:32)



the error message says nothing, it doesn't tell me which function has mismatched signature and what the signature should be.

I tried 

"-s SAFE_HEAP=1"
"-s ASSERTIONS=1"

when compiling, but they don't give an extra messages.         #"-s SAFE_HEAP=1" will crash the program at a different place saying memory alignment issue.


I also tried the node js option node --async-stack-traces ./clang.js 

This gives nothing too.

How can I debug this issue?



Thomas Lively

unread,
Nov 1, 2019, 1:32:29 PM11/1/19
to emscripte...@googlegroups.com
A good first step would be to add `--profiling`, which will preserve function names and not minify the JS.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/36ad539f-1582-45a2-9e47-851e15cbb780%40googlegroups.com.

Shi Yan

unread,
Nov 1, 2019, 3:00:28 PM11/1/19
to emscripten-discuss
Thank you for the tips, I have rebuilt llvm with --profiling, but unfortunately, the error message is the same:

RuntimeError: function signature mismatch
RuntimeError: function signature mismatch

/home/shiy/cib/cib/src/build/clang.js:123
      throw ex;
      ^
abort(RuntimeError: function signature mismatch) at Error
    at jsStackTrace (/home/shiy/cib/cib/src/build/clang.js:1748:17)
    at stackTrace (/home/shiy/cib/cib/src/build/clang.js:1765:16)
    at process.abort (/home/shiy/cib/cib/src/build/clang.js:1556:44)
    at process.emit (events.js:209:13)
    at processPromiseRejections (internal/process/promises.js:201:33)
    at processTicksAndRejections (internal/process/task_queues.js:86:32)

Alon Zakai

unread,
Nov 1, 2019, 5:22:21 PM11/1/19
to emscripte...@googlegroups.com
Trying in another VM might show a better stack trace (that handles the promise better). Alternatively, try disabling async compilation so there is no promise (-s WASM_ASYNC_COMPILATION=0).

Once you have a proper stack trace, the issue might be easy to debug. If not, try the sanitizers,


as a function signature mismatch is likely undefined behavior or memory corruption.


--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages