Fix elf/loadfail test build dependencies
[glibc.git] / debug / Makefile
blob96029f32ee890a20513e92b0fd0710e8479a66a9
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.
22 subdir := debug
24 include ../Makeconfig
26 headers := execinfo.h
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 \
42 wcpncpy_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 \
52 explicit_bzero_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
114 # _FORTIFY_SOURCE tests.
115 # Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
116 # preprocessor conditions based on tst-fortify.c.
118 # To add a new test condition, define a cflags-$(cond) make variable to set
119 # CFLAGS for the file.
121 tests-all-chk = tst-fortify
122 tests-c-chk =
123 tests-cc-chk =
125 CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
127 # No additional flags for the default tests.
128 define cflags-default
129 endef
131 define cflags-lfs
132 CFLAGS-tst-fortify-$(1)-lfs-$(2).$(1) += -D_FILE_OFFSET_BITS=64
133 endef
135 define cflags-nongnu
136 CFLAGS-tst-fortify-$(1)-nongnu-$(2).$(1) += -D_LARGEFILE64_SOURCE=1
137 endef
139 src-chk-nongnu = \#undef _GNU_SOURCE
141 # We know these tests have problems with format strings, this is what
142 # we are testing. Disable that warning. They are also testing
143 # deprecated functions (notably gets) so disable that warning as well.
144 # And they also generate warnings from warning attributes, which
145 # cannot be disabled via pragmas, so require -Wno-error to be used.
146 define gen-chk-test
147 tests-$(1)-chk += tst-fortify-$(1)-$(2)-$(3)
148 CFLAGS-tst-fortify-$(1)-$(2)-$(3).$(1) += -D_FORTIFY_SOURCE=$(3) -Wno-format \
149 -Wno-deprecated-declarations \
150 -Wno-error
151 $(eval $(call cflags-$(2),$(1),$(3)))
152 $(objpfx)tst-fortify-$(1)-$(2)-$(3).$(1): tst-fortify.c Makefile
153 ( echo "/* Autogenerated from Makefile. */"; \
154 echo "$(src-chk-$(2))"; \
155 echo "#include \"tst-fortify.c\"" ) > $$@.tmp
156 mv $$@.tmp $$@
157 endef
159 chk-extensions = c cc
160 chk-types = default lfs nongnu
161 chk-levels = 1 2 3
163 $(foreach e,$(chk-extensions), \
164 $(foreach t,$(chk-types), \
165 $(foreach l,$(chk-levels), \
166 $(eval $(call gen-chk-test,$(e),$(t),$(l))))))
168 tests-all-chk += $(tests-c-chk) $(tests-cc-chk)
170 define link-cc
171 LDLIBS-$(1) = -lstdc++
172 endef
173 $(foreach t,$(tests-cc-chk), $(eval $(call link-cc,$(t))))
175 # backtrace_symbols only works if we link with -rdynamic. backtrace
176 # requires unwind tables on most architectures.
177 CFLAGS-tst-backtrace2.c += -funwind-tables
178 CFLAGS-tst-backtrace3.c += -funwind-tables
179 CFLAGS-tst-backtrace4.c += -funwind-tables
180 CFLAGS-tst-backtrace5.c += -funwind-tables
181 CFLAGS-tst-backtrace6.c += -funwind-tables
182 LDFLAGS-tst-backtrace2 = -rdynamic
183 LDFLAGS-tst-backtrace3 = -rdynamic
184 LDFLAGS-tst-backtrace4 = -rdynamic
185 LDFLAGS-tst-backtrace5 = -rdynamic
186 LDFLAGS-tst-backtrace6 = -rdynamic
188 CFLAGS-tst-ssp-1.c += -fstack-protector-all
190 tests = backtrace-tst \
191 tst-longjmp_chk \
192 test-strcpy_chk \
193 test-stpcpy_chk \
194 tst-longjmp_chk2 \
195 tst-backtrace2 \
196 tst-backtrace3 \
197 tst-backtrace4 \
198 tst-backtrace5 \
199 tst-backtrace6 \
200 tst-realpath-chk \
201 $(tests-all-chk)
203 ifeq ($(have-ssp),yes)
204 tests += tst-ssp-1
205 endif
207 ifeq (,$(CXX))
208 tests-unsupported = $(tests-cc-chk)
209 endif
211 extra-libs = libpcprofile
212 extra-libs-others = $(extra-libs)
214 libpcprofile-routines = pcprofile
215 libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes))
217 others = pcprofiledump
218 install-bin = pcprofiledump
219 install-bin-script = xtrace
221 generated += xtrace
223 include ../Rules
225 ifeq ($(run-built-tests),yes)
226 LOCALES := de_DE.UTF-8
227 include ../gen-locales.mk
229 define chk-gen-locales
230 $(objpfx)$(1).out: $(gen-locales)
231 endef
232 $(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
233 endif
235 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
237 $(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o
239 $(objpfx)xtrace: xtrace.sh
240 rm -f $@.new
241 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
242 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
243 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
244 && rm -f $@ && mv $@.new $@ && chmod +x $@