emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.74k stars 3.3k forks source link

Dynamic linking causing runtime errors even before modules are loaded #14405

Open goldwaving opened 3 years ago

goldwaving commented 3 years ago

I have a project that compiles and runs fine. I am now working on adding dynamic link. When I add "-s MAIN_MODULE=1" and rebuild, I get runtime errors even before attempting to load any modules. The errors occurs before main() executes and seem to be relate to pthreads. The greater the PTHREAD_POOL_SIZE value, the greater the number of errors reported. There are no dynamic libraries to preload and no modules are being loaded yet. The code is exactly the same as before. The only change was adding "-s MAIN_MODULE=1".

project.worker.js:1 Uncaught TypeError: Cannot read property 'slice' of undefined at convertJsFunctionToWasm (project.js:1) at addFunctionWasm (project.js:1) at reportUndefinedSymbols (project.js:1) at preloadDylibs (project.js:1) at run (project.js:1) at project.js:1 at self.onmessage

and

project.worker.js:181 RuntimeError: abort(Assertion failed: Missing signature argument to addFunction: function emval_run_destructors(handle) { var destructors = emval_handle_array[handle].value; runDestructors(destructors); emval_decref(handle); }) at Error at jsStackTrace (project.js:2911) at stackTrace (project.js:3366) at abort (project.js:2171) at assert (project.js:1585) at addFunctionWasm (project.js:1442) at reportUndefinedSymbols (project.js:3319) at preloadDylibs (project.js:3333) at run (project.js:111096) at project.js:111216 at self.onmessage (project.worker.js:68) at abort (project.js:2173) at assert (project.js:1585) at addFunctionWasm (project.js:1442) at reportUndefinedSymbols (project.js:3319) at preloadDylibs (project.js:3333) at run (project.js:111096) at project.js:111216 at self.onmessage (project.worker.js:68)

goldwaving commented 3 years ago

There appears to be many __sig items missing in emval.js, such as:

__emval_run_destructors.sig = "vi";
__emval_set_property.sig = "viii";
__emval_get_property.sig = "iii";

Adding these solves the problem.

sbc100 commented 3 years ago

Would you mind uploading PR to add these?