1 # Copyright (C) 2002-2025 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <https://www.gnu.org/licenses/>.
19 # Sub-makefile for NPTL portion of the library.
26 bits/atomic_wide_counter.h \
29 bits/struct_rwlock.h \
34 extra-libs := libpthread
35 extra-libs-others := $(extra-libs)
43 cleanup_defer_compat \
55 old_pthread_cond_broadcast \
56 old_pthread_cond_destroy \
57 old_pthread_cond_init \
58 old_pthread_cond_signal \
59 old_pthread_cond_timedwait \
60 old_pthread_cond_wait \
62 pthread_attr_destroy \
63 pthread_attr_extension \
64 pthread_attr_getaffinity \
65 pthread_attr_getdetachstate \
66 pthread_attr_getguardsize \
67 pthread_attr_getinheritsched \
68 pthread_attr_getschedparam \
69 pthread_attr_getschedpolicy \
70 pthread_attr_getscope \
71 pthread_attr_getsigmask \
72 pthread_attr_getstack \
73 pthread_attr_getstackaddr \
74 pthread_attr_getstacksize \
76 pthread_attr_setaffinity \
77 pthread_attr_setdetachstate \
78 pthread_attr_setguardsize \
79 pthread_attr_setinheritsched \
80 pthread_attr_setschedparam \
81 pthread_attr_setschedpolicy \
82 pthread_attr_setscope \
83 pthread_attr_setsigmask \
84 pthread_attr_setsigmask_internal \
85 pthread_attr_setstack \
86 pthread_attr_setstackaddr \
87 pthread_attr_setstacksize \
88 pthread_barrier_destroy \
89 pthread_barrier_init \
90 pthread_barrier_wait \
91 pthread_barrierattr_destroy \
92 pthread_barrierattr_getpshared \
93 pthread_barrierattr_init \
94 pthread_barrierattr_setpshared \
96 pthread_cleanup_upto \
98 pthread_cond_broadcast \
99 pthread_cond_destroy \
101 pthread_cond_signal \
103 pthread_condattr_destroy \
104 pthread_condattr_getclock \
105 pthread_condattr_getpshared \
106 pthread_condattr_init \
107 pthread_condattr_setclock \
108 pthread_condattr_setpshared \
113 pthread_getaffinity \
114 pthread_getattr_default_np \
116 pthread_getconcurrency \
117 pthread_getcpuclockid \
119 pthread_getschedparam \
120 pthread_getspecific \
123 pthread_join_common \
128 pthread_kill_other_threads \
129 pthread_mutex_cond_lock \
131 pthread_mutex_consistent \
132 pthread_mutex_destroy \
133 pthread_mutex_getprioceiling \
136 pthread_mutex_setprioceiling \
137 pthread_mutex_timedlock \
138 pthread_mutex_trylock \
139 pthread_mutex_unlock \
140 pthread_mutexattr_destroy \
141 pthread_mutexattr_getprioceiling \
142 pthread_mutexattr_getprotocol \
143 pthread_mutexattr_getpshared \
144 pthread_mutexattr_getrobust \
145 pthread_mutexattr_gettype \
146 pthread_mutexattr_init \
147 pthread_mutexattr_setprioceiling \
148 pthread_mutexattr_setprotocol \
149 pthread_mutexattr_setpshared \
150 pthread_mutexattr_setrobust \
151 pthread_mutexattr_settype \
153 pthread_rwlock_clockrdlock \
154 pthread_rwlock_clockwrlock \
155 pthread_rwlock_destroy \
156 pthread_rwlock_init \
157 pthread_rwlock_rdlock \
158 pthread_rwlock_timedrdlock \
159 pthread_rwlock_timedwrlock \
160 pthread_rwlock_tryrdlock \
161 pthread_rwlock_trywrlock \
162 pthread_rwlock_unlock \
163 pthread_rwlock_wrlock \
164 pthread_rwlockattr_destroy \
165 pthread_rwlockattr_getkind_np \
166 pthread_rwlockattr_getpshared \
167 pthread_rwlockattr_init \
168 pthread_rwlockattr_setkind_np \
169 pthread_rwlockattr_setpshared \
171 pthread_setaffinity \
172 pthread_setattr_default_np \
173 pthread_setcancelstate \
174 pthread_setcanceltype \
175 pthread_setconcurrency \
177 pthread_setschedparam \
178 pthread_setschedprio \
179 pthread_setspecific \
182 pthread_spin_destroy \
185 pthread_spin_trylock \
186 pthread_spin_unlock \
208 libpthread-routines = libpthread-compat
209 libpthread-shared-only-routines = libpthread-compat
211 # Pretend that libpthread.so is a linker script, so that the symbolic
212 # link is not installed.
213 install-lib-ldscripts = libpthread.so
214 $(inst_libdir)/libpthread.so:
216 # Since cancellation handling is in large parts handled using exceptions
217 # we have to compile some files with exception handling enabled, some
218 # even with asynchronous unwind tables.
220 # nptl-init.c contains sigcancel_handler().
221 CFLAGS-nptl-init.c += -fexceptions -fasynchronous-unwind-tables
222 # The unwind code itself,
223 CFLAGS-unwind.c += -fexceptions
224 CFLAGS-unwind-forcedunwind.c += -fexceptions -fasynchronous-unwind-tables
226 # The following three functions must be async-cancel safe.
227 CFLAGS-pthread_cancel.c += -fexceptions -fasynchronous-unwind-tables
228 CFLAGS-pthread_setcancelstate.c += -fexceptions -fasynchronous-unwind-tables
229 CFLAGS-pthread_setcanceltype.c += -fexceptions -fasynchronous-unwind-tables
231 # These are internal functions which similar functionality as setcancelstate
233 CFLAGS-cancellation.c += -fexceptions -fasynchronous-unwind-tables
234 CFLAGS-syscall_cancel.c += -fexceptions -fasynchronous-unwind-tables
236 # Calling pthread_exit() must cause the registered cancel handlers to
237 # be executed. Therefore exceptions have to be thrown through this
239 CFLAGS-pthread_exit.c += -fexceptions
241 # Among others, __pthread_unwind is forwarded. This function must handle
243 CFLAGS-forward.c += -fexceptions
245 # The following are cancellation points. Some of the functions can
246 # block and therefore temporarily enable asynchronous cancellation.
247 # Those must be compiled asynchronous unwind tables.
248 CFLAGS-pthread_testcancel.c += -fexceptions
249 CFLAGS-pthread_join.c += -fexceptions -fasynchronous-unwind-tables
250 CFLAGS-pthread_timedjoin.c += -fexceptions -fasynchronous-unwind-tables
251 CFLAGS-pthread_clockjoin.c += -fexceptions -fasynchronous-unwind-tables
252 CFLAGS-pthread_once.c += $(uses-callbacks) -fexceptions \
253 -fasynchronous-unwind-tables
254 CFLAGS-pthread_cond_wait.c += -fexceptions -fasynchronous-unwind-tables
255 CFLAGS-pthread_kill.c = -fexceptions -fasynchronous-unwind-tables
256 CFLAGS-sem_wait.c += -fexceptions -fasynchronous-unwind-tables
257 CFLAGS-sem_timedwait.c += -fexceptions -fasynchronous-unwind-tables
258 CFLAGS-sem_clockwait.c = -fexceptions -fasynchronous-unwind-tables
260 CFLAGS-futex-internal.c += -fexceptions -fasynchronous-unwind-tables
262 LDLIBS-tst-once5 = -lstdc++
263 CFLAGS-tst-thread_local1.o = -std=gnu++11
264 LDLIBS-tst-thread_local1 = -lstdc++
265 CFLAGS-tst-thread-exit-clobber.o = -std=gnu++11
266 LDLIBS-tst-thread-exit-clobber = -lstdc++
267 CFLAGS-tst-minstack-throw.o = -std=gnu++11
268 LDLIBS-tst-minstack-throw = -lstdc++
288 tst-initializers1-c11 \
289 tst-initializers1-c89 \
290 tst-initializers1-c99 \
291 tst-initializers1-gnu11 \
292 tst-initializers1-gnu89 \
293 tst-initializers1-gnu99 \
294 tst-minstack-cancel \
311 tst-pthread-affinity-inheritance \
312 tst-pthread-attr-affinity \
313 tst-pthread-attr-affinity-fail \
314 tst-pthread-attr-sigmask \
315 tst-pthread-defaultattr-free \
316 tst-pthread-gdb-attach \
317 tst-pthread-gdb-attach-static \
318 tst-pthread-getcpuclockid-invalid \
319 tst-pthread-key1-static \
320 tst-pthread-timedlock-lockloop \
321 tst-pthread_exit-nothreads \
322 tst-pthread_exit-nothreads-static \
323 tst-pthread_gettid_np \
353 tst-thread-affinity-pthread \
354 tst-thread-affinity-pthread2 \
355 tst-thread-affinity-sched \
356 tst-thread-exit-clobber \
357 tst-thread-setspecific \
363 tests-nolibpthread = \
364 tst-pthread_exit-nothreads \
365 tst-pthread_exit-nothreads-static \
368 tests-container = tst-pthread-getattr
377 tst-mutexpi8-static \
404 # This test can run into task limits because of a linux kernel bug
405 # and then cause the make process to fail too, see bug 24537.
408 test-srcs = tst-oddstacklimit
410 gen-as-const-headers = \
413 # gen-as-const-headers
415 gen-py-const-headers := nptl_lock_constants.pysym
416 pretty-printers := nptl-printers.py
419 test-condattr-printers \
420 test-mutex-printers \
421 test-mutexattr-printers \
422 test-rwlock-printers \
423 test-rwlockattr-printers \
426 # We must specify both CFLAGS and CPPFLAGS to override any
427 # compiler options the user might have provided that conflict
428 # with what we need e.g. user specifies CPPFLAGS with -O2 and
430 CFLAGS-test-mutexattr-printers.c := $(CFLAGS-printers-tests)
431 CFLAGS-test-mutex-printers.c := $(CFLAGS-printers-tests)
432 CFLAGS-test-condattr-printers.c := $(CFLAGS-printers-tests)
433 CFLAGS-test-cond-printers.c := $(CFLAGS-printers-tests)
434 CFLAGS-test-rwlockattr-printers.c := $(CFLAGS-printers-tests)
435 CFLAGS-test-rwlock-printers.c := $(CFLAGS-printers-tests)
436 CPPFLAGS-test-mutexattr-printers.c := $(CFLAGS-printers-tests)
437 CPPFLAGS-test-mutex-printers.c := $(CFLAGS-printers-tests)
438 CPPFLAGS-test-condattr-printers.c := $(CFLAGS-printers-tests)
439 CPPFLAGS-test-cond-printers.c := $(CFLAGS-printers-tests)
440 CPPFLAGS-test-rwlockattr-printers.c := $(CFLAGS-printers-tests)
441 CPPFLAGS-test-rwlock-printers.c := $(CFLAGS-printers-tests)
443 # Reuse the CFLAGS setting for the GDB attaching test. It needs
444 # debugging information.
445 CFLAGS-tst-pthread-gdb-attach.c := $(CFLAGS-printers-tests)
446 CPPFLAGS-tst-pthread-gdb-attach.c := $(CFLAGS-printers-tests)
447 ifeq ($(build-shared)$(build-hardcoded-path-in-tests),yesno)
448 CPPFLAGS-tst-pthread-gdb-attach.c += -DDO_ADD_SYMBOL_FILE=1
450 CPPFLAGS-tst-pthread-gdb-attach.c += -DDO_ADD_SYMBOL_FILE=0
452 CFLAGS-tst-pthread-gdb-attach-static.c := $(CFLAGS-printers-tests)
453 CPPFLAGS-tst-pthread-gdb-attach-static.c := \
454 $(CFLAGS-printers-tests) -DDO_ADD_SYMBOL_FILE=0
455 # As of version 9.2, GDB cannot attach properly to PIE programs that
456 # were launched with an explicit ld.so invocation.
457 tst-pthread-gdb-attach-no-pie = yes
464 ifeq ($(build-shared),yes)
467 tst-compat-forwarder \
475 ifeq ($(have-z-execstack)$(have-test-cc-trampoline),yesyes)
476 tests += tst-execstack-threads
481 tst-audit-threads-mod1 \
482 tst-audit-threads-mod2 \
483 tst-compat-forwarder-mod \
495 $(addsuffix .os,$(strip $(modules-names))) \
504 ifneq ($(have-test-clang),yes)
506 tst-execstack-threads-mod \
510 # This test exercises compat symbols removed in glibc 2.34.
511 ifdef have-GLIBC_2.33
512 tests += tst-cleanup4
513 ifeq ($(build-shared),yes)
514 tests += tst-cleanupx4
518 tst-tls3mod.so-no-z-defs = yes
519 tst-tls5mod.so-no-z-defs = yes
520 tst-tls5moda.so-no-z-defs = yes
521 tst-tls5modb.so-no-z-defs = yes
522 tst-tls5modc.so-no-z-defs = yes
523 tst-tls5modd.so-no-z-defs = yes
524 tst-tls5mode.so-no-z-defs = yes
525 tst-tls5modf.so-no-z-defs = yes
527 ifeq ($(build-shared),yes)
529 # Set the `multidir' variable by grabbing the variable from the compiler.
530 # We do it once and save the result in a generated makefile.
531 -include $(objpfx)multidir.mk
532 $(objpfx)multidir.mk: $(common-objpfx)config.make
533 $(make-target-directory)
534 dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
535 echo "multidir := $$dir" > $@T
540 CFLAGS-ftrylockfile.c += $(libio-mtsafe)
541 CFLAGS-funlockfile.c += $(libio-mtsafe)
543 link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
544 $(common-objpfx)libc.a
547 tst-cancel24-static \
549 tst-mutexpi8-static \
550 tst-pthread-gdb-attach-static \
551 tst-pthread-key1-static \
552 tst-pthread_exit-nothreads-static \
554 tst-sem12-static tst-cond11-static \
555 tst-stackguard1-static \
558 tests += tst-cancel24-static
559 ifeq ($(static-cxx-tests),no)
560 tests-unsupported += tst-cancel24-static
566 tst-stackguard1-static \
568 xtests-static += tst-setuid1-static
570 ifeq ($(run-built-tests),yes)
572 $(objpfx)tst-dl-debug-tid.out \
573 $(objpfx)tst-oddstacklimit.out \
575 ifeq ($(build-shared),yes)
576 tests-special += $(objpfx)tst-tls6.out
578 tests-special += $(objpfx)tst-stack3-mem.out
584 # These tests require a C++ compiler and runtime.
585 tests-unsupported += \
587 tst-cancel24-static \
590 tst-thread-exit-clobber \
593 # These tests require a C++ compiler and runtime with thread_local support.
594 ifneq ($(have-cxx-thread_local),yes)
595 tests-unsupported += tst-thread_local1
600 ifeq (yes,$(build-shared))
601 # Make sure these things are built in the `make lib' pass so they can be used
602 # to run programs during the `make others' pass.
603 lib-noranlib: $(addprefix $(objpfx),$(extra-objs))
607 # 'pthread_self' is a simple memory or register load. Setting up the
608 # stack frame is more work than the actual operation. Disable the
609 # frame creation entirely. This will help applications which call the
610 # function frequently to get a thread-specific handle.
611 CFLAGS-pthread_self.os += -fomit-frame-pointer
613 # Run the cancellation and cleanup tests also for the modern, exception-based
614 # implementation. For this we have to pass the -fexceptions parameter.
615 CFLAGS-tst-cancelx7.c += -fexceptions
616 CFLAGS-tst-cancelx17.c += -fexceptions
617 CFLAGS-tst-cleanupx4.c += -fexceptions
618 CFLAGS-tst-cleanupx4aux.c += -fexceptions
619 CFLAGS-tst-initializers1.c += -W -Wall -Werror
620 CFLAGS-tst-initializers1-< = $(CFLAGS-tst-initializers1.c) \
621 $(patsubst tst-initializers1-%.c,-std=%,$<)
622 CFLAGS-tst-initializers1-c89.c += $(CFLAGS-tst-initializers1-<)
623 CFLAGS-tst-initializers1-c99.c += $(CFLAGS-tst-initializers1-<)
624 CFLAGS-tst-initializers1-c11.c += $(CFLAGS-tst-initializers1-<)
625 CFLAGS-tst-initializers1-gnu89.c += $(CFLAGS-tst-initializers1-<)
626 CFLAGS-tst-initializers1-gnu99.c += $(CFLAGS-tst-initializers1-<)
627 CFLAGS-tst-initializers1-gnu11.c += $(CFLAGS-tst-initializers1-<)
629 tst-cancel7-ARGS = --command "exec $(host-test-program-cmd)"
630 tst-cancelx7-ARGS = $(tst-cancel7-ARGS)
632 tst-stack3-ENV = MALLOC_TRACE=$(objpfx)tst-stack3.mtrace \
633 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
634 $(objpfx)tst-stack3-mem.out: $(objpfx)tst-stack3.out
635 $(common-objpfx)malloc/mtrace $(objpfx)tst-stack3.mtrace > $@; \
638 ifeq ($(run-built-tests),yes)
639 ifeq (yes,$(build-shared))
649 tst-stack4mod.sos=$(shell for i in 0 1 2 3 4 5 6 7 8 9 10 \
650 11 12 13 14 15 16 17 18 19; do \
651 for j in 0 1 2 3 4 5 6 7 8 9 10 \
652 11 12 13 14 15 16 17 18 19; do \
653 echo $(objpfx)tst-stack4mod-$$i-$$j.so; \
655 $(objpfx)tst-stack4.out: $(tst-stack4mod.sos)
656 $(tst-stack4mod.sos): $(objpfx)tst-stack4mod.so
659 rm -f $(tst-stack4mod.sos)
661 $(objpfx)tst-cleanup4: $(objpfx)tst-cleanup4aux.o
662 $(objpfx)tst-cleanupx4: $(objpfx)tst-cleanupx4aux.o
664 LDFLAGS-tst-tls3 = -rdynamic
665 LDFLAGS-tst-tls3mod.so = -Wl,-z,lazy
666 $(objpfx)tst-tls3.out: $(objpfx)tst-tls3mod.so
668 LDFLAGS-tst-tls3-malloc = -rdynamic
669 $(objpfx)tst-tls3-malloc.out: $(objpfx)tst-tls3mod.so
671 $(objpfx)tst-tls5: $(objpfx)tst-tls5mod.so
672 LDFLAGS-tst-tls5 = -Wl,--no-as-needed
673 LDFLAGS-tst-tls5mod.so = -Wl,-soname,tst-tls5mod.so
675 ifeq ($(build-shared),yes)
676 $(objpfx)tst-tls6.out: tst-tls6.sh $(objpfx)tst-tls5 \
677 $(objpfx)tst-tls5moda.so $(objpfx)tst-tls5modb.so \
678 $(objpfx)tst-tls5modc.so $(objpfx)tst-tls5modd.so \
679 $(objpfx)tst-tls5mode.so $(objpfx)tst-tls5modf.so
680 $(BASH) $< $(common-objpfx) '$(test-via-rtld-prefix)' \
681 '$(test-wrapper-env)' '$(run-program-env)'; \
685 LDLIBS-tst-cancel24 = -Wl,--no-as-needed -lstdc++
686 LDLIBS-tst-cancel24-static = $(LDLIBS-tst-cancel24)
688 ifeq ($(build-shared),yes)
696 tst-exec4-ARGS = $(host-test-program-cmd)
698 $(objpfx)tst-execstack-threads.out: $(objpfx)tst-execstack-threads-mod.so
699 LDFLAGS-tst-execstack-threads = -Wl,-z,noexecstack
700 LDFLAGS-tst-execstack-threads-mod.so = -Wl,-z,execstack
701 CFLAGS-tst-execstack-threads-mod.c += -Wno-trampolines
702 ifeq ($(have-no-error-execstack),yes)
703 LDFLAGS-tst-execstack-threads-mod.so += -Wl,--no-error-execstack
706 tst-stackguard1-ARGS = --command "$(host-test-program-cmd) --child"
707 tst-stackguard1-static-ARGS = --command "$(objpfx)tst-stackguard1-static --child"
709 ifeq ($(run-built-tests),yes)
710 $(objpfx)tst-dl-debug-tid.out: tst-dl-debug-tid.sh $(objpfx)tst-dl-debug-tid
711 $(SHELL) $< $(common-objpfx) '$(test-wrapper)' '$(rtld-prefix)' \
712 '$(test-wrapper-env)' '$(run-program-env)' \
713 $(objpfx)tst-dl-debug-tid > $@; $(evaluate-test)
715 $(objpfx)tst-oddstacklimit.out: $(objpfx)tst-oddstacklimit $(objpfx)tst-basic1
716 $(test-program-prefix) $< --command '$(host-test-program-cmd)' > $@; \
720 $(objpfx)tst-compat-forwarder: $(objpfx)tst-compat-forwarder-mod.so
722 # Protect against a build using -Wl,-z,now.
723 LDFLAGS-tst-audit-threads-mod1.so = -Wl,-z,lazy
724 LDFLAGS-tst-audit-threads-mod2.so = -Wl,-z,lazy
725 LDFLAGS-tst-audit-threads = -Wl,-z,lazy
726 $(objpfx)tst-audit-threads: $(objpfx)tst-audit-threads-mod2.so
727 $(objpfx)tst-audit-threads.out: $(objpfx)tst-audit-threads-mod1.so
728 tst-audit-threads-ENV = LD_AUDIT=$(objpfx)tst-audit-threads-mod1.so
730 # The test uses dlopen indirectly and would otherwise load system
732 tst-setuid1-static-ENV = \
733 LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)elf:$(common-objpfx)nss
735 tst-pthread-proc-maps-ENV = \
736 GLIBC_TUNABLES=glibc.malloc.arena_max=8:glibc.malloc.mmap_threshold=1024
737 tst-pthread-proc-maps-ARGS = 8
739 # The tests here better do not run in parallel.
740 ifeq ($(run-built-tests),yes)
741 ifneq ($(filter %tests,$(MAKECMDGOALS)),)