blob: 9ff357b6a85274891578592be32681d55595272f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001# Copyright (C) 1998-2015 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# <http://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 \
49 longjmp_chk ____longjmp_chk \
50 fdelt_chk poll_chk ppoll_chk \
51 stack_chk_fail fortify_fail \
52 $(static-only-routines)
53static-only-routines := warning-nop stack_chk_fail_local
54
55CFLAGS-backtrace.c = -fno-omit-frame-pointer
56CFLAGS-sprintf_chk.c = $(libio-mtsafe)
57CFLAGS-snprintf_chk.c = $(libio-mtsafe)
58CFLAGS-vsprintf_chk.c = $(libio-mtsafe)
59CFLAGS-vsnprintf_chk.c = $(libio-mtsafe)
60CFLAGS-asprintf_chk.c = $(libio-mtsafe)
61CFLAGS-vasprintf_chk.c = $(libio-mtsafe)
62CFLAGS-obprintf_chk.c = $(libio-mtsafe)
63CFLAGS-dprintf_chk.c = $(libio-mtsafe) $(exceptions)
64CFLAGS-vdprintf_chk.c = $(libio-mtsafe) $(exceptions)
65CFLAGS-printf_chk.c = $(libio-mtsafe) $(exceptions)
66CFLAGS-fprintf_chk.c = $(libio-mtsafe) $(exceptions)
67CFLAGS-vprintf_chk.c = $(libio-mtsafe) $(exceptions)
68CFLAGS-vfprintf_chk.c = $(libio-mtsafe) $(exceptions)
69CFLAGS-gets_chk.c = $(libio-mtsafe) $(exceptions)
70CFLAGS-fgets_chk.c = $(libio-mtsafe) $(exceptions)
71CFLAGS-fgets_u_chk.c = $(libio-mtsafe) $(exceptions)
72CFLAGS-fread_chk.c = $(libio-mtsafe) $(exceptions)
73CFLAGS-fread_u_chk.c = $(libio-mtsafe) $(exceptions)
74CFLAGS-swprintf_chk.c = $(libio-mtsafe)
75CFLAGS-vswprintf_chk.c = $(libio-mtsafe)
76CFLAGS-wprintf_chk.c = $(libio-mtsafe) $(exceptions)
77CFLAGS-fwprintf_chk.c = $(libio-mtsafe) $(exceptions)
78CFLAGS-vwprintf_chk.c = $(libio-mtsafe) $(exceptions)
79CFLAGS-vfwprintf_chk.c = $(libio-mtsafe) $(exceptions)
80CFLAGS-fgetws_chk.c = $(libio-mtsafe) $(exceptions)
81CFLAGS-fgetws_u_chk.c = $(libio-mtsafe) $(exceptions)
82CFLAGS-read_chk.c = -fexceptions -fasynchronous-unwind-tables
83CFLAGS-pread_chk.c = -fexceptions -fasynchronous-unwind-tables
84CFLAGS-pread64_chk.c = -fexceptions -fasynchronous-unwind-tables
85CFLAGS-recv_chk.c = -fexceptions -fasynchronous-unwind-tables
86CFLAGS-recvfrom_chk.c = -fexceptions -fasynchronous-unwind-tables
87
88# Need to make sure the settings here override what configure might have
89# set up for us, so keep the CFLAGS/CPPFLAGS split logical as the order is:
90# <user CFLAGS> <test CFLAGS> <user CPPFLAGS> <test CPPFLAGS>
91CFLAGS-tst-longjmp_chk.c = -fexceptions -fasynchronous-unwind-tables
92CPPFLAGS-tst-longjmp_chk.c = -D_FORTIFY_SOURCE=1
93CFLAGS-tst-longjmp_chk2.c = -fexceptions -fasynchronous-unwind-tables
94CPPFLAGS-tst-longjmp_chk2.c = -D_FORTIFY_SOURCE=1
95CFLAGS-tst-longjmp_chk3.c = -fexceptions -fasynchronous-unwind-tables
96CPPFLAGS-tst-longjmp_chk3.c = -D_FORTIFY_SOURCE=1
97
98# We know these tests have problems with format strings, this is what
99# we are testing. Disable that warning. They also generate warnings
100# from warning attributes, which cannot be disabled via pragmas, so
101# require -Wno-error to be used.
102CFLAGS-tst-chk1.c = -Wno-format -Wno-error
103CFLAGS-tst-chk2.c = -Wno-format -Wno-error
104CFLAGS-tst-chk3.c = -Wno-format -Wno-error
105CFLAGS-tst-chk4.cc = -Wno-format -Wno-error
106CFLAGS-tst-chk5.cc = -Wno-format -Wno-error
107CFLAGS-tst-chk6.cc = -Wno-format -Wno-error
108CFLAGS-tst-lfschk1.c = -Wno-format -Wno-error
109CFLAGS-tst-lfschk2.c = -Wno-format -Wno-error
110CFLAGS-tst-lfschk3.c = -Wno-format -Wno-error
111CFLAGS-tst-lfschk4.cc = -Wno-format -Wno-error
112CFLAGS-tst-lfschk5.cc = -Wno-format -Wno-error
113CFLAGS-tst-lfschk6.cc = -Wno-format -Wno-error
114LDLIBS-tst-chk4 = -lstdc++
115LDLIBS-tst-chk5 = -lstdc++
116LDLIBS-tst-chk6 = -lstdc++
117LDLIBS-tst-lfschk4 = -lstdc++
118LDLIBS-tst-lfschk5 = -lstdc++
119LDLIBS-tst-lfschk6 = -lstdc++
120
121# backtrace_symbols only works if we link with -rdynamic. backtrace
122# requires unwind tables on most architectures.
123CFLAGS-tst-backtrace2.c += -funwind-tables
124CFLAGS-tst-backtrace3.c += -funwind-tables
125CFLAGS-tst-backtrace4.c += -funwind-tables
126CFLAGS-tst-backtrace5.c += -funwind-tables
127CFLAGS-tst-backtrace6.c += -funwind-tables
128LDFLAGS-tst-backtrace2 = -rdynamic
129LDFLAGS-tst-backtrace3 = -rdynamic
130LDFLAGS-tst-backtrace4 = -rdynamic
131LDFLAGS-tst-backtrace5 = -rdynamic
132LDFLAGS-tst-backtrace6 = -rdynamic
133
134tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \
135 tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \
136 tst-chk4 tst-chk5 tst-chk6 tst-lfschk4 tst-lfschk5 tst-lfschk6 \
137 tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 tst-backtrace4 \
138 tst-backtrace5 tst-backtrace6
139
140ifeq (,$(CXX))
141tests-unsupported = tst-chk4 tst-chk5 tst-chk6 \
142 tst-lfschk4 tst-lfschk5 tst-lfschk6
143endif
144
145extra-libs = libSegFault libpcprofile
146extra-libs-others = $(extra-libs)
147
148libSegFault-routines = segfault
149libSegFault-inhibit-o = $(filter-out .os,$(object-suffixes))
150
151libpcprofile-routines = pcprofile
152libpcprofile-inhibit-o = $(filter-out .os,$(object-suffixes))
153
154others = pcprofiledump
155install-bin = pcprofiledump
156install-bin-script = xtrace
157
158ifeq ($(build-shared),yes)
159install-bin-script += catchsegv
160endif
161generated += catchsegv xtrace
162
163include ../Rules
164
165sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
166
167$(objpfx)catchsegv: catchsegv.sh $(common-objpfx)soversions.mk \
168 $(common-objpfx)config.make
169 slibpfx=`echo $(slibdir)|sed 's/lib\(64\|\)$$/\\\\\\\\$$LIB/'`; \
170 sed -e 's|@VERSION@|$(version)|' -e "s|@SLIB@|$$slibpfx|" \
171 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
172 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $< > $@.new
173 chmod 555 $@.new
174 mv -f $@.new $@
175
176$(objpfx)pcprofiledump: $(objpfx)pcprofiledump.o
177
178$(objpfx)xtrace: xtrace.sh
179 rm -f $@.new
180 sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \
181 -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \
182 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
183 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
184 && rm -f $@ && mv $@.new $@ && chmod +x $@