1 # Copyright (C) 2002-2023 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 \
60 old_pthread_cond_broadcast \
61 old_pthread_cond_destroy \
62 old_pthread_cond_init \
63 old_pthread_cond_signal \
64 old_pthread_cond_timedwait \
65 old_pthread_cond_wait \
68 pthread_attr_destroy \
69 pthread_attr_extension \
70 pthread_attr_getaffinity \
71 pthread_attr_getdetachstate \
72 pthread_attr_getguardsize \
73 pthread_attr_getinheritsched \
74 pthread_attr_getschedparam \
75 pthread_attr_getschedpolicy \
76 pthread_attr_getscope \
77 pthread_attr_getsigmask \
78 pthread_attr_getstack \
79 pthread_attr_getstackaddr \
80 pthread_attr_getstacksize \
82 pthread_attr_setaffinity \
83 pthread_attr_setdetachstate \
84 pthread_attr_setguardsize \
85 pthread_attr_setinheritsched \
86 pthread_attr_setschedparam \
87 pthread_attr_setschedpolicy \
88 pthread_attr_setscope \
89 pthread_attr_setsigmask \
90 pthread_attr_setsigmask_internal \
91 pthread_attr_setstack \
92 pthread_attr_setstackaddr \
93 pthread_attr_setstacksize \
94 pthread_barrier_destroy \
95 pthread_barrier_init \
96 pthread_barrier_wait \
97 pthread_barrierattr_destroy \
98 pthread_barrierattr_getpshared \
99 pthread_barrierattr_init \
100 pthread_barrierattr_setpshared \
102 pthread_cleanup_upto \
104 pthread_cond_broadcast \
105 pthread_cond_destroy \
107 pthread_cond_signal \
109 pthread_condattr_destroy \
110 pthread_condattr_getclock \
111 pthread_condattr_getpshared \
112 pthread_condattr_init \
113 pthread_condattr_setclock \
114 pthread_condattr_setpshared \
119 pthread_getaffinity \
120 pthread_getattr_default_np \
122 pthread_getconcurrency \
123 pthread_getcpuclockid \
125 pthread_getschedparam \
126 pthread_getspecific \
128 pthread_join_common \
133 pthread_kill_other_threads \
134 pthread_mutex_cond_lock \
136 pthread_mutex_consistent \
137 pthread_mutex_destroy \
138 pthread_mutex_getprioceiling \
141 pthread_mutex_setprioceiling \
142 pthread_mutex_timedlock \
143 pthread_mutex_trylock \
144 pthread_mutex_unlock \
145 pthread_mutexattr_destroy \
146 pthread_mutexattr_getprioceiling \
147 pthread_mutexattr_getprotocol \
148 pthread_mutexattr_getpshared \
149 pthread_mutexattr_getrobust \
150 pthread_mutexattr_gettype \
151 pthread_mutexattr_init \
152 pthread_mutexattr_setprioceiling \
153 pthread_mutexattr_setprotocol \
154 pthread_mutexattr_setpshared \
155 pthread_mutexattr_setrobust \
156 pthread_mutexattr_settype \
158 pthread_rwlock_clockrdlock \
159 pthread_rwlock_clockwrlock \
160 pthread_rwlock_destroy \
161 pthread_rwlock_init \
162 pthread_rwlock_rdlock \
163 pthread_rwlock_timedrdlock \
164 pthread_rwlock_timedwrlock \
165 pthread_rwlock_tryrdlock \
166 pthread_rwlock_trywrlock \
167 pthread_rwlock_unlock \
168 pthread_rwlock_wrlock \
169 pthread_rwlockattr_destroy \
170 pthread_rwlockattr_getkind_np \
171 pthread_rwlockattr_getpshared \
172 pthread_rwlockattr_init \
173 pthread_rwlockattr_setkind_np \
174 pthread_rwlockattr_setpshared \
176 pthread_setaffinity \
177 pthread_setattr_default_np \
178 pthread_setcancelstate \
179 pthread_setcanceltype \
180 pthread_setconcurrency \
182 pthread_setschedparam \
183 pthread_setschedprio \
184 pthread_setspecific \
187 pthread_spin_destroy \
190 pthread_spin_trylock \
191 pthread_spin_unlock \
211 static-only-routines
= pthread_atfork
212 libpthread-routines
= libpthread-compat
213 libpthread-shared-only-routines
= libpthread-compat
215 # Pretend that libpthread.so is a linker script, so that the symbolic
216 # link is not installed.
217 install-lib-ldscripts
= libpthread.so
218 $(inst_libdir
)/libpthread.so
:
220 # Since cancellation handling is in large parts handled using exceptions
221 # we have to compile some files with exception handling enabled, some
222 # even with asynchronous unwind tables.
224 # nptl-init.c contains sigcancel_handler().
225 CFLAGS-nptl-init.c
+= -fexceptions
-fasynchronous-unwind-tables
226 # The unwind code itself,
227 CFLAGS-unwind.c
+= -fexceptions
228 CFLAGS-unwind-forcedunwind.c
+= -fexceptions
-fasynchronous-unwind-tables
230 # The following three functions must be async-cancel safe.
231 CFLAGS-pthread_cancel.c
+= -fexceptions
-fasynchronous-unwind-tables
232 CFLAGS-pthread_setcancelstate.c
+= -fexceptions
-fasynchronous-unwind-tables
233 CFLAGS-pthread_setcanceltype.c
+= -fexceptions
-fasynchronous-unwind-tables
235 # These are internal functions which similar functionality as setcancelstate
237 CFLAGS-cancellation.c
+= -fasynchronous-unwind-tables
239 # Calling pthread_exit() must cause the registered cancel handlers to
240 # be executed. Therefore exceptions have to be thrown through this
242 CFLAGS-pthread_exit.c
+= -fexceptions
244 # Among others, __pthread_unwind is forwarded. This function must handle
246 CFLAGS-forward.c
+= -fexceptions
248 # The following are cancellation points. Some of the functions can
249 # block and therefore temporarily enable asynchronous cancellation.
250 # Those must be compiled asynchronous unwind tables.
251 CFLAGS-pthread_testcancel.c
+= -fexceptions
252 CFLAGS-pthread_join.c
+= -fexceptions
-fasynchronous-unwind-tables
253 CFLAGS-pthread_timedjoin.c
+= -fexceptions
-fasynchronous-unwind-tables
254 CFLAGS-pthread_clockjoin.c
+= -fexceptions
-fasynchronous-unwind-tables
255 CFLAGS-pthread_once.c
+= $(uses-callbacks
) -fexceptions \
256 -fasynchronous-unwind-tables
257 CFLAGS-pthread_cond_wait.c
+= -fexceptions
-fasynchronous-unwind-tables
258 CFLAGS-pthread_kill.c
= -fexceptions
-fasynchronous-unwind-tables
259 CFLAGS-sem_wait.c
+= -fexceptions
-fasynchronous-unwind-tables
260 CFLAGS-sem_timedwait.c
+= -fexceptions
-fasynchronous-unwind-tables
261 CFLAGS-sem_clockwait.c
= -fexceptions
-fasynchronous-unwind-tables
263 CFLAGS-futex-internal.c
+= -fexceptions
-fasynchronous-unwind-tables
265 LDLIBS-tst-once5
= -lstdc
++
266 CFLAGS-tst-thread_local1.o
= -std
=gnu
++11
267 LDLIBS-tst-thread_local1
= -lstdc
++
268 CFLAGS-tst-thread-exit-clobber.o
= -std
=gnu
++11
269 LDLIBS-tst-thread-exit-clobber
= -lstdc
++
270 CFLAGS-tst-minstack-throw.o
= -std
=gnu
++11
271 LDLIBS-tst-minstack-throw
= -lstdc
++
273 tests
= tst-attr2 tst-attr3 tst-default-attr \
274 tst-mutex5a tst-mutex7a \
275 tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \
276 tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
277 tst-mutexpi9 tst-mutexpi10 \
279 tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \
280 tst-robustpi6 tst-robustpi7 tst-robustpi9 \
281 tst-rwlock2 tst-rwlock2a tst-rwlock2b tst-rwlock3 \
282 tst-rwlock6 tst-rwlock7 tst-rwlock8 \
283 tst-rwlock9 tst-rwlock10 tst-rwlock11 \
284 tst-rwlock15 tst-rwlock17 tst-rwlock18 \
288 tst-cancel4_1 tst-cancel4_2 \
289 tst-cancel7 tst-cancel17 tst-cancel24 \
291 tst-exec4 tst-exec5 \
292 tst-stack2 tst-stack3 tst-stack4 \
293 tst-pthread-attr-affinity \
294 tst-pthread-attr-affinity-fail \
298 tst-initializers1
$(addprefix tst-initializers1-
,\
299 c89 gnu89 c99 gnu99 c11 gnu11
) \
302 tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \
305 tst-thread-affinity-pthread \
306 tst-thread-affinity-pthread2 \
307 tst-thread-affinity-sched \
308 tst-pthread-defaultattr-free \
309 tst-pthread-attr-sigmask \
310 tst-pthread-timedlock-lockloop \
311 tst-pthread-gdb-attach tst-pthread-gdb-attach-static \
312 tst-pthread_exit-nothreads \
313 tst-pthread_exit-nothreads-static \
314 tst-thread-setspecific
316 tests-nolibpthread
= \
317 tst-pthread_exit-nothreads \
318 tst-pthread_exit-nothreads-static \
320 tests-container
= tst-pthread-getattr
322 tests-internal
:= tst-robustpi8 tst-rwlock19 tst-rwlock20 \
323 tst-sem11 tst-sem12 tst-sem13 \
324 tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \
325 tst-mutexpi8 tst-mutexpi8-static \
329 xtests
= tst-setuid1 tst-setuid1-static tst-setuid2 \
330 tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \
331 tst-mutexpp5 tst-mutexpp9
336 # This test can run into task limits because of a linux kernel bug
337 # and then cause the make process to fail too, see bug 24537.
340 test-srcs
= tst-oddstacklimit
342 gen-as-const-headers
= unwindbuf.sym
344 gen-py-const-headers
:= nptl_lock_constants.pysym
345 pretty-printers
:= nptl-printers.py
346 tests-printers
:= test-mutexattr-printers test-mutex-printers \
347 test-condattr-printers test-cond-printers \
348 test-rwlockattr-printers test-rwlock-printers
350 # We must specify both CFLAGS and CPPFLAGS to override any
351 # compiler options the user might have provided that conflict
352 # with what we need e.g. user specifies CPPFLAGS with -O2 and
354 CFLAGS-test-mutexattr-printers.c
:= $(CFLAGS-printers-tests
)
355 CFLAGS-test-mutex-printers.c
:= $(CFLAGS-printers-tests
)
356 CFLAGS-test-condattr-printers.c
:= $(CFLAGS-printers-tests
)
357 CFLAGS-test-cond-printers.c
:= $(CFLAGS-printers-tests
)
358 CFLAGS-test-rwlockattr-printers.c
:= $(CFLAGS-printers-tests
)
359 CFLAGS-test-rwlock-printers.c
:= $(CFLAGS-printers-tests
)
360 CPPFLAGS-test-mutexattr-printers.c
:= $(CFLAGS-printers-tests
)
361 CPPFLAGS-test-mutex-printers.c
:= $(CFLAGS-printers-tests
)
362 CPPFLAGS-test-condattr-printers.c
:= $(CFLAGS-printers-tests
)
363 CPPFLAGS-test-cond-printers.c
:= $(CFLAGS-printers-tests
)
364 CPPFLAGS-test-rwlockattr-printers.c
:= $(CFLAGS-printers-tests
)
365 CPPFLAGS-test-rwlock-printers.c
:= $(CFLAGS-printers-tests
)
367 # Reuse the CFLAGS setting for the GDB attaching test. It needs
368 # debugging information.
369 CFLAGS-tst-pthread-gdb-attach.c
:= $(CFLAGS-printers-tests
)
370 CPPFLAGS-tst-pthread-gdb-attach.c
:= $(CFLAGS-printers-tests
)
371 ifeq ($(build-shared
)$(build-hardcoded-path-in-tests
),yesno
)
372 CPPFLAGS-tst-pthread-gdb-attach.c
+= -DDO_ADD_SYMBOL_FILE
=1
374 CPPFLAGS-tst-pthread-gdb-attach.c
+= -DDO_ADD_SYMBOL_FILE
=0
376 CFLAGS-tst-pthread-gdb-attach-static.c
:= $(CFLAGS-printers-tests
)
377 CPPFLAGS-tst-pthread-gdb-attach-static.c
:= \
378 $(CFLAGS-printers-tests
) -DDO_ADD_SYMBOL_FILE
=0
379 # As of version 9.2, GDB cannot attach properly to PIE programs that
380 # were launched with an explicit ld.so invocation.
381 tst-pthread-gdb-attach-no-pie
= yes
383 tests
+= tst-cancelx7 tst-cancelx17
385 ifeq ($(build-shared
),yes
)
386 tests
+= tst-compat-forwarder tst-audit-threads
387 tests-internal
+= tst-tls3 tst-tls3-malloc tst-tls5 tst-stackguard1
388 ifeq ($(have-z-execstack
),yes
)
389 tests
+= tst-execstack
393 modules-names
= tst-tls3mod \
394 tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
395 tst-tls5modd tst-tls5mode tst-tls5modf tst-stack4mod \
397 tst-compat-forwarder-mod tst-audit-threads-mod1 \
398 tst-audit-threads-mod2
399 extra-test-objs
+= $(addsuffix .os
,$(strip $(modules-names
))) \
400 tst-cleanup4aux.o tst-cleanupx4aux.o
401 test-extras
+= tst-cleanup4aux tst-cleanupx4aux
403 # This test exercises compat symbols removed in glibc 2.34.
404 ifdef have-GLIBC_2.33
405 tests
+= tst-cleanup4
406 ifeq ($(build-shared
),yes
)
407 tests
+= tst-cleanupx4
411 tst-tls3mod.so-no-z-defs
= yes
412 tst-tls5mod.so-no-z-defs
= yes
413 tst-tls5moda.so-no-z-defs
= yes
414 tst-tls5modb.so-no-z-defs
= yes
415 tst-tls5modc.so-no-z-defs
= yes
416 tst-tls5modd.so-no-z-defs
= yes
417 tst-tls5mode.so-no-z-defs
= yes
418 tst-tls5modf.so-no-z-defs
= yes
420 ifeq ($(build-shared
),yes
)
422 # Set the `multidir' variable by grabbing the variable from the compiler.
423 # We do it once and save the result in a generated makefile.
424 -include $(objpfx
)multidir.mk
425 $(objpfx
)multidir.mk
: $(common-objpfx
)config.make
426 $(make-target-directory
)
427 dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
428 echo
"multidir := $$dir" > $@T
433 CFLAGS-ftrylockfile.c
+= $(libio-mtsafe
)
434 CFLAGS-funlockfile.c
+= $(libio-mtsafe
)
436 link-libc-static
:= $(common-objpfx
)libc.a
$(static-gnulib
) \
437 $(common-objpfx
)libc.a
439 tests-static
+= tst-stackguard1-static \
440 tst-cancel24-static \
441 tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
442 tst-sem12-static tst-cond11-static \
443 tst-pthread-gdb-attach-static \
444 tst-pthread_exit-nothreads-static
446 tests
+= tst-cancel24-static
448 tests-internal
+= tst-sem11-static tst-sem12-static tst-stackguard1-static
449 xtests-static
+= tst-setuid1-static
451 ifeq ($(run-built-tests
),yes
)
452 tests-special
+= $(objpfx
)tst-stack3-mem.out
$(objpfx
)tst-oddstacklimit.out
453 ifeq ($(build-shared
),yes
)
454 tests-special
+= $(objpfx
)tst-tls6.out
459 # These tests require a C++ compiler and runtime.
460 tests-unsupported
+= tst-cancel24 tst-cancel24-static tst-once5 \
461 tst-thread-exit-clobber tst-minstack-throw
463 # These tests require a C++ compiler and runtime with thread_local support.
464 ifneq ($(have-cxx-thread_local
),yes
)
465 tests-unsupported
+= tst-thread_local1
470 ifeq (yes
,$(build-shared
))
471 # Make sure these things are built in the `make lib' pass so they can be used
472 # to run programs during the `make others' pass.
473 lib-noranlib
: $(addprefix $(objpfx
),$(extra-objs
))
477 # 'pthread_self' is a simple memory or register load. Setting up the
478 # stack frame is more work than the actual operation. Disable the
479 # frame creation entirely. This will help applications which call the
480 # function frequently to get a thread-specific handle.
481 CFLAGS-pthread_self.os
+= -fomit-frame-pointer
483 # Run the cancellation and cleanup tests also for the modern, exception-based
484 # implementation. For this we have to pass the -fexceptions parameter.
485 CFLAGS-tst-cancelx7.c
+= -fexceptions
486 CFLAGS-tst-cancelx17.c
+= -fexceptions
487 CFLAGS-tst-cleanupx4.c
+= -fexceptions
488 CFLAGS-tst-cleanupx4aux.c
+= -fexceptions
489 CFLAGS-tst-initializers1.c
+= -W
-Wall
-Werror
490 CFLAGS-tst-initializers1-
< = $(CFLAGS-tst-initializers1.c
) \
491 $(patsubst tst-initializers1-
%.c
,-std
=%,$<)
492 CFLAGS-tst-initializers1-c89.c
+= $(CFLAGS-tst-initializers1-
<)
493 CFLAGS-tst-initializers1-c99.c
+= $(CFLAGS-tst-initializers1-
<)
494 CFLAGS-tst-initializers1-c11.c
+= $(CFLAGS-tst-initializers1-
<)
495 CFLAGS-tst-initializers1-gnu89.c
+= $(CFLAGS-tst-initializers1-
<)
496 CFLAGS-tst-initializers1-gnu99.c
+= $(CFLAGS-tst-initializers1-
<)
497 CFLAGS-tst-initializers1-gnu11.c
+= $(CFLAGS-tst-initializers1-
<)
499 tst-cancel7-ARGS
= --command
"exec $(host-test-program-cmd)"
500 tst-cancelx7-ARGS
= $(tst-cancel7-ARGS
)
502 tst-stack3-ENV
= MALLOC_TRACE
=$(objpfx
)tst-stack3.mtrace \
503 LD_PRELOAD
=$(common-objpfx
)/malloc
/libc_malloc_debug.so
504 $(objpfx
)tst-stack3-mem.out
: $(objpfx
)tst-stack3.out
505 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-stack3.mtrace
> $@
; \
507 generated
+= tst-stack3-mem.out tst-stack3.mtrace
509 tst-stack4mod.sos
=$(shell for i in
0 1 2 3 4 5 6 7 8 9 10 \
510 11 12 13 14 15 16 17 18 19; do \
511 for j in
0 1 2 3 4 5 6 7 8 9 10 \
512 11 12 13 14 15 16 17 18 19; do \
513 echo
$(objpfx
)tst-stack4mod-
$$i-$$j.so
; \
515 $(objpfx
)tst-stack4.out
: $(tst-stack4mod.sos
)
516 $(tst-stack4mod.sos
): $(objpfx
)tst-stack4mod.so
519 rm -f
$(tst-stack4mod.sos
)
521 $(objpfx
)tst-cleanup4
: $(objpfx
)tst-cleanup4aux.o
522 $(objpfx
)tst-cleanupx4
: $(objpfx
)tst-cleanupx4aux.o
524 LDFLAGS-tst-tls3
= -rdynamic
525 $(objpfx
)tst-tls3.out
: $(objpfx
)tst-tls3mod.so
527 LDFLAGS-tst-tls3-malloc
= -rdynamic
528 $(objpfx
)tst-tls3-malloc.out
: $(objpfx
)tst-tls3mod.so
530 $(objpfx
)tst-tls5
: $(objpfx
)tst-tls5mod.so
531 LDFLAGS-tst-tls5
= -Wl
,--no-as-needed
532 LDFLAGS-tst-tls5mod.so
= -Wl
,-soname
,tst-tls5mod.so
534 ifeq ($(build-shared
),yes
)
535 $(objpfx
)tst-tls6.out
: tst-tls6.sh
$(objpfx
)tst-tls5 \
536 $(objpfx
)tst-tls5moda.so
$(objpfx
)tst-tls5modb.so \
537 $(objpfx
)tst-tls5modc.so
$(objpfx
)tst-tls5modd.so \
538 $(objpfx
)tst-tls5mode.so
$(objpfx
)tst-tls5modf.so
539 $(BASH
) $< $(common-objpfx
) '$(test-via-rtld-prefix)' \
540 '$(test-wrapper-env)' '$(run-program-env)'; \
544 LDLIBS-tst-cancel24
= -Wl
,--no-as-needed
-lstdc
++
545 LDLIBS-tst-cancel24-static
= $(LDLIBS-tst-cancel24
)
547 ifeq ($(build-shared
),yes
)
549 generated
+= multidir.mk tst-tls6.out
552 tst-exec4-ARGS
= $(host-test-program-cmd
)
554 $(objpfx
)tst-execstack.out
: $(objpfx
)tst-execstack-mod.so
555 LDFLAGS-tst-execstack
= -Wl
,-z
,noexecstack
556 CFLAGS-tst-execstack-mod.c
+= -Wno-trampolines
558 tst-stackguard1-ARGS
= --command
"$(host-test-program-cmd) --child"
559 tst-stackguard1-static-ARGS
= --command
"$(objpfx)tst-stackguard1-static --child"
561 ifeq ($(run-built-tests
),yes
)
562 $(objpfx
)tst-oddstacklimit.out
: $(objpfx
)tst-oddstacklimit
$(objpfx
)tst-basic1
563 $(test-program-prefix
) $< --command
'$(host-test-program-cmd)' > $@
; \
567 $(objpfx
)tst-compat-forwarder
: $(objpfx
)tst-compat-forwarder-mod.so
569 tst-mutex10-ENV
= GLIBC_TUNABLES
=glibc.elision.enable
=1
571 # Protect against a build using -Wl,-z,now.
572 LDFLAGS-tst-audit-threads-mod1.so
= -Wl
,-z
,lazy
573 LDFLAGS-tst-audit-threads-mod2.so
= -Wl
,-z
,lazy
574 LDFLAGS-tst-audit-threads
= -Wl
,-z
,lazy
575 $(objpfx
)tst-audit-threads
: $(objpfx
)tst-audit-threads-mod2.so
576 $(objpfx
)tst-audit-threads.out
: $(objpfx
)tst-audit-threads-mod1.so
577 tst-audit-threads-ENV
= LD_AUDIT
=$(objpfx
)tst-audit-threads-mod1.so
579 # The test uses dlopen indirectly and would otherwise load system
581 tst-setuid1-static-ENV
= \
582 LD_LIBRARY_PATH
=$(ld-library-path
):$(common-objpfx
)elf
:$(common-objpfx
)nss
584 # The tests here better do not run in parallel.
585 ifeq ($(run-built-tests
),yes
)
586 ifneq ($(filter %tests
,$(MAKECMDGOALS
)),)