1 # Copyright (C) 2002, 2003 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, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # Sub-makefile for NPTL portion of the library.
24 nptl-version := $(shell sed -n 's/^[^0-9]* \([0-9.]*\).*$$/\1/p' Banner)
26 headers := pthread.h semaphore.h bits/semaphore.h
28 extra-libs := libpthread
29 extra-libs-others := $(extra-libs)
30 install-lib-ldscripts := libpthread.so
32 routines = alloca_cutoff forward libc-lowlevellock libc-lowlevelmutex \
34 shared-only-routines = forward
36 libpthread-routines = init events version \
37 pthread_create pthread_exit pthread_detach \
38 pthread_join pthread_tryjoin pthread_timedjoin \
39 pthread_self pthread_equal pthread_yield \
40 pthread_getconcurrency pthread_setconcurrency \
41 pthread_getschedparam pthread_setschedparam \
42 pthread_attr_init pthread_attr_destroy \
43 pthread_attr_getdetachstate pthread_attr_setdetachstate \
44 pthread_attr_getguardsize pthread_attr_setguardsize \
45 pthread_attr_getschedparam pthread_attr_setschedparam \
46 pthread_attr_getschedpolicy pthread_attr_setschedpolicy \
47 pthread_attr_getinheritsched \
48 pthread_attr_setinheritsched \
49 pthread_attr_getscope pthread_attr_setscope \
50 pthread_attr_getstackaddr pthread_attr_setstackaddr \
51 pthread_attr_getstacksize pthread_attr_setstacksize \
52 pthread_attr_getstack pthread_attr_setstack \
54 pthread_mutex_init pthread_mutex_destroy \
55 pthread_mutex_lock pthread_mutex_trylock \
56 pthread_mutex_timedlock pthread_mutex_unlock \
57 pthread_mutexattr_init pthread_mutexattr_destroy \
58 pthread_mutexattr_getpshared \
59 pthread_mutexattr_setpshared \
60 pthread_mutexattr_gettype pthread_mutexattr_settype \
61 pthread_rwlock_init pthread_rwlock_destroy \
62 pthread_rwlock_rdlock pthread_rwlock_timedrdlock \
63 pthread_rwlock_wrlock pthread_rwlock_timedwrlock \
64 pthread_rwlock_tryrdlock pthread_rwlock_trywrlock \
65 pthread_rwlock_unlock \
66 pthread_rwlockattr_init pthread_rwlockattr_destroy \
67 pthread_rwlockattr_getpshared \
68 pthread_rwlockattr_setpshared \
69 pthread_rwlockattr_getkind_np \
70 pthread_rwlockattr_setkind_np \
71 pthread_cond_init pthread_cond_destroy \
72 pthread_cond_wait pthread_cond_timedwait \
73 pthread_cond_signal pthread_cond_broadcast \
74 old_pthread_cond_init old_pthread_cond_destroy \
75 old_pthread_cond_wait old_pthread_cond_timedwait \
76 old_pthread_cond_signal old_pthread_cond_broadcast \
77 pthread_condattr_init pthread_condattr_destroy \
78 pthread_condattr_getpshared pthread_condattr_setpshared \
79 pthread_condattr_getclock pthread_condattr_setclock \
80 pthread_spin_init pthread_spin_destroy \
81 pthread_spin_lock pthread_spin_trylock \
83 pthread_barrier_init pthread_barrier_destroy \
84 pthread_barrier_wait \
85 pthread_barrierattr_init pthread_barrierattr_destroy \
86 pthread_barrierattr_getpshared \
87 pthread_barrierattr_setpshared \
88 pthread_key_create pthread_key_delete \
89 pthread_getspecific pthread_setspecific \
90 pthread_sigmask pthread_kill \
91 pthread_cancel pthread_testcancel \
92 pthread_setcancelstate pthread_setcanceltype \
94 old_pthread_atfork pthread_atfork \
95 pthread_getcpuclockid \
96 pthread_clock_gettime pthread_clock_settime \
97 sem_init sem_destroy \
98 sem_open sem_close sem_unlink \
100 sem_wait sem_trywait sem_timedwait sem_post \
101 cleanup cleanup_defer \
104 lowlevellock lowlevelmutex \
106 ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
107 ptw-connect ptw-recv ptw-recvfrom ptw-recvmsg ptw-send \
108 ptw-sendmsg ptw-sendto ptw-fsync ptw-lseek ptw-llseek \
109 ptw-msync ptw-nanosleep ptw-open ptw-open64 ptw-pause \
110 ptw-pread ptw-pread64 ptw-pwrite ptw-pwrite64 \
111 ptw-tcdrain ptw-wait ptw-waitpid ptw-msgrcv ptw-msgsnd \
114 flockfile ftrylockfile funlockfile \
116 herrno res pt-allocrtsig \
117 pthread_kill_other_threads
119 libpthread-shared-only-routines = version pt-allocrtsig
120 libpthread-static-only-routines = pthread_atfork
122 libpthread-nonshared = pthread_atfork
124 CFLAGS-pthread_atfork.c = -DNOT_IN_libc
126 # Don't generate deps for calls with no sources. See sysdeps/unix/Makefile.
127 omit-deps = $(unix-syscalls:%=ptw-%)
130 tests = tst-attr1 tst-attr2 \
131 tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
133 tst-spin1 tst-spin2 tst-spin3 \
134 tst-cond1 tst-cond2 tst-cond3 tst-cond4 tst-cond5 tst-cond6 tst-cond7 \
135 tst-cond8 tst-cond9 tst-cond10 tst-cond11 \
136 tst-rwlock1 tst-rwlock2 tst-rwlock3 tst-rwlock4 tst-rwlock5 \
137 tst-rwlock6 tst-rwlock7 tst-rwlock8 tst-rwlock9 tst-rwlock10 \
139 tst-once1 tst-once2 tst-once3 tst-once4 \
140 tst-key1 tst-key2 tst-key3 tst-key4 \
141 tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 \
142 tst-barrier1 tst-barrier2 tst-barrier3 \
144 tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
145 tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
146 tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 \
148 tst-tsd1 tst-tsd2 tst-tsd3 tst-tsd4 \
150 tst-fork1 tst-fork2 tst-fork3 tst-fork4 \
152 tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \
153 tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \
155 tst-cleanup1 tst-cleanup2 tst-cleanup3 \
156 tst-flock1 tst-flock2 \
157 tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \
158 tst-exec1 tst-exec2 tst-exec3 \
160 tst-stdio1 tst-stdio2 \
165 tst-locale1 tst-locale2 \
173 gen-as-const-headers = pthread-errnos.sym
175 LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
178 include ../Makeconfig
180 ifeq ($(build-shared),yes)
181 tests += tst-atfork2 tst-tls3
184 modules-names = tst-atfork2mod tst-tls3mod
185 extra-objs += $(addsuffix .os,$(strip $(modules-names)))
186 test-extras += $(modules-names)
187 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
189 $(test-modules): $(objpfx)%.so: $(objpfx)%.os
192 ifeq ($(build-shared),yes)
193 others: $(objpfx)libpthread_nonshared.a
196 $(objpfx)libpthread_nonshared.a: $(addprefix $(objpfx),$(addsuffix .os,$(libpthread-nonshared)))
197 $(AR) $(ARFLAGS) $@ $^
199 ifeq ($(build-shared),yes)
203 CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions
206 CFLAGS-flockfile.c = -D_IO_MTSAFE_IO
207 CFLAGS-ftrylockfile.c = -D_IO_MTSAFE_IO
208 CFLAGS-funlockfile.c = -D_IO_MTSAFE_IO
210 ifeq ($(build-static),yes)
211 tests-static += tst-locale1 tst-locale2
213 # These tests are linked with libc before libpthread
214 tests-reverse += tst-cancel5
218 ifeq (yes,$(build-shared))
219 # Make sure these things are built in the `make lib' pass so they can be used
220 # to run programs during the `make others' pass.
221 lib-noranlib: $(addprefix $(objpfx),$(extra-objs))
224 # What we install as libpthread.so for programs to link against is in fact a
225 # link script. It contains references for the various libraries we need.
226 # The libpthread.so object is not complete since some functions are only
227 # defined in libpthread_nonshared.a.
228 # We need to use absolute paths since otherwise local copies (if they exist)
229 # of the files are taken by the linker.
230 install: $(inst_libdir)/libpthread.so
231 $(inst_libdir)/libpthread.so: $(common-objpfx)format.lds \
232 $(objpfx)libpthread.so$(libpthread.so-version) \
233 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
234 $(libprefix)pthread) \
236 (echo '/* GNU ld script';\
237 echo ' Use the shared library, but some functions are only in';\
238 echo ' the static library, so try that secondarily. */';\
240 echo 'GROUP ( $(slibdir)/libpthread.so$(libpthread.so-version)' \
241 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)pthread)'\
245 $(inst_libdir)/libpthread_nonshared.a: $(objpfx)libpthread_nonshared.a
248 # 'pthread_self' is a simple memory or register load. Setting up the
249 # stack frame is more work than the actual operation. Disable the
250 # frame creation entirely. This will help applications which call the
251 # function frequently to get a thread-specific handle.
252 CFLAGS-pthread_self.os += -fomit-frame-pointer
254 CFLAGS-tst-unload.c += -DPREFIX=\"$(objpfx)\"
256 tst-cancel7-ARGS = --command "$(built-program-cmd)"
257 tst-umask1-ARGS = $(objpfx)tst-umask1.temp
259 $(objpfx)tst-atfork2: $(libdl) $(shared-thread-library)
260 LDFLAGS-tst-atfork2 = -rdynamic
261 tst-atfork2-ENV = MALLOC_TRACE=$(objpfx)tst-atfork2.mtrace
262 $(objpfx)tst-atfork2mod.so: $(shared-thread-library)
264 $(objpfx)tst-tls3: $(libdl) $(shared-thread-library)
265 LDFLAGS-tst-tls3 = -rdynamic
266 $(objpfx)tst-tls3.out: $(objpfx)tst-tls3mod.so
267 $(objpfx)tst-tls3mod.so: $(shared-thread-library)
269 $(objpfx)tst-dlsym1: $(libdl) $(shared-thread-library)
271 ifeq (yes,$(build-shared))
272 $(objpfx)tst-cond11: $(common-objpfx)rt/librt.so
274 $(objpfx)tst-cond11: $(common-objpfx)rt/librt.a
277 extra-B-pthread.so = -B$(common-objpfx)nptl/
278 $(objpfx)libpthread.so: $(objpfx)crti.o
279 $(objpfx)libpthread.so: +preinit += $(objpfx)crti.o
281 # Depend on libc.so so a DT_NEEDED is generated in the shared objects.
282 # This ensures they will load libc.so for needed symbols if loaded by
283 # a statically-linked program that hasn't already loaded it.
284 # Depend on ld.so too to get proper versions of ld.so symbols.
285 $(objpfx)libpthread.so: $(common-objpfx)libc.so \
286 $(common-objpfx)libc_nonshared.a \
287 $(if $(filter yes,$(elf)), $(elfobjdir)/ld.so)
289 # Make sure we link with the thread library.
290 ifeq ($(build-shared),yes)
291 $(addprefix $(objpfx), \
292 $(filter-out $(tests-static) $(tests-reverse), \
293 $(tests) $(test-srcs))): $(objpfx)libpthread.so \
294 $(objpfx)libpthread_nonshared.a
295 $(objpfx)tst-unload: $(common-objpfx)dlfcn/libdl.so
296 # $(objpfx)../libc.so is used instead of $(common-objpfx)libc.so,
297 # since otherwise libpthread.so comes before libc.so when linking.
298 $(addprefix $(objpfx), $(tests-reverse)): \
299 $(objpfx)../libc.so $(objpfx)libpthread.so \
300 $(objpfx)libpthread_nonshared.a
301 $(addprefix $(objpfx),$(tests-static)): $(objpfx)libpthread.a
303 $(objpfx)tst-atfork2.out: $(objpfx)tst-atfork2mod.so
305 $(addprefix $(objpfx),$(tests) $(test-srcs)): $(objpfx)libpthread.a
308 ifeq ($(build-shared),yes)
309 vpath pt-initfini.c $(full_config_sysdirs)
311 $(objpfx)pt-initfini.s: pt-initfini.c
312 $(compile.c) -S $(CFLAGS-pt-initfini.s) -finhibit-size-directive \
313 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
315 # We only have one kind of startup code files. Static binaries and
316 # shared libraries are build using the PIC version.
317 $(objpfx)crti.S: $(objpfx)pt-initfini.s
318 sed -n -e '1,/@HEADER_ENDS/p' \
319 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
320 -e '/@TRAILER_BEGINS/,$$p' $< > $@
322 $(objpfx)defs.h: $(objpfx)pt-initfini.s
323 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
324 $(AWK) -f ../csu/defs.awk > $@
326 $(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
327 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
329 generated += crti.S defs.h pt-initfini.s $(objpfx)tst-atfork2.mtrace \
330 $(addsuffix .so,$(strip $(modules-names)))
332 $(objpfx)version.d: $(objpfx)banner.h
333 $(objpfx)version.os: $(objpfx)banner.h
334 $(objpfx)banner.h: Banner
335 sed 's/\(.*\)/"\1\\n"/' $< > $@
336 generated += banner.h
337 # Give libpthread.so an entry point and make it directly runnable itself.
338 LDFLAGS-pthread.so += -e __nptl_main
341 ifeq (no,$(cross-compiling))
342 ifeq (yes,$(build-shared))
343 tests: $(objpfx)tst-cancel-wrappers.out
344 $(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
345 $(SHELL) $< $(common-objpfx)libc_pic.a \
346 $(common-objpfx)libc.a \
347 $(objpfx)libpthread_pic.a \
348 $(objpfx)libpthread.a > $@