Skip to content

Commit 244759d

Browse files
authored
Only link crtbegin library when building with pthreads enabled (#26690)
In particular the function defined in this library are not needed when building with just `-sWASM_WORKERS`.
1 parent 61f9883 commit 244759d

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ commands:
216216
command: |
217217
ls -l ~/cache/sysroot/lib/wasm32-emscripten || echo "no build"
218218
ls -l ~/cache/sysroot/include/emscripten/heap.h
219-
cat ~/cache/sysroot/lib/wasm32-emscripten/crtbegin.o.ccache-log
219+
cat ~/cache/sysroot/lib/wasm32-emscripten/crtbegin-mt.o.ccache-log
220220
date
221221
cat ~/cache/build/libcompiler_rt/absvdi2.o.ccache-log
222222
ccache -s

embuilder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
'libstandalonewasm-nocatch',
9292
'crt1',
9393
'crt1_proxy_main',
94-
'crtbegin',
94+
'crtbegin-mt',
9595
'libunwind-legacyexcept',
9696
'libunwind-wasmexcept',
9797
'libnoexit',
@@ -117,7 +117,7 @@
117117
'libGL-mt-emu-webgl2-getprocaddr',
118118
'libGL-mt-emu-webgl2-ofb-getprocaddr',
119119
'libsockets_proxy',
120-
'crtbegin',
120+
'crtbegin-mt',
121121
'libsanitizer_common_rt',
122122
'libubsan_rt',
123123
'libwasm_workers-debug',

test/codesize/audio_worklet_wasm.expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ function ha(a) {
229229
function y() {
230230
Z = {
231231
g: ha,
232-
b: Q,
232+
c: Q,
233233
h: R,
234234
e: aa,
235235
i: ba,
236236
f: ca,
237-
c: da,
237+
b: da,
238238
a: v,
239239
d: fa
240240
};

test/codesize/hello_wasm_worker_wasm.expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ function B() {
5555

5656
function k() {
5757
E = {
58-
e: t,
58+
d: t,
5959
c: w,
6060
b: x,
61-
d: y,
61+
e: y,
6262
f: A,
6363
g: B,
6464
a: g

test/codesize/test_minimal_runtime_code_size_audio_worklet.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"a.js": 4446,
55
"a.js.gz": 2299,
66
"a.wasm": 1393,
7-
"a.wasm.gz": 933,
7+
"a.wasm.gz": 931,
88
"total": 6354,
9-
"total_gz": 3587
9+
"total_gz": 3585
1010
}

test/codesize/test_minimal_runtime_code_size_hello_wasm_worker.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 355,
44
"a.js": 952,
55
"a.js.gz": 601,
6-
"a.wasm": 2638,
6+
"a.wasm": 2640,
77
"a.wasm.gz": 1476,
8-
"total": 4105,
8+
"total": 4107,
99
"total_gz": 2432
1010
}

tools/system_libs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,10 @@ def can_use(self):
16091609
return super().can_use() and settings.PROXY_TO_PTHREAD
16101610

16111611

1612-
class crtbegin(MuslInternalLibrary):
1613-
name = 'crtbegin'
1612+
class crtbegin_mt(MuslInternalLibrary):
1613+
# This library defines _emscripten_tls_init/_emscripten_tls_free which are linked into
1614+
# every module (i.e. not just the main module).
1615+
name = 'crtbegin-mt'
16141616
cflags = ['-pthread']
16151617
src_dir = 'system/lib/pthread'
16161618
src_files = ['emscripten_tls_init.c']
@@ -1621,7 +1623,7 @@ def get_ext(self):
16211623
return '.o'
16221624

16231625
def can_use(self):
1624-
return super().can_use() and settings.SHARED_MEMORY
1626+
return super().can_use() and settings.PTHREADS
16251627

16261628

16271629
class libcxxabi(ExceptionLibrary, MTLibrary, DebugLibrary):
@@ -2331,8 +2333,8 @@ def add_library(libname, whole_archive=False):
23312333
libs_to_link.append((lib.get_link_flag(), whole_archive or need_whole_archive))
23322334

23332335
if not options.nostartfiles:
2334-
if settings.SHARED_MEMORY:
2335-
add_library('crtbegin')
2336+
if settings.PTHREADS:
2337+
add_library('crtbegin-mt')
23362338

23372339
if not settings.SIDE_MODULE:
23382340
if settings.STANDALONE_WASM:

0 commit comments

Comments
 (0)