]> git.ipfire.org Git - thirdparty/glibc.git/blame - gmon/Makefile
gmon: fix memory corruption issues [BZ# 30101]
[thirdparty/glibc.git] / gmon / Makefile
CommitLineData
6d7e8eda 1# Copyright (C) 1995-2023 Free Software Foundation, Inc.
bde12187 2# Copyright The GNU Toolchain Authors.
11c981a9
RM
3# This file is part of the GNU C Library.
4
5# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
11c981a9
RM
9
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
41bdb6e2 13# Lesser General Public License for more details.
11c981a9 14
41bdb6e2 15# You should have received a copy of the GNU Lesser General Public
59ba27a6 16# License along with the GNU C Library; if not, see
5a82c748 17# <https://www.gnu.org/licenses/>.
11c981a9
RM
18
19#
20# Sub-makefile for gmon portion of the library.
21#
22subdir := gmon
23
a5f891ac
JM
24include ../Makeconfig
25
a341068d 26headers := sys/gmon.h sys/gmon_out.h sys/profil.h
7ed87317 27routines := gmon mcount profil sprofil prof-freq
0e043598 28
bde12187 29tests = tst-sprofil tst-gmon tst-mcount-overflow tst-mcleanup
9f0d7b6d
UD
30ifeq ($(build-profile),yes)
31tests += tst-profile-static
32tests-static += tst-profile-static
33
34LDFLAGS-tst-profile-static = -profile
35endif
11c981a9 36
a4777c46
L
37tests += tst-gmon-static
38tests-static += tst-gmon-static
39
d165ca64
L
40ifeq (yesyes,$(have-fpie)$(build-shared))
41tests += tst-gmon-pie
42tests-pie += tst-gmon-pie
9d7a3741
L
43ifeq (yes,$(enable-static-pie))
44tests += tst-gmon-static-pie
45tests-static += tst-gmon-static-pie
46endif
d165ca64
L
47endif
48
d99d7e26
RM
49# The mcount code won't work without a frame pointer.
50CFLAGS-mcount.c := -fno-omit-frame-pointer
51
0c251257 52CFLAGS-tst-gmon.c := -fno-omit-frame-pointer -pg
ce16eb52 53tst-gmon-no-pie = yes
26803075 54CRT-tst-gmon := $(csu-objpfx)g$(start-installed-name)
6014c65d 55tst-gmon-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon.data
6b11a6ad 56ifeq ($(run-built-tests),yes)
6014c65d 57tests-special += $(objpfx)tst-gmon-gprof.out
6b11a6ad 58endif
6014c65d 59
31be941e
SK
60CFLAGS-tst-mcount-overflow.c := -fno-omit-frame-pointer -pg
61tst-mcount-overflow-no-pie = yes
62CRT-tst-mcount-overflow := $(csu-objpfx)g$(start-installed-name)
63# Intentionally use invalid config where maxarcs<minarcs to check warning is printed
64tst-mcount-overflow-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcount-overflow.data \
65 GLIBC_TUNABLES=glibc.gmon.minarcs=51:glibc.gmon.maxarcs=50
66# Send stderr into output file because we make sure expected messages are printed
67tst-mcount-overflow-ARGS := 2>&1 1>/dev/null | cat
68ifeq ($(run-built-tests),yes)
69tests-special += $(objpfx)tst-mcount-overflow-check.out
70endif
71
bde12187
SK
72CFLAGS-tst-mcleanup.c := -fno-omit-frame-pointer -pg
73tst-mcleanup-no-pie = yes
74CRT-tst-mcleanup := $(csu-objpfx)g$(start-installed-name)
75tst-mcleanup-ENV := GMON_OUT_PREFIX=$(objpfx)tst-mcleanup.data
76ifeq ($(run-built-tests),yes)
77tests-special += $(objpfx)tst-mcleanup.out
78endif
79
a4777c46 80CFLAGS-tst-gmon-static.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
26803075 81CRT-tst-gmon-static := $(csu-objpfx)g$(static-start-installed-name)
9d7a3741 82tst-gmon-static-no-pie = yes
a4777c46
L
83tst-gmon-static-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static.data
84ifeq ($(run-built-tests),yes)
85tests-special += $(objpfx)tst-gmon-static-gprof.out
86endif
87
d165ca64 88CFLAGS-tst-gmon-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
26803075 89CRT-tst-gmon-pie := $(csu-objpfx)g$(start-installed-name)
d165ca64
L
90tst-gmon-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-pie.data
91ifeq ($(run-built-tests),yes)
92tests-special += $(objpfx)tst-gmon-pie-gprof.out
93endif
94
9d7a3741
L
95ifeq (yes,$(enable-static-pie))
96CFLAGS-tst-gmon-static-pie.c := $(PIE-ccflag) -fno-omit-frame-pointer -pg
26803075 97CRT-tst-gmon-static-pie := $(csu-objpfx)gr$(static-start-installed-name)
9d7a3741
L
98tst-gmon-static-pie-ENV := GMON_OUT_PREFIX=$(objpfx)tst-gmon-static-pie.data
99ifeq ($(run-built-tests),yes)
100tests-special += $(objpfx)tst-gmon-static-pie-gprof.out
101endif
102endif
103
d165ca64 104
d7d06f79
UD
105include ../Rules
106
d99d7e26 107# We cannot compile mcount.c with -pg because that would
6d52618b 108# create recursive calls. Just copy the normal static object.
92777700
RM
109# On systems where `profil' is not a system call, the same
110# problem exists for the internal functions in profil.c.
111
87a07a43 112noprof := mcount $(sysdep_noprof)
92777700 113ifeq (,$(filter profil,$(unix-syscalls)))
4c48b267 114noprof += profil sprofil
92777700
RM
115endif
116
40a55d20 117$(noprof:%=$(objpfx)%.op): %.op: %.o
d99d7e26
RM
118 rm -f $@
119 ln $< $@
6014c65d
FW
120
121# GMON_OUTPUT_PREFIX only sets the output prefix. The actual file
122# name contains the PID as well.
123$(objpfx)tst-gmon.out: clean-tst-gmon-data
124clean-tst-gmon-data:
125 rm -f $(objpfx)tst-gmon.data.*
126
31be941e
SK
127$(objpfx)tst-mcount-overflow.o: clean-tst-mcount-overflow-data
128clean-tst-mcount-overflow-data:
129 rm -f $(objpfx)tst-mcount-overflow.data.*
130
131$(objpfx)tst-mcount-overflow-check.out: tst-mcount-overflow-check.sh $(objpfx)tst-mcount-overflow.out
132 $(SHELL) $< $(objpfx)tst-mcount-overflow > $@; \
133 $(evaluate-test)
134
bde12187
SK
135$(objpfx)tst-mcleanup.out: clean-tst-mcleanup-data
136clean-tst-mcleanup-data:
137 rm -f $(objpfx)tst-mcleanup.data.*
138
6014c65d
FW
139$(objpfx)tst-gmon-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon.out
140 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon $(objpfx)tst-gmon.data.* > $@; \
141 $(evaluate-test)
d165ca64 142
a4777c46
L
143$(objpfx)tst-gmon-static.out: clean-tst-gmon-static-data
144clean-tst-gmon-static-data:
145 rm -f $(objpfx)tst-gmon-static.data.*
146
147$(objpfx)tst-gmon-static-gprof.out: tst-gmon-static-gprof.sh \
148 $(objpfx)tst-gmon-static.out
149 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static \
150 $(objpfx)tst-gmon-static.data.* > $@; \
151 $(evaluate-test)
152
d165ca64
L
153$(objpfx)tst-gmon-pie.out: clean-tst-gmon-pie-data
154clean-tst-gmon-pie-data:
155 rm -f $(objpfx)tst-gmon-pie.data.*
156
157$(objpfx)tst-gmon-pie-gprof.out: tst-gmon-gprof.sh $(objpfx)tst-gmon-pie.out
158 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-pie $(objpfx)tst-gmon-pie.data.* > $@; \
159 $(evaluate-test)
9d7a3741
L
160
161$(objpfx)tst-gmon-static-pie.out: clean-tst-gmon-static-pie-data
162clean-tst-gmon-static-pie-data:
163 rm -f $(objpfx)tst-gmon-static-pie.data.*
164
165$(objpfx)tst-gmon-static-pie-gprof.out: tst-gmon-static-gprof.sh \
166 $(objpfx)tst-gmon-static-pie.out
167 $(SHELL) $< $(GPROF) $(objpfx)tst-gmon-static-pie \
168 $(objpfx)tst-gmon-static-pie.data.* > $@; \
169 $(evaluate-test)