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 tests-internal
:= tst-mallocstate tst-scratch_buffer
52 # The dynarray framework is only available inside glibc.
56 tst-dynarray-at-fail \
58 ifneq (no
,$(have-tunables
))
59 tests
+= tst-malloc-usable-tunables tst-mxfast
60 tests-static
+= tst-malloc-usable-static-tunables
63 tests
+= $(tests-static
)
64 test-srcs
= tst-mtrace
66 # These tests either are run with MALLOC_CHECK_=3 by default or do not work
67 # with MALLOC_CHECK_=3 because they expect a specific failure.
68 tests-exclude-mcheck
= tst-mcheck tst-malloc-usable \
69 tst-interpose-nothread tst-interpose-static-nothread \
70 tst-interpose-static-thread tst-malloc-too-large \
71 tst-mxfast tst-safe-linking
73 # Run all tests with MALLOC_CHECK_=3
74 tests-mcheck
= $(filter-out $(tests-exclude-mcheck
),$(tests
))
76 routines
= malloc morecore mcheck mtrace obstack reallocarray \
77 scratch_buffer_grow scratch_buffer_grow_preserve \
78 scratch_buffer_set_array_size \
80 dynarray_emplace_enlarge \
83 dynarray_resize_clear \
84 alloc_buffer_alloc_array \
85 alloc_buffer_allocate \
86 alloc_buffer_copy_bytes \
87 alloc_buffer_copy_string \
88 alloc_buffer_create_failure \
90 install-lib
:= libmcheck.a
91 non-lib.a
:= libmcheck.a
94 extra-libs
= libmemusage
95 extra-libs-others
= $(extra-libs
)
97 # Helper objects for some tests.
99 tst-interpose-aux-nothread.o \
100 tst-interpose-aux-thread.o \
103 tst-interpose-aux-nothread \
104 tst-interpose-aux-thread \
106 libmemusage-routines
= memusage
107 libmemusage-inhibit-o
= $(filter-out .os
,$(object-suffixes
))
109 $(objpfx
)tst-malloc-backtrace
: $(shared-thread-library
)
110 $(objpfx
)tst-malloc-thread-exit
: $(shared-thread-library
)
111 $(objpfx
)tst-malloc-thread-fail
: $(shared-thread-library
)
112 $(objpfx
)tst-malloc-fork-deadlock
: $(shared-thread-library
)
113 $(objpfx
)tst-malloc-stats-cancellation
: $(shared-thread-library
)
114 $(objpfx
)tst-malloc-backtrace-mcheck
: $(shared-thread-library
)
115 $(objpfx
)tst-malloc-thread-exit-mcheck
: $(shared-thread-library
)
116 $(objpfx
)tst-malloc-thread-fail-mcheck
: $(shared-thread-library
)
117 $(objpfx
)tst-malloc-fork-deadlock-mcheck
: $(shared-thread-library
)
118 $(objpfx
)tst-malloc-stats-cancellation-mcheck
: $(shared-thread-library
)
120 # Export the __malloc_initialize_hook variable to libc.so.
121 LDFLAGS-tst-mallocstate
= -rdynamic
123 # These should be removed by `make clean'.
124 extra-objs
= mcheck-init.o libmcheck.a
125 others-extras
= mcheck-init.o
127 # Include the cleanup handler.
128 aux
:= set-freeres thread-freeres
130 # The Perl script to analyze the output of the mtrace functions.
132 install-bin-script
= mtrace
135 # The Perl script will print addresses and to do this nicely we must know
136 # whether we are on a 32 or 64 bit machine.
137 ifneq ($(findstring wordsize-32
,$(config-sysdirs
)),)
144 # Unless we get a test for the availability of libgd which also works
145 # for cross-compiling we disable the memusagestat generation in this
147 ifneq ($(cross-compiling
),yes
)
148 # If the gd library is available we build the `memusagestat' program.
150 others
: $(objpfx
)memusage
151 others
+= memusagestat
152 install-bin
= memusagestat
153 install-bin-script
+= memusage
154 generated
+= memusagestat memusage
155 extra-objs
+= memusagestat.o
157 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
158 # The directory specified by --with-headers usually contains only the basic
159 # kernel interface headers, not something like libgd. So the simplest thing
160 # is to presume that the standard system headers will be ok for this file.
161 $(objpfx
)memusagestat.o
: sysincludes
= # nothing
165 # Another goal which can be used to override the configure decision.
166 .PHONY
: do-memusagestat
167 do-memusagestat
: $(objpfx
)memusagestat
169 memusagestat-modules
= memusagestat
171 cpp-srcs-left
:= $(memusagestat-modules
)
173 include $(patsubst %,$(..
)libof-iterator.mk
,$(cpp-srcs-left
))
175 LDLIBS-memusagestat
= $(libgd-LDFLAGS
) -lgd
-lpng
-lz
-lm
177 ifeq ($(run-built-tests
),yes
)
178 ifeq (yes
,$(build-shared
))
180 tests-special
+= $(objpfx
)tst-mtrace.out
181 tests-special
+= $(objpfx
)tst-dynarray-mem.out
182 tests-special
+= $(objpfx
)tst-dynarray-fail-mem.out
189 CFLAGS-mcheck-init.c
+= $(PIC-ccflag
)
190 CFLAGS-obstack.c
+= $(uses-callbacks
)
192 $(objpfx
)libmcheck.a
: $(objpfx
)mcheck-init.o
194 $(patsubst %/,cd
% &&,$(objpfx
)) \
197 lib
: $(objpfx
)libmcheck.a
199 ifeq ($(run-built-tests
),yes
)
200 ifeq (yes
,$(build-shared
))
202 $(objpfx
)tst-mtrace.out
: tst-mtrace.sh
$(objpfx
)tst-mtrace
203 $(SHELL
) $< $(common-objpfx
) '$(test-program-prefix-before-env)' \
204 '$(run-program-env)' '$(test-program-prefix-after-env)'; \
210 tst-mcheck-ENV
= MALLOC_CHECK_
=3
211 tst-malloc-usable-ENV
= MALLOC_CHECK_
=3
212 tst-malloc-usable-static-ENV
= $(tst-malloc-usable-ENV
)
213 tst-malloc-usable-tunables-ENV
= GLIBC_TUNABLES
=glibc.malloc.
check=3
214 tst-malloc-usable-static-tunables-ENV
= $(tst-malloc-usable-tunables-ENV
)
216 tst-mxfast-ENV
= GLIBC_TUNABLES
=glibc.malloc.tcache_count
=0:glibc.malloc.mxfast
=0
218 ifeq ($(experimental-malloc
),yes
)
219 CPPFLAGS-malloc.c
+= -DUSE_TCACHE
=1
221 CPPFLAGS-malloc.c
+= -DUSE_TCACHE
=0
223 # Uncomment this for test releases. For public releases it is too expensive.
224 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
226 sLIBdir
:= $(shell echo
$(slibdir
) | sed
's,lib\(\|64\)$$,\\\\$$LIB,')
228 $(objpfx
)mtrace
: mtrace.pl
230 sed
-e
's|@PERL@|$(PERL)|' -e
's|@XXX@|$(address-width)|' \
231 -e
's|@VERSION@|$(version)|' \
232 -e
's|@PKGVERSION@|$(PKGVERSION)|' \
233 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
234 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
236 $(objpfx
)memusage
: memusage.sh
238 sed
-e
's|@BASH@|$(BASH)|' -e
's|@VERSION@|$(version)|' \
239 -e
's|@SLIBDIR@|$(sLIBdir)|' -e
's|@BINDIR@|$(bindir)|' \
240 -e
's|@PKGVERSION@|$(PKGVERSION)|' \
241 -e
's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^
> $@.new \
242 && rm -f
$@
&& mv
$@.new
$@
&& chmod
+x
$@
245 # The implementation uses `dlsym'
246 $(objpfx
)libmemusage.so
: $(libdl
)
249 $(foreach o
,$(all-object-suffixes
),$(objpfx
)malloc
$(o
)): arena.c hooks.c
251 # Compile the tests with a flag which suppresses the mallopt call in
253 $(tests
:%=$(objpfx
)%.o
): CPPFLAGS
+= -DTEST_NO_MALLOPT
255 $(objpfx
)tst-interpose-nothread
: $(objpfx
)tst-interpose-aux-nothread.o
256 $(objpfx
)tst-interpose-thread
: \
257 $(objpfx
)tst-interpose-aux-thread.o
$(shared-thread-library
)
258 $(objpfx
)tst-interpose-thread-mcheck
: \
259 $(objpfx
)tst-interpose-aux-thread.o
$(shared-thread-library
)
260 $(objpfx
)tst-interpose-static-nothread
: $(objpfx
)tst-interpose-aux-nothread.o
261 $(objpfx
)tst-interpose-static-thread
: \
262 $(objpfx
)tst-interpose-aux-thread.o
$(static-thread-library
)
264 tst-dynarray-ENV
= MALLOC_TRACE
=$(objpfx
)tst-dynarray.mtrace
265 $(objpfx
)tst-dynarray-mem.out
: $(objpfx
)tst-dynarray.out
266 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-dynarray.mtrace
> $@
; \
269 tst-dynarray-fail-ENV
= MALLOC_TRACE
=$(objpfx
)tst-dynarray-fail.mtrace
270 $(objpfx
)tst-dynarray-fail-mem.out
: $(objpfx
)tst-dynarray-fail.out
271 $(common-objpfx
)malloc
/mtrace
$(objpfx
)tst-dynarray-fail.mtrace
> $@
; \
274 $(objpfx
)tst-malloc-tcache-leak
: $(shared-thread-library
)
275 $(objpfx
)tst-malloc_info
: $(shared-thread-library
)
276 $(objpfx
)tst-mallocfork2
: $(shared-thread-library
)
277 $(objpfx
)tst-malloc-tcache-leak-mcheck
: $(shared-thread-library
)
278 $(objpfx
)tst-malloc_info-mcheck
: $(shared-thread-library
)
279 $(objpfx
)tst-mallocfork2-mcheck
: $(shared-thread-library
)