Skip to content

Commit 246209c

Browse files
authored
Fix closure errors with MINIMAL_RUNTIME + USE_PTHREADS. NFC. (#14936)
1 parent 1fffdd5 commit 246209c

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

emcc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ def default_setting(name, new_default):
18841884
'_emscripten_tls_init',
18851885
'_pthread_self',
18861886
'_pthread_testcancel',
1887+
'_exit',
18871888
]
18881889
# Some of these symbols are using by worker.js but otherwise unreferenced.
18891890
# Because emitDCEGraph only considered the main js file, and not worker.js

src/library_pthread.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var LibraryPThread = {
99
$PThread__deps: ['_emscripten_thread_init',
1010
'emscripten_futex_wake', '$killThread',
1111
'$cancelThread', '$cleanupThread',
12+
'exit',
1213
#if !MINIMAL_RUNTIME
1314
'$handleException',
1415
#endif
@@ -57,7 +58,9 @@ var LibraryPThread = {
5758
// things.
5859
PThread['receiveObjectTransfer'] = PThread.receiveObjectTransfer;
5960
PThread['threadInit'] = PThread.threadInit;
61+
#if !MINIMAL_RUNTIME
6062
PThread['setExitStatus'] = PThread.setExitStatus;
63+
#endif
6164
#endif
6265
},
6366
// Maps pthread_t to pthread info objects
@@ -130,9 +133,11 @@ var LibraryPThread = {
130133
},
131134
#endif
132135

136+
#if !MINIMAL_RUNTIME
133137
setExitStatus: function(status) {
134138
EXITSTATUS = status;
135139
},
140+
#endif
136141

137142
terminateAllThreads: function() {
138143
for (var t in PThread.pthreads) {
@@ -305,10 +310,10 @@ var LibraryPThread = {
305310
err("exitProcess requested by worker");
306311
#endif
307312
#if MINIMAL_RUNTIME
308-
exit(d['returnCode']);
313+
_exit(d['returnCode']);
309314
#else
310315
try {
311-
exit(d['returnCode']);
316+
_exit(d['returnCode']);
312317
} catch (e) {
313318
handleException(e);
314319
}

src/minimal_runtime_worker_externs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
// These externs are needed for MINIMAL_RUNTIME + USE_PTHREADS + !MODULARIZE
7+
// These externs are needed for MINIMAL_RUNTIME + USE_PTHREADS
88
// This file should go away in the future when worker.js is refactored to live inside the JS module.
99

1010
var ENVIRONMENT_IS_PTHREAD;

src/preamble_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ if (!ENVIRONMENT_IS_PTHREAD) {
108108
#if USE_PTHREADS
109109
} else {
110110
#if MODULARIZE
111-
updateGlobalBufferAndViews({{{EXPORT_NAME}}}.buffer);
111+
updateGlobalBufferAndViews(Module.buffer);
112112
#else
113113
updateGlobalBufferAndViews(wasmMemory.buffer);
114114
#endif

src/shell_minimal.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var ENVIRONMENT_IS_NODE = typeof process === 'object';
3232
var ENVIRONMENT_IS_SHELL = typeof read === 'function';
3333
#endif
3434

35-
#if ASSERTIONS
35+
#if ASSERTIONS || USE_PTHREADS
3636
#if !ENVIRONMENT_MAY_BE_NODE && !ENVIRONMENT_MAY_BE_SHELL
3737
var ENVIRONMENT_IS_WEB = true
3838
#elif ENVIRONMENT && !ENVIRONMENT.includes(',')
@@ -43,10 +43,8 @@ var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_SHELL;
4343
var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_SHELL;
4444
#else
4545
var ENVIRONMENT_IS_WEB = !ENVIRONMENT_IS_NODE;
46-
#else
47-
4846
#endif
49-
#endif // ASSERTIONS
47+
#endif // ASSERTIONS || USE_PTHREADS
5048

5149
#if ASSERTIONS && ENVIRONMENT_MAY_BE_NODE && ENVIRONMENT_MAY_BE_SHELL
5250
if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) {

tests/test_browser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,11 +4701,12 @@ def test_pthread_hello_thread(self, opts):
47014701
# Tests that a pthreads build of -s MINIMAL_RUNTIME=1 works well in different build modes
47024702
@parameterized({
47034703
'': ([],),
4704-
'O3': (['-O3'],)
4704+
'modularize': (['-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
4705+
'O3': (['-O3'],),
4706+
'O3_modularize': (['-O3', '-sMODULARIZE', '-sEXPORT_NAME=MyModule'],),
47054707
})
47064708
def test_minimal_runtime_hello_thread(self, opts):
4707-
for modularize in [[], ['-s', 'MODULARIZE', '-s', 'EXPORT_NAME=MyModule']]:
4708-
self.btest_exit(test_file('pthread/hello_thread.c'), expected='1', args=['-s', 'MINIMAL_RUNTIME', '-s', 'USE_PTHREADS'] + modularize + opts)
4709+
self.btest_exit(test_file('pthread/hello_thread.c'), expected='1', args=['--closure=1', '-sMINIMAL_RUNTIME', '-sUSE_PTHREADS'] + opts)
47094710

47104711
# Tests memory growth in pthreads mode, but still on the main thread.
47114712
@requires_threads

tools/building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ def add_to_path(dirname):
834834
if settings.DYNCALLS:
835835
CLOSURE_EXTERNS += [path_from_root('src/closure-externs/dyncall-externs.js')]
836836

837-
if settings.MINIMAL_RUNTIME and settings.USE_PTHREADS and not settings.MODULARIZE:
837+
if settings.MINIMAL_RUNTIME and settings.USE_PTHREADS:
838838
CLOSURE_EXTERNS += [path_from_root('src/minimal_runtime_worker_externs.js')]
839839

840840
args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS']

0 commit comments

Comments
 (0)