Skip to content

Commit 0859a3a

Browse files
authored
Move emscripten_proxy_main.c to crt1_proxy_main.c. NFC (#17195)
This really is the crt1.o for applications built with PROXY_TO_PTHREAD.
1 parent f677b26 commit 0859a3a

File tree

10 files changed

+42
-26
lines changed

10 files changed

+42
-26
lines changed

embuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'struct_info',
5757
'libstandalonewasm',
5858
'crt1',
59+
'crt1_proxy_main',
5960
'libunwind-except',
6061
'libnoexit',
6162
]

emcc.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,6 @@ def setup_pthreads(target):
15471547
if settings.MINIMAL_RUNTIME:
15481548
building.user_requested_exports.add('exit')
15491549

1550-
if settings.PROXY_TO_PTHREAD:
1551-
settings.REQUIRED_EXPORTS += ['emscripten_proxy_main']
1552-
15531550
# All proxying async backends will need this.
15541551
if settings.WASMFS:
15551552
settings.REQUIRED_EXPORTS += ['emscripten_proxy_finish']
@@ -1744,8 +1741,7 @@ def phase_linker_setup(options, state, newargs, user_settings):
17441741
settings.EXPECT_MAIN = 0
17451742
else:
17461743
assert not settings.EXPORTED_FUNCTIONS
1747-
# With PROXY_TO_PTHREAD we don't export `main` at all but instead
1748-
# we export `emscripten_proxy_main` (elsewhwere).
1744+
# With PROXY_TO_PTHREAD we don't export `main` at all but instead `_emscripten_proxy_main`.
17491745
if not settings.PROXY_TO_PTHREAD:
17501746
settings.EXPORTED_FUNCTIONS = ['_main']
17511747

src/postamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function callMain(args) {
131131
#if PROXY_TO_PTHREAD
132132
// User requested the PROXY_TO_PTHREAD option, so call a stub main which pthread_create()s a new thread
133133
// that will call the user's real main() for the application.
134-
var entryFunction = Module['_emscripten_proxy_main'];
134+
var entryFunction = Module['__emscripten_proxy_main'];
135135
#else
136136
var entryFunction = Module['_main'];
137137
#endif

src/postamble_minimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function run() {
1919
// User requested the PROXY_TO_PTHREAD option, so call a stub main which
2020
// pthread_create()s a new thread that will call the user's real main() for
2121
// the application.
22-
var ret = _emscripten_proxy_main();
22+
var ret = __emscripten_proxy_main();
2323
#else
2424
var ret = _main();
2525

system/lib/pthread/emscripten_proxy_main.c renamed to system/lib/libc/crt1_proxy_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void* _main_thread(void* param) {
3333
return NULL;
3434
}
3535

36-
int emscripten_proxy_main(int argc, char** argv) {
36+
EMSCRIPTEN_KEEPALIVE int _emscripten_proxy_main(int argc, char** argv) {
3737
pthread_attr_t attr;
3838
pthread_attr_init(&attr);
3939
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

tests/other/metadce/test_metadce_minimal_pthreads.funcs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ $__pthread_setcancelstate
1010
$__set_thread_state
1111
$__stdio_write
1212
$__timedwait
13-
$__wake.2
13+
$__wake
1414
$__wasi_syscall_ret
1515
$__wasm_call_ctors
1616
$__wasm_init_memory
1717
$__wasm_init_tls
1818
$_do_call
1919
$_emscripten_proxy_execute_task_queue
20+
$_emscripten_proxy_main
2021
$_emscripten_thread_crashed
2122
$_emscripten_thread_exit
2223
$_emscripten_thread_free_data
@@ -27,7 +28,7 @@ $_main_thread
2728
$a_cas
2829
$a_cas_p.1
2930
$a_dec
30-
$a_fetch_add.1
31+
$a_fetch_add
3132
$a_inc
3233
$a_swap
3334
$add
@@ -37,17 +38,16 @@ $dlmalloc
3738
$do_dispatch_to_thread
3839
$em_queued_call_malloc
3940
$emscripten_async_run_in_main_thread
41+
$emscripten_current_thread_process_queued_calls
4042
$emscripten_futex_wait
4143
$emscripten_futex_wake
42-
$emscripten_proxy_execute_queue
43-
$emscripten_proxy_main
4444
$emscripten_run_in_main_runtime_thread_js
4545
$emscripten_stack_set_limits
4646
$get_tasks_for_thread
4747
$init_file_lock
4848
$init_mparams
4949
$memset
50-
$pthread_mutexattr_destroy
50+
$pthread_attr_destroy
5151
$sbrk
5252
$stackAlloc
5353
$stackRestore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16048
1+
16051
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18318
1+
18289

tools/building.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,14 @@ def lld_flags_for_executable(external_symbols):
336336
if not settings.EXPECT_MAIN:
337337
cmd += ['--entry=_initialize']
338338
else:
339-
# TODO(sbc): Avoid passing --no-entry when we know we have an entry point.
340-
# For now we need to do this sice the entry point can be either `main` or
341-
# `__main_argv_argc`, but we should address that by using a single `_start`
342-
# function like we do in STANDALONE_WASM mode.
343-
cmd += ['--no-entry']
339+
if settings.PROXY_TO_PTHREAD:
340+
cmd += ['--entry=_emscripten_proxy_main']
341+
else:
342+
# TODO(sbc): Avoid passing --no-entry when we know we have an entry point.
343+
# For now we need to do this sice the entry point can be either `main` or
344+
# `__main_argv_argc`, but we should address that by using a single `_start`
345+
# function like we do in STANDALONE_WASM mode.
346+
cmd += ['--no-entry']
344347
if not settings.ALLOW_MEMORY_GROWTH:
345348
cmd.append('--max-memory=%d' % settings.INITIAL_MEMORY)
346349
elif settings.MAXIMUM_MEMORY != -1:

tools/system_libs.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ def get_files(self):
834834
'proxying.c',
835835
'pthread_create.c',
836836
'pthread_kill.c',
837-
'emscripten_proxy_main.c',
838837
'emscripten_thread_init.c',
839838
'emscripten_thread_state.S',
840839
'emscripten_futex_wait.c',
@@ -1170,6 +1169,20 @@ def can_use(self):
11701169
return super().can_use() and settings.STANDALONE_WASM
11711170

11721171

1172+
class crt1_proxy_main(MuslInternalLibrary):
1173+
name = 'crt1_proxy_main'
1174+
src_dir = 'system/lib/libc'
1175+
src_files = ['crt1_proxy_main.c']
1176+
1177+
force_object_files = True
1178+
1179+
def get_ext(self):
1180+
return '.o'
1181+
1182+
def can_use(self):
1183+
return super().can_use() and settings.PROXY_TO_PTHREAD
1184+
1185+
11731186
class crtbegin(MuslInternalLibrary):
11741187
name = 'crtbegin'
11751188
cflags = ['-sUSE_PTHREADS']
@@ -1825,11 +1838,14 @@ def add_library(libname):
18251838
if settings.SHARED_MEMORY:
18261839
add_library('crtbegin')
18271840

1828-
if settings.STANDALONE_WASM:
1829-
if settings.EXPECT_MAIN:
1830-
add_library('crt1')
1831-
else:
1832-
add_library('crt1_reactor')
1841+
if not settings.SIDE_MODULE:
1842+
if settings.STANDALONE_WASM:
1843+
if settings.EXPECT_MAIN:
1844+
add_library('crt1')
1845+
else:
1846+
add_library('crt1_reactor')
1847+
elif settings.PROXY_TO_PTHREAD:
1848+
add_library('crt1_proxy_main')
18331849

18341850
if settings.SIDE_MODULE:
18351851
return libs_to_link

0 commit comments

Comments
 (0)