From ab6c507d60ff57ae30ed6fc53039dd24583b84e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Fri, 19 Sep 2025 23:09:59 +0300 Subject: [PATCH 1/4] Fix -sEXIT_RUNTIME in MINIMAL_RUNTIME build mode. Fixes 13 tests in minimal0 suite, e.g. minimal0.test_static_variable. --- .circleci/config.yml | 1 + src/postamble_minimal.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ff9d94611889..ab5c508087c7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -706,6 +706,7 @@ jobs: wasmfs.test_fs_llseek_rawfs wasmfs.test_freetype minimal0.test_utf + minimal0.test_static_variable omitexports0.test_asyncify_longjmp strict.test_no_declare_asm_module_exports " diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 68d7bb38daf6b..34ea6f6cb8657 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -80,7 +80,18 @@ function run() { _main({{{ argc_argv() }}}).then(exitRuntime); #elif EXIT_RUNTIME // In regular exitRuntime mode, exit with the given return code from main(). - exitRuntime(_main({{{ argc_argv() }}})); + try { + exitRuntime(_main({{{ argc_argv() }}})); + } catch(e) { + if (!e.match(/^exit\(\d+\)$/)) { + throw e; + } +#if RUNTIME_DEBUG + else { + out(`main() called ${e}.`); // e.g. "main() called exit(0)." + } +#endif + } #else // Run a persistent (never-exiting) application starting at main(). _main({{{ argc_argv() }}}); From bbae0298df473af26e3ac1255f5241aacb1bf845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Sat, 20 Sep 2025 00:09:25 +0300 Subject: [PATCH 2/4] Smaller code size --- src/postamble_minimal.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 34ea6f6cb8657..bfb5dfe8886c5 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -87,9 +87,7 @@ function run() { throw e; } #if RUNTIME_DEBUG - else { - out(`main() called ${e}.`); // e.g. "main() called exit(0)." - } + out(`main() called ${e}.`); // e.g. "main() called exit(0)." #endif } #else From a3e76410c3ab2255a5fbfedc60960e6678a1b381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Sat, 20 Sep 2025 00:17:16 +0300 Subject: [PATCH 3/4] dbg --- src/postamble_minimal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index bfb5dfe8886c5..3830b933485d2 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -87,7 +87,7 @@ function run() { throw e; } #if RUNTIME_DEBUG - out(`main() called ${e}.`); // e.g. "main() called exit(0)." + dbg(`main() called ${e}.`); // e.g. "main() called exit(0)." #endif } #else From 4b5cc444d46cdc0baaedfe2433aae76b51403b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Sun, 21 Sep 2025 01:36:51 +0300 Subject: [PATCH 4/4] Call onExit to finish tests in browser --- src/postamble_minimal.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 3830b933485d2..b45b2724ee899 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -83,12 +83,19 @@ function run() { try { exitRuntime(_main({{{ argc_argv() }}})); } catch(e) { - if (!e.match(/^exit\(\d+\)$/)) { + var exitCode = e.match(/^exit\(\d+\)$/); + if (exitCode) { throw e; } #if RUNTIME_DEBUG dbg(`main() called ${e}.`); // e.g. "main() called exit(0)." #endif + // Report to Module that the program exited. TODO: Find a way to not emit + // this code unconditionally, as it may not be needed by the user. In + // MINIMAL_RUNTIME, the use of Module object is discouraged, since it leads + // to non-DCEable patterns of code. This call is present here mainly for + // Emscripten test harness purposes. + Module['onExit']?.(exitCode[1]); } #else // Run a persistent (never-exiting) application starting at main().