]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | # Copyright (C) 1998-2023 Free Software Foundation, Inc. |
db27f125 | 2 | # Copyright The GNU Toolchain Authors. |
2de7874e UD |
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 | |
41bdb6e2 AJ |
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. | |
2de7874e UD |
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 | |
41bdb6e2 | 13 | # Lesser General Public License for more details. |
2de7874e | 14 | |
41bdb6e2 | 15 | # You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | # License along with the GNU C Library; if not, see |
5a82c748 | 17 | # <https://www.gnu.org/licenses/>. |
2de7874e UD |
18 | |
19 | # | |
20 | # Sub-makefile for debug portion of the library. | |
21 | # | |
22 | subdir := debug | |
23 | ||
a5f891ac JM |
24 | include ../Makeconfig |
25 | ||
2de7874e UD |
26 | headers := execinfo.h |
27 | ||
ee586a6d RM |
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. | |
4e464116 | 31 | routines = \ |
e475bc25 | 32 | $(static-only-routines) \ |
4e464116 FW |
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 | longjmp_chk \ | |
59 | mbsnrtowcs_chk \ | |
60 | mbsrtowcs_chk \ | |
61 | mbstowcs_chk \ | |
62 | memcpy_chk \ | |
63 | memmove_chk \ | |
64 | mempcpy_chk \ | |
65 | memset_chk \ | |
66 | noophooks \ | |
67 | obprintf_chk \ | |
68 | poll_chk \ | |
69 | ppoll_chk \ | |
70 | pread64_chk \ | |
71 | pread_chk \ | |
72 | printf_chk \ | |
73 | read_chk \ | |
74 | readlink_chk \ | |
75 | readlinkat_chk \ | |
76 | readonly-area \ | |
77 | realpath_chk \ | |
78 | recv_chk \ | |
79 | recvfrom_chk \ | |
80 | snprintf_chk \ | |
81 | sprintf_chk \ | |
82 | stack_chk_fail \ | |
83 | stpcpy_chk \ | |
84 | stpncpy_chk \ | |
85 | strcat_chk \ | |
86 | strcpy_chk \ | |
454a20c8 FW |
87 | strlcat_chk \ |
88 | strlcpy_chk \ | |
4e464116 FW |
89 | strncat_chk \ |
90 | strncpy_chk \ | |
91 | swprintf_chk \ | |
92 | ttyname_r_chk \ | |
93 | vasprintf_chk \ | |
94 | vdprintf_chk \ | |
95 | vfprintf_chk \ | |
96 | vfwprintf_chk \ | |
97 | vobprintf_chk \ | |
98 | vprintf_chk \ | |
99 | vsnprintf_chk \ | |
100 | vsprintf_chk \ | |
101 | vswprintf_chk \ | |
102 | vwprintf_chk \ | |
103 | wcpcpy_chk \ | |
104 | wcpncpy_chk \ | |
105 | wcrtomb_chk \ | |
106 | wcscat_chk \ | |
107 | wcscpy_chk \ | |
b54e5d1c FW |
108 | wcslcat_chk \ |
109 | wcslcpy_chk \ | |
4e464116 FW |
110 | wcsncat_chk \ |
111 | wcsncpy_chk \ | |
112 | wcsnrtombs_chk \ | |
113 | wcsrtombs_chk \ | |
114 | wcstombs_chk \ | |
115 | wctomb_chk \ | |
116 | wmemcpy_chk \ | |
117 | wmemmove_chk \ | |
118 | wmempcpy_chk \ | |
119 | wmemset_chk \ | |
120 | wprintf_chk \ | |
4e464116 | 121 | # routines |
34aec973 | 122 | static-only-routines := stack_chk_fail_local |
2de7874e | 123 | |
2b4fca86 L |
124 | # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local |
125 | # is an alias of __stack_chk_fail in stack_chk_fail.o. | |
126 | elide-routines.o := stack_chk_fail_local | |
127 | ||
524a8ef2 | 128 | # Building the stack-protector failure routines with stack protection |
38cade0c FW |
129 | # is not required since we have already failed a stack check and are |
130 | # exiting the process. However, the local aliases which jump to the | |
131 | # real routines should still be compiled with stack protection | |
132 | # (stack_chk_fail_local.c), so that the statically linked parts of the | |
133 | # library have the expected flags. | |
524a8ef2 | 134 | |
36975e8e | 135 | CFLAGS-stack_chk_fail.c += $(no-stack-protector) |
36975e8e L |
136 | |
137 | CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables | |
138 | CFLAGS-sprintf_chk.c += $(libio-mtsafe) | |
139 | CFLAGS-snprintf_chk.c += $(libio-mtsafe) | |
140 | CFLAGS-vsprintf_chk.c += $(libio-mtsafe) | |
141 | CFLAGS-vsnprintf_chk.c += $(libio-mtsafe) | |
142 | CFLAGS-asprintf_chk.c += $(libio-mtsafe) | |
143 | CFLAGS-vasprintf_chk.c += $(libio-mtsafe) | |
144 | CFLAGS-obprintf_chk.c += $(libio-mtsafe) | |
145 | CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions | |
146 | CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions | |
147 | CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions | |
148 | CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions | |
149 | CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions | |
150 | CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions | |
151 | CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions | |
152 | CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions | |
153 | CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions | |
154 | CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions | |
155 | CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions | |
156 | CFLAGS-swprintf_chk.c += $(libio-mtsafe) | |
157 | CFLAGS-vswprintf_chk.c += $(libio-mtsafe) | |
158 | CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions | |
159 | CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions | |
160 | CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions | |
161 | CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions | |
162 | CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions | |
163 | CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions | |
164 | CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables | |
165 | CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables | |
166 | CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables | |
167 | CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables | |
168 | CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables | |
fed806c3 MF |
169 | |
170 | # Need to make sure the settings here override what configure might have | |
171 | # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is: | |
172 | # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS> | |
36975e8e | 173 | CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables |
20c894d2 | 174 | CPPFLAGS-tst-longjmp_chk.c += $(no-fortify-source),-D_FORTIFY_SOURCE=1 |
36975e8e | 175 | CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables |
20c894d2 | 176 | CPPFLAGS-tst-longjmp_chk2.c += $(no-fortify-source),-D_FORTIFY_SOURCE=1 |
36975e8e | 177 | CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables |
20c894d2 FB |
178 | CPPFLAGS-tst-longjmp_chk3.c += $(no-fortify-source),-D_FORTIFY_SOURCE=1 |
179 | CPPFLAGS-tst-realpath-chk.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 | |
180 | CPPFLAGS-tst-chk-cancel.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 | |
be7a5468 | 181 | CFLAGS-tst-sprintf-fortify-rdonly.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 |
446e2c93 | 182 | CFLAGS-tst-fortify-syslog.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2 |
2de7874e | 183 | |
db27f125 SP |
184 | # _FORTIFY_SOURCE tests. |
185 | # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and | |
186 | # preprocessor conditions based on tst-fortify.c. | |
187 | # | |
188 | # To add a new test condition, define a cflags-$(cond) make variable to set | |
189 | # CFLAGS for the file. | |
190 | ||
191 | tests-all-chk = tst-fortify | |
2e274cd8 AZ |
192 | tests-c-def-chk = |
193 | tests-cc-def-chk = | |
194 | tests-c-time64-chk = | |
195 | tests-cc-time64-chk = | |
db27f125 SP |
196 | |
197 | CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error | |
198 | ||
199 | # No additional flags for the default tests. | |
200 | define cflags-default | |
201 | endef | |
202 | ||
203 | define cflags-lfs | |
2e274cd8 | 204 | CFLAGS-tst-fortify-$(1)-lfs-$(2)-$(3).$(1) += -D_FILE_OFFSET_BITS=64 |
db27f125 SP |
205 | endef |
206 | ||
fcfc9086 | 207 | define cflags-nongnu |
2e274cd8 | 208 | CFLAGS-tst-fortify-$(1)-nongnu-$(2)-$(3).$(1) += -D_LARGEFILE64_SOURCE=1 |
fcfc9086 SP |
209 | endef |
210 | ||
211 | src-chk-nongnu = \#undef _GNU_SOURCE | |
212 | ||
7a344d1d | 213 | # We know these tests have problems with format strings, this is what |
7caa5054 ZW |
214 | # we are testing. Disable that warning. They are also testing |
215 | # deprecated functions (notably gets) so disable that warning as well. | |
216 | # And they also generate warnings from warning attributes, which | |
217 | # cannot be disabled via pragmas, so require -Wno-error to be used. | |
db27f125 | 218 | define gen-chk-test |
2e274cd8 | 219 | tests-$(1)-$(4)-chk += tst-fortify-$(1)-$(2)-$(3)-$(4) |
20c894d2 | 220 | CFLAGS-tst-fortify-$(1)-$(2)-$(3)-$(4).$(1) += $(no-fortify-source),-D_FORTIFY_SOURCE=$(3) -Wno-format \ |
db27f125 SP |
221 | -Wno-deprecated-declarations \ |
222 | -Wno-error | |
2e274cd8 AZ |
223 | $(eval $(call cflags-$(2),$(1),$(3),$(4))) |
224 | $(objpfx)tst-fortify-$(1)-$(2)-$(3)-$(4).$(1): tst-fortify.c Makefile | |
db27f125 | 225 | ( echo "/* Autogenerated from Makefile. */"; \ |
fcfc9086 | 226 | echo "$(src-chk-$(2))"; \ |
db27f125 SP |
227 | echo "#include \"tst-fortify.c\"" ) > $$@.tmp |
228 | mv $$@.tmp $$@ | |
229 | endef | |
230 | ||
231 | chk-extensions = c cc | |
fcfc9086 | 232 | chk-types = default lfs nongnu |
2e274cd8 AZ |
233 | # 64 bit time_t implies LFS. |
234 | chk-types-time64 = default nongnu | |
db27f125 SP |
235 | chk-levels = 1 2 3 |
236 | ||
237 | $(foreach e,$(chk-extensions), \ | |
238 | $(foreach t,$(chk-types), \ | |
239 | $(foreach l,$(chk-levels), \ | |
2e274cd8 | 240 | $(eval $(call gen-chk-test,$(e),$(t),$(l),def))))) |
db27f125 | 241 | |
2e274cd8 AZ |
242 | tests-all-chk += $(tests-c-def-chk) $(tests-cc-def-chk) |
243 | ||
244 | $(foreach e,$(chk-extensions), \ | |
245 | $(foreach t,$(chk-types-time64), \ | |
246 | $(foreach l,$(chk-levels), \ | |
247 | $(eval $(call gen-chk-test,$(e),$(t),$(l),time64))))) | |
248 | ||
249 | tests-all-time64-chk += $(tests-c-time64-chk) $(tests-cc-time64-chk) | |
db27f125 SP |
250 | |
251 | define link-cc | |
252 | LDLIBS-$(1) = -lstdc++ | |
253 | endef | |
2e274cd8 AZ |
254 | $(foreach t,$(tests-cc-def-chk), $(eval $(call link-cc,$(t)))) |
255 | $(foreach t,$(tests-cc-time64-chk), $(eval $(call link-cc,$(t)))) | |
5852d1e5 | 256 | |
31d470ac JM |
257 | # backtrace_symbols only works if we link with -rdynamic. backtrace |
258 | # requires unwind tables on most architectures. | |
259 | CFLAGS-tst-backtrace2.c += -funwind-tables | |
260 | CFLAGS-tst-backtrace3.c += -funwind-tables | |
261 | CFLAGS-tst-backtrace4.c += -funwind-tables | |
262 | CFLAGS-tst-backtrace5.c += -funwind-tables | |
d400dcac | 263 | CFLAGS-tst-backtrace6.c += -funwind-tables |
31d470ac JM |
264 | LDFLAGS-tst-backtrace2 = -rdynamic |
265 | LDFLAGS-tst-backtrace3 = -rdynamic | |
266 | LDFLAGS-tst-backtrace4 = -rdynamic | |
267 | LDFLAGS-tst-backtrace5 = -rdynamic | |
d400dcac | 268 | LDFLAGS-tst-backtrace6 = -rdynamic |
31d470ac | 269 | |
36975e8e | 270 | CFLAGS-tst-ssp-1.c += -fstack-protector-all |
ed421fca | 271 | |
0d50f477 FW |
272 | # Disable compiler optimizations around vsprintf (the function under test). |
273 | CFLAGS-tst-sprintf-fortify-unchecked.c = \ | |
274 | -fno-builtin-vsprintf -fno-builtin-__vsprintf_chk | |
275 | ||
e475bc25 CD |
276 | tests = \ |
277 | $(tests-all-chk) \ | |
278 | backtrace-tst \ | |
279 | test-stpcpy_chk \ | |
280 | test-strcpy_chk \ | |
281 | tst-backtrace2 \ | |
282 | tst-backtrace3 \ | |
283 | tst-backtrace4 \ | |
284 | tst-backtrace5 \ | |
285 | tst-backtrace6 \ | |
286 | tst-longjmp_chk \ | |
287 | tst-longjmp_chk2 \ | |
288 | tst-realpath-chk \ | |
be7a5468 | 289 | tst-sprintf-fortify-rdonly \ |
e475bc25 CD |
290 | tst-sprintf-fortify-unchecked \ |
291 | # tests | |
2de7874e | 292 | |
2e274cd8 | 293 | tests-time64 += \ |
e475bc25 CD |
294 | $(tests-all-time64-chk) \ |
295 | # tests-time64 | |
2e274cd8 | 296 | |
446e2c93 AZ |
297 | tests-container += \ |
298 | tst-fortify-syslog \ | |
299 | # tests-container | |
300 | ||
ed421fca L |
301 | ifeq ($(have-ssp),yes) |
302 | tests += tst-ssp-1 | |
303 | endif | |
304 | ||
dc30acf2 | 305 | ifeq ($(have-thread-library), yes) |
cd84e30c | 306 | tests += tst-chk-cancel |
dc30acf2 AS |
307 | endif |
308 | ||
44a6213c | 309 | ifeq (,$(CXX)) |
1a8335a4 | 310 | tests-unsupported = $(tests-cc-def-chk) $(tests-cc-time64-chk) |
e4693aa7 RM |
311 | endif |
312 | ||
65ccd641 | 313 | extra-libs = libpcprofile |
107f8131 UD |
314 | extra-libs-others = $(extra-libs) |
315 | ||
87843f15 UD |
316 | libpcprofile-routines = pcprofile |
317 | libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes)) | |
318 | ||
08920a50 | 319 | others = pcprofiledump |
6c3ebebd UD |
320 | install-bin = pcprofiledump |
321 | install-bin-script = xtrace | |
cab30d75 | 322 | |
65ccd641 | 323 | generated += xtrace |
6ce7ab19 | 324 | |
2de7874e | 325 | include ../Rules |
107f8131 | 326 | |
f881f6ff AS |
327 | ifeq ($(run-built-tests),yes) |
328 | LOCALES := de_DE.UTF-8 | |
329 | include ../gen-locales.mk | |
330 | ||
db27f125 SP |
331 | define chk-gen-locales |
332 | $(objpfx)$(1).out: $(gen-locales) | |
333 | endef | |
334 | $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t)))) | |
2e274cd8 | 335 | $(foreach t, $(tests-all-time64-chk), $(eval $(call chk-gen-locales,$(t)))) |
f881f6ff AS |
336 | endif |
337 | ||
f50fa10c UD |
338 | sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,') |
339 | ||
cab30d75 | 340 | $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o |
cab30d75 UD |
341 | |
342 | $(objpfx)xtrace: xtrace.sh | |
343 | rm -f $@.new | |
5188a9d0 RG |
344 | sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \ |
345 | -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \ | |
8b748aed | 346 | -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \ |
cab30d75 | 347 | && rm -f $@ && mv $@.new $@ && chmod +x $@ |
dc30acf2 | 348 | |
cd84e30c | 349 | $(objpfx)tst-chk-cancel: $(shared-thread-library) |