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.
31 routines
= backtrace backtracesyms backtracesymsfd noophooks \
32 memcpy_chk memmove_chk mempcpy_chk memset_chk stpcpy_chk \
33 strcat_chk strcpy_chk strncat_chk strncpy_chk stpncpy_chk \
34 sprintf_chk vsprintf_chk snprintf_chk vsnprintf_chk \
35 printf_chk fprintf_chk vprintf_chk vfprintf_chk \
36 gets_chk chk_fail readonly-area fgets_chk fgets_u_chk \
37 read_chk pread_chk pread64_chk recv_chk recvfrom_chk \
38 readlink_chk readlinkat_chk getwd_chk getcwd_chk \
39 realpath_chk fread_chk fread_u_chk \
40 wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \
41 wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \
43 swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \
44 vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \
45 confstr_chk getgroups_chk ttyname_r_chk \
46 gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \
47 wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk mbstowcs_chk \
48 wcstombs_chk asprintf_chk vasprintf_chk dprintf_chk \
49 vdprintf_chk obprintf_chk vobprintf_chk \
50 longjmp_chk ____longjmp_chk \
51 fdelt_chk poll_chk ppoll_chk \
53 stack_chk_fail fortify_fail \
54 $(static-only-routines
)
55 static-only-routines
:= stack_chk_fail_local
57 # Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local
58 # is an alias of __stack_chk_fail in stack_chk_fail.o.
59 elide-routines.o
:= stack_chk_fail_local
61 # Building the stack-protector failure routines with stack protection
62 # is not required since we have already failed a stack check and are
63 # exiting the process. However, the local aliases which jump to the
64 # real routines should still be compiled with stack protection
65 # (stack_chk_fail_local.c), so that the statically linked parts of the
66 # library have the expected flags.
68 CFLAGS-stack_chk_fail.c
+= $(no-stack-protector
)
70 CFLAGS-backtrace.c
+= -fno-omit-frame-pointer
-funwind-tables
71 CFLAGS-sprintf_chk.c
+= $(libio-mtsafe
)
72 CFLAGS-snprintf_chk.c
+= $(libio-mtsafe
)
73 CFLAGS-vsprintf_chk.c
+= $(libio-mtsafe
)
74 CFLAGS-vsnprintf_chk.c
+= $(libio-mtsafe
)
75 CFLAGS-asprintf_chk.c
+= $(libio-mtsafe
)
76 CFLAGS-vasprintf_chk.c
+= $(libio-mtsafe
)
77 CFLAGS-obprintf_chk.c
+= $(libio-mtsafe
)
78 CFLAGS-dprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
79 CFLAGS-vdprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
80 CFLAGS-printf_chk.c
+= $(libio-mtsafe
) -fexceptions
81 CFLAGS-fprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
82 CFLAGS-vprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
83 CFLAGS-vfprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
84 CFLAGS-gets_chk.c
+= $(libio-mtsafe
) -fexceptions
85 CFLAGS-fgets_chk.c
+= $(libio-mtsafe
) -fexceptions
86 CFLAGS-fgets_u_chk.c
+= $(libio-mtsafe
) -fexceptions
87 CFLAGS-fread_chk.c
+= $(libio-mtsafe
) -fexceptions
88 CFLAGS-fread_u_chk.c
+= $(libio-mtsafe
) -fexceptions
89 CFLAGS-swprintf_chk.c
+= $(libio-mtsafe
)
90 CFLAGS-vswprintf_chk.c
+= $(libio-mtsafe
)
91 CFLAGS-wprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
92 CFLAGS-fwprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
93 CFLAGS-vwprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
94 CFLAGS-vfwprintf_chk.c
+= $(libio-mtsafe
) -fexceptions
95 CFLAGS-fgetws_chk.c
+= $(libio-mtsafe
) -fexceptions
96 CFLAGS-fgetws_u_chk.c
+= $(libio-mtsafe
) -fexceptions
97 CFLAGS-read_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
98 CFLAGS-pread_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
99 CFLAGS-pread64_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
100 CFLAGS-recv_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
101 CFLAGS-recvfrom_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
103 # Need to make sure the settings here override what configure might have
104 # set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is:
105 # <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS>
106 CFLAGS-tst-longjmp_chk.c
+= -fexceptions
-fasynchronous-unwind-tables
107 CPPFLAGS-tst-longjmp_chk.c
+= -D_FORTIFY_SOURCE
=1
108 CFLAGS-tst-longjmp_chk2.c
+= -fexceptions
-fasynchronous-unwind-tables
109 CPPFLAGS-tst-longjmp_chk2.c
+= -D_FORTIFY_SOURCE
=1
110 CFLAGS-tst-longjmp_chk3.c
+= -fexceptions
-fasynchronous-unwind-tables
111 CPPFLAGS-tst-longjmp_chk3.c
+= -D_FORTIFY_SOURCE
=1
112 CPPFLAGS-tst-realpath-chk.c
+= -D_FORTIFY_SOURCE
=2
113 CPPFLAGS-tst-chk-cancel.c
+= -D_FORTIFY_SOURCE
=2
115 # _FORTIFY_SOURCE tests.
116 # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
117 # preprocessor conditions based on tst-fortify.c.
119 # To add a new test condition, define a cflags-$(cond) make variable to set
120 # CFLAGS for the file.
122 tests-all-chk
= tst-fortify
126 tests-cc-time64-chk
=
128 CFLAGS-tst-fortify.c
+= -Wno-format
-Wno-deprecated-declarations
-Wno-error
130 # No additional flags for the default tests.
131 define cflags-default
135 CFLAGS-tst-fortify-
$(1)-lfs-
$(2)-$(3).
$(1) += -D_FILE_OFFSET_BITS
=64
139 CFLAGS-tst-fortify-
$(1)-nongnu-
$(2)-$(3).
$(1) += -D_LARGEFILE64_SOURCE
=1
142 src-chk-nongnu
= \
#undef _GNU_SOURCE
144 # We know these tests have problems with format strings, this is what
145 # we are testing. Disable that warning. They are also testing
146 # deprecated functions (notably gets) so disable that warning as well.
147 # And they also generate warnings from warning attributes, which
148 # cannot be disabled via pragmas, so require -Wno-error to be used.
150 tests-
$(1)-$(4)-chk
+= tst-fortify-
$(1)-$(2)-$(3)-$(4)
151 CFLAGS-tst-fortify-
$(1)-$(2)-$(3)-$(4).
$(1) += -D_FORTIFY_SOURCE
=$(3) -Wno-format \
152 -Wno-deprecated-declarations \
154 $(eval
$(call cflags-
$(2),$(1),$(3),$(4)))
155 $(objpfx
)tst-fortify-
$(1)-$(2)-$(3)-$(4).
$(1): tst-fortify.c Makefile
156 ( echo
"/* Autogenerated from Makefile. */"; \
157 echo
"$(src-chk-$(2))"; \
158 echo
"#include \"tst-fortify.c\"" ) > $$@.tmp
162 chk-extensions
= c
cc
163 chk-types
= default lfs nongnu
164 # 64 bit time_t implies LFS.
165 chk-types-time64
= default nongnu
168 $(foreach e
,$(chk-extensions
), \
169 $(foreach t
,$(chk-types
), \
170 $(foreach l
,$(chk-levels
), \
171 $(eval
$(call gen-chk-test
,$(e
),$(t
),$(l
),def
)))))
173 tests-all-chk
+= $(tests-c-def-chk
) $(tests-cc-def-chk
)
175 $(foreach e
,$(chk-extensions
), \
176 $(foreach t
,$(chk-types-time64
), \
177 $(foreach l
,$(chk-levels
), \
178 $(eval
$(call gen-chk-test
,$(e
),$(t
),$(l
),time64
)))))
180 tests-all-time64-chk
+= $(tests-c-time64-chk
) $(tests-cc-time64-chk
)
183 LDLIBS-
$(1) = -lstdc
++
185 $(foreach t
,$(tests-cc-def-chk
), $(eval
$(call link-cc
,$(t
))))
186 $(foreach t
,$(tests-cc-time64-chk
), $(eval
$(call link-cc
,$(t
))))
188 # backtrace_symbols only works if we link with -rdynamic. backtrace
189 # requires unwind tables on most architectures.
190 CFLAGS-tst-backtrace2.c
+= -funwind-tables
191 CFLAGS-tst-backtrace3.c
+= -funwind-tables
192 CFLAGS-tst-backtrace4.c
+= -funwind-tables
193 CFLAGS-tst-backtrace5.c
+= -funwind-tables
194 CFLAGS-tst-backtrace6.c
+= -funwind-tables
195 LDFLAGS-tst-backtrace2
= -rdynamic
196 LDFLAGS-tst-backtrace3
= -rdynamic
197 LDFLAGS-tst-backtrace4
= -rdynamic
198 LDFLAGS-tst-backtrace5
= -rdynamic
199 LDFLAGS-tst-backtrace6
= -rdynamic
201 CFLAGS-tst-ssp-1.c
+= -fstack-protector-all
203 # Disable compiler optimizations around vsprintf (the function under test).
204 CFLAGS-tst-sprintf-fortify-unchecked.c
= \
205 -fno-builtin-vsprintf
-fno-builtin-__vsprintf_chk
207 tests
= backtrace-tst \
218 tst-sprintf-fortify-unchecked \
222 $(tests-all-time64-chk
) \
225 ifeq ($(have-ssp
),yes
)
229 ifeq ($(have-thread-library
), yes
)
230 tests
+= tst-chk-cancel
234 tests-unsupported
= $(tests-cc-def-chk
) $(tests-cc-time64-chk
)
237 extra-libs
= libpcprofile
238 extra-libs-others
= $(extra-libs
)
240 libpcprofile-routines
= pcprofile
241 libpcprofile-inhibit-o
= $(filter-out .os
,$(object-suffixes
))
243 others
= pcprofiledump
244 install-bin
= pcprofiledump
245 install-bin-script
= xtrace
251 ifeq ($(run-built-tests
),yes
)
252 LOCALES
:= de_DE.UTF-8
253 include ..
/gen-locales.mk
255 define chk-gen-locales
256 $(objpfx
)$(1).out
: $(gen-locales
)
258 $(foreach t
, $(tests-all-chk
), $(eval
$(call chk-gen-locales
,$(t
))))
259 $(foreach t
, $(tests-all-time64-chk
), $(eval
$(call chk-gen-locales
,$(t
))))
262 sLIBdir
:= $(shell echo
$(slibdir
) | sed
's,lib\(\|64\)$$,\\\\$$LIB,')
264 $(objpfx
)pcprofiledump
: $(objpfx
)pcprofiledump.o
266 $(objpfx
)xtrace
: xtrace.sh
268 sed
-e
's|@VERSION@|$(version)|' -e
's|@SLIBDIR@|$(sLIBdir)|' \
269 -e
's|@BINDIR@|$(bindir)|' -e
's|@PKGVERSION@|$(PKGVERSION)|' \
270 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
271 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
273 $(objpfx
)tst-chk-cancel
: $(shared-thread-library
)