Skip to content

Commit a265b14

Browse files
committed
Fix argv passing in PROXY_TO_PTHREAD mode
This was broken in #17153 but we didn't have any tests. The fix is to export `main` even though we don't technically need to. We could add a little complexity to allow metadce to remove it, but I'm not sure its worth it. Fixes: #17338
1 parent e9b628c commit a265b14

8 files changed

+25
-5
lines changed

emcc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,9 +1747,7 @@ def phase_linker_setup(options, state, newargs, user_settings):
17471747
settings.EXPECT_MAIN = 0
17481748
else:
17491749
assert not settings.EXPORTED_FUNCTIONS
1750-
# With PROXY_TO_PTHREAD we don't export `main` at all but instead `_emscripten_proxy_main`.
1751-
if not settings.PROXY_TO_PTHREAD:
1752-
settings.EXPORTED_FUNCTIONS = ['_main']
1750+
settings.EXPORTED_FUNCTIONS = ['_main']
17531751

17541752
if settings.STANDALONE_WASM:
17551753
# In STANDALONE_WASM mode we either build a command or a reactor.

tests/other/metadce/test_metadce_minimal_pthreads.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ A
22
B
33
C
44
D
5+
E
56
o
67
p
78
q

tests/other/metadce/test_metadce_minimal_pthreads.funcs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ $emscripten_stack_set_limits
4646
$get_tasks_for_thread
4747
$init_file_lock
4848
$init_mparams
49+
$main
4950
$memset
5051
$pthread_attr_destroy
5152
$sbrk
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15917
1+
15983
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18289
1+
18299

tests/pthread/test_pthread_argv.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char* argv[]) {
4+
printf("%d\n", argc);
5+
// Skip arg 0 because it will be an absolute path that varies between
6+
// machines.
7+
for (int i = 1; i < argc; i++) {
8+
printf("%d: %s\n", i, argv[i]);
9+
}
10+
return 0;
11+
}

tests/pthread/test_pthread_argv.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3
2+
1: hello
3+
2: world

tests/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,12 @@ def test_pthread_stdout_after_main(self):
28332833
# streams were locked when the main thread returned.
28342834
self.do_runf(test_file('pthread/test_pthread_stdout_after_main.c'))
28352835

2836+
@node_pthreads
2837+
def test_pthread_argv(self):
2838+
self.set_setting('PROXY_TO_PTHREAD')
2839+
self.set_setting('EXIT_RUNTIME')
2840+
self.do_run_in_out_file_test('pthread/test_pthread_argv.cpp', args=['hello', 'world'])
2841+
28362842
def test_tcgetattr(self):
28372843
self.do_runf(test_file('termios/test_tcgetattr.c'), 'success')
28382844

0 commit comments

Comments
 (0)