libio: Improve fortify with clang
[glibc.git] / gmon / Makefile
blobdb19c205d121bed29b888cef54c90c52aaabd7df
1 # Copyright (C) 1995-2024 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 gmon portion of the library.
22 subdir := gmon
24 include ../Makeconfig
26 headers := \
27 sys/gmon.h \
28 sys/gmon_out.h \
29 sys/profil.h \
30 # headers
31 routines := \
32 gmon \
33 mcount \
34 prof-freq \
35 profil \
36 sprofil \
37 # routines
39 tests = \
40 tst-gmon \
41 tst-mcleanup \
42 tst-mcount-overflow \
43 tst-sprofil \
44 # tests
45 ifeq ($(build-profile),yes)
46 tests += tst-profile-static
47 tests-static += tst-profile-static
49 LDFLAGS-tst-profile-static = -profile
50 endif
52 tests += tst-gmon-static
53 tests-static += tst-gmon-static
55 ifeq (yesyes,$(have-fpie)$(build-shared))
56 tests += tst-gmon-pie
57 tests-pie += tst-gmon-pie
58 ifeq (yes,$(enable-static-pie))
59 tests += tst-gmon-static-pie
60 tests-static += tst-gmon-static-pie
61 endif
62 endif
64 # The mcount code won't work without a frame pointer.
65 CFLAGS-mcount.c := -fno-omit-frame-pointer
67 CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
68 tst-gmon-no-pie = yes
69 CRT-tst-gmon := $(csu-objpfx)g$(start-installed-name)
70 tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data
71 ifeq ($(run-built-tests),yes)
72 tests-special += $(objpfx)tst-gmon-gprof.out
73 endif
75 CFLAGS-tst-mcount-overflow.c := -fno-omit-frame-pointer -pg
76 tst-mcount-overflow-no-pie = yes
77 CRT-tst-mcount-overflow := $(csu-objpfx)g$(start-installed-name)
78 # Intentionally use invalid config where maxarcs<minarcs to check warning is printed
79 tst-mcount-overflow-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcount-overflow.data \
80 GLIBC_TUNABLES=glibc.gmon.minarcs=51:glibc.gmon.maxarcs=50
81 # Send stderr into output file because we make sure expected messages are printed
82 tst-mcount-overflow-ARGS := 2>&1 1>/dev/null | cat
83 ifeq ($(run-built-tests),yes)
84 tests-special += $(objpfx)tst-mcount-overflow-check.out
85 endif
87 CFLAGS-tst-mcleanup.c := -fno-omit-frame-pointer -pg
88 tst-mcleanup-no-pie = yes
89 CRT-tst-mcleanup := $(csu-objpfx)g$(start-installed-name)
90 tst-mcleanup-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcleanup.data
91 ifeq ($(run-built-tests),yes)
92 tests-special += $(objpfx)tst-mcleanup.out
93 endif
95 CFLAGS-tst-gmon-static.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
96 CRT-tst-gmon-static := $(csu-objpfx)g$(static-start-installed-name)
97 tst-gmon-static-no-pie = yes
98 tst-gmon-static-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static.data
99 ifeq ($(run-built-tests),yes)
100 tests-special += $(objpfx)tst-gmon-static-gprof.out
101 endif
103 CFLAGS-tst-gmon-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
104 CRT-tst-gmon-pie := $(csu-objpfx)g$(start-installed-name)
105 tst-gmon-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-pie.data
106 ifeq ($(run-built-tests),yes)
107 tests-special += $(objpfx)tst-gmon-pie-gprof.out
108 endif
110 ifeq (yes,$(enable-static-pie))
111 CFLAGS-tst-gmon-static-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
112 CRT-tst-gmon-static-pie := $(csu-objpfx)gr$(static-start-installed-name)
113 tst-gmon-static-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static-pie.data
114 ifeq ($(run-built-tests),yes)
115 tests-special += $(objpfx)tst-gmon-static-pie-gprof.out
116 endif
117 endif
120 include ../Rules
122 # We cannot compile mcount.c with -pg because that would
123 # create recursive calls. Just copy the normal static object.
124 # On systems where `profil' is not a system call, the same
125 # problem exists for the internal functions in profil.c.
127 noprof := mcount $(sysdep_noprof)
128 ifeq (,$(filter profil,$(unix-syscalls)))
129 noprof += profil sprofil
130 endif
132 $(noprof:%=$(objpfx)%.op): %.op: %.o
133 rm -f $@
134 ln $< $@
136 # GMON_OUTPUT_PREFIX only sets the output prefix. The actual file
137 # name contains the PID as well.
138 $(objpfx)tst-gmon.out: clean-tst-gmon-data
139 clean-tst-gmon-data:
140 rm -f $(objpfx)tst-gmon.data.*
142 $(objpfx)tst-mcount-overflow.o: clean-tst-mcount-overflow-data
143 clean-tst-mcount-overflow-data:
144 rm -f $(objpfx)tst-mcount-overflow.data.*
146 $(objpfx)tst-mcount-overflow-check.out: tst-mcount-overflow-check.sh $(objpfx)tst-mcount-overflow.out
147 $(SHELL) $< $(objpfx)tst-mcount-overflow > $@; \
148 $(evaluate-test)
150 $(objpfx)tst-mcleanup.out: clean-tst-mcleanup-data
151 clean-tst-mcleanup-data:
152 rm -f $(objpfx)tst-mcleanup.data.*
154 $(objpfx)tst-gmon-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon.out
155 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon $(objpfx)tst-gmon.data.* > $@; \
156 $(evaluate-test)
158 $(objpfx)tst-gmon-static.out: clean-tst-gmon-static-data
159 clean-tst-gmon-static-data:
160 rm -f $(objpfx)tst-gmon-static.data.*
162 $(objpfx)tst-gmon-static-gprof.out: tst-gmon-static-gprof.sh \
163 $(objpfx)tst-gmon-static.out
164 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static \
165 $(objpfx)tst-gmon-static.data.* > $@; \
166 $(evaluate-test)
168 $(objpfx)tst-gmon-pie.out: clean-tst-gmon-pie-data
169 clean-tst-gmon-pie-data:
170 rm -f $(objpfx)tst-gmon-pie.data.*
172 $(objpfx)tst-gmon-pie-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon-pie.out
173 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-pie $(objpfx)tst-gmon-pie.data.* > $@; \
174 $(evaluate-test)
176 $(objpfx)tst-gmon-static-pie.out: clean-tst-gmon-static-pie-data
177 clean-tst-gmon-static-pie-data:
178 rm -f $(objpfx)tst-gmon-static-pie.data.*
180 $(objpfx)tst-gmon-static-pie-gprof.out: tst-gmon-static-gprof.sh \
181 $(objpfx)tst-gmon-static-pie.out
182 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static-pie \
183 $(objpfx)tst-gmon-static-pie.data.* > $@; \
184 $(evaluate-test)