Update ChangeLog.old/ChangeLog.23.
[glibc.git] / malloc / Makefile
blob9b70831d383cb5229b1d9d38719574e63dc8a3c6
1 # Copyright (C) 1991-2021 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
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.
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.
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/>.
19 # Makefile for malloc routines
21 subdir := malloc
23 include ../Makeconfig
25 dist-headers := malloc.h
26 headers := $(dist-headers) obstack.h mcheck.h
27 tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
28 tst-malloc-check tst-mallocfork tst-trim1 \
29 tst-malloc-usable tst-realloc tst-reallocarray tst-posix_memalign \
30 tst-pvalloc tst-pvalloc-fortify tst-memalign tst-mallopt \
31 tst-malloc-backtrace tst-malloc-thread-exit \
32 tst-malloc-thread-fail tst-malloc-fork-deadlock \
33 tst-mallocfork2 \
34 tst-mallocfork3 \
35 tst-interpose-nothread \
36 tst-interpose-thread \
37 tst-alloc_buffer \
38 tst-free-errno \
39 tst-malloc-tcache-leak \
40 tst-malloc_info tst-mallinfo2 \
41 tst-malloc-too-large \
42 tst-malloc-stats-cancellation \
43 tst-tcfree1 tst-tcfree2 tst-tcfree3 \
44 tst-safe-linking \
45 tst-mallocalign1 \
47 tests-static := \
48 tst-interpose-static-nothread \
49 tst-interpose-static-thread
51 # Test for the malloc_set_state symbol removed in glibc 2.25.
52 ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes)
53 tests += tst-mallocstate tst-compathooks-off tst-compathooks-on
54 endif
56 tests-internal := tst-scratch_buffer
58 # The dynarray framework is only available inside glibc.
59 tests-internal += \
60 tst-dynarray \
61 tst-dynarray-fail \
62 tst-dynarray-at-fail \
64 ifneq (no,$(have-tunables))
65 tests += tst-malloc-usable-tunables tst-mxfast
66 endif
68 tests += $(tests-static)
69 test-srcs = tst-mtrace
71 # These tests either are run with MALLOC_CHECK_=3 by default or do not work
72 # with MALLOC_CHECK_=3 because they expect a specific failure.
73 tests-exclude-malloc-check = tst-malloc-check tst-malloc-usable \
74 tst-mxfast tst-safe-linking \
75 tst-compathooks-off tst-compathooks-on
77 # Run all tests with MALLOC_CHECK_=3
78 tests-malloc-check = $(filter-out $(tests-exclude-malloc-check) \
79 $(tests-static),$(tests))
81 # -lmcheck needs __malloc_initialize_hook, which was deprecated in 2.24.
82 ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes)
83 # Tests that don't play well with mcheck. They are either bugs in mcheck or
84 # the tests expect specific internal behavior that is changed due to linking to
85 # libmcheck.a.
86 tests-exclude-mcheck = tst-mallocstate \
87 tst-safe-linking \
88 tst-malloc-backtrace \
89 tst-malloc-fork-deadlock \
90 tst-malloc-stats-cancellation \
91 tst-malloc-tcache-leak \
92 tst-malloc-thread-exit \
93 tst-malloc-thread-fail \
94 tst-malloc-usable-tunables \
95 tst-malloc_info \
96 tst-compathooks-off tst-compathooks-on
98 tests-mcheck = $(filter-out $(tests-exclude-mcheck) $(tests-static), $(tests))
99 endif
101 routines = malloc mcheck mtrace obstack reallocarray \
102 scratch_buffer_dupfree \
103 scratch_buffer_grow scratch_buffer_grow_preserve \
104 scratch_buffer_set_array_size \
105 dynarray_at_failure \
106 dynarray_emplace_enlarge \
107 dynarray_finalize \
108 dynarray_resize \
109 dynarray_resize_clear \
110 alloc_buffer_alloc_array \
111 alloc_buffer_allocate \
112 alloc_buffer_copy_bytes \
113 alloc_buffer_copy_string \
114 alloc_buffer_create_failure \
116 install-lib := libmcheck.a
117 non-lib.a := libmcheck.a
119 # Additional libraries.
120 extra-libs = libmemusage libc_malloc_debug
121 extra-libs-others = $(extra-libs)
123 # Helper objects for some tests.
124 extra-tests-objs += \
125 tst-interpose-aux-nothread.o \
126 tst-interpose-aux-thread.o \
128 test-extras = \
129 tst-interpose-aux-nothread \
130 tst-interpose-aux-thread \
132 libmemusage-routines = memusage
133 libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
135 libc_malloc_debug-routines = malloc-debug $(sysdep_malloc_debug_routines)
136 libc_malloc_debug-inhibit-o = $(filter-out .os,$(object-suffixes))
138 $(objpfx)tst-malloc-backtrace: $(shared-thread-library)
139 $(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
140 $(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
141 $(objpfx)tst-mallocfork3: $(shared-thread-library)
142 $(objpfx)tst-mallocfork3-mcheck: $(shared-thread-library)
143 $(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
144 $(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
145 $(objpfx)tst-malloc-backtrace-mcheck: $(shared-thread-library)
146 $(objpfx)tst-malloc-thread-exit-mcheck: $(shared-thread-library)
147 $(objpfx)tst-malloc-thread-fail-mcheck: $(shared-thread-library)
148 $(objpfx)tst-malloc-fork-deadlock-mcheck: $(shared-thread-library)
149 $(objpfx)tst-malloc-stats-cancellation-mcheck: $(shared-thread-library)
150 $(objpfx)tst-mallocfork3-malloc-check: $(shared-thread-library)
151 $(objpfx)tst-malloc-backtrace-malloc-check: $(shared-thread-library)
152 $(objpfx)tst-malloc-thread-exit-malloc-check: $(shared-thread-library)
153 $(objpfx)tst-malloc-thread-fail-malloc-check: $(shared-thread-library)
154 $(objpfx)tst-malloc-fork-deadlock-malloc-check: $(shared-thread-library)
155 $(objpfx)tst-malloc-stats-cancellation-malloc-check: $(shared-thread-library)
157 # These should be removed by `make clean'.
158 extra-objs = mcheck-init.o libmcheck.a
159 others-extras = mcheck-init.o
161 # Include the cleanup handler.
162 aux := set-freeres thread-freeres
164 # The Perl script to analyze the output of the mtrace functions.
165 ifneq ($(PERL),no)
166 install-bin-script = mtrace
167 generated += mtrace
169 # The Perl script will print addresses and to do this nicely we must know
170 # whether we are on a 32 or 64 bit machine.
171 ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
172 address-width=10
173 else
174 address-width=18
175 endif
176 endif
178 # Unless we get a test for the availability of libgd which also works
179 # for cross-compiling we disable the memusagestat generation in this
180 # situation.
181 ifneq ($(cross-compiling),yes)
182 # If the gd library is available we build the `memusagestat' program.
183 ifneq ($(LIBGD),no)
184 others: $(objpfx)memusage
185 others += memusagestat
186 install-bin = memusagestat
187 install-bin-script += memusage
188 generated += memusagestat memusage
189 extra-objs += memusagestat.o
191 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
192 # The directory specified by --with-headers usually contains only the basic
193 # kernel interface headers, not something like libgd. So the simplest thing
194 # is to presume that the standard system headers will be ok for this file.
195 $(objpfx)memusagestat.o: sysincludes = # nothing
196 endif
197 endif
199 # Another goal which can be used to override the configure decision.
200 .PHONY: do-memusagestat
201 do-memusagestat: $(objpfx)memusagestat
203 memusagestat-modules = memusagestat
205 cpp-srcs-left := $(memusagestat-modules)
206 lib := memusagestat
207 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
209 LDLIBS-memusagestat = $(libgd-LDFLAGS) -lgd -lpng -lz -lm
211 ifeq ($(run-built-tests),yes)
212 ifeq (yes,$(build-shared))
213 ifneq ($(PERL),no)
214 tests-special += $(objpfx)tst-mtrace.out
215 tests-special += $(objpfx)tst-dynarray-mem.out
216 tests-special += $(objpfx)tst-dynarray-fail-mem.out
217 endif
218 endif
219 endif
221 include ../Rules
223 CFLAGS-mcheck-init.c += $(PIC-ccflag)
224 CFLAGS-obstack.c += $(uses-callbacks)
226 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
227 -rm -f $@
228 $(patsubst %/,cd % &&,$(objpfx)) \
229 $(LN_S) $(<F) $(@F)
231 lib: $(objpfx)libmcheck.a
233 ifeq ($(run-built-tests),yes)
234 ifeq (yes,$(build-shared))
235 ifneq ($(PERL),no)
236 $(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
237 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
238 '$(run-program-env)' '$(test-program-prefix-after-env)'; \
239 $(evaluate-test)
240 endif
241 endif
242 endif
244 tst-malloc-check-ENV = MALLOC_CHECK_=3 \
245 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
246 tst-malloc-usable-ENV = MALLOC_CHECK_=3 \
247 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
248 tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3 \
249 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
251 tst-mxfast-ENV = GLIBC_TUNABLES=glibc.malloc.tcache_count=0:glibc.malloc.mxfast=0
253 CPPFLAGS-malloc-debug.c += -DUSE_TCACHE=0
254 ifeq ($(experimental-malloc),yes)
255 CPPFLAGS-malloc.c += -DUSE_TCACHE=1
256 else
257 CPPFLAGS-malloc.c += -DUSE_TCACHE=0
258 endif
259 # Uncomment this for test releases. For public releases it is too expensive.
260 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
262 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
264 $(objpfx)mtrace: mtrace.pl
265 rm -f $@.new
266 sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
267 -e 's|@VERSION@|$(version)|' \
268 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
269 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
270 && rm -f $@ && mv $@.new $@ && chmod +x $@
272 $(objpfx)memusage: memusage.sh
273 rm -f $@.new
274 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
275 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
276 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
277 && rm -f $@ && mv $@.new $@ && chmod +x $@
279 # Compile the tests with a flag which suppresses the mallopt call in
280 # the test skeleton.
281 $(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
283 $(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
284 $(objpfx)tst-interpose-nothread-mcheck: $(objpfx)tst-interpose-aux-nothread.o
285 $(objpfx)tst-interpose-nothread-malloc-check: \
286 $(objpfx)tst-interpose-aux-nothread.o
287 $(objpfx)tst-interpose-thread: \
288 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
289 $(objpfx)tst-interpose-thread-mcheck: \
290 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
291 $(objpfx)tst-interpose-thread-malloc-check: \
292 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
293 $(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
294 $(objpfx)tst-interpose-static-thread: \
295 $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
297 tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace \
298 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
299 $(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
300 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
301 $(evaluate-test)
303 tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace \
304 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
305 $(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
306 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
307 $(evaluate-test)
309 $(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
310 $(objpfx)tst-malloc_info: $(shared-thread-library)
311 $(objpfx)tst-mallocfork2: $(shared-thread-library)
312 $(objpfx)tst-malloc-tcache-leak-mcheck: $(shared-thread-library)
313 $(objpfx)tst-malloc_info-mcheck: $(shared-thread-library)
314 $(objpfx)tst-mallocfork2-mcheck: $(shared-thread-library)
315 $(objpfx)tst-malloc-tcache-leak-malloc-check: $(shared-thread-library)
316 $(objpfx)tst-malloc_info-malloc-check: $(shared-thread-library)
317 $(objpfx)tst-mallocfork2-malloc-check: $(shared-thread-library)
319 tst-compathooks-on-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
320 tst-compathooks-on-mcheck-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
321 tst-compathooks-on-malloc-check-ENV = \
322 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
323 tst-mallocstate-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
324 tst-mallocstate-malloc-check-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
326 # The test needs malloc_get_state/malloc_set_state which is in
327 # libc_malloc_debug.so.
328 $(objpfx)tst-mallocstate: $(objpfx)libc_malloc_debug.so
329 $(objpfx)tst-mallocstate-malloc-check: $(objpfx)libc_malloc_debug.so