1 # Copyright (C) 1998-2022 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-read-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 CFLAGS-tst-fortify.c
+= -Wno-format
-Wno-deprecated-declarations
-Wno-error
128 # No additional flags for the default tests.
129 define cflags-default
133 CFLAGS-tst-fortify-
$(1)-lfs-
$(2).
$(1) += -D_FILE_OFFSET_BITS
=64
137 CFLAGS-tst-fortify-
$(1)-nongnu-
$(2).
$(1) += -D_LARGEFILE64_SOURCE
=1
140 src-chk-nongnu
= \
#undef _GNU_SOURCE
142 # We know these tests have problems with format strings, this is what
143 # we are testing. Disable that warning. They are also testing
144 # deprecated functions (notably gets) so disable that warning as well.
145 # And they also generate warnings from warning attributes, which
146 # cannot be disabled via pragmas, so require -Wno-error to be used.
148 tests-
$(1)-chk
+= tst-fortify-
$(1)-$(2)-$(3)
149 CFLAGS-tst-fortify-
$(1)-$(2)-$(3).
$(1) += -D_FORTIFY_SOURCE
=$(3) -Wno-format \
150 -Wno-deprecated-declarations \
152 $(eval
$(call cflags-
$(2),$(1),$(3)))
153 $(objpfx
)tst-fortify-
$(1)-$(2)-$(3).
$(1): tst-fortify.c Makefile
154 ( echo
"/* Autogenerated from Makefile. */"; \
155 echo
"$(src-chk-$(2))"; \
156 echo
"#include \"tst-fortify.c\"" ) > $$@.tmp
160 chk-extensions
= c
cc
161 chk-types
= default lfs nongnu
164 $(foreach e
,$(chk-extensions
), \
165 $(foreach t
,$(chk-types
), \
166 $(foreach l
,$(chk-levels
), \
167 $(eval
$(call gen-chk-test
,$(e
),$(t
),$(l
))))))
169 tests-all-chk
+= $(tests-c-chk
) $(tests-cc-chk
)
172 LDLIBS-
$(1) = -lstdc
++
174 $(foreach t
,$(tests-cc-chk
), $(eval
$(call link-cc
,$(t
))))
176 # backtrace_symbols only works if we link with -rdynamic. backtrace
177 # requires unwind tables on most architectures.
178 CFLAGS-tst-backtrace2.c
+= -funwind-tables
179 CFLAGS-tst-backtrace3.c
+= -funwind-tables
180 CFLAGS-tst-backtrace4.c
+= -funwind-tables
181 CFLAGS-tst-backtrace5.c
+= -funwind-tables
182 CFLAGS-tst-backtrace6.c
+= -funwind-tables
183 LDFLAGS-tst-backtrace2
= -rdynamic
184 LDFLAGS-tst-backtrace3
= -rdynamic
185 LDFLAGS-tst-backtrace4
= -rdynamic
186 LDFLAGS-tst-backtrace5
= -rdynamic
187 LDFLAGS-tst-backtrace6
= -rdynamic
189 CFLAGS-tst-ssp-1.c
+= -fstack-protector-all
191 tests
= backtrace-tst \
204 ifeq ($(have-ssp
),yes
)
208 ifeq ($(have-thread-library
), yes
)
209 tests
+= tst-read-chk-cancel
213 tests-unsupported
= $(tests-cc-chk
)
216 extra-libs
= libpcprofile
217 extra-libs-others
= $(extra-libs
)
219 libpcprofile-routines
= pcprofile
220 libpcprofile-inhibit-o
= $(filter-out .os
,$(object-suffixes
))
222 others
= pcprofiledump
223 install-bin
= pcprofiledump
224 install-bin-script
= xtrace
230 ifeq ($(run-built-tests
),yes
)
231 LOCALES
:= de_DE.UTF-8
232 include ..
/gen-locales.mk
234 define chk-gen-locales
235 $(objpfx
)$(1).out
: $(gen-locales
)
237 $(foreach t
, $(tests-all-chk
), $(eval
$(call chk-gen-locales
,$(t
))))
240 sLIBdir
:= $(shell echo
$(slibdir
) | sed
's,lib\(\|64\)$$,\\\\$$LIB,')
242 $(objpfx
)pcprofiledump
: $(objpfx
)pcprofiledump.o
244 $(objpfx
)xtrace
: xtrace.sh
246 sed
-e
's|@VERSION@|$(version)|' -e
's|@SLIBDIR@|$(sLIBdir)|' \
247 -e
's|@BINDIR@|$(bindir)|' -e
's|@PKGVERSION@|$(PKGVERSION)|' \
248 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
249 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
251 $(objpfx
)tst-read-chk-cancel
: $(shared-thread-library
)