Skip to content

Commit f58da13

Browse files
committed
Remove unnecessary dependency on stderr debug builds. NFC
In debug builds this stub version was bringing in other dependencies via `getpid` -> `__syscall_getpid` -> `stderr`. Due to the way object file dependecies get resolved this means that any dependency on any function in `library_pthread_stub.c` was bringing in `stderr` which in turn adds `__stdio_write/read/lseek` to the wasm table (which is not amenable to DCE). This change solves the issue in two separate ways: 1. Move move_emscripten_main_browser_thread_id in pthread_self_stub.c meaning the dependency on getpid() is more specific. 2. Avoid the use of `stderr` in `emscripten_syscall_stubs.c`
1 parent 272bc3b commit f58da13

File tree

8 files changed

+8
-16
lines changed

8 files changed

+8
-16
lines changed

system/lib/libc/emscripten_syscall_stubs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/stat.h>
2222
#include <time.h>
2323
#include <sys/utsname.h>
24+
#include <emscripten/console.h>
2425

2526
static int g_pid = 42;
2627
static int g_pgid = 42;
@@ -32,7 +33,7 @@ static mode_t g_umask = S_IRWXU | S_IRWXG | S_IRWXO;
3233
#define REPORT(name)
3334
#else
3435
#define REPORT(name) \
35-
fprintf(stderr, "warning: unsupported syscall: __syscall_" #name "\n");
36+
emscripten_console_error("warning: unsupported syscall: __syscall_" #name "\n");
3637
#endif
3738

3839
#define UNIMPLEMENTED(name, args) \

system/lib/pthread/library_pthread_stub.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,6 @@ weak_alias(__pthread_detach, emscripten_builtin_pthread_detach);
220220
weak_alias(__pthread_detach, pthread_detach);
221221
weak_alias(__pthread_detach, thrd_detach);
222222

223-
pthread_t emscripten_main_browser_thread_id() {
224-
return __pthread_self();
225-
}
226-
227223
// pthread_equal is defined as a macro in C, as a function for C++; undef it
228224
// here so we define the function for C++ that links to us.
229225
#ifdef pthread_equal

system/lib/pthread/pthread_self_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ static long dummy_getpid() {
2020
}
2121
weak_alias(dummy_getpid, __syscall_getpid);
2222

23+
pthread_t emscripten_main_browser_thread_id() {
24+
return &__main_pthread;
25+
}
26+
2327
__attribute__((constructor))
2428
static void init_pthread_self(void) {
2529
__main_pthread.locale = &libc.global_locale;

tests/other/metadce/hello_world.funcs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ $__fwritex
77
$__get_tp
88
$__lock
99
$__lockfile
10-
$__lseek
1110
$__lshrti3
1211
$__memcpy
1312
$__ofl_lock
1413
$__ofl_unlock
1514
$__original_main
16-
$__stdio_close
17-
$__stdio_seek
1815
$__stdio_write
1916
$__syscall_getpid
2017
$__towrite
@@ -24,7 +21,6 @@ $__unlockfile
2421
$__vfprintf_internal
2522
$__wasi_syscall_ret
2623
$__wasm_call_ctors
27-
$dummy
2824
$dynCall_jiji
2925
$emscripten_stack_get_end
3026
$emscripten_stack_get_free
@@ -39,7 +35,6 @@ $getint
3935
$getpid
4036
$init_pthread_self
4137
$isdigit
42-
$legalfunc$__wasi_fd_seek
4338
$legalstub$dynCall_jiji
4439
$main
4540
$memchr
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
env.emscripten_memcpy_big
22
env.setTempRet0
3-
wasi_snapshot_preview1.fd_close
4-
wasi_snapshot_preview1.fd_seek
53
wasi_snapshot_preview1.fd_write
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
125729
1+
125367

tests/other/metadce/hello_world.sent

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
emscripten_memcpy_big
2-
fd_close
3-
fd_seek
42
fd_write
53
setTempRet0

tests/other/metadce/hello_world.size

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12408
1+
12066

0 commit comments

Comments
 (0)