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

ASYNCIFY_DEBUG causes stack overflow for empty program #23333

Open
JensMunkHansen opened this issue Jan 8, 2025 · 3 comments · Fixed by #23334
Open

ASYNCIFY_DEBUG causes stack overflow for empty program #23333

JensMunkHansen opened this issue Jan 8, 2025 · 3 comments · Fixed by #23334

Comments

@JensMunkHansen
Copy link

Create an empty C++ module and create an ES6 module.

Compile options for target Dummy: -fexceptions;-pthread;-matomics;-mbulk-memory;-msimd128;-O0;-g3
Compile definitions for target Dummy: COMPILE_DEFINITIONS-NOTFOUND
Include directories for target Dummy: INCLUDE_DIRECTORIES-NOTFOUND
Link libraries for target Dummy: Threads::Threads
Link options for target Dummy: -sASSERTIONS=2;-sERROR_ON_UNDEFINED_SYMBOLS=1;-sDISABLE_EXCEPTION_CATCHING=0;-sALLOW_BLOCKING_ON_MAIN_THREAD=0;-lembind;-sNO_EXIT_RUNTIME=1;-sMODULARIZE=1;-sEXPORT_ES6=1;-sINCLUDE_FULL_LIBRARY;-sALLOW_TABLE_GROWTH=1;-sEXPORT_NAME=loadDummyTestModule;-sINITIAL_MEMORY=1GB;-sALLOW_MEMORY_GROWTH=0;-sENVIRONMENT=node,worker;-pthread;-flto;--enable-bulk-memory;-sUSE_PTHREADS=1;-sSTACK_SIZE=1048576;-sPTHREAD_POOL_SIZE=2;-sPTHREAD_POOL_SIZE_STRICT=16;-sSHARED_MEMORY=1;-sWASM=1;-sASYNCIFY_STACK_SIZE=81920;-sASYNCIFY=1;-sASYNCIFY_DEBUG=2;-sEXPORTED_RUNTIME_METHODS=['ENV','FS','addFunction','removeFunction','wasmTable','ccall','cwrap','stringToNewUTF8','spawnThread'];-sEXPORTED_FUNCTIONS=['_free','_malloc'];-sASYNCIFY_IMPORTS=[];-O0;-g3
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/jmh/git/vtkEmbinding/build
[ 0%] Built target Dummy_copy_run_Dummy.js
[100%] Linking CXX executable Dummy.js

error: library_async.js: failure to execute js library "library_async.js":
error: library_async.js: use -sVERBOSE to see more details
Internal compiler error in src/compiler.mjs!
Please create a bug report at https://github.com/emscripten-core/emscripten/issues/
with a log of the build and the input files used to run. Exception message: "library_async.preprocessed.js:73
dbg(ASYNCIFY: ${' '.repeat(Asyncify.exportCallStack.length} try ${x});
^^^^^^

SyntaxError: missing ) after argument list
at new Script (node:vm:117:7)
at createScript (node:vm:269:10)
at Module.runInContext (node:vm:300:10)
at runInMacroContext (file:///home/jmh/github/emsdk/upstream/emscripten/src/utility.mjs:333:13)
at Object.load (file:///home/jmh/github/emsdk/upstream/emscripten/src/modules.mjs:248:9)
at Module.runJSify (file:///home/jmh/github/emsdk/upstream/emscripten/src/jsifier.mjs:169:18)
at file:///home/jmh/github/emsdk/upstream/emscripten/src/compiler.mjs:89:11
em++: error: '/home/jmh/github/emsdk/node/20.18.0_64bit/bin/node /home/jmh/github/emsdk/upstream/emscripten/src/compiler.mjs /tmp/tmpj8etiry9.json --symbols-only' failed (returned 1)

I discovered another issue. The generated code..

  debugInit() {
        function pthreadLogPrefix() {
          var t = 0;
          if (runtimeInitialized && typeof _pthread_self != 'undefined'
          ) {
            t = _pthread_self();
          }
          return `w:${workerID},t:${ptrToString(t)}: `;
        }
  
        // Prefix all err()/dbg() messages with the calling thread ID.
        var origDbg = dbg;
        dbg = (...args) => origDbg(pthreadLogPrefix() + args.join(' '));
      },

Causes a stack overflow during the early initialization. I patched the generated code and removed dbg and reinserted after the module was fully initialize. The issue only occurs if you use -sASYNCIFY_DEBUG.

I use the latest release 3.1.74

Thanks in advance

@sbc100
Copy link
Collaborator

sbc100 commented Jan 8, 2025

Woops!

Looks like this only effect -sASYNCIFY_DEBUG=2 so -sASYNCIFY_DEBUG should still work until we can land a fix.

sbc100 added a commit to sbc100/emscripten that referenced this issue Jan 8, 2025
@JensMunkHansen
Copy link
Author

JensMunkHansen commented Jan 8, 2025 via email

@sbc100
Copy link
Collaborator

sbc100 commented Jan 8, 2025

I see, there is a second issue. The syntax error is only present with -sASYNCIFY_DEBUG=2. That first issue is fixed in #23334

@sbc100 sbc100 closed this as completed in ee7a686 Jan 8, 2025
@sbc100 sbc100 reopened this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants