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.
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.
32 $(static-only-routines
) \
122 static-only-routines
:= stack_chk_fail_local
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
128 # Building the stack-protector failure routines with stack protection
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.
135 CFLAGS-stack_chk_fail.c
+= $(no-stack-protector
)
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
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>
173 CFLAGS-tst-longjmp_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
174 CPPFLAGS-tst-longjmp_chk.c
+= $(no-fortify-source
),-D_FORTIFY_SOURCE
=1
175 CFLAGS-tst-longjmp_chk2.c
+= -fexceptions
-fasynchronous-unwind-tables
176 CPPFLAGS-tst-longjmp_chk2.c
+= $(no-fortify-source
),-D_FORTIFY_SOURCE
=1
177 CFLAGS-tst-longjmp_chk3.c
+= -fexceptions
-fasynchronous-unwind-tables
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
182 # _FORTIFY_SOURCE tests.
183 # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
184 # preprocessor conditions based on tst-fortify.c.
186 # To add a new test condition, define a cflags-$(cond) make variable to set
187 # CFLAGS for the file.
189 tests-all-chk
= tst-fortify
193 tests-cc-time64-chk
=
195 CFLAGS-tst-fortify.c
+= -Wno-format
-Wno-deprecated-declarations
-Wno-error
197 # No additional flags for the default tests.
198 define cflags-default
202 CFLAGS-tst-fortify-
$(1)-lfs-
$(2)-$(3).
$(1) += -D_FILE_OFFSET_BITS
=64
206 CFLAGS-tst-fortify-
$(1)-nongnu-
$(2)-$(3).
$(1) += -D_LARGEFILE64_SOURCE
=1
209 src-chk-nongnu
= \
#undef _GNU_SOURCE
211 # We know these tests have problems with format strings, this is what
212 # we are testing. Disable that warning. They are also testing
213 # deprecated functions (notably gets) so disable that warning as well.
214 # And they also generate warnings from warning attributes, which
215 # cannot be disabled via pragmas, so require -Wno-error to be used.
217 tests-
$(1)-$(4)-chk
+= tst-fortify-
$(1)-$(2)-$(3)-$(4)
218 CFLAGS-tst-fortify-
$(1)-$(2)-$(3)-$(4).
$(1) += $(no-fortify-source
),-D_FORTIFY_SOURCE
=$(3) -Wno-format \
219 -Wno-deprecated-declarations \
221 $(eval
$(call cflags-
$(2),$(1),$(3),$(4)))
222 $(objpfx
)tst-fortify-
$(1)-$(2)-$(3)-$(4).
$(1): tst-fortify.c Makefile
223 ( echo
"/* Autogenerated from Makefile. */"; \
224 echo
"$(src-chk-$(2))"; \
225 echo
"#include \"tst-fortify.c\"" ) > $$@.tmp
229 chk-extensions
= c
cc
230 chk-types
= default lfs nongnu
231 # 64 bit time_t implies LFS.
232 chk-types-time64
= default nongnu
235 $(foreach e
,$(chk-extensions
), \
236 $(foreach t
,$(chk-types
), \
237 $(foreach l
,$(chk-levels
), \
238 $(eval
$(call gen-chk-test
,$(e
),$(t
),$(l
),def
)))))
240 tests-all-chk
+= $(tests-c-def-chk
) $(tests-cc-def-chk
)
242 $(foreach e
,$(chk-extensions
), \
243 $(foreach t
,$(chk-types-time64
), \
244 $(foreach l
,$(chk-levels
), \
245 $(eval
$(call gen-chk-test
,$(e
),$(t
),$(l
),time64
)))))
247 tests-all-time64-chk
+= $(tests-c-time64-chk
) $(tests-cc-time64-chk
)
250 LDLIBS-
$(1) = -lstdc
++
252 $(foreach t
,$(tests-cc-def-chk
), $(eval
$(call link-cc
,$(t
))))
253 $(foreach t
,$(tests-cc-time64-chk
), $(eval
$(call link-cc
,$(t
))))
255 # backtrace_symbols only works if we link with -rdynamic. backtrace
256 # requires unwind tables on most architectures.
257 CFLAGS-tst-backtrace2.c
+= -funwind-tables
258 CFLAGS-tst-backtrace3.c
+= -funwind-tables
259 CFLAGS-tst-backtrace4.c
+= -funwind-tables
260 CFLAGS-tst-backtrace5.c
+= -funwind-tables
261 CFLAGS-tst-backtrace6.c
+= -funwind-tables
262 LDFLAGS-tst-backtrace2
= -rdynamic
263 LDFLAGS-tst-backtrace3
= -rdynamic
264 LDFLAGS-tst-backtrace4
= -rdynamic
265 LDFLAGS-tst-backtrace5
= -rdynamic
266 LDFLAGS-tst-backtrace6
= -rdynamic
268 CFLAGS-tst-ssp-1.c
+= -fstack-protector-all
270 # Disable compiler optimizations around vsprintf (the function under test).
271 CFLAGS-tst-sprintf-fortify-unchecked.c
= \
272 -fno-builtin-vsprintf
-fno-builtin-__vsprintf_chk
287 tst-sprintf-fortify-unchecked \
291 $(tests-all-time64-chk
) \
294 ifeq ($(have-ssp
),yes
)
298 ifeq ($(have-thread-library
), yes
)
299 tests
+= tst-chk-cancel
303 tests-unsupported
= $(tests-cc-def-chk
) $(tests-cc-time64-chk
)
306 extra-libs
= libpcprofile
307 extra-libs-others
= $(extra-libs
)
309 libpcprofile-routines
= pcprofile
310 libpcprofile-inhibit-o
= $(filter-out .os
,$(object-suffixes
))
312 others
= pcprofiledump
313 install-bin
= pcprofiledump
314 install-bin-script
= xtrace
320 ifeq ($(run-built-tests
),yes
)
321 LOCALES
:= de_DE.UTF-8
322 include ..
/gen-locales.mk
324 define chk-gen-locales
325 $(objpfx
)$(1).out
: $(gen-locales
)
327 $(foreach t
, $(tests-all-chk
), $(eval
$(call chk-gen-locales
,$(t
))))
328 $(foreach t
, $(tests-all-time64-chk
), $(eval
$(call chk-gen-locales
,$(t
))))
331 sLIBdir
:= $(shell echo
$(slibdir
) | sed
's,lib\(\|64\)$$,\\\\$$LIB,')
333 $(objpfx
)pcprofiledump
: $(objpfx
)pcprofiledump.o
335 $(objpfx
)xtrace
: xtrace.sh
337 sed
-e
's|@VERSION@|$(version)|' -e
's|@SLIBDIR@|$(sLIBdir)|' \
338 -e
's|@BINDIR@|$(bindir)|' -e
's|@PKGVERSION@|$(PKGVERSION)|' \
339 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
340 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
342 $(objpfx
)tst-chk-cancel
: $(shared-thread-library
)