1 # Copyright (C) 2002-2021 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.
25 headers
:= pthread.h semaphore.h bits
/semaphore.h \
26 bits
/struct_mutex.h bits
/struct_rwlock.h
28 extra-libs
:= libpthread
29 extra-libs-others
:= $(extra-libs
)
37 cleanup_defer_compat \
47 libc_multiple_threads \
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 \
63 pthread_attr_destroy \
64 pthread_attr_extension \
65 pthread_attr_getaffinity \
66 pthread_attr_getdetachstate \
67 pthread_attr_getguardsize \
68 pthread_attr_getinheritsched \
69 pthread_attr_getschedparam \
70 pthread_attr_getschedpolicy \
71 pthread_attr_getscope \
72 pthread_attr_getsigmask \
73 pthread_attr_getstack \
74 pthread_attr_getstackaddr \
75 pthread_attr_getstacksize \
77 pthread_attr_setaffinity \
78 pthread_attr_setdetachstate \
79 pthread_attr_setguardsize \
80 pthread_attr_setinheritsched \
81 pthread_attr_setschedparam \
82 pthread_attr_setschedpolicy \
83 pthread_attr_setscope \
84 pthread_attr_setsigmask \
85 pthread_attr_setsigmask_internal \
86 pthread_attr_setstack \
87 pthread_attr_setstackaddr \
88 pthread_attr_setstacksize \
89 pthread_barrier_destroy \
90 pthread_barrier_init \
91 pthread_barrier_wait \
92 pthread_barrierattr_destroy \
93 pthread_barrierattr_getpshared \
94 pthread_barrierattr_init \
95 pthread_barrierattr_setpshared \
97 pthread_cleanup_upto \
99 pthread_cond_broadcast \
100 pthread_cond_destroy \
102 pthread_cond_signal \
104 pthread_condattr_destroy \
105 pthread_condattr_getclock \
106 pthread_condattr_getpshared \
107 pthread_condattr_init \
108 pthread_condattr_setclock \
109 pthread_condattr_setpshared \
114 pthread_getaffinity \
115 pthread_getattr_default_np \
117 pthread_getconcurrency \
118 pthread_getcpuclockid \
120 pthread_getschedparam \
121 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 \
206 static-only-routines
= pthread_atfork
207 libpthread-routines
= libpthread-compat
208 libpthread-shared-only-routines
= libpthread-compat
210 # Pretend that libpthread.so is a linker script, so that the symbolic
211 # link is not installed.
212 install-lib-ldscripts
= libpthread.so
213 $(inst_libdir
)/libpthread.so
:
215 # Since cancellation handling is in large parts handled using exceptions
216 # we have to compile some files with exception handling enabled, some
217 # even with asynchronous unwind tables.
219 # nptl-init.c contains sigcancel_handler().
220 CFLAGS-nptl-init.c
+= -fexceptions
-fasynchronous-unwind-tables
221 # The unwind code itself,
222 CFLAGS-unwind.c
+= -fexceptions
223 CFLAGS-unwind-forcedunwind.c
+= -fexceptions
-fasynchronous-unwind-tables
225 # The following three functions must be async-cancel safe.
226 CFLAGS-pthread_cancel.c
+= -fexceptions
-fasynchronous-unwind-tables
227 CFLAGS-pthread_setcancelstate.c
+= -fexceptions
-fasynchronous-unwind-tables
228 CFLAGS-pthread_setcanceltype.c
+= -fexceptions
-fasynchronous-unwind-tables
230 # These are internal functions which similar functionality as setcancelstate
232 CFLAGS-cancellation.c
+= -fasynchronous-unwind-tables
234 # Calling pthread_exit() must cause the registered cancel handlers to
235 # be executed. Therefore exceptions have to be thrown through this
237 CFLAGS-pthread_exit.c
+= -fexceptions
239 # Among others, __pthread_unwind is forwarded. This function must handle
241 CFLAGS-forward.c
+= -fexceptions
243 # The following are cancellation points. Some of the functions can
244 # block and therefore temporarily enable asynchronous cancellation.
245 # Those must be compiled asynchronous unwind tables.
246 CFLAGS-pthread_testcancel.c
+= -fexceptions
247 CFLAGS-pthread_join.c
+= -fexceptions
-fasynchronous-unwind-tables
248 CFLAGS-pthread_timedjoin.c
+= -fexceptions
-fasynchronous-unwind-tables
249 CFLAGS-pthread_clockjoin.c
+= -fexceptions
-fasynchronous-unwind-tables
250 CFLAGS-pthread_once.c
+= $(uses-callbacks
) -fexceptions \
251 -fasynchronous-unwind-tables
252 CFLAGS-pthread_cond_wait.c
+= -fexceptions
-fasynchronous-unwind-tables
253 CFLAGS-pthread_kill.c
= -fexceptions
-fasynchronous-unwind-tables
254 CFLAGS-sem_wait.c
+= -fexceptions
-fasynchronous-unwind-tables
255 CFLAGS-sem_timedwait.c
+= -fexceptions
-fasynchronous-unwind-tables
256 CFLAGS-sem_clockwait.c
= -fexceptions
-fasynchronous-unwind-tables
258 CFLAGS-futex-internal.c
+= -fexceptions
-fasynchronous-unwind-tables
260 LDLIBS-tst-once5
= -lstdc
++
261 CFLAGS-tst-thread_local1.o
= -std
=gnu
++11
262 LDLIBS-tst-thread_local1
= -lstdc
++
263 CFLAGS-tst-thread-exit-clobber.o
= -std
=gnu
++11
264 LDLIBS-tst-thread-exit-clobber
= -lstdc
++
265 CFLAGS-tst-minstack-throw.o
= -std
=gnu
++11
266 LDLIBS-tst-minstack-throw
= -lstdc
++
268 tests
= tst-attr2 tst-attr3 tst-default-attr \
269 tst-mutex5a tst-mutex7a \
270 tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \
271 tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
272 tst-mutexpi9 tst-mutexpi10 \
273 tst-cond22 tst-cond26 \
274 tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \
275 tst-robustpi6 tst-robustpi7 tst-robustpi9 \
276 tst-rwlock2 tst-rwlock2a tst-rwlock2b tst-rwlock3 \
277 tst-rwlock6 tst-rwlock7 tst-rwlock8 \
278 tst-rwlock9 tst-rwlock10 tst-rwlock11 \
279 tst-rwlock15 tst-rwlock17 tst-rwlock18 \
283 tst-cancel4_1 tst-cancel4_2 \
284 tst-cancel7 tst-cancel17 tst-cancel24 \
286 tst-exec4 tst-exec5 \
287 tst-stack2 tst-stack3 tst-stack4 \
288 tst-pthread-attr-affinity \
289 tst-pthread-attr-affinity-fail \
293 tst-initializers1
$(addprefix tst-initializers1-
,\
294 c89 gnu89 c99 gnu99 c11 gnu11
) \
297 tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \
300 tst-thread-affinity-pthread \
301 tst-thread-affinity-pthread2 \
302 tst-thread-affinity-sched \
303 tst-pthread-defaultattr-free \
304 tst-pthread-attr-sigmask \
305 tst-pthread-timedlock-lockloop \
306 tst-pthread-gdb-attach tst-pthread-gdb-attach-static \
307 tst-pthread_exit-nothreads \
308 tst-pthread_exit-nothreads-static \
309 tst-thread-setspecific
311 tests-nolibpthread
= \
312 tst-pthread_exit-nothreads \
313 tst-pthread_exit-nothreads-static \
315 tests-container
= tst-pthread-getattr
317 tests-internal
:= tst-robustpi8 tst-rwlock19 tst-rwlock20 \
318 tst-sem11 tst-sem12 tst-sem13 \
319 tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \
320 tst-mutexpi8 tst-mutexpi8-static \
323 xtests
= tst-setuid1 tst-setuid1-static tst-setuid2 \
324 tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \
325 tst-mutexpp5 tst-mutexpp9
330 # This test can run into task limits because of a linux kernel bug
331 # and then cause the make process to fail too, see bug 24537.
334 test-srcs
= tst-oddstacklimit
336 gen-as-const-headers
= unwindbuf.sym \
337 pthread-pi-defines.sym
339 gen-py-const-headers
:= nptl_lock_constants.pysym
340 pretty-printers
:= nptl-printers.py
341 tests-printers
:= test-mutexattr-printers test-mutex-printers \
342 test-condattr-printers test-cond-printers \
343 test-rwlockattr-printers test-rwlock-printers
345 # We must specify both CFLAGS and CPPFLAGS to override any
346 # compiler options the user might have provided that conflict
347 # with what we need e.g. user specifies CPPFLAGS with -O2 and
349 CFLAGS-test-mutexattr-printers.c
:= $(CFLAGS-printers-tests
)
350 CFLAGS-test-mutex-printers.c
:= $(CFLAGS-printers-tests
)
351 CFLAGS-test-condattr-printers.c
:= $(CFLAGS-printers-tests
)
352 CFLAGS-test-cond-printers.c
:= $(CFLAGS-printers-tests
)
353 CFLAGS-test-rwlockattr-printers.c
:= $(CFLAGS-printers-tests
)
354 CFLAGS-test-rwlock-printers.c
:= $(CFLAGS-printers-tests
)
355 CPPFLAGS-test-mutexattr-printers.c
:= $(CFLAGS-printers-tests
)
356 CPPFLAGS-test-mutex-printers.c
:= $(CFLAGS-printers-tests
)
357 CPPFLAGS-test-condattr-printers.c
:= $(CFLAGS-printers-tests
)
358 CPPFLAGS-test-cond-printers.c
:= $(CFLAGS-printers-tests
)
359 CPPFLAGS-test-rwlockattr-printers.c
:= $(CFLAGS-printers-tests
)
360 CPPFLAGS-test-rwlock-printers.c
:= $(CFLAGS-printers-tests
)
362 # Reuse the CFLAGS setting for the GDB attaching test. It needs
363 # debugging information.
364 CFLAGS-tst-pthread-gdb-attach.c
:= $(CFLAGS-printers-tests
)
365 CPPFLAGS-tst-pthread-gdb-attach.c
:= $(CFLAGS-printers-tests
)
366 ifeq ($(build-shared
)$(build-hardcoded-path-in-tests
),yesno
)
367 CPPFLAGS-tst-pthread-gdb-attach.c
+= -DDO_ADD_SYMBOL_FILE
=1
369 CPPFLAGS-tst-pthread-gdb-attach.c
+= -DDO_ADD_SYMBOL_FILE
=0
371 CFLAGS-tst-pthread-gdb-attach-static.c
:= $(CFLAGS-printers-tests
)
372 CPPFLAGS-tst-pthread-gdb-attach-static.c
:= \
373 $(CFLAGS-printers-tests
) -DDO_ADD_SYMBOL_FILE
=0
374 # As of version 9.2, GDB cannot attach properly to PIE programs that
375 # were launched with an explicit ld.so invocation.
376 tst-pthread-gdb-attach-no-pie
= yes
378 tests
+= tst-cancelx7 tst-cancelx17
380 ifeq ($(build-shared
),yes
)
381 tests
+= tst-compat-forwarder tst-audit-threads
382 tests-internal
+= tst-tls3 tst-tls3-malloc tst-tls5 tst-stackguard1
383 ifeq ($(have-z-execstack
),yes
)
384 tests
+= tst-execstack
388 modules-names
= tst-tls3mod \
389 tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
390 tst-tls5modd tst-tls5mode tst-tls5modf tst-stack4mod \
392 tst-compat-forwarder-mod tst-audit-threads-mod1 \
393 tst-audit-threads-mod2
394 extra-test-objs
+= $(addsuffix .os
,$(strip $(modules-names
))) \
395 tst-cleanup4aux.o tst-cleanupx4aux.o
396 test-extras
+= tst-cleanup4aux tst-cleanupx4aux
398 # This test exercises compat symbols removed in glibc 2.34.
399 ifdef have-GLIBC_2.33
400 tests
+= tst-cleanup4
401 ifeq ($(build-shared
),yes
)
402 tests
+= tst-cleanupx4
406 tst-tls3mod.so-no-z-defs
= yes
407 tst-tls5mod.so-no-z-defs
= yes
408 tst-tls5moda.so-no-z-defs
= yes
409 tst-tls5modb.so-no-z-defs
= yes
410 tst-tls5modc.so-no-z-defs
= yes
411 tst-tls5modd.so-no-z-defs
= yes
412 tst-tls5mode.so-no-z-defs
= yes
413 tst-tls5modf.so-no-z-defs
= yes
415 ifeq ($(build-shared
),yes
)
417 # Set the `multidir' variable by grabbing the variable from the compiler.
418 # We do it once and save the result in a generated makefile.
419 -include $(objpfx
)multidir.mk
420 $(objpfx
)multidir.mk
: $(common-objpfx
)config.make
421 $(make-target-directory
)
422 dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
423 echo
"multidir := $$dir" > $@T
428 CFLAGS-ftrylockfile.c
+= $(libio-mtsafe
)
429 CFLAGS-funlockfile.c
+= $(libio-mtsafe
)
431 link-libc-static
:= $(common-objpfx
)libc.a
$(static-gnulib
) \
432 $(common-objpfx
)libc.a
434 tests-static
+= tst-stackguard1-static \
435 tst-cancel24-static \
436 tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
437 tst-sem12-static tst-cond11-static \
438 tst-pthread-gdb-attach-static \
439 tst-pthread_exit-nothreads-static
441 tests
+= tst-cancel24-static
443 tests-internal
+= tst-sem11-static tst-sem12-static tst-stackguard1-static
444 xtests-static
+= tst-setuid1-static
446 ifeq ($(run-built-tests
),yes
)
447 tests-special
+= $(objpfx
)tst-stack3-mem.out
$(objpfx
)tst-oddstacklimit.out
448 ifeq ($(build-shared
),yes
)
449 tests-special
+= $(objpfx
)tst-tls6.out
454 # These tests require a C++ compiler and runtime.
455 tests-unsupported
+= tst-cancel24 tst-cancel24-static tst-once5 \
456 tst-thread-exit-clobber tst-minstack-throw
458 # These tests require a C++ compiler and runtime with thread_local support.
459 ifneq ($(have-cxx-thread_local
),yes
)
460 tests-unsupported
+= tst-thread_local1
465 ifeq (yes
,$(build-shared
))
466 # Make sure these things are built in the `make lib' pass so they can be used
467 # to run programs during the `make others' pass.
468 lib-noranlib
: $(addprefix $(objpfx
),$(extra-objs
))
472 # 'pthread_self' is a simple memory or register load. Setting up the
473 # stack frame is more work than the actual operation. Disable the
474 # frame creation entirely. This will help applications which call the
475 # function frequently to get a thread-specific handle.
476 CFLAGS-pthread_self.os
+= -fomit-frame-pointer
478 # Run the cancellation and cleanup tests also for the modern, exception-based
479 # implementation. For this we have to pass the -fexceptions parameter.
480 CFLAGS-tst-cancelx7.c
+= -fexceptions
481 CFLAGS-tst-cancelx17.c
+= -fexceptions
482 CFLAGS-tst-cleanupx4.c
+= -fexceptions
483 CFLAGS-tst-cleanupx4aux.c
+= -fexceptions
484 CFLAGS-tst-initializers1.c
+= -W
-Wall
-Werror
485 CFLAGS-tst-initializers1-
< = $(CFLAGS-tst-initializers1.c
) \
486 $(patsubst tst-initializers1-
%.c
,-std
=%,$<)
487 CFLAGS-tst-initializers1-c89.c
+= $(CFLAGS-tst-initializers1-
<)
488 CFLAGS-tst-initializers1-c99.c
+= $(CFLAGS-tst-initializers1-
<)
489 CFLAGS-tst-initializers1-c11.c
+= $(CFLAGS-tst-initializers1-
<)
490 CFLAGS-tst-initializers1-gnu89.c
+= $(CFLAGS-tst-initializers1-
<)
491 CFLAGS-tst-initializers1-gnu99.c
+= $(CFLAGS-tst-initializers1-
<)
492 CFLAGS-tst-initializers1-gnu11.c
+= $(CFLAGS-tst-initializers1-
<)
494 tst-cancel7-ARGS
= --command
"exec $(host-test-program-cmd)"
495 tst-cancelx7-ARGS
= $(tst-cancel7-ARGS
)
497 tst-stack3-ENV
= MALLOC_TRACE
=$(objpfx
)tst-stack3.mtrace
498 $(objpfx
)tst-stack3-mem.out
: $(objpfx
)tst-stack3.out
499 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-stack3.mtrace
> $@
; \
501 generated
+= tst-stack3-mem.out tst-stack3.mtrace
503 tst-stack4mod.sos
=$(shell for i in
0 1 2 3 4 5 6 7 8 9 10 \
504 11 12 13 14 15 16 17 18 19; do \
505 for j in
0 1 2 3 4 5 6 7 8 9 10 \
506 11 12 13 14 15 16 17 18 19; do \
507 echo
$(objpfx
)tst-stack4mod-
$$i-$$j.so
; \
509 $(objpfx
)tst-stack4.out
: $(tst-stack4mod.sos
)
510 $(tst-stack4mod.sos
): $(objpfx
)tst-stack4mod.so
513 rm -f
$(tst-stack4mod.sos
)
515 $(objpfx
)tst-cleanup4
: $(objpfx
)tst-cleanup4aux.o
516 $(objpfx
)tst-cleanupx4
: $(objpfx
)tst-cleanupx4aux.o
518 LDFLAGS-tst-tls3
= -rdynamic
519 $(objpfx
)tst-tls3.out
: $(objpfx
)tst-tls3mod.so
521 LDFLAGS-tst-tls3-malloc
= -rdynamic
522 $(objpfx
)tst-tls3-malloc.out
: $(objpfx
)tst-tls3mod.so
524 $(objpfx
)tst-tls5
: $(objpfx
)tst-tls5mod.so
525 LDFLAGS-tst-tls5
= -Wl
,--no-as-needed
526 LDFLAGS-tst-tls5mod.so
= -Wl
,-soname
,tst-tls5mod.so
528 ifeq ($(build-shared
),yes
)
529 $(objpfx
)tst-tls6.out
: tst-tls6.sh
$(objpfx
)tst-tls5 \
530 $(objpfx
)tst-tls5moda.so
$(objpfx
)tst-tls5modb.so \
531 $(objpfx
)tst-tls5modc.so
$(objpfx
)tst-tls5modd.so \
532 $(objpfx
)tst-tls5mode.so
$(objpfx
)tst-tls5modf.so
533 $(BASH
) $< $(common-objpfx
) '$(test-via-rtld-prefix)' \
534 '$(test-wrapper-env)' '$(run-program-env)'; \
538 LDLIBS-tst-cancel24
= -Wl
,--no-as-needed
-lstdc
++
539 LDLIBS-tst-cancel24-static
= $(LDLIBS-tst-cancel24
)
541 ifeq ($(build-shared
),yes
)
543 generated
+= multidir.mk tst-tls6.out
546 tst-exec4-ARGS
= $(host-test-program-cmd
)
548 $(objpfx
)tst-execstack.out
: $(objpfx
)tst-execstack-mod.so
549 LDFLAGS-tst-execstack
= -Wl
,-z
,noexecstack
550 CFLAGS-tst-execstack-mod.c
+= -Wno-trampolines
552 tst-stackguard1-ARGS
= --command
"$(host-test-program-cmd) --child"
553 tst-stackguard1-static-ARGS
= --command
"$(objpfx)tst-stackguard1-static --child"
555 ifeq ($(run-built-tests
),yes
)
556 $(objpfx
)tst-oddstacklimit.out
: $(objpfx
)tst-oddstacklimit
$(objpfx
)tst-basic1
557 $(test-program-prefix
) $< --command
'$(host-test-program-cmd)' > $@
; \
561 $(objpfx
)tst-compat-forwarder
: $(objpfx
)tst-compat-forwarder-mod.so
563 tst-mutex10-ENV
= GLIBC_TUNABLES
=glibc.elision.enable
=1
565 # Protect against a build using -Wl,-z,now.
566 LDFLAGS-tst-audit-threads-mod1.so
= -Wl
,-z
,lazy
567 LDFLAGS-tst-audit-threads-mod2.so
= -Wl
,-z
,lazy
568 LDFLAGS-tst-audit-threads
= -Wl
,-z
,lazy
569 $(objpfx
)tst-audit-threads
: $(objpfx
)tst-audit-threads-mod2.so
570 $(objpfx
)tst-audit-threads.out
: $(objpfx
)tst-audit-threads-mod1.so
571 tst-audit-threads-ENV
= LD_AUDIT
=$(objpfx
)tst-audit-threads-mod1.so
573 # The test uses dlopen indirectly and would otherwise load system
575 tst-setuid1-static-ENV
= \
576 LD_LIBRARY_PATH
=$(ld-library-path
):$(common-objpfx
)elf
:$(common-objpfx
)nss
578 # The tests here better do not run in parallel.
579 ifeq ($(run-built-tests
),yes
)
580 ifneq ($(filter %tests
,$(MAKECMDGOALS
)),)