Skip to content

Commit 3e34bdf

Browse files
committed
Transform pthread allow list to deny list
Since that's easier to maintain. This commit also ensures that the following files are included during complication when targeting pthreads: cnd_broadcast.c cnd_destroy.c cnd_init.c cnd_signal.c cnd_timedwait.c cnd_wait.c mtx_destroy.c mtx_init.c mtx_lock.c mtx_timedlock.c mtx_trylock.c mtx_unlock.c pthread_setattr_default_np.c tss_create.c tss_delete.c tss_set.c
1 parent 5d8646d commit 3e34bdf

File tree

1 file changed

+36
-70
lines changed

1 file changed

+36
-70
lines changed

tools/system_libs.py

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def get_files(self):
678678

679679
# musl modules
680680
ignore = [
681-
'ipc', 'passwd', 'thread', 'signal', 'sched', 'ipc', 'time', 'linux',
681+
'ipc', 'passwd', 'signal', 'sched', 'ipc', 'time', 'linux',
682682
'aio', 'exit', 'legacy', 'mq', 'search', 'setjmp', 'env',
683683
'ldso', 'malloc'
684684
]
@@ -714,6 +714,41 @@ def get_files(self):
714714
shared.path_from_root('system', 'lib', 'libc', 'emscripten_asan_fcntl.c'),
715715
]
716716

717+
if self.is_mt:
718+
ignore += [
719+
'clone.c', '__lock.c',
720+
'pthread_cleanup_push.c', 'pthread_create.c',
721+
'pthread_kill.c', 'pthread_sigmask.c',
722+
'__set_thread_area.c', 'synccall.c',
723+
'__syscall_cp.c', '__tls_get_addr.c',
724+
'__unmapself.c',
725+
# Empty files, simply ignore them.
726+
'syscall_cp.c', 'tls.c',
727+
# TODO: Support this, see #12216.
728+
'pthread_setname_np.c',
729+
]
730+
libc_files += files_in_path(
731+
path_components=['system', 'lib', 'pthread'],
732+
filenames=[
733+
'library_pthread.c',
734+
'emscripten_thread_state.s',
735+
])
736+
else:
737+
ignore += ['thread']
738+
libc_files += files_in_path(
739+
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
740+
filenames=[
741+
'pthread_self.c',
742+
# C11 thread library functions
743+
'thrd_create.c',
744+
'thrd_exit.c',
745+
'thrd_join.c',
746+
'thrd_sleep.c',
747+
'thrd_yield.c',
748+
'call_once.c',
749+
])
750+
libc_files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
751+
717752
# These are included in wasm_libc_rt instead
718753
ignore += [os.path.basename(f) for f in get_wasm_libc_rt_files()]
719754

@@ -771,77 +806,8 @@ def get_files(self):
771806
path_components=['system', 'lib', 'pthread'],
772807
filenames=['emscripten_atomic.c'])
773808

774-
libc_files += files_in_path(
775-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
776-
filenames=[
777-
'pthread_self.c',
778-
# C11 thread library functions
779-
'thrd_create.c',
780-
'thrd_exit.c',
781-
'thrd_join.c',
782-
'thrd_sleep.c',
783-
'thrd_yield.c',
784-
'call_once.c',
785-
])
786-
787809
libc_files += glob_in_path(['system', 'lib', 'libc', 'compat'], '*.c')
788810

789-
if self.is_mt:
790-
libc_files += files_in_path(
791-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
792-
filenames=[
793-
# TODO(kleisauke): Perhaps we should transform this allow list to a deny list?
794-
'pthread_join.c', 'pthread_cancel.c',
795-
'pthread_testcancel.c', 'pthread_detach.c',
796-
'pthread_attr_destroy.c', 'pthread_condattr_setpshared.c',
797-
'pthread_mutex_lock.c', 'pthread_spin_destroy.c', 'pthread_attr_get.c',
798-
'pthread_cond_broadcast.c', 'pthread_mutex_setprioceiling.c',
799-
'pthread_spin_init.c', 'pthread_attr_init.c', 'pthread_cond_destroy.c',
800-
'pthread_mutex_timedlock.c', 'pthread_spin_lock.c',
801-
'pthread_attr_setdetachstate.c', 'pthread_cond_init.c',
802-
'pthread_mutex_trylock.c', 'pthread_spin_trylock.c',
803-
'pthread_attr_setguardsize.c', 'pthread_cond_signal.c',
804-
'pthread_mutex_unlock.c', 'pthread_spin_unlock.c',
805-
'pthread_attr_setinheritsched.c', 'pthread_cond_timedwait.c',
806-
'pthread_once.c', 'sem_destroy.c', 'pthread_attr_setschedparam.c',
807-
'pthread_cond_wait.c', 'pthread_rwlockattr_destroy.c', 'sem_getvalue.c',
808-
'pthread_attr_setschedpolicy.c', 'pthread_equal.c', 'pthread_rwlockattr_init.c',
809-
'sem_init.c', 'pthread_attr_setscope.c', 'pthread_getspecific.c',
810-
'pthread_rwlockattr_setpshared.c', 'sem_open.c', 'pthread_attr_setstack.c',
811-
'pthread_key_create.c', 'pthread_rwlock_destroy.c', 'sem_post.c',
812-
'pthread_attr_setstacksize.c', 'pthread_mutexattr_destroy.c',
813-
'pthread_rwlock_init.c', 'sem_timedwait.c', 'pthread_barrierattr_destroy.c',
814-
'pthread_mutexattr_init.c', 'pthread_rwlock_rdlock.c', 'sem_trywait.c',
815-
'pthread_barrierattr_init.c', 'pthread_mutexattr_setprotocol.c',
816-
'pthread_rwlock_timedrdlock.c', 'sem_unlink.c',
817-
'pthread_barrierattr_setpshared.c', 'pthread_mutexattr_setpshared.c',
818-
'pthread_rwlock_timedwrlock.c', 'sem_wait.c', 'pthread_barrier_destroy.c',
819-
'pthread_mutexattr_setrobust.c', 'pthread_rwlock_tryrdlock.c',
820-
'__timedwait.c', 'pthread_barrier_init.c', 'pthread_mutexattr_settype.c',
821-
'pthread_rwlock_trywrlock.c', 'vmlock.c', 'pthread_barrier_wait.c',
822-
'pthread_mutex_consistent.c', 'pthread_rwlock_unlock.c', '__wait.c',
823-
'pthread_condattr_destroy.c', 'pthread_mutex_destroy.c',
824-
'pthread_rwlock_wrlock.c', 'pthread_condattr_init.c',
825-
'pthread_mutex_getprioceiling.c', 'pthread_setcanceltype.c',
826-
'pthread_condattr_setclock.c', 'pthread_mutex_init.c',
827-
'pthread_setspecific.c', 'pthread_setcancelstate.c',
828-
'pthread_getconcurrency.c', 'pthread_setconcurrency.c',
829-
'pthread_getschedparam.c', 'pthread_setschedparam.c',
830-
'pthread_setschedprio.c', 'pthread_atfork.c',
831-
'pthread_getcpuclockid.c',
832-
'pthread_getattr_np.c',
833-
'default_attr.c',
834-
'lock_ptc.c',
835-
])
836-
libc_files += files_in_path(
837-
path_components=['system', 'lib', 'pthread'],
838-
filenames=[
839-
'library_pthread.c',
840-
'emscripten_thread_state.s',
841-
])
842-
else:
843-
libc_files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
844-
845811
return libc_files
846812

847813

0 commit comments

Comments
 (0)