mips: align stack in clone [BZ #28223]
[glibc.git] / malloc / Makefile
blob63cd7c0734d97ba3c8a601e4f73b078425cdf1e9
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 \
97 tst-mxfast
99 tests-mcheck = $(filter-out $(tests-exclude-mcheck) $(tests-static), $(tests))
100 endif
102 routines = malloc mcheck mtrace obstack reallocarray \
103 scratch_buffer_dupfree \
104 scratch_buffer_grow scratch_buffer_grow_preserve \
105 scratch_buffer_set_array_size \
106 dynarray_at_failure \
107 dynarray_emplace_enlarge \
108 dynarray_finalize \
109 dynarray_resize \
110 dynarray_resize_clear \
111 alloc_buffer_alloc_array \
112 alloc_buffer_allocate \
113 alloc_buffer_copy_bytes \
114 alloc_buffer_copy_string \
115 alloc_buffer_create_failure \
117 install-lib := libmcheck.a
118 non-lib.a := libmcheck.a
120 # Additional libraries.
121 extra-libs = libmemusage libc_malloc_debug
122 extra-libs-others = $(extra-libs)
124 # Helper objects for some tests.
125 extra-tests-objs += \
126 tst-interpose-aux-nothread.o \
127 tst-interpose-aux-thread.o \
129 test-extras = \
130 tst-interpose-aux-nothread \
131 tst-interpose-aux-thread \
133 libmemusage-routines = memusage
134 libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
136 libc_malloc_debug-routines = malloc-debug $(sysdep_malloc_debug_routines)
137 libc_malloc_debug-inhibit-o = $(filter-out .os,$(object-suffixes))
139 $(objpfx)tst-malloc-backtrace: $(shared-thread-library)
140 $(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
141 $(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
142 $(objpfx)tst-mallocfork3: $(shared-thread-library)
143 $(objpfx)tst-mallocfork3-mcheck: $(shared-thread-library)
144 $(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
145 $(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
146 $(objpfx)tst-malloc-backtrace-mcheck: $(shared-thread-library)
147 $(objpfx)tst-malloc-thread-exit-mcheck: $(shared-thread-library)
148 $(objpfx)tst-malloc-thread-fail-mcheck: $(shared-thread-library)
149 $(objpfx)tst-malloc-fork-deadlock-mcheck: $(shared-thread-library)
150 $(objpfx)tst-malloc-stats-cancellation-mcheck: $(shared-thread-library)
151 $(objpfx)tst-mallocfork3-malloc-check: $(shared-thread-library)
152 $(objpfx)tst-malloc-backtrace-malloc-check: $(shared-thread-library)
153 $(objpfx)tst-malloc-thread-exit-malloc-check: $(shared-thread-library)
154 $(objpfx)tst-malloc-thread-fail-malloc-check: $(shared-thread-library)
155 $(objpfx)tst-malloc-fork-deadlock-malloc-check: $(shared-thread-library)
156 $(objpfx)tst-malloc-stats-cancellation-malloc-check: $(shared-thread-library)
158 # These should be removed by `make clean'.
159 extra-objs = mcheck-init.o libmcheck.a
160 others-extras = mcheck-init.o
162 # Include the cleanup handler.
163 aux := set-freeres thread-freeres
165 # The Perl script to analyze the output of the mtrace functions.
166 ifneq ($(PERL),no)
167 install-bin-script = mtrace
168 generated += mtrace
170 # The Perl script will print addresses and to do this nicely we must know
171 # whether we are on a 32 or 64 bit machine.
172 ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
173 address-width=10
174 else
175 address-width=18
176 endif
177 endif
179 # Unless we get a test for the availability of libgd which also works
180 # for cross-compiling we disable the memusagestat generation in this
181 # situation.
182 ifneq ($(cross-compiling),yes)
183 # If the gd library is available we build the `memusagestat' program.
184 ifneq ($(LIBGD),no)
185 others: $(objpfx)memusage
186 others += memusagestat
187 install-bin = memusagestat
188 install-bin-script += memusage
189 generated += memusagestat memusage
190 extra-objs += memusagestat.o
192 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
193 # The directory specified by --with-headers usually contains only the basic
194 # kernel interface headers, not something like libgd. So the simplest thing
195 # is to presume that the standard system headers will be ok for this file.
196 $(objpfx)memusagestat.o: sysincludes = # nothing
197 endif
198 endif
200 # Another goal which can be used to override the configure decision.
201 .PHONY: do-memusagestat
202 do-memusagestat: $(objpfx)memusagestat
204 memusagestat-modules = memusagestat
206 cpp-srcs-left := $(memusagestat-modules)
207 lib := memusagestat
208 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
210 LDLIBS-memusagestat = $(libgd-LDFLAGS) -lgd -lpng -lz -lm
212 ifeq ($(run-built-tests),yes)
213 ifeq (yes,$(build-shared))
214 ifneq ($(PERL),no)
215 tests-special += $(objpfx)tst-mtrace.out
216 tests-special += $(objpfx)tst-dynarray-mem.out
217 tests-special += $(objpfx)tst-dynarray-fail-mem.out
218 endif
219 endif
220 endif
222 include ../Rules
224 CFLAGS-mcheck-init.c += $(PIC-ccflag)
225 CFLAGS-obstack.c += $(uses-callbacks)
227 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
228 -rm -f $@
229 $(patsubst %/,cd % &&,$(objpfx)) \
230 $(LN_S) $(<F) $(@F)
232 lib: $(objpfx)libmcheck.a
234 ifeq ($(run-built-tests),yes)
235 ifeq (yes,$(build-shared))
236 ifneq ($(PERL),no)
237 $(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
238 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
239 '$(run-program-env)' '$(test-program-prefix-after-env)'; \
240 $(evaluate-test)
241 endif
242 endif
243 endif
245 tst-malloc-check-ENV = MALLOC_CHECK_=3 \
246 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
247 tst-malloc-usable-ENV = MALLOC_CHECK_=3 \
248 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
249 tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3 \
250 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
252 tst-mxfast-ENV = GLIBC_TUNABLES=glibc.malloc.tcache_count=0:glibc.malloc.mxfast=0
254 CPPFLAGS-malloc-debug.c += -DUSE_TCACHE=0
255 ifeq ($(experimental-malloc),yes)
256 CPPFLAGS-malloc.c += -DUSE_TCACHE=1
257 else
258 CPPFLAGS-malloc.c += -DUSE_TCACHE=0
259 endif
260 # Uncomment this for test releases. For public releases it is too expensive.
261 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
263 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
265 $(objpfx)mtrace: mtrace.pl
266 rm -f $@.new
267 sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
268 -e 's|@VERSION@|$(version)|' \
269 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
270 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
271 && rm -f $@ && mv $@.new $@ && chmod +x $@
273 $(objpfx)memusage: memusage.sh
274 rm -f $@.new
275 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
276 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
277 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
278 && rm -f $@ && mv $@.new $@ && chmod +x $@
280 # Compile the tests with a flag which suppresses the mallopt call in
281 # the test skeleton.
282 $(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
284 $(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
285 $(objpfx)tst-interpose-nothread-mcheck: $(objpfx)tst-interpose-aux-nothread.o
286 $(objpfx)tst-interpose-nothread-malloc-check: \
287 $(objpfx)tst-interpose-aux-nothread.o
288 $(objpfx)tst-interpose-thread: \
289 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
290 $(objpfx)tst-interpose-thread-mcheck: \
291 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
292 $(objpfx)tst-interpose-thread-malloc-check: \
293 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
294 $(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
295 $(objpfx)tst-interpose-static-thread: \
296 $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
298 tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace \
299 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
300 $(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
301 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
302 $(evaluate-test)
304 tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace \
305 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
306 $(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
307 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
308 $(evaluate-test)
310 $(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
311 $(objpfx)tst-malloc_info: $(shared-thread-library)
312 $(objpfx)tst-mallocfork2: $(shared-thread-library)
313 $(objpfx)tst-malloc-tcache-leak-mcheck: $(shared-thread-library)
314 $(objpfx)tst-malloc_info-mcheck: $(shared-thread-library)
315 $(objpfx)tst-mallocfork2-mcheck: $(shared-thread-library)
316 $(objpfx)tst-malloc-tcache-leak-malloc-check: $(shared-thread-library)
317 $(objpfx)tst-malloc_info-malloc-check: $(shared-thread-library)
318 $(objpfx)tst-mallocfork2-malloc-check: $(shared-thread-library)
320 tst-compathooks-on-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
321 tst-compathooks-on-mcheck-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
322 tst-compathooks-on-malloc-check-ENV = \
323 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
324 tst-mallocstate-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
325 tst-mallocstate-malloc-check-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
327 # The test needs malloc_get_state/malloc_set_state which is in
328 # libc_malloc_debug.so.
329 $(objpfx)tst-mallocstate: $(objpfx)libc_malloc_debug.so
330 $(objpfx)tst-mallocstate-malloc-check: $(objpfx)libc_malloc_debug.so