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
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-mcheck 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 \
34 tst-interpose-nothread \
35 tst-interpose-thread \
38 tst-malloc-tcache-leak \
39 tst-malloc_info tst-mallinfo2 \
40 tst-malloc-too-large \
41 tst-malloc-stats-cancellation \
42 tst-tcfree1 tst-tcfree2 tst-tcfree3 \
46 tst-interpose-static-nothread \
47 tst-interpose-static-thread \
48 tst-malloc-usable-static \
50 # Test for the malloc_set_state symbol removed in glibc 2.25.
51 ifeq ($(have-GLIBC_2.24
)$(build-shared
),yesyes
)
52 tests
+= tst-mallocstate
55 tests-internal
:= tst-scratch_buffer
57 # The dynarray framework is only available inside glibc.
61 tst-dynarray-at-fail \
63 ifneq (no
,$(have-tunables
))
64 tests
+= tst-malloc-usable-tunables tst-mxfast
65 tests-static
+= tst-malloc-usable-static-tunables
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-mcheck
= tst-mcheck tst-malloc-usable \
74 tst-interpose-nothread tst-interpose-static-nothread \
75 tst-interpose-static-thread tst-malloc-too-large \
76 tst-mxfast tst-safe-linking
78 # Run all tests with MALLOC_CHECK_=3
79 tests-mcheck
= $(filter-out $(tests-exclude-mcheck
),$(tests
))
81 routines
= malloc morecore mcheck mtrace obstack reallocarray \
82 scratch_buffer_dupfree \
83 scratch_buffer_grow scratch_buffer_grow_preserve \
84 scratch_buffer_set_array_size \
86 dynarray_emplace_enlarge \
89 dynarray_resize_clear \
90 alloc_buffer_alloc_array \
91 alloc_buffer_allocate \
92 alloc_buffer_copy_bytes \
93 alloc_buffer_copy_string \
94 alloc_buffer_create_failure \
96 install-lib
:= libmcheck.a
97 non-lib.a
:= libmcheck.a
100 extra-libs
= libmemusage
101 extra-libs-others
= $(extra-libs
)
103 # Helper objects for some tests.
104 extra-tests-objs
+= \
105 tst-interpose-aux-nothread.o \
106 tst-interpose-aux-thread.o \
109 tst-interpose-aux-nothread \
110 tst-interpose-aux-thread \
112 libmemusage-routines
= memusage
113 libmemusage-inhibit-o
= $(filter-out .os
,$(object-suffixes
))
115 $(objpfx
)tst-malloc-backtrace
: $(shared-thread-library
)
116 $(objpfx
)tst-malloc-thread-exit
: $(shared-thread-library
)
117 $(objpfx
)tst-malloc-thread-fail
: $(shared-thread-library
)
118 $(objpfx
)tst-malloc-fork-deadlock
: $(shared-thread-library
)
119 $(objpfx
)tst-malloc-stats-cancellation
: $(shared-thread-library
)
120 $(objpfx
)tst-malloc-backtrace-mcheck
: $(shared-thread-library
)
121 $(objpfx
)tst-malloc-thread-exit-mcheck
: $(shared-thread-library
)
122 $(objpfx
)tst-malloc-thread-fail-mcheck
: $(shared-thread-library
)
123 $(objpfx
)tst-malloc-fork-deadlock-mcheck
: $(shared-thread-library
)
124 $(objpfx
)tst-malloc-stats-cancellation-mcheck
: $(shared-thread-library
)
126 # These should be removed by `make clean'.
127 extra-objs
= mcheck-init.o libmcheck.a
128 others-extras
= mcheck-init.o
130 # Include the cleanup handler.
131 aux
:= set-freeres thread-freeres
133 # The Perl script to analyze the output of the mtrace functions.
135 install-bin-script
= mtrace
138 # The Perl script will print addresses and to do this nicely we must know
139 # whether we are on a 32 or 64 bit machine.
140 ifneq ($(findstring wordsize-32
,$(config-sysdirs
)),)
147 # Unless we get a test for the availability of libgd which also works
148 # for cross-compiling we disable the memusagestat generation in this
150 ifneq ($(cross-compiling
),yes
)
151 # If the gd library is available we build the `memusagestat' program.
153 others
: $(objpfx
)memusage
154 others
+= memusagestat
155 install-bin
= memusagestat
156 install-bin-script
+= memusage
157 generated
+= memusagestat memusage
158 extra-objs
+= memusagestat.o
160 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
161 # The directory specified by --with-headers usually contains only the basic
162 # kernel interface headers, not something like libgd. So the simplest thing
163 # is to presume that the standard system headers will be ok for this file.
164 $(objpfx
)memusagestat.o
: sysincludes
= # nothing
168 # Another goal which can be used to override the configure decision.
169 .PHONY
: do-memusagestat
170 do-memusagestat
: $(objpfx
)memusagestat
172 memusagestat-modules
= memusagestat
174 cpp-srcs-left
:= $(memusagestat-modules
)
176 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
178 LDLIBS-memusagestat
= $(libgd-LDFLAGS
) -lgd
-lpng
-lz
-lm
180 ifeq ($(run-built-tests
),yes
)
181 ifeq (yes
,$(build-shared
))
183 tests-special
+= $(objpfx
)tst-mtrace.out
184 tests-special
+= $(objpfx
)tst-dynarray-mem.out
185 tests-special
+= $(objpfx
)tst-dynarray-fail-mem.out
192 CFLAGS-mcheck-init.c
+= $(PIC-ccflag
)
193 CFLAGS-obstack.c
+= $(uses-callbacks
)
195 $(objpfx
)libmcheck.a
: $(objpfx
)mcheck-init.o
197 $(patsubst %/,cd
% &&,$(objpfx
)) \
200 lib
: $(objpfx
)libmcheck.a
202 ifeq ($(run-built-tests
),yes
)
203 ifeq (yes
,$(build-shared
))
205 $(objpfx
)tst-mtrace.out
: tst-mtrace.sh
$(objpfx
)tst-mtrace
206 $(SHELL
) $< $(common-objpfx
) '$(test-program-prefix-before-env)' \
207 '$(run-program-env)' '$(test-program-prefix-after-env)'; \
213 tst-mcheck-ENV
= MALLOC_CHECK_
=3
214 tst-malloc-usable-ENV
= MALLOC_CHECK_
=3
215 tst-malloc-usable-static-ENV
= $(tst-malloc-usable-ENV
)
216 tst-malloc-usable-tunables-ENV
= GLIBC_TUNABLES
=glibc.malloc.
check=3
217 tst-malloc-usable-static-tunables-ENV
= $(tst-malloc-usable-tunables-ENV
)
219 tst-mxfast-ENV
= GLIBC_TUNABLES
=glibc.malloc.tcache_count
=0:glibc.malloc.mxfast
=0
221 ifeq ($(experimental-malloc
),yes
)
222 CPPFLAGS-malloc.c
+= -DUSE_TCACHE
=1
224 CPPFLAGS-malloc.c
+= -DUSE_TCACHE
=0
226 # Uncomment this for test releases. For public releases it is too expensive.
227 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
229 sLIBdir
:= $(shell echo
$(slibdir
) | sed
's,lib\(\|64\)$$,\\\\$$LIB,')
231 $(objpfx
)mtrace
: mtrace.pl
233 sed
-e
's|@PERL@|$(PERL)|' -e
's|@XXX@|$(address-width)|' \
234 -e
's|@VERSION@|$(version)|' \
235 -e
's|@PKGVERSION@|$(PKGVERSION)|' \
236 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
237 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
239 $(objpfx
)memusage
: memusage.sh
241 sed
-e
's|@VERSION@|$(version)|' -e
's|@SLIBDIR@|$(sLIBdir)|' \
242 -e
's|@BINDIR@|$(bindir)|' -e
's|@PKGVERSION@|$(PKGVERSION)|' \
243 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
244 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
247 # The implementation uses `dlsym'
248 $(objpfx
)libmemusage.so
: $(libdl
)
251 $(foreach o
,$(all-object-suffixes
),$(objpfx
)malloc
$(o
)): arena.c hooks.c
253 # Compile the tests with a flag which suppresses the mallopt call in
255 $(tests
:%=$(objpfx
)%.o
): CPPFLAGS
+= -DTEST_NO_MALLOPT
257 $(objpfx
)tst-interpose-nothread
: $(objpfx
)tst-interpose-aux-nothread.o
258 $(objpfx
)tst-interpose-thread
: \
259 $(objpfx
)tst-interpose-aux-thread.o
$(shared-thread-library
)
260 $(objpfx
)tst-interpose-thread-mcheck
: \
261 $(objpfx
)tst-interpose-aux-thread.o
$(shared-thread-library
)
262 $(objpfx
)tst-interpose-static-nothread
: $(objpfx
)tst-interpose-aux-nothread.o
263 $(objpfx
)tst-interpose-static-thread
: \
264 $(objpfx
)tst-interpose-aux-thread.o
$(static-thread-library
)
266 tst-dynarray-ENV
= MALLOC_TRACE
=$(objpfx
)tst-dynarray.mtrace
267 $(objpfx
)tst-dynarray-mem.out
: $(objpfx
)tst-dynarray.out
268 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-dynarray.mtrace
> $@
; \
271 tst-dynarray-fail-ENV
= MALLOC_TRACE
=$(objpfx
)tst-dynarray-fail.mtrace
272 $(objpfx
)tst-dynarray-fail-mem.out
: $(objpfx
)tst-dynarray-fail.out
273 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-dynarray-fail.mtrace
> $@
; \
276 $(objpfx
)tst-malloc-tcache-leak
: $(shared-thread-library
)
277 $(objpfx
)tst-malloc_info
: $(shared-thread-library
)
278 $(objpfx
)tst-mallocfork2
: $(shared-thread-library
)
279 $(objpfx
)tst-malloc-tcache-leak-mcheck
: $(shared-thread-library
)
280 $(objpfx
)tst-malloc_info-mcheck
: $(shared-thread-library
)
281 $(objpfx
)tst-mallocfork2-mcheck
: $(shared-thread-library
)