Skip to content

Instantly share code, notes, and snippets.

@xor2k
Last active August 13, 2017 08:46
Show Gist options
  • Save xor2k/6fae4abcb4d8c4b4f456dad39256f9a3 to your computer and use it in GitHub Desktop.
Save xor2k/6fae4abcb4d8c4b4f456dad39256f9a3 to your computer and use it in GitHub Desktop.
WebAssembly module function signature mismatch example

This error has been fixed in Node.js v8.3 resp. Chrome v60 resp. Chromium v60.

WebAssembly module function signature mismatch example

Build index.html (and main.js for node.js) using

sh build.sh

(make sure to use latest Emscripten incoming). That creates a file index.html and main.js. You can then run sh server.sh in your command line and open http://localhost:8080 in your browser (or run node main.js in the command line).

Then, in Chrome (v59) and node.js (v8.2.1, installed for Ubuntu 16.4 from https://nodejs.org/en/download/package-manager, compare comment in build.sh) an error occurs at runtime

[...] RuntimeError: function signature mismatch [...]

Firefox (v54) seems to be fine.

The error disappears if line 11 is removed and build.sh run again:

// std::cerr << "yay" << std::endl;
#!/bin/sh
flags="-O0 --memory-init-file 0 -fno-exceptions"
em++ ${flags} -s SIDE_MODULE=1 -s WASM=1 -o main_side.wasm main.cc
# build for node.js
EMCC_FORCE_STDLIBS=libc,libcxx,libcxxabi em++ ${flags} \
-s WASM=1 -s MAIN_MODULE=1 -o main.js null.cc --pre-js pre.js
# build for firefox and chrome, then run server.js
# and open http://localhost:8080 in your browser
EMCC_FORCE_STDLIBS=libc,libcxx,libcxxabi em++ ${flags} \
-s WASM=1 -s MAIN_MODULE=1 --proxy-to-worker -o index.html \
null.cc --pre-js pre.js
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdio.h>
int main(int argc, char** argv){
std::vector<int> v(1);
v[0] = 5;
std::cerr << "yay" << std::endl;
printf("yay\n");
printf("%d\n", v[0]);
return 0;
}
// empty file, fine
var Module={};
Module.preInit = [function(){
Module.dynamicLibraries = ['main_side.wasm'];
}];
#!/bin/sh
python -m SimpleHTTPServer 8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment