1# Copyright (C) 1998-2021 Free Software Foundation, Inc. 2# This file is part of the GNU C Library. 3 4# The GNU C Library is free software; you can redistribute it and/or 5# modify it under the terms of the GNU Lesser General Public 6# License as published by the Free Software Foundation; either 7# version 2.1 of the License, or (at your option) any later version. 8 9# The GNU C Library is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12# Lesser General Public License for more details. 13 14# You should have received a copy of the GNU Lesser General Public 15# License along with the GNU C Library; if not, see 16# <https://www.gnu.org/licenses/>. 17 18# 19# Sub-makefile for debug portion of the library. 20# 21subdir := debug 22 23include ../Makeconfig 24 25headers := execinfo.h 26 27# Note that ptsname_r_chk and getlogin_r are not here, but in 28# login/Makefile instead. If that subdir is omitted from the 29# build, its _FORTIFY_SOURCE support will be too. 30routines = backtrace backtracesyms backtracesymsfd noophooks \ 31 memcpy_chk memmove_chk mempcpy_chk memset_chk stpcpy_chk \ 32 strcat_chk strcpy_chk strncat_chk strncpy_chk stpncpy_chk \ 33 sprintf_chk vsprintf_chk snprintf_chk vsnprintf_chk \ 34 printf_chk fprintf_chk vprintf_chk vfprintf_chk \ 35 gets_chk chk_fail readonly-area fgets_chk fgets_u_chk \ 36 read_chk pread_chk pread64_chk recv_chk recvfrom_chk \ 37 readlink_chk readlinkat_chk getwd_chk getcwd_chk \ 38 realpath_chk fread_chk fread_u_chk \ 39 wctomb_chk wcscpy_chk wmemcpy_chk wmemmove_chk wmempcpy_chk \ 40 wcpcpy_chk wcsncpy_chk wcscat_chk wcsncat_chk wmemset_chk \ 41 wcpncpy_chk \ 42 swprintf_chk vswprintf_chk wprintf_chk fwprintf_chk \ 43 vwprintf_chk vfwprintf_chk fgetws_chk fgetws_u_chk \ 44 confstr_chk getgroups_chk ttyname_r_chk \ 45 gethostname_chk getdomainname_chk wcrtomb_chk mbsnrtowcs_chk \ 46 wcsnrtombs_chk mbsrtowcs_chk wcsrtombs_chk mbstowcs_chk \ 47 wcstombs_chk asprintf_chk vasprintf_chk dprintf_chk \ 48 vdprintf_chk obprintf_chk vobprintf_chk \ 49 longjmp_chk ____longjmp_chk \ 50 fdelt_chk poll_chk ppoll_chk \ 51 explicit_bzero_chk \ 52 stack_chk_fail fortify_fail \ 53 $(static-only-routines) 54static-only-routines := stack_chk_fail_local 55 56# Don't add stack_chk_fail_local.o to libc.a since __stack_chk_fail_local 57# is an alias of __stack_chk_fail in stack_chk_fail.o. 58elide-routines.o := stack_chk_fail_local 59 60# Building the stack-protector failure routines with stack protection 61# is not required since we have already failed a stack check and are 62# exiting the process. However, the local aliases which jump to the 63# real routines should still be compiled with stack protection 64# (stack_chk_fail_local.c), so that the statically linked parts of the 65# library have the expected flags. 66 67CFLAGS-stack_chk_fail.c += $(no-stack-protector) 68 69CFLAGS-backtrace.c += -fno-omit-frame-pointer -funwind-tables 70CFLAGS-sprintf_chk.c += $(libio-mtsafe) 71CFLAGS-snprintf_chk.c += $(libio-mtsafe) 72CFLAGS-vsprintf_chk.c += $(libio-mtsafe) 73CFLAGS-vsnprintf_chk.c += $(libio-mtsafe) 74CFLAGS-asprintf_chk.c += $(libio-mtsafe) 75CFLAGS-vasprintf_chk.c += $(libio-mtsafe) 76CFLAGS-obprintf_chk.c += $(libio-mtsafe) 77CFLAGS-dprintf_chk.c += $(libio-mtsafe) -fexceptions 78CFLAGS-vdprintf_chk.c += $(libio-mtsafe) -fexceptions 79CFLAGS-printf_chk.c += $(libio-mtsafe) -fexceptions 80CFLAGS-fprintf_chk.c += $(libio-mtsafe) -fexceptions 81CFLAGS-vprintf_chk.c += $(libio-mtsafe) -fexceptions 82CFLAGS-vfprintf_chk.c += $(libio-mtsafe) -fexceptions 83CFLAGS-gets_chk.c += $(libio-mtsafe) -fexceptions 84CFLAGS-fgets_chk.c += $(libio-mtsafe) -fexceptions 85CFLAGS-fgets_u_chk.c += $(libio-mtsafe) -fexceptions 86CFLAGS-fread_chk.c += $(libio-mtsafe) -fexceptions 87CFLAGS-fread_u_chk.c += $(libio-mtsafe) -fexceptions 88CFLAGS-swprintf_chk.c += $(libio-mtsafe) 89CFLAGS-vswprintf_chk.c += $(libio-mtsafe) 90CFLAGS-wprintf_chk.c += $(libio-mtsafe) -fexceptions 91CFLAGS-fwprintf_chk.c += $(libio-mtsafe) -fexceptions 92CFLAGS-vwprintf_chk.c += $(libio-mtsafe) -fexceptions 93CFLAGS-vfwprintf_chk.c += $(libio-mtsafe) -fexceptions 94CFLAGS-fgetws_chk.c += $(libio-mtsafe) -fexceptions 95CFLAGS-fgetws_u_chk.c += $(libio-mtsafe) -fexceptions 96CFLAGS-read_chk.c += -fexceptions -fasynchronous-unwind-tables 97CFLAGS-pread_chk.c += -fexceptions -fasynchronous-unwind-tables 98CFLAGS-pread64_chk.c += -fexceptions -fasynchronous-unwind-tables 99CFLAGS-recv_chk.c += -fexceptions -fasynchronous-unwind-tables 100CFLAGS-recvfrom_chk.c += -fexceptions -fasynchronous-unwind-tables 101 102# Need to make sure the settings here override what configure might have 103# set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is: 104# <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS> 105CFLAGS-tst-longjmp_chk.c += -fexceptions -fasynchronous-unwind-tables 106CPPFLAGS-tst-longjmp_chk.c += -D_FORTIFY_SOURCE=1 107CFLAGS-tst-longjmp_chk2.c += -fexceptions -fasynchronous-unwind-tables 108CPPFLAGS-tst-longjmp_chk2.c += -D_FORTIFY_SOURCE=1 109CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables 110CPPFLAGS-tst-longjmp_chk3.c += -D_FORTIFY_SOURCE=1 111CPPFLAGS-tst-realpath-chk.c += -D_FORTIFY_SOURCE=2 112 113# We know these tests have problems with format strings, this is what 114# we are testing. Disable that warning. They are also testing 115# deprecated functions (notably gets) so disable that warning as well. 116# And they also generate warnings from warning attributes, which 117# cannot be disabled via pragmas, so require -Wno-error to be used. 118CFLAGS-tst-chk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error 119CFLAGS-tst-chk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error 120CFLAGS-tst-chk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error 121CFLAGS-tst-chk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 122CFLAGS-tst-chk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 123CFLAGS-tst-chk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 124CFLAGS-tst-chk7.c += -Wno-format -Wno-deprecated-declarations -Wno-error 125CFLAGS-tst-chk8.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 126CFLAGS-tst-lfschk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error 127CFLAGS-tst-lfschk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error 128CFLAGS-tst-lfschk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error 129CFLAGS-tst-lfschk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 130CFLAGS-tst-lfschk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 131CFLAGS-tst-lfschk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error 132LDLIBS-tst-chk4 = -lstdc++ 133LDLIBS-tst-chk5 = -lstdc++ 134LDLIBS-tst-chk6 = -lstdc++ 135LDLIBS-tst-chk8 = -lstdc++ 136LDLIBS-tst-lfschk4 = -lstdc++ 137LDLIBS-tst-lfschk5 = -lstdc++ 138LDLIBS-tst-lfschk6 = -lstdc++ 139 140# backtrace_symbols only works if we link with -rdynamic. backtrace 141# requires unwind tables on most architectures. 142CFLAGS-tst-backtrace2.c += -funwind-tables 143CFLAGS-tst-backtrace3.c += -funwind-tables 144CFLAGS-tst-backtrace4.c += -funwind-tables 145CFLAGS-tst-backtrace5.c += -funwind-tables 146CFLAGS-tst-backtrace6.c += -funwind-tables 147LDFLAGS-tst-backtrace2 = -rdynamic 148LDFLAGS-tst-backtrace3 = -rdynamic 149LDFLAGS-tst-backtrace4 = -rdynamic 150LDFLAGS-tst-backtrace5 = -rdynamic 151LDFLAGS-tst-backtrace6 = -rdynamic 152 153CFLAGS-tst-ssp-1.c += -fstack-protector-all 154 155tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \ 156 tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \ 157 tst-chk4 tst-chk5 tst-chk6 tst-chk7 tst-chk8 tst-lfschk4 tst-lfschk5 \ 158 tst-lfschk6 tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 \ 159 tst-backtrace4 tst-backtrace5 tst-backtrace6 tst-realpath-chk 160 161ifeq ($(have-ssp),yes) 162tests += tst-ssp-1 163endif 164 165ifeq (,$(CXX)) 166tests-unsupported = tst-chk4 tst-chk5 tst-chk6 tst-chk8 \ 167 tst-lfschk4 tst-lfschk5 tst-lfschk6 168endif 169 170extra-libs = libSegFault libpcprofile 171extra-libs-others = $(extra-libs) 172 173libSegFault-routines = segfault 174libSegFault-inhibit-o = $(filter-out .os,$(object-suffixes)) 175 176libpcprofile-routines = pcprofile 177libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes)) 178 179others = pcprofiledump 180install-bin = pcprofiledump 181install-bin-script = xtrace 182 183ifeq ($(build-shared),yes) 184install-bin-script += catchsegv 185endif 186generated += catchsegv xtrace 187 188include ../Rules 189 190ifeq ($(run-built-tests),yes) 191LOCALES := de_DE.UTF-8 192include ../gen-locales.mk 193 194$(objpfx)tst-chk1.out: $(gen-locales) 195$(objpfx)tst-chk2.out: $(gen-locales) 196$(objpfx)tst-chk3.out: $(gen-locales) 197$(objpfx)tst-chk4.out: $(gen-locales) 198$(objpfx)tst-chk5.out: $(gen-locales) 199$(objpfx)tst-chk6.out: $(gen-locales) 200$(objpfx)tst-chk7.out: $(gen-locales) 201$(objpfx)tst-chk8.out: $(gen-locales) 202$(objpfx)tst-lfschk1.out: $(gen-locales) 203$(objpfx)tst-lfschk2.out: $(gen-locales) 204$(objpfx)tst-lfschk3.out: $(gen-locales) 205$(objpfx)tst-lfschk4.out: $(gen-locales) 206$(objpfx)tst-lfschk5.out: $(gen-locales) 207$(objpfx)tst-lfschk6.out: $(gen-locales) 208endif 209 210sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,') 211 212$(objpfx)catchsegv: catchsegv.sh $(common-objpfx)soversions.mk \ 213 $(common-objpfx)config.make 214 slibpfx=`echo $(slibdir)|sed 's/lib\(64\|\)$$/\\\\\\\\$$LIB/'`; \ 215 sed -e 's|@VERSION@|$(version)|' -e "s|@SLIB@|$$slibpfx|" \ 216 -e 's|@PKGVERSION@|$(PKGVERSION)|' \ 217 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $< > $@.new 218 chmod 555 $@.new 219 mv -f $@.new $@ 220 221$(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o 222 223$(objpfx)xtrace: xtrace.sh 224 rm -f $@.new 225 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \ 226 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \ 227 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \ 228 && rm -f $@ && mv $@.new $@ && chmod +x $@ 229