Skip to content

Commit e0074c6

Browse files
committed
Move PROXY_TO_PTHREAD handling all into native code. NFC
Fixes: #17144
1 parent 87fb2d0 commit e0074c6

9 files changed

+17
-32
lines changed

src/library_pthread.js

-24
Original file line numberDiff line numberDiff line change
@@ -808,30 +808,6 @@ var LibraryPThread = {
808808
return 0;
809809
},
810810

811-
#if PROXY_TO_PTHREAD
812-
__call_main__deps: ['exit', '$exitOnMainThread'],
813-
__call_main: function(argc, argv) {
814-
#if !EXIT_RUNTIME
815-
// EXIT_RUNTIME==0 set, keeping main thread alive by default.
816-
noExitRuntime = true;
817-
#endif
818-
var returnCode = {{{ exportedAsmFunc('_main') }}}(argc, argv);
819-
#if EXIT_RUNTIME
820-
if (!keepRuntimeAlive()) {
821-
// exitRuntime enabled, proxied main() finished in a pthread, shut down the process.
822-
#if PTHREADS_DEBUG
823-
err('Proxied main thread finished with return code ' + returnCode + '. EXIT_RUNTIME=1 set, quitting process.');
824-
#endif
825-
exitOnMainThread(returnCode);
826-
}
827-
#else
828-
#if PTHREADS_DEBUG
829-
err('Proxied main thread finished with return code ' + returnCode + '. EXIT_RUNTIME=0 set, so keeping main thread alive for asynchronous event operations.');
830-
#endif
831-
#endif
832-
},
833-
#endif
834-
835811
// This function is call by a pthread to signal that exit() was called and
836812
// that the entire process should exit.
837813
// This function is always called from a pthread, but is executed on the

system/lib/pthread/emscripten_proxy_main.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <pthread.h>
9+
#include <stdlib.h>
910

1011
#include <emscripten.h>
1112
#include <emscripten/stack.h>
@@ -14,12 +15,13 @@
1415
static int _main_argc;
1516
static char** _main_argv;
1617

17-
extern void __call_main(int argc, char** argv);
18+
extern int main(int argc, char** argv);
1819

1920
static void* _main_thread(void* param) {
2021
// This is the main runtime thread for the application.
2122
emscripten_set_thread_name(pthread_self(), "Application main thread");
22-
__call_main(_main_argc, _main_argv);
23+
int rtn = main(_main_argc, _main_argv);
24+
exit(rtn);
2325
return NULL;
2426
}
2527

tests/other/metadce/test_metadce_minimal_pthreads.exports

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A
22
B
33
C
44
D
5-
E
5+
n
66
o
77
p
88
q

tests/other/metadce/test_metadce_minimal_pthreads.imports

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ a.j
1111
a.k
1212
a.l
1313
a.m
14-
a.n
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16131
1+
16079

tests/other/metadce/test_metadce_minimal_pthreads.sent

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ j
1111
k
1212
l
1313
m
14-
n
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18310
1+
18307

tests/test_core.py

+9
Original file line numberDiff line numberDiff line change
@@ -9195,6 +9195,15 @@ def test_pthread_dylink_longjmp(self):
91959195
main = test_file('core/pthread/test_pthread_dylink_longjmp.c')
91969196
self.dylink_testf(main, need_reverse=False)
91979197

9198+
@needs_dylink
9199+
@node_pthreads
9200+
def test_pthread_dylink_main_module_1(self):
9201+
self.emcc_args.append('-Wno-experimental')
9202+
self.set_setting('EXIT_RUNTIME')
9203+
self.set_setting('USE_PTHREADS')
9204+
self.set_setting('MAIN_MODULE')
9205+
self.do_runf(test_file('hello_world.c'))
9206+
91989207
@needs_dylink
91999208
@node_pthreads
92009209
def test_Module_dynamicLibraries_pthreads(self):

tests/test_other.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11416,7 +11416,7 @@ def test_no_main_with_PROXY_TO_PTHREAD(self):
1141611416
void foo() {}
1141711417
''')
1141811418
err = self.expect_fail([EMCC, 'lib.cpp', '-pthread', '-sPROXY_TO_PTHREAD'])
11419-
self.assertContained('emcc: error: PROXY_TO_PTHREAD proxies main() for you, but no main exists', err)
11419+
self.assertContained('error: undefined symbol: main (referenced by top-level compiled C/C++ code)', err)
1142011420

1142111421
def test_archive_bad_extension(self):
1142211422
# Regression test for https://github.com/emscripten-core/emscripten/issues/14012

0 commit comments

Comments
 (0)