Skip to content

Commit 5dc1e7c

Browse files
authored
Merge pthreads library into libc (#12880)
This is how musl does it and there is no reason we shouldn't follow suite.
1 parent 1765ab5 commit 5dc1e7c

File tree

3 files changed

+57
-68
lines changed

3 files changed

+57
-68
lines changed

embuilder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
'libdlmalloc-debug',
4444
'libemmalloc',
4545
'libemmalloc-64bit',
46-
'libpthread_stub',
4746
'libsockets',
4847
'libc_rt_wasm',
4948
'struct_info',
@@ -165,8 +164,6 @@ def main():
165164
for task in SYSTEM_TASKS + USER_TASKS:
166165
if '-mt' in task:
167166
skip_tasks.append(task)
168-
if 'pthread' in task and 'stub' not in task:
169-
skip_tasks.append(task)
170167
print('Skipping building of %s, because we don\'t support threads and PIC code.' % ', '.join(skip_tasks))
171168
# cocos2d: must be ported, errors on
172169
# "Cannot recognize the target platform; are you targeting an unsupported platform?"

tests/test_other.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,6 @@ def test_node_emscripten_num_logical_cores(self):
25392539
puts("ok");
25402540
}
25412541
''')
2542-
# Pass -s USE_PTHREADS=1 to ensure we don't link against libpthread_stub.a
25432542
self.run_process([EMCC, 'src.cpp', '-s', 'USE_PTHREADS=1', '-s', 'ENVIRONMENT=node'])
25442543
ret = self.run_process(config.NODE_JS + ['--experimental-wasm-threads', 'a.out.js'], stdout=PIPE).stdout
25452544
self.assertContained('ok', ret)
@@ -4140,7 +4139,7 @@ class time_iterator {
41404139
# fail! not enough stdlibs
41414140
'partial_only': [{'EMCC_FORCE_STDLIBS': 'libc++,libc,libc++abi', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, True],
41424141
# force all the needed stdlibs, so this works even though we ignore the input file
4143-
'full_only': [{'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libpthread,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, False],
4142+
'full_only': [{'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}, False],
41444143
})
41454144
def test_only_force_stdlibs(self, env, fail):
41464145
with env_modify(env):
@@ -4167,7 +4166,7 @@ def test_only_force_stdlibs_2(self):
41674166
}
41684167
}
41694168
''')
4170-
with env_modify({'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libmalloc,libpthread', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
4169+
with env_modify({'EMCC_FORCE_STDLIBS': 'libc,libc++abi,libc++,libmalloc', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
41714170
self.run_process([EMXX, 'src.cpp', '-s', 'DISABLE_EXCEPTION_CATCHING=0'])
41724171
self.assertContained('Caught exception: std::exception', self.run_js('a.out.js'))
41734172

tools/system_libs.py

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,61 @@ def get_files(self):
751751
path_components=['system', 'lib', 'libc'],
752752
filenames=['extras.c', 'wasi-helpers.c'])
753753

754+
libc_files += files_in_path(
755+
path_components=['system', 'lib', 'pthread'],
756+
filenames=['emscripten_atomic.c'])
757+
758+
libc_files += files_in_path(
759+
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
760+
filenames=['pthread_self.c'])
761+
762+
if self.is_mt:
763+
libc_files += files_in_path(
764+
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
765+
filenames=[
766+
'pthread_attr_destroy.c', 'pthread_condattr_setpshared.c',
767+
'pthread_mutex_lock.c', 'pthread_spin_destroy.c', 'pthread_attr_get.c',
768+
'pthread_cond_broadcast.c', 'pthread_mutex_setprioceiling.c',
769+
'pthread_spin_init.c', 'pthread_attr_init.c', 'pthread_cond_destroy.c',
770+
'pthread_mutex_timedlock.c', 'pthread_spin_lock.c',
771+
'pthread_attr_setdetachstate.c', 'pthread_cond_init.c',
772+
'pthread_mutex_trylock.c', 'pthread_spin_trylock.c',
773+
'pthread_attr_setguardsize.c', 'pthread_cond_signal.c',
774+
'pthread_mutex_unlock.c', 'pthread_spin_unlock.c',
775+
'pthread_attr_setinheritsched.c', 'pthread_cond_timedwait.c',
776+
'pthread_once.c', 'sem_destroy.c', 'pthread_attr_setschedparam.c',
777+
'pthread_cond_wait.c', 'pthread_rwlockattr_destroy.c', 'sem_getvalue.c',
778+
'pthread_attr_setschedpolicy.c', 'pthread_equal.c', 'pthread_rwlockattr_init.c',
779+
'sem_init.c', 'pthread_attr_setscope.c', 'pthread_getspecific.c',
780+
'pthread_rwlockattr_setpshared.c', 'sem_open.c', 'pthread_attr_setstack.c',
781+
'pthread_key_create.c', 'pthread_rwlock_destroy.c', 'sem_post.c',
782+
'pthread_attr_setstacksize.c', 'pthread_mutexattr_destroy.c',
783+
'pthread_rwlock_init.c', 'sem_timedwait.c', 'pthread_barrierattr_destroy.c',
784+
'pthread_mutexattr_init.c', 'pthread_rwlock_rdlock.c', 'sem_trywait.c',
785+
'pthread_barrierattr_init.c', 'pthread_mutexattr_setprotocol.c',
786+
'pthread_rwlock_timedrdlock.c', 'sem_unlink.c',
787+
'pthread_barrierattr_setpshared.c', 'pthread_mutexattr_setpshared.c',
788+
'pthread_rwlock_timedwrlock.c', 'sem_wait.c', 'pthread_barrier_destroy.c',
789+
'pthread_mutexattr_setrobust.c', 'pthread_rwlock_tryrdlock.c',
790+
'__timedwait.c', 'pthread_barrier_init.c', 'pthread_mutexattr_settype.c',
791+
'pthread_rwlock_trywrlock.c', 'vmlock.c', 'pthread_barrier_wait.c',
792+
'pthread_mutex_consistent.c', 'pthread_rwlock_unlock.c', '__wait.c',
793+
'pthread_condattr_destroy.c', 'pthread_mutex_destroy.c',
794+
'pthread_rwlock_wrlock.c', 'pthread_condattr_init.c',
795+
'pthread_mutex_getprioceiling.c', 'pthread_setcanceltype.c',
796+
'pthread_condattr_setclock.c', 'pthread_mutex_init.c',
797+
'pthread_setspecific.c', 'pthread_setcancelstate.c',
798+
])
799+
libc_files += files_in_path(
800+
path_components=['system', 'lib', 'pthread'],
801+
filenames=[
802+
'library_pthread.c',
803+
'emscripten_tls_init.c',
804+
'emscripten_thread_state.s',
805+
])
806+
else:
807+
libc_files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
808+
754809
return libc_files
755810

756811

@@ -1152,67 +1207,6 @@ class libhtml5(Library):
11521207
src_glob = '*.c'
11531208

11541209

1155-
class libpthread(AsanInstrumentedLibrary, MuslInternalLibrary, MTLibrary):
1156-
name = 'libpthread'
1157-
cflags = ['-O2']
1158-
1159-
def get_files(self):
1160-
files = [shared.path_from_root('system', 'lib', 'pthread', 'emscripten_atomic.c')]
1161-
files += files_in_path(
1162-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
1163-
filenames=['pthread_self.c'])
1164-
if self.is_mt:
1165-
files += files_in_path(
1166-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
1167-
filenames=[
1168-
'pthread_attr_destroy.c', 'pthread_condattr_setpshared.c',
1169-
'pthread_mutex_lock.c', 'pthread_spin_destroy.c', 'pthread_attr_get.c',
1170-
'pthread_cond_broadcast.c', 'pthread_mutex_setprioceiling.c',
1171-
'pthread_spin_init.c', 'pthread_attr_init.c', 'pthread_cond_destroy.c',
1172-
'pthread_mutex_timedlock.c', 'pthread_spin_lock.c',
1173-
'pthread_attr_setdetachstate.c', 'pthread_cond_init.c',
1174-
'pthread_mutex_trylock.c', 'pthread_spin_trylock.c',
1175-
'pthread_attr_setguardsize.c', 'pthread_cond_signal.c',
1176-
'pthread_mutex_unlock.c', 'pthread_spin_unlock.c',
1177-
'pthread_attr_setinheritsched.c', 'pthread_cond_timedwait.c',
1178-
'pthread_once.c', 'sem_destroy.c', 'pthread_attr_setschedparam.c',
1179-
'pthread_cond_wait.c', 'pthread_rwlockattr_destroy.c', 'sem_getvalue.c',
1180-
'pthread_attr_setschedpolicy.c', 'pthread_equal.c', 'pthread_rwlockattr_init.c',
1181-
'sem_init.c', 'pthread_attr_setscope.c', 'pthread_getspecific.c',
1182-
'pthread_rwlockattr_setpshared.c', 'sem_open.c', 'pthread_attr_setstack.c',
1183-
'pthread_key_create.c', 'pthread_rwlock_destroy.c', 'sem_post.c',
1184-
'pthread_attr_setstacksize.c', 'pthread_mutexattr_destroy.c',
1185-
'pthread_rwlock_init.c', 'sem_timedwait.c', 'pthread_barrierattr_destroy.c',
1186-
'pthread_mutexattr_init.c', 'pthread_rwlock_rdlock.c', 'sem_trywait.c',
1187-
'pthread_barrierattr_init.c', 'pthread_mutexattr_setprotocol.c',
1188-
'pthread_rwlock_timedrdlock.c', 'sem_unlink.c',
1189-
'pthread_barrierattr_setpshared.c', 'pthread_mutexattr_setpshared.c',
1190-
'pthread_rwlock_timedwrlock.c', 'sem_wait.c', 'pthread_barrier_destroy.c',
1191-
'pthread_mutexattr_setrobust.c', 'pthread_rwlock_tryrdlock.c',
1192-
'__timedwait.c', 'pthread_barrier_init.c', 'pthread_mutexattr_settype.c',
1193-
'pthread_rwlock_trywrlock.c', 'vmlock.c', 'pthread_barrier_wait.c',
1194-
'pthread_mutex_consistent.c', 'pthread_rwlock_unlock.c', '__wait.c',
1195-
'pthread_condattr_destroy.c', 'pthread_mutex_destroy.c',
1196-
'pthread_rwlock_wrlock.c', 'pthread_condattr_init.c',
1197-
'pthread_mutex_getprioceiling.c', 'pthread_setcanceltype.c',
1198-
'pthread_condattr_setclock.c', 'pthread_mutex_init.c',
1199-
'pthread_setspecific.c', 'pthread_setcancelstate.c',
1200-
])
1201-
files += files_in_path(
1202-
path_components=['system', 'lib', 'pthread'],
1203-
filenames=[
1204-
'library_pthread.c',
1205-
'emscripten_tls_init.c',
1206-
'emscripten_thread_state.s',
1207-
])
1208-
else:
1209-
files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
1210-
return files
1211-
1212-
def get_base_name_prefix(self):
1213-
return 'libpthread' if self.is_mt else 'libpthread_stub'
1214-
1215-
12161210
class CompilerRTLibrary(Library):
12171211
cflags = ['-O2', '-fno-builtin']
12181212
# compiler_rt files can't currently be part of LTO although we are hoping to remove this
@@ -1540,7 +1534,6 @@ def add_library(lib):
15401534
add_library(system_libs_map['libunwind'])
15411535
if shared.Settings.MALLOC != 'none':
15421536
add_library(system_libs_map['libmalloc'])
1543-
add_library(system_libs_map['libpthread'])
15441537
if shared.Settings.STANDALONE_WASM:
15451538
add_library(system_libs_map['libstandalonewasm'])
15461539
add_library(system_libs_map['libc_rt_wasm'])

0 commit comments

Comments
 (0)