@@ -970,6 +970,138 @@ class libnoexit(Library):
970970 src_files = ['atexit_dummy.c' ]
971971
972972
973+ class libpthread (MuslInternalLibrary ,
974+ DebugLibrary ,
975+ AsanInstrumentedLibrary ):
976+ name = 'libpthread'
977+ # See libc
978+ cflags = ['-Os' , '-fno-inline-functions' , '-fno-builtin' ]
979+ cflags += ['-Wno-unused-but-set-variable' ,
980+ '-Wno-unused-variable' ,
981+ '-Wno-shift-op-parentheses' ,
982+ '-Wno-unused-label' ,
983+ '-Wno-logical-op-parentheses' ,
984+ '-Wno-bitwise-op-parentheses' ]
985+
986+ def __init__ (self , ** kwargs ):
987+ self .is_stub = kwargs .pop ('stub' )
988+ super ().__init__ (** kwargs )
989+
990+ def get_cflags (self ):
991+ cflags = super ().get_cflags ()
992+ if not self .is_stub :
993+ cflags += ['-pthread' ]
994+ return cflags
995+
996+ def get_base_name (self ):
997+ name = super ().get_base_name ()
998+ if self .is_stub :
999+ name += '-stub'
1000+ return name
1001+
1002+ @classmethod
1003+ def vary_on (cls ):
1004+ return super ().vary_on () + ['stub' ]
1005+
1006+ @classmethod
1007+ def get_default_variation (cls , ** kwargs ):
1008+ return super ().get_default_variation (stub = not settings .PTHREADS , ** kwargs )
1009+
1010+ def get_files (self ):
1011+ files = files_in_path (
1012+ path = 'system/lib/pthread' ,
1013+ filenames = ['thread_profiler.c' ])
1014+
1015+ if self .is_stub :
1016+ # Include just a subset of the thread directory
1017+ files += files_in_path (
1018+ path = 'system/lib/libc/musl/src/thread' ,
1019+ filenames = [
1020+ 'pthread_self.c' ,
1021+ 'pthread_cleanup_push.c' ,
1022+ 'pthread_attr_init.c' ,
1023+ 'pthread_attr_destroy.c' ,
1024+ 'pthread_attr_get.c' ,
1025+ 'pthread_attr_setdetachstate.c' ,
1026+ 'pthread_attr_setguardsize.c' ,
1027+ 'pthread_attr_setinheritsched.c' ,
1028+ 'pthread_attr_setschedparam.c' ,
1029+ 'pthread_attr_setschedpolicy.c' ,
1030+ 'pthread_attr_setscope.c' ,
1031+ 'pthread_attr_setstack.c' ,
1032+ 'pthread_attr_setstacksize.c' ,
1033+ 'pthread_getconcurrency.c' ,
1034+ 'pthread_getcpuclockid.c' ,
1035+ 'pthread_getschedparam.c' ,
1036+ 'pthread_setschedprio.c' ,
1037+ 'pthread_setconcurrency.c' ,
1038+ 'default_attr.c' ,
1039+ # C11 thread library functions
1040+ 'call_once.c' ,
1041+ 'tss_create.c' ,
1042+ 'tss_delete.c' ,
1043+ 'tss_set.c' ,
1044+ 'cnd_broadcast.c' ,
1045+ 'cnd_destroy.c' ,
1046+ 'cnd_init.c' ,
1047+ 'cnd_signal.c' ,
1048+ 'cnd_timedwait.c' ,
1049+ 'cnd_wait.c' ,
1050+ 'mtx_destroy.c' ,
1051+ 'mtx_init.c' ,
1052+ 'mtx_lock.c' ,
1053+ 'mtx_timedlock.c' ,
1054+ 'mtx_trylock.c' ,
1055+ 'mtx_unlock.c' ,
1056+ 'thrd_create.c' ,
1057+ 'thrd_exit.c' ,
1058+ 'thrd_join.c' ,
1059+ 'thrd_sleep.c' ,
1060+ 'thrd_yield.c' ,
1061+ ])
1062+ files += files_in_path (
1063+ path = 'system/lib/pthread' ,
1064+ filenames = [
1065+ 'library_pthread_stub.c' ,
1066+ 'pthread_self_stub.c' ,
1067+ 'proxying_stub.c' ,
1068+ ])
1069+ else :
1070+ files += glob_in_path (
1071+ path = 'system/lib/libc/musl/src/thread' ,
1072+ glob_pattern = '*.c' ,
1073+ excludes = [
1074+ 'clone.c' ,
1075+ 'pthread_create.c' ,
1076+ 'pthread_kill.c' , 'pthread_sigmask.c' ,
1077+ '__set_thread_area.c' , 'synccall.c' ,
1078+ '__syscall_cp.c' , '__tls_get_addr.c' ,
1079+ '__unmapself.c' ,
1080+ # Empty files, simply ignore them.
1081+ 'syscall_cp.c' , 'tls.c' ,
1082+ # TODO: Support these. See #12216.
1083+ 'pthread_setname_np.c' ,
1084+ 'pthread_getname_np.c' ,
1085+ ])
1086+ files += files_in_path (
1087+ path = 'system/lib/pthread' ,
1088+ filenames = [
1089+ 'library_pthread.c' ,
1090+ 'em_task_queue.c' ,
1091+ 'proxying.c' ,
1092+ 'proxying_legacy.c' ,
1093+ 'thread_mailbox.c' ,
1094+ 'pthread_create.c' ,
1095+ 'pthread_kill.c' ,
1096+ 'emscripten_thread_init.c' ,
1097+ 'emscripten_thread_state.S' ,
1098+ 'emscripten_futex_wait.c' ,
1099+ 'emscripten_futex_wake.c' ,
1100+ 'emscripten_yield.c' ,
1101+ ])
1102+ return files
1103+
1104+
9731105class libc (MuslInternalLibrary ,
9741106 DebugLibrary ,
9751107 AsanInstrumentedLibrary ,
@@ -1083,7 +1215,7 @@ def get_files(self):
10831215 ignore = [
10841216 'ipc' , 'passwd' , 'signal' , 'sched' , 'time' , 'linux' ,
10851217 'aio' , 'exit' , 'legacy' , 'mq' , 'setjmp' ,
1086- 'ldso' , 'malloc'
1218+ 'ldso' , 'malloc' , 'thread'
10871219 ]
10881220
10891221 # individual files
@@ -1105,91 +1237,6 @@ def get_files(self):
11051237
11061238 ignore += LIBC_SOCKETS
11071239
1108- if self .is_mt :
1109- ignore += [
1110- 'clone.c' ,
1111- 'pthread_create.c' ,
1112- 'pthread_kill.c' , 'pthread_sigmask.c' ,
1113- '__set_thread_area.c' , 'synccall.c' ,
1114- '__syscall_cp.c' , '__tls_get_addr.c' ,
1115- '__unmapself.c' ,
1116- # Empty files, simply ignore them.
1117- 'syscall_cp.c' , 'tls.c' ,
1118- # TODO: Support these. See #12216.
1119- 'pthread_setname_np.c' ,
1120- 'pthread_getname_np.c' ,
1121- ]
1122- libc_files += files_in_path (
1123- path = 'system/lib/pthread' ,
1124- filenames = [
1125- 'library_pthread.c' ,
1126- 'em_task_queue.c' ,
1127- 'proxying.c' ,
1128- 'proxying_legacy.c' ,
1129- 'thread_mailbox.c' ,
1130- 'pthread_create.c' ,
1131- 'pthread_kill.c' ,
1132- 'emscripten_thread_init.c' ,
1133- 'emscripten_thread_state.S' ,
1134- 'emscripten_futex_wait.c' ,
1135- 'emscripten_futex_wake.c' ,
1136- 'emscripten_yield.c' ,
1137- ])
1138- else :
1139- ignore += ['thread' ]
1140- libc_files += files_in_path (
1141- path = 'system/lib/libc/musl/src/thread' ,
1142- filenames = [
1143- 'pthread_self.c' ,
1144- 'pthread_cleanup_push.c' ,
1145- 'pthread_attr_init.c' ,
1146- 'pthread_attr_destroy.c' ,
1147- 'pthread_attr_get.c' ,
1148- 'pthread_attr_setdetachstate.c' ,
1149- 'pthread_attr_setguardsize.c' ,
1150- 'pthread_attr_setinheritsched.c' ,
1151- 'pthread_attr_setschedparam.c' ,
1152- 'pthread_attr_setschedpolicy.c' ,
1153- 'pthread_attr_setscope.c' ,
1154- 'pthread_attr_setstack.c' ,
1155- 'pthread_attr_setstacksize.c' ,
1156- 'pthread_getconcurrency.c' ,
1157- 'pthread_getcpuclockid.c' ,
1158- 'pthread_getschedparam.c' ,
1159- 'pthread_setschedprio.c' ,
1160- 'pthread_setconcurrency.c' ,
1161- 'default_attr.c' ,
1162- # C11 thread library functions
1163- 'call_once.c' ,
1164- 'tss_create.c' ,
1165- 'tss_delete.c' ,
1166- 'tss_set.c' ,
1167- 'cnd_broadcast.c' ,
1168- 'cnd_destroy.c' ,
1169- 'cnd_init.c' ,
1170- 'cnd_signal.c' ,
1171- 'cnd_timedwait.c' ,
1172- 'cnd_wait.c' ,
1173- 'mtx_destroy.c' ,
1174- 'mtx_init.c' ,
1175- 'mtx_lock.c' ,
1176- 'mtx_timedlock.c' ,
1177- 'mtx_trylock.c' ,
1178- 'mtx_unlock.c' ,
1179- 'thrd_create.c' ,
1180- 'thrd_exit.c' ,
1181- 'thrd_join.c' ,
1182- 'thrd_sleep.c' ,
1183- 'thrd_yield.c' ,
1184- ])
1185- libc_files += files_in_path (
1186- path = 'system/lib/pthread' ,
1187- filenames = [
1188- 'library_pthread_stub.c' ,
1189- 'pthread_self_stub.c' ,
1190- 'proxying_stub.c' ,
1191- ])
1192-
11931240 # These files are in libc directories, but only built in libc_optz.
11941241 ignore += [
11951242 'pow_small.c' , 'log_small.c' , 'log2_small.c'
@@ -1305,10 +1352,6 @@ def get_files(self):
13051352 if settings .RELOCATABLE :
13061353 libc_files += files_in_path (path = 'system/lib/libc' , filenames = ['dynlink.c' ])
13071354
1308- libc_files += files_in_path (
1309- path = 'system/lib/pthread' ,
1310- filenames = ['thread_profiler.c' ])
1311-
13121355 libc_files += glob_in_path ('system/lib/libc/compat' , '*.c' )
13131356
13141357 # Check for missing file in non_lto_files list. Do this here
@@ -2377,6 +2420,7 @@ def add_sanitizer_libs():
23772420 if settings .ALLOW_UNIMPLEMENTED_SYSCALLS :
23782421 add_library ('libstubs' )
23792422 if '-nolibc' not in args :
2423+ add_library ('libpthread' )
23802424 if not settings .EXIT_RUNTIME :
23812425 add_library ('libnoexit' )
23822426 add_library ('libc' )
0 commit comments