]> git.ipfire.org Git - thirdparty/glibc.git/blame - malloc/Makefile
Remove --enable-tunables configure option
[thirdparty/glibc.git] / malloc / Makefile
CommitLineData
6d7e8eda 1# Copyright (C) 1991-2023 Free Software Foundation, Inc.
f65fd747
UD
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
f65fd747
UD
8
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
41bdb6e2 12# Lesser General Public License for more details.
f65fd747 13
41bdb6e2 14# You should have received a copy of the GNU Lesser General Public
59ba27a6 15# License along with the GNU C Library; if not, see
5a82c748 16# <https://www.gnu.org/licenses/>.
f65fd747
UD
17
18#
19# Makefile for malloc routines
20#
33a934a3 21subdir := malloc
f65fd747 22
a5f891ac 23include ../Makeconfig
f65fd747
UD
24
25dist-headers := malloc.h
bd355af0 26headers := $(dist-headers) obstack.h mcheck.h
fa8d436c 27tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
568123a7 28 tst-malloc-check tst-mallocfork tst-trim1 \
2e0bbbfb 29 tst-malloc-usable tst-realloc tst-reallocarray tst-posix_memalign \
768c83b7 30 tst-pvalloc tst-pvalloc-fortify tst-memalign tst-mallopt \
1bd5483e 31 tst-malloc-backtrace tst-malloc-thread-exit \
56290d6e 32 tst-malloc-thread-fail tst-malloc-fork-deadlock \
ef4f9764 33 tst-mallocfork2 \
c32c868a 34 tst-mallocfork3 \
ef4f9764
FW
35 tst-interpose-nothread \
36 tst-interpose-thread \
4dd8e7c0 37 tst-alloc_buffer \
69fda43b 38 tst-free-errno \
1e26d351 39 tst-malloc-tcache-leak \
cdf64542 40 tst-malloc_info tst-mallinfo2 \
8e448310 41 tst-malloc-too-large \
402ecba4 42 tst-malloc-stats-cancellation \
7c9a7c68 43 tst-tcfree1 tst-tcfree2 tst-tcfree3 \
6310d570 44 tst-safe-linking \
dc76a059 45 tst-mallocalign1 \
ef4f9764
FW
46
47tests-static := \
48 tst-interpose-static-nothread \
2d2d9f2b 49 tst-interpose-static-thread
34a63b09 50
178c0e48 51# Test for the malloc_set_state symbol removed in glibc 2.25.
2d2d9f2b
SP
52ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes)
53tests += tst-mallocstate tst-compathooks-off tst-compathooks-on
178c0e48
FW
54endif
55
56tests-internal := tst-scratch_buffer
7c3018f9 57
91b6eb11
FW
58# The dynarray framework is only available inside glibc.
59tests-internal += \
60 tst-dynarray \
61 tst-dynarray-fail \
62 tst-dynarray-at-fail \
63
f9769a23 64tests += tst-malloc-usable-tunables tst-mxfast
ef4f9764 65
0f9317dc 66tests += $(tests-static)
990c32b9 67test-srcs = tst-mtrace
f65fd747 68
4f969166
SP
69# These tests either are run with MALLOC_CHECK_=3 by default or do not work
70# with MALLOC_CHECK_=3 because they expect a specific failure.
451659cc 71tests-exclude-malloc-check = tst-malloc-check tst-malloc-usable \
2d2d9f2b
SP
72 tst-mxfast tst-safe-linking \
73 tst-compathooks-off tst-compathooks-on
4f969166
SP
74
75# Run all tests with MALLOC_CHECK_=3
ddcc612c
SP
76tests-malloc-check = $(filter-out $(tests-exclude-malloc-check) \
77 $(tests-static),$(tests))
4f969166 78
98d5fcb8
AZ
79# Run all tests with GLIBC_TUNABLES=glibc.malloc.hugetlb={1,2} which check
80# the Transparent Huge Pages support (1) or automatic huge page support (2).
81# We need exclude some tests that define the ENV vars.
5f6d8d97
AZ
82tests-exclude-hugetlb1 = \
83 tst-compathooks-off \
84 tst-compathooks-on \
85 tst-interpose-nothread \
86 tst-interpose-thread \
87 tst-interpose-static-nothread \
88 tst-interpose-static-thread \
89 tst-malloc-usable \
90 tst-malloc-usable-tunables \
91 tst-mallocstate
c1beb51d
AZ
92# The tst-free-errno relies on the used malloc page size to mmap an
93# overlapping region.
94tests-exclude-hugetlb2 = \
95 $(tests-exclude-hugetlb1) \
96 tst-free-errno
5f6d8d97
AZ
97tests-malloc-hugetlb1 = \
98 $(filter-out $(tests-exclude-hugetlb1), $(tests))
98d5fcb8 99tests-malloc-hugetlb2 = \
c1beb51d 100 $(filter-out $(tests-exclude-hugetlb2), $(tests))
5f6d8d97 101
0075c4f3
SP
102# -lmcheck needs __malloc_initialize_hook, which was deprecated in 2.24.
103ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes)
784fff6e
SP
104# Tests that don't play well with mcheck. They are either bugs in mcheck or
105# the tests expect specific internal behavior that is changed due to linking to
106# libmcheck.a.
107tests-exclude-mcheck = tst-mallocstate \
6856975e 108 tst-safe-linking \
784fff6e
SP
109 tst-malloc-backtrace \
110 tst-malloc-fork-deadlock \
111 tst-malloc-stats-cancellation \
112 tst-malloc-tcache-leak \
113 tst-malloc-thread-exit \
114 tst-malloc-thread-fail \
784fff6e
SP
115 tst-malloc-usable-tunables \
116 tst-malloc_info \
505a964a
SP
117 tst-compathooks-off tst-compathooks-on \
118 tst-mxfast
784fff6e 119
ddcc612c 120tests-mcheck = $(filter-out $(tests-exclude-mcheck) $(tests-static), $(tests))
0075c4f3 121endif
784fff6e 122
55a4dd39 123routines = malloc mcheck mtrace obstack reallocarray \
cfcfd461 124 scratch_buffer_grow scratch_buffer_grow_preserve \
91b6eb11
FW
125 scratch_buffer_set_array_size \
126 dynarray_at_failure \
127 dynarray_emplace_enlarge \
128 dynarray_finalize \
129 dynarray_resize \
130 dynarray_resize_clear \
4dd8e7c0
FW
131 alloc_buffer_alloc_array \
132 alloc_buffer_allocate \
133 alloc_buffer_copy_bytes \
134 alloc_buffer_copy_string \
135 alloc_buffer_create_failure \
f65fd747 136
6d52618b
UD
137install-lib := libmcheck.a
138non-lib.a := libmcheck.a
139
2d2d9f2b
SP
140# Additional libraries.
141extra-libs = libmemusage libc_malloc_debug
c8f3e6db
UD
142extra-libs-others = $(extra-libs)
143
ef4f9764 144# Helper objects for some tests.
1fe00d3e 145extra-test-objs += \
ef4f9764
FW
146 tst-interpose-aux-nothread.o \
147 tst-interpose-aux-thread.o \
148
149test-extras = \
150 tst-interpose-aux-nothread \
151 tst-interpose-aux-thread \
152
e5874a42
UD
153libmemusage-routines = memusage
154libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
c8f3e6db 155
b5bd5bfe 156libc_malloc_debug-routines = malloc-debug $(sysdep_malloc_debug_routines)
2d2d9f2b
SP
157libc_malloc_debug-inhibit-o = $(filter-out .os,$(object-suffixes))
158
b87e4137
ST
159$(objpfx)tst-malloc-backtrace: $(shared-thread-library)
160$(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
161$(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
c32c868a
AZ
162$(objpfx)tst-mallocfork3: $(shared-thread-library)
163$(objpfx)tst-mallocfork3-mcheck: $(shared-thread-library)
29d79486 164$(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
402ecba4 165$(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
784fff6e
SP
166$(objpfx)tst-malloc-backtrace-mcheck: $(shared-thread-library)
167$(objpfx)tst-malloc-thread-exit-mcheck: $(shared-thread-library)
168$(objpfx)tst-malloc-thread-fail-mcheck: $(shared-thread-library)
169$(objpfx)tst-malloc-fork-deadlock-mcheck: $(shared-thread-library)
170$(objpfx)tst-malloc-stats-cancellation-mcheck: $(shared-thread-library)
63c60cff 171$(objpfx)tst-mallocfork3-malloc-check: $(shared-thread-library)
451659cc
SP
172$(objpfx)tst-malloc-backtrace-malloc-check: $(shared-thread-library)
173$(objpfx)tst-malloc-thread-exit-malloc-check: $(shared-thread-library)
174$(objpfx)tst-malloc-thread-fail-malloc-check: $(shared-thread-library)
175$(objpfx)tst-malloc-fork-deadlock-malloc-check: $(shared-thread-library)
176$(objpfx)tst-malloc-stats-cancellation-malloc-check: $(shared-thread-library)
53c38911
ST
177$(objpfx)tst-malloc-thread-exit-malloc-hugetlb1: $(shared-thread-library)
178$(objpfx)tst-malloc-thread-fail-malloc-hugetlb1: $(shared-thread-library)
179$(objpfx)tst-mallocfork2-malloc-hugetlb1: $(shared-thread-library)
180$(objpfx)tst-mallocfork3-malloc-hugetlb1: $(shared-thread-library)
181$(objpfx)tst-malloc-fork-deadlock-malloc-hugetlb1: $(shared-thread-library)
182$(objpfx)tst-malloc-stats-cancellation-malloc-hugetlb1: $(shared-thread-library)
183$(objpfx)tst-malloc-thread-exit-malloc-hugetlb2: $(shared-thread-library)
184$(objpfx)tst-malloc-thread-fail-malloc-hugetlb2: $(shared-thread-library)
185$(objpfx)tst-mallocfork2-malloc-hugetlb2: $(shared-thread-library)
186$(objpfx)tst-mallocfork3-malloc-hugetlb2: $(shared-thread-library)
187$(objpfx)tst-malloc-fork-deadlock-malloc-hugetlb2: $(shared-thread-library)
188$(objpfx)tst-malloc-stats-cancellation-malloc-hugetlb2: $(shared-thread-library)
fff94fa2 189
6d52618b 190# These should be removed by `make clean'.
469e977f 191extra-objs = mcheck-init.o libmcheck.a
d8287b36 192others-extras = mcheck-init.o
6d52618b 193
a5a0310d 194# Include the cleanup handler.
e8783fd5 195aux := set-freeres thread-freeres
a5a0310d 196
eacde9d0 197# The Perl script to analyze the output of the mtrace functions.
a2b08ee5 198ifneq ($(PERL),no)
6c3ebebd 199install-bin-script = mtrace
f08e9a26 200generated += mtrace
a2b08ee5
UD
201
202# The Perl script will print addresses and to do this nicely we must know
203# whether we are on a 32 or 64 bit machine.
737547be 204ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
a2b08ee5
UD
205address-width=10
206else
207address-width=18
208endif
209endif
210
48d99185
UD
211# Unless we get a test for the availability of libgd which also works
212# for cross-compiling we disable the memusagestat generation in this
213# situation.
214ifneq ($(cross-compiling),yes)
e5874a42 215# If the gd library is available we build the `memusagestat' program.
c8f3e6db 216ifneq ($(LIBGD),no)
f50fa10c 217others: $(objpfx)memusage
f9b645b4 218others += memusagestat
f8d8a265
UD
219install-bin = memusagestat
220install-bin-script += memusage
991dca90 221generated += memusagestat memusage
469e977f 222extra-objs += memusagestat.o
c843e065 223
cb8a6dbd 224# The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
c843e065
RM
225# The directory specified by --with-headers usually contains only the basic
226# kernel interface headers, not something like libgd. So the simplest thing
227# is to presume that the standard system headers will be ok for this file.
228$(objpfx)memusagestat.o: sysincludes = # nothing
c8f3e6db 229endif
48d99185 230endif
c8f3e6db
UD
231
232# Another goal which can be used to override the configure decision.
e5874a42
UD
233.PHONY: do-memusagestat
234do-memusagestat: $(objpfx)memusagestat
c8f3e6db 235
e5874a42 236memusagestat-modules = memusagestat
9cd47470
SP
237
238cpp-srcs-left := $(memusagestat-modules)
239lib := memusagestat
2bfdaedd 240include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
9cd47470 241
f9b645b4 242LDLIBS-memusagestat = $(libgd-LDFLAGS) -lgd -lpng -lz -lm
c8f3e6db 243
f214606a
JM
244ifeq ($(run-built-tests),yes)
245ifeq (yes,$(build-shared))
246ifneq ($(PERL),no)
247tests-special += $(objpfx)tst-mtrace.out
91b6eb11
FW
248tests-special += $(objpfx)tst-dynarray-mem.out
249tests-special += $(objpfx)tst-dynarray-fail-mem.out
f214606a
JM
250endif
251endif
252endif
253
f65fd747
UD
254include ../Rules
255
36975e8e
L
256CFLAGS-mcheck-init.c += $(PIC-ccflag)
257CFLAGS-obstack.c += $(uses-callbacks)
c6359097 258
6d52618b
UD
259$(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
260 -rm -f $@
e7c5513d
UD
261 $(patsubst %/,cd % &&,$(objpfx)) \
262 $(LN_S) $(<F) $(@F)
6d52618b
UD
263
264lib: $(objpfx)libmcheck.a
265
03ac099f 266ifeq ($(run-built-tests),yes)
02ba6e61 267ifeq (yes,$(build-shared))
9317ba7c 268ifneq ($(PERL),no)
3f36c563 269$(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
8540f6d2 270 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
8f8052c2 271 '$(run-program-env)' '$(test-program-prefix-after-env)'; \
f0881698 272 $(evaluate-test)
02ba6e61 273endif
77e4b6fe 274endif
9317ba7c 275endif
199d6eb0 276
2d2d9f2b
SP
277tst-malloc-check-ENV = MALLOC_CHECK_=3 \
278 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
279tst-malloc-usable-ENV = MALLOC_CHECK_=3 \
280 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
281tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3 \
282 LD_PRELOAD=$(objpfx)/libc_malloc_debug.so
bfc832cc 283
c48d92b4
DD
284tst-mxfast-ENV = GLIBC_TUNABLES=glibc.malloc.tcache_count=0:glibc.malloc.mxfast=0
285
b5bd5bfe 286CPPFLAGS-malloc-debug.c += -DUSE_TCACHE=0
d5c3fafc 287CPPFLAGS-malloc.c += -DUSE_TCACHE=1
831372e7 288# Uncomment this for test releases. For public releases it is too expensive.
fa8d436c 289#CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
a2b08ee5 290
f50fa10c
UD
291sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
292
a2b08ee5 293$(objpfx)mtrace: mtrace.pl
dfd2257a 294 rm -f $@.new
a2b08ee5 295 sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
8b748aed
JM
296 -e 's|@VERSION@|$(version)|' \
297 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
298 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
43fc8f18
UD
299 && rm -f $@ && mv $@.new $@ && chmod +x $@
300
e5874a42 301$(objpfx)memusage: memusage.sh
43fc8f18 302 rm -f $@.new
5188a9d0
RG
303 sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
304 -e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
8b748aed 305 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
43fc8f18
UD
306 && rm -f $@ && mv $@.new $@ && chmod +x $@
307
f690b569
FW
308# Compile the tests with a flag which suppresses the mallopt call in
309# the test skeleton.
310$(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
ef4f9764
FW
311
312$(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
784fff6e 313$(objpfx)tst-interpose-nothread-mcheck: $(objpfx)tst-interpose-aux-nothread.o
451659cc
SP
314$(objpfx)tst-interpose-nothread-malloc-check: \
315 $(objpfx)tst-interpose-aux-nothread.o
ef4f9764
FW
316$(objpfx)tst-interpose-thread: \
317 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
784fff6e
SP
318$(objpfx)tst-interpose-thread-mcheck: \
319 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
451659cc 320$(objpfx)tst-interpose-thread-malloc-check: \
4f969166 321 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
ef4f9764
FW
322$(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
323$(objpfx)tst-interpose-static-thread: \
324 $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
91b6eb11 325
2d2d9f2b
SP
326tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace \
327 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
91b6eb11
FW
328$(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
329 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
330 $(evaluate-test)
331
2d2d9f2b
SP
332tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace \
333 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
91b6eb11
FW
334$(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
335 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
336 $(evaluate-test)
1e26d351
CD
337
338$(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
7a9368a1 339$(objpfx)tst-malloc_info: $(shared-thread-library)
b2f601ba 340$(objpfx)tst-mallocfork2: $(shared-thread-library)
784fff6e
SP
341$(objpfx)tst-malloc-tcache-leak-mcheck: $(shared-thread-library)
342$(objpfx)tst-malloc_info-mcheck: $(shared-thread-library)
343$(objpfx)tst-mallocfork2-mcheck: $(shared-thread-library)
451659cc
SP
344$(objpfx)tst-malloc-tcache-leak-malloc-check: $(shared-thread-library)
345$(objpfx)tst-malloc_info-malloc-check: $(shared-thread-library)
346$(objpfx)tst-mallocfork2-malloc-check: $(shared-thread-library)
53c38911
ST
347$(objpfx)tst-malloc-tcache-leak-malloc-hugetlb1: $(shared-thread-library)
348$(objpfx)tst-malloc-tcache-leak-malloc-hugetlb2: $(shared-thread-library)
349$(objpfx)tst-malloc_info-malloc-hugetlb1: $(shared-thread-library)
350$(objpfx)tst-malloc_info-malloc-hugetlb2: $(shared-thread-library)
2d2d9f2b
SP
351
352tst-compathooks-on-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
353tst-compathooks-on-mcheck-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
354tst-compathooks-on-malloc-check-ENV = \
355 LD_PRELOAD=$(objpfx)libc_malloc_debug.so
356tst-mallocstate-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
357tst-mallocstate-malloc-check-ENV = LD_PRELOAD=$(objpfx)libc_malloc_debug.so
0552fd2c
SP
358
359# The test needs malloc_get_state/malloc_set_state which is in
360# libc_malloc_debug.so.
361$(objpfx)tst-mallocstate: $(objpfx)libc_malloc_debug.so
362$(objpfx)tst-mallocstate-malloc-check: $(objpfx)libc_malloc_debug.so