@@ -984,6 +984,138 @@ class libnoexit(Library):
984984 src_files = ['atexit_dummy.c' ]
985985
986986
987+ class libpthread (MuslInternalLibrary ,
988+ DebugLibrary ,
989+ AsanInstrumentedLibrary ):
990+ name = 'libpthread'
991+ # See libc
992+ cflags = ['-Os' , '-fno-inline-functions' , '-fno-builtin' ]
993+ cflags += ['-Wno-unused-but-set-variable' ,
994+ '-Wno-unused-variable' ,
995+ '-Wno-shift-op-parentheses' ,
996+ '-Wno-unused-label' ,
997+ '-Wno-logical-op-parentheses' ,
998+ '-Wno-bitwise-op-parentheses' ]
999+
1000+ def __init__ (self , ** kwargs ):
1001+ self .is_stub = kwargs .pop ('stub' )
1002+ super ().__init__ (** kwargs )
1003+
1004+ def get_cflags (self ):
1005+ cflags = super ().get_cflags ()
1006+ if not self .is_stub :
1007+ cflags += ['-pthread' ]
1008+ return cflags
1009+
1010+ def get_base_name (self ):
1011+ name = super ().get_base_name ()
1012+ if self .is_stub :
1013+ name += '-stub'
1014+ return name
1015+
1016+ @classmethod
1017+ def vary_on (cls ):
1018+ return super ().vary_on () + ['stub' ]
1019+
1020+ @classmethod
1021+ def get_default_variation (cls , ** kwargs ):
1022+ return super ().get_default_variation (stub = not settings .PTHREADS , ** kwargs )
1023+
1024+ def get_files (self ):
1025+ files = files_in_path (
1026+ path = 'system/lib/pthread' ,
1027+ filenames = ['thread_profiler.c' ])
1028+
1029+ if self .is_stub :
1030+ # Include just a subset of the thread directory
1031+ files += files_in_path (
1032+ path = 'system/lib/libc/musl/src/thread' ,
1033+ filenames = [
1034+ 'pthread_self.c' ,
1035+ 'pthread_cleanup_push.c' ,
1036+ 'pthread_attr_init.c' ,
1037+ 'pthread_attr_destroy.c' ,
1038+ 'pthread_attr_get.c' ,
1039+ 'pthread_attr_setdetachstate.c' ,
1040+ 'pthread_attr_setguardsize.c' ,
1041+ 'pthread_attr_setinheritsched.c' ,
1042+ 'pthread_attr_setschedparam.c' ,
1043+ 'pthread_attr_setschedpolicy.c' ,
1044+ 'pthread_attr_setscope.c' ,
1045+ 'pthread_attr_setstack.c' ,
1046+ 'pthread_attr_setstacksize.c' ,
1047+ 'pthread_getconcurrency.c' ,
1048+ 'pthread_getcpuclockid.c' ,
1049+ 'pthread_getschedparam.c' ,
1050+ 'pthread_setschedprio.c' ,
1051+ 'pthread_setconcurrency.c' ,
1052+ 'default_attr.c' ,
1053+ # C11 thread library functions
1054+ 'call_once.c' ,
1055+ 'tss_create.c' ,
1056+ 'tss_delete.c' ,
1057+ 'tss_set.c' ,
1058+ 'cnd_broadcast.c' ,
1059+ 'cnd_destroy.c' ,
1060+ 'cnd_init.c' ,
1061+ 'cnd_signal.c' ,
1062+ 'cnd_timedwait.c' ,
1063+ 'cnd_wait.c' ,
1064+ 'mtx_destroy.c' ,
1065+ 'mtx_init.c' ,
1066+ 'mtx_lock.c' ,
1067+ 'mtx_timedlock.c' ,
1068+ 'mtx_trylock.c' ,
1069+ 'mtx_unlock.c' ,
1070+ 'thrd_create.c' ,
1071+ 'thrd_exit.c' ,
1072+ 'thrd_join.c' ,
1073+ 'thrd_sleep.c' ,
1074+ 'thrd_yield.c' ,
1075+ ])
1076+ files += files_in_path (
1077+ path = 'system/lib/pthread' ,
1078+ filenames = [
1079+ 'library_pthread_stub.c' ,
1080+ 'pthread_self_stub.c' ,
1081+ 'proxying_stub.c' ,
1082+ ])
1083+ else :
1084+ files += glob_in_path (
1085+ path = 'system/lib/libc/musl/src/thread' ,
1086+ glob_pattern = '*.c' ,
1087+ excludes = [
1088+ 'clone.c' ,
1089+ 'pthread_create.c' ,
1090+ 'pthread_kill.c' , 'pthread_sigmask.c' ,
1091+ '__set_thread_area.c' , 'synccall.c' ,
1092+ '__syscall_cp.c' , '__tls_get_addr.c' ,
1093+ '__unmapself.c' ,
1094+ # Empty files, simply ignore them.
1095+ 'syscall_cp.c' , 'tls.c' ,
1096+ # TODO: Support these. See #12216.
1097+ 'pthread_setname_np.c' ,
1098+ 'pthread_getname_np.c' ,
1099+ ])
1100+ files += files_in_path (
1101+ path = 'system/lib/pthread' ,
1102+ filenames = [
1103+ 'library_pthread.c' ,
1104+ 'em_task_queue.c' ,
1105+ 'proxying.c' ,
1106+ 'proxying_legacy.c' ,
1107+ 'thread_mailbox.c' ,
1108+ 'pthread_create.c' ,
1109+ 'pthread_kill.c' ,
1110+ 'emscripten_thread_init.c' ,
1111+ 'emscripten_thread_state.S' ,
1112+ 'emscripten_futex_wait.c' ,
1113+ 'emscripten_futex_wake.c' ,
1114+ 'emscripten_yield.c' ,
1115+ ])
1116+ return files
1117+
1118+
9871119class libc (MuslInternalLibrary ,
9881120 DebugLibrary ,
9891121 AsanInstrumentedLibrary ,
@@ -1098,7 +1230,7 @@ def get_files(self):
10981230 ignore = [
10991231 'ipc' , 'passwd' , 'signal' , 'sched' , 'time' , 'linux' ,
11001232 'aio' , 'exit' , 'legacy' , 'mq' , 'setjmp' ,
1101- 'ldso' , 'malloc'
1233+ 'ldso' , 'malloc' , 'thread'
11021234 ]
11031235
11041236 # individual files
@@ -1120,91 +1252,6 @@ def get_files(self):
11201252
11211253 ignore += LIBC_SOCKETS
11221254
1123- if self .is_mt :
1124- ignore += [
1125- 'clone.c' ,
1126- 'pthread_create.c' ,
1127- 'pthread_kill.c' , 'pthread_sigmask.c' ,
1128- '__set_thread_area.c' , 'synccall.c' ,
1129- '__syscall_cp.c' , '__tls_get_addr.c' ,
1130- '__unmapself.c' ,
1131- # Empty files, simply ignore them.
1132- 'syscall_cp.c' , 'tls.c' ,
1133- # TODO: Support these. See #12216.
1134- 'pthread_setname_np.c' ,
1135- 'pthread_getname_np.c' ,
1136- ]
1137- libc_files += files_in_path (
1138- path = 'system/lib/pthread' ,
1139- filenames = [
1140- 'library_pthread.c' ,
1141- 'em_task_queue.c' ,
1142- 'proxying.c' ,
1143- 'proxying_legacy.c' ,
1144- 'thread_mailbox.c' ,
1145- 'pthread_create.c' ,
1146- 'pthread_kill.c' ,
1147- 'emscripten_thread_init.c' ,
1148- 'emscripten_thread_state.S' ,
1149- 'emscripten_futex_wait.c' ,
1150- 'emscripten_futex_wake.c' ,
1151- 'emscripten_yield.c' ,
1152- ])
1153- else :
1154- ignore += ['thread' ]
1155- libc_files += files_in_path (
1156- path = 'system/lib/libc/musl/src/thread' ,
1157- filenames = [
1158- 'pthread_self.c' ,
1159- 'pthread_cleanup_push.c' ,
1160- 'pthread_attr_init.c' ,
1161- 'pthread_attr_destroy.c' ,
1162- 'pthread_attr_get.c' ,
1163- 'pthread_attr_setdetachstate.c' ,
1164- 'pthread_attr_setguardsize.c' ,
1165- 'pthread_attr_setinheritsched.c' ,
1166- 'pthread_attr_setschedparam.c' ,
1167- 'pthread_attr_setschedpolicy.c' ,
1168- 'pthread_attr_setscope.c' ,
1169- 'pthread_attr_setstack.c' ,
1170- 'pthread_attr_setstacksize.c' ,
1171- 'pthread_getconcurrency.c' ,
1172- 'pthread_getcpuclockid.c' ,
1173- 'pthread_getschedparam.c' ,
1174- 'pthread_setschedprio.c' ,
1175- 'pthread_setconcurrency.c' ,
1176- 'default_attr.c' ,
1177- # C11 thread library functions
1178- 'call_once.c' ,
1179- 'tss_create.c' ,
1180- 'tss_delete.c' ,
1181- 'tss_set.c' ,
1182- 'cnd_broadcast.c' ,
1183- 'cnd_destroy.c' ,
1184- 'cnd_init.c' ,
1185- 'cnd_signal.c' ,
1186- 'cnd_timedwait.c' ,
1187- 'cnd_wait.c' ,
1188- 'mtx_destroy.c' ,
1189- 'mtx_init.c' ,
1190- 'mtx_lock.c' ,
1191- 'mtx_timedlock.c' ,
1192- 'mtx_trylock.c' ,
1193- 'mtx_unlock.c' ,
1194- 'thrd_create.c' ,
1195- 'thrd_exit.c' ,
1196- 'thrd_join.c' ,
1197- 'thrd_sleep.c' ,
1198- 'thrd_yield.c' ,
1199- ])
1200- libc_files += files_in_path (
1201- path = 'system/lib/pthread' ,
1202- filenames = [
1203- 'library_pthread_stub.c' ,
1204- 'pthread_self_stub.c' ,
1205- 'proxying_stub.c' ,
1206- ])
1207-
12081255 # These files are in libc directories, but only built in libc_optz.
12091256 ignore += [
12101257 'pow_small.c' , 'log_small.c' , 'log2_small.c'
@@ -1322,10 +1369,6 @@ def get_files(self):
13221369 if settings .RELOCATABLE :
13231370 libc_files += files_in_path (path = 'system/lib/libc' , filenames = ['dynlink.c' ])
13241371
1325- libc_files += files_in_path (
1326- path = 'system/lib/pthread' ,
1327- filenames = ['thread_profiler.c' ])
1328-
13291372 libc_files += glob_in_path ('system/lib/libc/compat' , '*.c' )
13301373
13311374 # Check for missing file in non_lto_files list. Do this here
@@ -2378,6 +2421,7 @@ def add_sanitizer_libs():
23782421 if settings .ALLOW_UNIMPLEMENTED_SYSCALLS :
23792422 add_library ('libstubs' )
23802423 if not options .nolibc :
2424+ add_library ('libpthread' )
23812425 if not settings .EXIT_RUNTIME :
23822426 add_library ('libnoexit' )
23832427 add_library ('libc' )
0 commit comments