Debian Codegraph @

debug/Makefile

raw symbols SCIP
1 # Copyright (C) 1998-2026 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
4
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.
9
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.
14
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/>.
18
19 #
20 # Sub-makefile for debug portion of the library.
21 #
22 subdir := debug
23
24 include ../Makeconfig
25
26 headers := execinfo.h
27
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 $(static-only-routines) \
33 ____longjmp_chk \
34 asprintf_chk \
35 backtrace \
36 backtracesyms \
37 backtracesymsfd \
38 chk_fail \
39 confstr_chk \
40 dprintf_chk \
41 explicit_bzero_chk \
42 fdelt_chk \
43 fgets_chk \
44 fgets_u_chk \
45 fgetws_chk \
46 fgetws_u_chk \
47 fortify_fail \
48 fprintf_chk \
49 fread_chk \
50 fread_u_chk \
51 fwprintf_chk \
52 getcwd_chk \
53 getdomainname_chk \
54 getgroups_chk \
55 gethostname_chk \
56 gets_chk \
57 getwd_chk \
58 inet_ntop_chk \
59 inet_pton_chk \
60 longjmp_chk \
61 mbsnrtowcs_chk \
62 mbsrtowcs_chk \
63 mbstowcs_chk \
64 memcpy_chk \
65 memmove_chk \
66 mempcpy_chk \
67 memset_chk \
68 memset_explicit_chk \
69 noophooks \
70 obprintf_chk \
71 poll_chk \
72 ppoll_chk \
73 pread64_chk \
74 pread_chk \
75 printf_chk \
76 read_chk \
77 readlink_chk \
78 readlinkat_chk \
79 readonly-area \
80 readonly-area-fallback \
81 realpath_chk \
82 recv_chk \
83 recvfrom_chk \
84 snprintf_chk \
85 sprintf_chk \
86 stack_chk_fail \
87 stpcpy_chk \
88 stpncpy_chk \
89 strcat_chk \
90 strcpy_chk \
91 strlcat_chk \
92 strlcpy_chk \
93 strncat_chk \
94 strncpy_chk \
95 swprintf_chk \
96 ttyname_r_chk \
97 vasprintf_chk \
98 vdprintf_chk \
99 vfprintf_chk \
100 vfwprintf_chk \
101 vobprintf_chk \
102 vprintf_chk \
103 vsnprintf_chk \
104 vsprintf_chk \
105 vswprintf_chk \
106 vwprintf_chk \
107 wcpcpy_chk \
108 wcpncpy_chk \
109 wcrtomb_chk \
110 wcscat_chk \
111 wcscpy_chk \
112 wcslcat_chk \
113 wcslcpy_chk \
114 wcsncat_chk \
115 wcsncpy_chk \
116 wcsnrtombs_chk \
117 wcsrtombs_chk \
118 wcstombs_chk \
119 wctomb_chk \
120 wmemcpy_chk \
121 wmemmove_chk \
122 wmempcpy_chk \
123 wmemset_chk \
124 wprintf_chk \
125 # routines
126 static-only-routines := stack_chk_fail_local
127
128 # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local
129 # is an alias of __stack_chk_fail in stack_chk_fail.o.
130 elide-routines.o := stack_chk_fail_local
131
132 # Building the stack-protector failure routines with stack protection
133 # is not required since we have already failed a stack check and are
134 # exiting the process. However, the local aliases which jump to the
135 # real routines should still be compiled with stack protection
136 # (stack_chk_fail_local.c), so that the statically linked parts of the
137 # library have the expected flags.
138
139 CFLAGS-stack_chk_fail.c += $(no-stack-protector)
140
141 CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables
142 CFLAGS-sprintf_chk.c += $(libio-mtsafe)
143 CFLAGS-snprintf_chk.c += $(libio-mtsafe)
144 CFLAGS-vsprintf_chk.c += $(libio-mtsafe)
145 CFLAGS-vsnprintf_chk.c += $(libio-mtsafe)
146 CFLAGS-asprintf_chk.c += $(libio-mtsafe)
147 CFLAGS-vasprintf_chk.c += $(libio-mtsafe)
148 CFLAGS-obprintf_chk.c += $(libio-mtsafe)
149 CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions
150 CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions
151 CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions
152 CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions
153 CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions
154 CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions
155 CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions
156 CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions
157 CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions
158 CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions
159 CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions
160 CFLAGS-swprintf_chk.c += $(libio-mtsafe)
161 CFLAGS-vswprintf_chk.c += $(libio-mtsafe)
162 CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions
163 CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions
164 CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions
165 CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions
166 CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions
167 CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions
168 CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables
169 CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables
170 CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables
171 CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables
172 CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables
173
174 # Need to make sure the settings here override what configure might have
175 # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is:
176 # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS>
177 CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables
178 CPPFLAGS-tst-longjmp_chk.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
179 CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables
180 CPPFLAGS-tst-longjmp_chk2.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
181 CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables
182 CPPFLAGS-tst-longjmp_chk3.c += $(no-fortify-source) -D_FORTIFY_SOURCE=1
183 CPPFLAGS-tst-realpath-chk.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
184 CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
185 CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
186 CFLAGS-tst-sprintf-fortify-rdonly-mod.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
187 CFLAGS-tst-sprintf-fortify-rdonly-dlopen.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
188 CFLAGS-tst-sprintf-fortify-rdonly-static.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
189 CFLAGS-tst-fortify-syslog.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
190 CFLAGS-tst-fortify-wide.c += $(no-fortify-source) -D_FORTIFY_SOURCE=2
191 LDFLAGS-tst-sprintf-fortify-rdonly-static += $(relro-LDFLAGS)
192
193 $(objpfx)tst-sprintf-fortify-rdonly: $(objpfx)tst-sprintf-fortify-rdonly-mod.so
194 $(objpfx)tst-sprintf-fortify-rdonly.out: \
195 $(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
196 $(objpfx)tst-sprintf-fortify-rdonly-static: \
197 $(objpfx)tst-sprintf-fortify-rdonly-dlopen.o
198 $(objpfx)tst-sprintf-fortify-rdonly-static.out: \
199 $(objpfx)tst-sprintf-fortify-rdonly-dlopen.so
200 tst-sprintf-fortify-rdonly-static-ENV = \
201 LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)/elf
202
203 # _FORTIFY_SOURCE tests.
204 # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
205 # preprocessor conditions based on tst-fortify.c.
206 #
207 # To add a new test condition, define a cflags-$(cond) make variable to set
208 # CFLAGS for the file.
209
210 tests-all-chk = tst-fortify
211 tests-c-def-chk =
212 tests-cc-def-chk =
213 tests-c-time64-chk =
214 tests-cc-time64-chk =
215
216 CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
217
218 # No additional flags for the default tests.
219 define cflags-default
220 endef
221
222 define cflags-lfs
223 CFLAGS-tst-fortify-$(1)-lfs-$(2)-$(3).$(1) += -D_FILE_OFFSET_BITS=64
224 endef
225
226 define cflags-nongnu
227 CFLAGS-tst-fortify-$(1)-nongnu-$(2)-$(3).$(1) += -D_LARGEFILE64_SOURCE=1
228 endef
229
230 src-chk-nongnu = \#undef _GNU_SOURCE
231
232 # We know these tests have problems with format strings, this is what
233 # we are testing. Disable that warning. They are also testing
234 # deprecated functions (notably gets) so disable that warning as well.
235 # And they also generate warnings from warning attributes, which
236 # cannot be disabled via pragmas, so require -Wno-error to be used.
237 define gen-chk-test
238 tests-$(1)-$(4)-chk += tst-fortify-$(1)-$(2)-$(3)-$(4)
239 CFLAGS-tst-fortify-$(1)-$(2)-$(3)-$(4).$(1) += $(no-fortify-source) -D_FORTIFY_SOURCE=$(3) \
240 -Wno-format \
241 -Wno-deprecated-declarations \
242 -Wno-error
243 $(eval $(call cflags-$(2),$(1),$(3),$(4)))
244 $(objpfx)tst-fortify-$(1)-$(2)-$(3)-$(4).$(1): tst-fortify.c Makefile
245 ( echo "/* Autogenerated from Makefile. */"; \
246 echo "$(src-chk-$(2))"; \
247 echo "#include \"tst-fortify.c\"" ) > [email protected]
248 mv [email protected] $$@
249 endef
250
251 chk-extensions = c cc
252 chk-types = default lfs nongnu
253 # 64 bit time_t implies LFS.
254 chk-types-time64 = default nongnu
255 chk-levels = 1 2 3
256
257 $(foreach e,$(chk-extensions), \
258 $(foreach t,$(chk-types), \
259 $(foreach l,$(chk-levels), \
260 $(eval $(call gen-chk-test,$(e),$(t),$(l),def)))))
261
262 tests-all-chk += $(tests-c-def-chk) $(tests-cc-def-chk)
263
264 $(foreach e,$(chk-extensions), \
265 $(foreach t,$(chk-types-time64), \
266 $(foreach l,$(chk-levels), \
267 $(eval $(call gen-chk-test,$(e),$(t),$(l),time64)))))
268
269 tests-all-time64-chk += $(tests-c-time64-chk) $(tests-cc-time64-chk)
270
271 define link-cc
272 LDLIBS-$(1) = -lstdc++
273 endef
274 $(foreach t,$(tests-cc-def-chk), $(eval $(call link-cc,$(t))))
275 $(foreach t,$(tests-cc-time64-chk), $(eval $(call link-cc,$(t))))
276
277 # backtrace_symbols only works if we link with -rdynamic. backtrace
278 # requires unwind tables on most architectures.
279 CFLAGS-tst-backtrace2.c += -funwind-tables
280 CFLAGS-tst-backtrace3.c += -funwind-tables
281 CFLAGS-tst-backtrace4.c += -funwind-tables
282 CFLAGS-tst-backtrace5.c += -funwind-tables
283 CFLAGS-tst-backtrace6.c += -funwind-tables
284 LDFLAGS-tst-backtrace2 = -rdynamic
285 LDFLAGS-tst-backtrace3 = -rdynamic
286 LDFLAGS-tst-backtrace4 = -rdynamic
287 LDFLAGS-tst-backtrace5 = -rdynamic
288 LDFLAGS-tst-backtrace6 = -rdynamic
289
290 $(objpfx)tst-backtrace1: $(shared-thread-library)
291
292 # When SFrame is enabled, make sure the dwarf unwinder is also exercised.
293 ifeq ($(enable-gsframe),yes)
294 dw_unwind_pair := \
295 tst-backtrace1-nosframe:tst-backtrace1 \
296 tst-backtrace2-nosframe:tst-backtrace2 \
297 tst-backtrace3-nosframe:tst-backtrace3 \
298 tst-backtrace4-nosframe:tst-backtrace4 \
299 tst-backtrace5-nosframe:tst-backtrace5 \
300 tst-backtrace6-nosframe:tst-backtrace6
301
302 first_column = $(foreach pair,$(dw_unwind_pair),$(word 1,$(subst :, ,$(pair))))
303 tests-dw-unwind = $(patsubst %,$(objpfx)%.out,$(first_column))
304 ifeq ($(run-built-tests),yes)
305 tests-special += $(tests-dw-unwind)
306 endif
307 endif
308
309 define make-strip-rule
310 $(objpfx)$(word 1,$(subst :, ,$(1))): $(objpfx)$(word 2,$(subst :, ,$(1)))
311 $(STRIP) --remove-section=.sframe $$< -o $$@
312 endef
313
314 $(foreach pair,$(dw_unwind_pair),$(eval $(call make-strip-rule,$(pair))))
315
316 define make-run-rule
317 $(objpfx)$(word 1,$(subst :, ,$(1))).out: /dev/null $(objpfx)$(word 1,$(subst :, ,$(1)))
318 $$(make-test-out) > $$@; $$(evaluate-test)
319 endef
320
321 $(foreach pair,$(dw_unwind_pair),$(eval $(call make-run-rule,$(pair))))
322
323 CFLAGS-tst-ssp-1.c += -fstack-protector-all
324
325 # Disable compiler optimizations around vsprintf (the function under test).
326 CFLAGS-tst-sprintf-fortify-unchecked.c = \
327 -fno-builtin-vsprintf -fno-builtin-__vsprintf_chk
328
329 tests = \
330 $(tests-all-chk) \
331 backtrace-tst \
332 test-stpcpy_chk \
333 test-strcpy_chk \
334 tst-backtrace1 \
335 tst-backtrace2 \
336 tst-backtrace3 \
337 tst-backtrace4 \
338 tst-backtrace5 \
339 tst-backtrace6 \
340 tst-fortify-wide \
341 tst-longjmp_chk \
342 tst-longjmp_chk2 \
343 tst-longjmp_chk3 \
344 tst-realpath-chk \
345 tst-sprintf-fortify-rdonly \
346 tst-sprintf-fortify-rdonly-static \
347 tst-sprintf-fortify-unchecked \
348 # tests
349
350 tests-static = \
351 tst-sprintf-fortify-rdonly-static \
352 # tests-static
353
354 tests-time64 += \
355 $(tests-all-time64-chk) \
356 # tests-time64
357
358 tests-container += \
359 tst-fortify-syslog \
360 # tests-container
361
362 modules-names += \
363 tst-sprintf-fortify-rdonly-dlopen \
364 tst-sprintf-fortify-rdonly-mod \
365 # modules-names
366
367 ifeq ($(have-ssp),yes)
368 tests += tst-ssp-1
369 endif
370
371 ifeq ($(have-thread-library), yes)
372 tests += tst-chk-cancel
373 endif
374
375 ifeq (,$(CXX))
376 tests-unsupported = $(tests-cc-def-chk) $(tests-cc-time64-chk)
377 endif
378
379 extra-libs = libpcprofile
380 extra-libs-others = $(extra-libs)
381
382 libpcprofile-routines = pcprofile
383 libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes))
384
385 others = pcprofiledump
386 install-bin = pcprofiledump
387 install-bin-script = xtrace
388
389 generated += xtrace
390
391 include ../Rules
392
393 ifeq ($(run-built-tests),yes)
394 LOCALES := de_DE.UTF-8
395 include ../gen-locales.mk
396
397 define chk-gen-locales
398 $(objpfx)$(1).out: $(gen-locales)
399 endef
400 $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
401 $(foreach t, $(tests-all-time64-chk), $(eval $(call chk-gen-locales,$(t))))
402 endif
403
404 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
405
406 $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o
407
408 $(objpfx)xtrace: xtrace.sh
409 rm -f [email protected]
410 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
411 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
412 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > [email protected] \
413 && rm -f $@ && mv [email protected] $@ && chmod +x $@
414
415 $(objpfx)tst-chk-cancel: $(shared-thread-library)