Skip to content

Commit 4058071

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 a0ed598 commit 4058071

8 files changed

+21
-7
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/core/test_hello_argc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
*/
77

88
#include <stdio.h>
9+
910
int main(int argc, char** argv) {
1011
printf("hello, world! %d\n", argc);
12+
// Skip arg 0 because it will be an absolute path that varies between
13+
// machines.
14+
for (int i = 1; i < argc; i++) {
15+
printf("%d: %s\n", i, argv[i]);
16+
}
1117
return 0;
1218
}

tests/core/test_hello_argc.out

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

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/test_core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,13 @@ def test_wasm_synchronous_compilation(self):
459459

460460
@also_with_standalone_wasm()
461461
def test_hello_argc(self):
462-
self.do_core_test('test_hello_argc.c')
462+
self.do_core_test('test_hello_argc.c', args=['hello', 'world'])
463+
464+
@node_pthreads
465+
def test_hello_argc_pthreads(self):
466+
self.set_setting('PROXY_TO_PTHREAD')
467+
self.set_setting('EXIT_RUNTIME')
468+
self.do_core_test('test_hello_argc.c', args=['hello', 'world'])
463469

464470
@also_with_wasmfs
465471
def test_intvars(self):

0 commit comments

Comments
 (0)