nptl: Reformat Makefile.
[glibc.git] / debug / Makefile
bloba8b4036cdc1e7032df9715bda1f9396656fe8e50
1 # Copyright (C) 1998-2023 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
20 # Sub-makefile for debug portion of the library.
22 subdir := debug
24 include ../Makeconfig
26 headers := execinfo.h
28 # Note that ptsname_r_chk and getlogin_r are not here, but in
29 # login/Makefile instead. If that subdir is omitted from the
30 # build, its _FORTIFY_SOURCE support will be too.
31 routines = \
32 ____longjmp_chk \
33 asprintf_chk \
34 backtrace \
35 backtracesyms \
36 backtracesymsfd \
37 chk_fail \
38 confstr_chk \
39 dprintf_chk \
40 explicit_bzero_chk \
41 fdelt_chk \
42 fgets_chk \
43 fgets_u_chk \
44 fgetws_chk \
45 fgetws_u_chk \
46 fortify_fail \
47 fprintf_chk \
48 fread_chk \
49 fread_u_chk \
50 fwprintf_chk \
51 getcwd_chk \
52 getdomainname_chk \
53 getgroups_chk \
54 gethostname_chk \
55 gets_chk \
56 getwd_chk \
57 longjmp_chk \
58 mbsnrtowcs_chk \
59 mbsrtowcs_chk \
60 mbstowcs_chk \
61 memcpy_chk \
62 memmove_chk \
63 mempcpy_chk \
64 memset_chk \
65 noophooks \
66 obprintf_chk \
67 poll_chk \
68 ppoll_chk \
69 pread64_chk \
70 pread_chk \
71 printf_chk \
72 read_chk \
73 readlink_chk \
74 readlinkat_chk \
75 readonly-area \
76 realpath_chk \
77 recv_chk \
78 recvfrom_chk \
79 snprintf_chk \
80 sprintf_chk \
81 stack_chk_fail \
82 stpcpy_chk \
83 stpncpy_chk \
84 strcat_chk \
85 strcpy_chk \
86 strncat_chk \
87 strncpy_chk \
88 swprintf_chk \
89 ttyname_r_chk \
90 vasprintf_chk \
91 vdprintf_chk \
92 vfprintf_chk \
93 vfwprintf_chk \
94 vobprintf_chk \
95 vprintf_chk \
96 vsnprintf_chk \
97 vsprintf_chk \
98 vswprintf_chk \
99 vwprintf_chk \
100 wcpcpy_chk \
101 wcpncpy_chk \
102 wcrtomb_chk \
103 wcscat_chk \
104 wcscpy_chk \
105 wcsncat_chk \
106 wcsncpy_chk \
107 wcsnrtombs_chk \
108 wcsrtombs_chk \
109 wcstombs_chk \
110 wctomb_chk \
111 wmemcpy_chk \
112 wmemmove_chk \
113 wmempcpy_chk \
114 wmemset_chk \
115 wprintf_chk \
116 $(static-only-routines) \
117 # routines
118 static-only-routines := stack_chk_fail_local
120 # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local
121 # is an alias of __stack_chk_fail in stack_chk_fail.o.
122 elide-routines.o := stack_chk_fail_local
124 # Building the stack-protector failure routines with stack protection
125 # is not required since we have already failed a stack check and are
126 # exiting the process. However, the local aliases which jump to the
127 # real routines should still be compiled with stack protection
128 # (stack_chk_fail_local.c), so that the statically linked parts of the
129 # library have the expected flags.
131 CFLAGS-stack_chk_fail.c += $(no-stack-protector)
133 CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables
134 CFLAGS-sprintf_chk.c += $(libio-mtsafe)
135 CFLAGS-snprintf_chk.c += $(libio-mtsafe)
136 CFLAGS-vsprintf_chk.c += $(libio-mtsafe)
137 CFLAGS-vsnprintf_chk.c += $(libio-mtsafe)
138 CFLAGS-asprintf_chk.c += $(libio-mtsafe)
139 CFLAGS-vasprintf_chk.c += $(libio-mtsafe)
140 CFLAGS-obprintf_chk.c += $(libio-mtsafe)
141 CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions
142 CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions
143 CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions
144 CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions
145 CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions
146 CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions
147 CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions
148 CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions
149 CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions
150 CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions
151 CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions
152 CFLAGS-swprintf_chk.c += $(libio-mtsafe)
153 CFLAGS-vswprintf_chk.c += $(libio-mtsafe)
154 CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions
155 CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions
156 CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions
157 CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions
158 CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions
159 CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions
160 CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables
161 CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables
162 CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables
163 CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables
164 CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables
166 # Need to make sure the settings here override what configure might have
167 # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is:
168 # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS>
169 CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables
170 CPPFLAGS-tst-longjmp_chk.c += -D_FORTIFY_SOURCE=1
171 CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables
172 CPPFLAGS-tst-longjmp_chk2.c += -D_FORTIFY_SOURCE=1
173 CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables
174 CPPFLAGS-tst-longjmp_chk3.c += -D_FORTIFY_SOURCE=1
175 CPPFLAGS-tst-realpath-chk.c += -D_FORTIFY_SOURCE=2
176 CPPFLAGS-tst-chk-cancel.c += -D_FORTIFY_SOURCE=2
178 # _FORTIFY_SOURCE tests.
179 # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
180 # preprocessor conditions based on tst-fortify.c.
182 # To add a new test condition, define a cflags-$(cond) make variable to set
183 # CFLAGS for the file.
185 tests-all-chk = tst-fortify
186 tests-c-def-chk =
187 tests-cc-def-chk =
188 tests-c-time64-chk =
189 tests-cc-time64-chk =
191 CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
193 # No additional flags for the default tests.
194 define cflags-default
195 endef
197 define cflags-lfs
198 CFLAGS-tst-fortify-$(1)-lfs-$(2)-$(3).$(1) += -D_FILE_OFFSET_BITS=64
199 endef
201 define cflags-nongnu
202 CFLAGS-tst-fortify-$(1)-nongnu-$(2)-$(3).$(1) += -D_LARGEFILE64_SOURCE=1
203 endef
205 src-chk-nongnu = \#undef _GNU_SOURCE
207 # We know these tests have problems with format strings, this is what
208 # we are testing. Disable that warning. They are also testing
209 # deprecated functions (notably gets) so disable that warning as well.
210 # And they also generate warnings from warning attributes, which
211 # cannot be disabled via pragmas, so require -Wno-error to be used.
212 define gen-chk-test
213 tests-$(1)-$(4)-chk += tst-fortify-$(1)-$(2)-$(3)-$(4)
214 CFLAGS-tst-fortify-$(1)-$(2)-$(3)-$(4).$(1) += -D_FORTIFY_SOURCE=$(3) -Wno-format \
215 -Wno-deprecated-declarations \
216 -Wno-error
217 $(eval $(call cflags-$(2),$(1),$(3),$(4)))
218 $(objpfx)tst-fortify-$(1)-$(2)-$(3)-$(4).$(1): tst-fortify.c Makefile
219 ( echo "/* Autogenerated from Makefile. */"; \
220 echo "$(src-chk-$(2))"; \
221 echo "#include \"tst-fortify.c\"" ) > $$@.tmp
222 mv $$@.tmp $$@
223 endef
225 chk-extensions = c cc
226 chk-types = default lfs nongnu
227 # 64 bit time_t implies LFS.
228 chk-types-time64 = default nongnu
229 chk-levels = 1 2 3
231 $(foreach e,$(chk-extensions), \
232 $(foreach t,$(chk-types), \
233 $(foreach l,$(chk-levels), \
234 $(eval $(call gen-chk-test,$(e),$(t),$(l),def)))))
236 tests-all-chk += $(tests-c-def-chk) $(tests-cc-def-chk)
238 $(foreach e,$(chk-extensions), \
239 $(foreach t,$(chk-types-time64), \
240 $(foreach l,$(chk-levels), \
241 $(eval $(call gen-chk-test,$(e),$(t),$(l),time64)))))
243 tests-all-time64-chk += $(tests-c-time64-chk) $(tests-cc-time64-chk)
245 define link-cc
246 LDLIBS-$(1) = -lstdc++
247 endef
248 $(foreach t,$(tests-cc-def-chk), $(eval $(call link-cc,$(t))))
249 $(foreach t,$(tests-cc-time64-chk), $(eval $(call link-cc,$(t))))
251 # backtrace_symbols only works if we link with -rdynamic. backtrace
252 # requires unwind tables on most architectures.
253 CFLAGS-tst-backtrace2.c += -funwind-tables
254 CFLAGS-tst-backtrace3.c += -funwind-tables
255 CFLAGS-tst-backtrace4.c += -funwind-tables
256 CFLAGS-tst-backtrace5.c += -funwind-tables
257 CFLAGS-tst-backtrace6.c += -funwind-tables
258 LDFLAGS-tst-backtrace2 = -rdynamic
259 LDFLAGS-tst-backtrace3 = -rdynamic
260 LDFLAGS-tst-backtrace4 = -rdynamic
261 LDFLAGS-tst-backtrace5 = -rdynamic
262 LDFLAGS-tst-backtrace6 = -rdynamic
264 CFLAGS-tst-ssp-1.c += -fstack-protector-all
266 # Disable compiler optimizations around vsprintf (the function under test).
267 CFLAGS-tst-sprintf-fortify-unchecked.c = \
268 -fno-builtin-vsprintf -fno-builtin-__vsprintf_chk
270 tests = backtrace-tst \
271 tst-longjmp_chk \
272 test-strcpy_chk \
273 test-stpcpy_chk \
274 tst-longjmp_chk2 \
275 tst-backtrace2 \
276 tst-backtrace3 \
277 tst-backtrace4 \
278 tst-backtrace5 \
279 tst-backtrace6 \
280 tst-realpath-chk \
281 tst-sprintf-fortify-unchecked \
282 $(tests-all-chk)
284 tests-time64 += \
285 $(tests-all-time64-chk) \
286 # tests-time64
288 ifeq ($(have-ssp),yes)
289 tests += tst-ssp-1
290 endif
292 ifeq ($(have-thread-library), yes)
293 tests += tst-chk-cancel
294 endif
296 ifeq (,$(CXX))
297 tests-unsupported = $(tests-cc-def-chk) $(tests-cc-time64-chk)
298 endif
300 extra-libs = libpcprofile
301 extra-libs-others = $(extra-libs)
303 libpcprofile-routines = pcprofile
304 libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes))
306 others = pcprofiledump
307 install-bin = pcprofiledump
308 install-bin-script = xtrace
310 generated += xtrace
312 include ../Rules
314 ifeq ($(run-built-tests),yes)
315 LOCALES := de_DE.UTF-8
316 include ../gen-locales.mk
318 define chk-gen-locales
319 $(objpfx)$(1).out: $(gen-locales)
320 endef
321 $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
322 $(foreach t, $(tests-all-time64-chk), $(eval $(call chk-gen-locales,$(t))))
323 endif
325 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
327 $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o
329 $(objpfx)xtrace: xtrace.sh
330 rm -f $@.new
331 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
332 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
333 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
334 && rm -f $@ && mv $@.new $@ && chmod +x $@
336 $(objpfx)tst-chk-cancel: $(shared-thread-library)