2021-01-02 11:32:25 -08:00
|
|
|
# Copyright (C) 1991-2021 Free Software Foundation, Inc.
|
1996-12-08 08:01:13 +00:00
|
|
|
# This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
1996-12-08 08:01:13 +00:00
|
|
|
|
|
|
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
# Lesser General Public License for more details.
|
1996-12-08 08:01:13 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
# License along with the GNU C Library; if not, see
|
2019-09-06 22:40:42 -07:00
|
|
|
# <https://www.gnu.org/licenses/>.
|
1996-12-08 08:01:13 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Makefile for malloc routines
|
|
|
|
|
#
|
1997-01-26 05:33:35 +00:00
|
|
|
subdir := malloc
|
1996-12-08 08:01:13 +00:00
|
|
|
|
2014-02-26 23:12:03 +00:00
|
|
|
include ../Makeconfig
|
1996-12-08 08:01:13 +00:00
|
|
|
|
|
|
|
|
dist-headers := malloc.h
|
1997-12-14 22:24:57 +00:00
|
|
|
headers := $(dist-headers) obstack.h mcheck.h
|
2002-01-29 07:54:51 +00:00
|
|
|
tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
|
2016-11-20 20:46:30 -05:00
|
|
|
tst-mcheck tst-mallocfork tst-trim1 \
|
2017-05-30 18:26:19 -03:00
|
|
|
tst-malloc-usable tst-realloc tst-reallocarray tst-posix_memalign \
|
2020-01-17 15:05:34 +01:00
|
|
|
tst-pvalloc tst-pvalloc-fortify tst-memalign tst-mallopt \
|
2015-12-29 20:32:35 +01:00
|
|
|
tst-malloc-backtrace tst-malloc-thread-exit \
|
2016-05-12 08:54:17 +02:00
|
|
|
tst-malloc-thread-fail tst-malloc-fork-deadlock \
|
2016-08-26 22:40:27 +02:00
|
|
|
tst-mallocfork2 \
|
|
|
|
|
tst-interpose-nothread \
|
|
|
|
|
tst-interpose-thread \
|
2017-06-21 22:43:57 +02:00
|
|
|
tst-alloc_buffer \
|
2020-12-29 00:45:49 -08:00
|
|
|
tst-free-errno \
|
2017-09-28 11:05:18 -06:00
|
|
|
tst-malloc-tcache-leak \
|
2020-09-01 16:17:25 -04:00
|
|
|
tst-malloc_info tst-mallinfo2 \
|
2018-01-18 16:47:06 +00:00
|
|
|
tst-malloc-too-large \
|
2018-02-10 16:24:17 -05:00
|
|
|
tst-malloc-stats-cancellation \
|
2018-11-30 22:13:09 -05:00
|
|
|
tst-tcfree1 tst-tcfree2 tst-tcfree3 \
|
2020-04-02 07:26:35 -04:00
|
|
|
tst-safe-linking \
|
2016-08-26 22:40:27 +02:00
|
|
|
|
|
|
|
|
tests-static := \
|
|
|
|
|
tst-interpose-static-nothread \
|
|
|
|
|
tst-interpose-static-thread \
|
2016-12-31 23:33:27 +05:30
|
|
|
tst-malloc-usable-static \
|
2017-01-01 09:27:03 +01:00
|
|
|
|
2021-03-09 21:07:24 +01:00
|
|
|
# Test for the malloc_set_state symbol removed in glibc 2.25.
|
|
|
|
|
ifeq ($(have-GLIBC_2.24)$(build-shared),yesyes)
|
|
|
|
|
tests += tst-mallocstate
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
tests-internal := tst-scratch_buffer
|
2016-11-20 20:46:30 -05:00
|
|
|
|
2017-06-02 11:59:28 +02:00
|
|
|
# The dynarray framework is only available inside glibc.
|
|
|
|
|
tests-internal += \
|
|
|
|
|
tst-dynarray \
|
|
|
|
|
tst-dynarray-fail \
|
|
|
|
|
tst-dynarray-at-fail \
|
|
|
|
|
|
2017-01-01 09:27:03 +01:00
|
|
|
ifneq (no,$(have-tunables))
|
2019-08-15 11:37:18 +02:00
|
|
|
tests += tst-malloc-usable-tunables tst-mxfast
|
2017-01-01 09:27:03 +01:00
|
|
|
tests-static += tst-malloc-usable-static-tunables
|
|
|
|
|
endif
|
2016-08-26 22:40:27 +02:00
|
|
|
|
2016-09-10 16:10:51 +05:30
|
|
|
tests += $(tests-static)
|
2017-06-09 14:08:57 +02:00
|
|
|
test-srcs = tst-mtrace
|
1996-12-08 08:01:13 +00:00
|
|
|
|
2020-12-23 13:04:45 +05:30
|
|
|
# These tests either are run with MALLOC_CHECK_=3 by default or do not work
|
|
|
|
|
# with MALLOC_CHECK_=3 because they expect a specific failure.
|
|
|
|
|
tests-exclude-mcheck = tst-mcheck tst-malloc-usable \
|
|
|
|
|
tst-interpose-nothread tst-interpose-static-nothread \
|
2021-05-17 14:00:19 +02:00
|
|
|
tst-interpose-static-thread \
|
2020-12-23 13:04:45 +05:30
|
|
|
tst-mxfast tst-safe-linking
|
|
|
|
|
|
|
|
|
|
# Run all tests with MALLOC_CHECK_=3
|
|
|
|
|
tests-mcheck = $(filter-out $(tests-exclude-mcheck),$(tests))
|
|
|
|
|
|
2017-05-30 18:26:19 -03:00
|
|
|
routines = malloc morecore mcheck mtrace obstack reallocarray \
|
2020-12-28 09:50:23 -03:00
|
|
|
scratch_buffer_dupfree \
|
2015-04-07 11:03:43 +02:00
|
|
|
scratch_buffer_grow scratch_buffer_grow_preserve \
|
2017-06-02 11:59:28 +02:00
|
|
|
scratch_buffer_set_array_size \
|
|
|
|
|
dynarray_at_failure \
|
|
|
|
|
dynarray_emplace_enlarge \
|
|
|
|
|
dynarray_finalize \
|
|
|
|
|
dynarray_resize \
|
|
|
|
|
dynarray_resize_clear \
|
2017-06-21 22:43:57 +02:00
|
|
|
alloc_buffer_alloc_array \
|
|
|
|
|
alloc_buffer_allocate \
|
|
|
|
|
alloc_buffer_copy_bytes \
|
|
|
|
|
alloc_buffer_copy_string \
|
|
|
|
|
alloc_buffer_create_failure \
|
1996-12-08 08:01:13 +00:00
|
|
|
|
1996-12-20 01:39:50 +00:00
|
|
|
install-lib := libmcheck.a
|
|
|
|
|
non-lib.a := libmcheck.a
|
|
|
|
|
|
1999-10-04 04:37:58 +00:00
|
|
|
# Additional library.
|
2000-06-20 06:36:03 +00:00
|
|
|
extra-libs = libmemusage
|
1999-10-04 04:37:58 +00:00
|
|
|
extra-libs-others = $(extra-libs)
|
|
|
|
|
|
2016-08-26 22:40:27 +02:00
|
|
|
# Helper objects for some tests.
|
|
|
|
|
extra-tests-objs += \
|
|
|
|
|
tst-interpose-aux-nothread.o \
|
|
|
|
|
tst-interpose-aux-thread.o \
|
|
|
|
|
|
|
|
|
|
test-extras = \
|
|
|
|
|
tst-interpose-aux-nothread \
|
|
|
|
|
tst-interpose-aux-thread \
|
|
|
|
|
|
2000-06-20 06:36:03 +00:00
|
|
|
libmemusage-routines = memusage
|
|
|
|
|
libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
|
1999-10-04 04:37:58 +00:00
|
|
|
|
2016-03-22 09:58:48 +01:00
|
|
|
$(objpfx)tst-malloc-backtrace: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
|
2016-04-14 09:17:02 +02:00
|
|
|
$(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
|
2018-02-10 16:24:17 -05:00
|
|
|
$(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
|
2020-12-23 13:04:45 +05:30
|
|
|
$(objpfx)tst-malloc-backtrace-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-thread-exit-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-thread-fail-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-fork-deadlock-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc-stats-cancellation-mcheck: $(shared-thread-library)
|
2015-05-19 06:40:37 +05:30
|
|
|
|
1996-12-20 01:39:50 +00:00
|
|
|
# These should be removed by `make clean'.
|
2000-08-24 12:39:25 +00:00
|
|
|
extra-objs = mcheck-init.o libmcheck.a
|
2017-10-16 20:50:04 +02:00
|
|
|
others-extras = mcheck-init.o
|
1996-12-20 01:39:50 +00:00
|
|
|
|
1997-09-30 17:10:40 +00:00
|
|
|
# Include the cleanup handler.
|
2003-02-22 00:55:36 +00:00
|
|
|
aux := set-freeres thread-freeres
|
1997-09-30 17:10:40 +00:00
|
|
|
|
2001-04-09 04:55:59 +00:00
|
|
|
# The Perl script to analyze the output of the mtrace functions.
|
1997-09-27 00:21:42 +00:00
|
|
|
ifneq ($(PERL),no)
|
2001-08-29 23:31:38 +00:00
|
|
|
install-bin-script = mtrace
|
2014-02-28 13:00:27 -08:00
|
|
|
generated += mtrace
|
1997-09-27 00:21:42 +00:00
|
|
|
|
|
|
|
|
# The Perl script will print addresses and to do this nicely we must know
|
|
|
|
|
# whether we are on a 32 or 64 bit machine.
|
1998-06-05 20:59:11 +00:00
|
|
|
ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
|
1997-09-27 00:21:42 +00:00
|
|
|
address-width=10
|
|
|
|
|
else
|
|
|
|
|
address-width=18
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2001-01-30 01:45:30 +00:00
|
|
|
# Unless we get a test for the availability of libgd which also works
|
|
|
|
|
# for cross-compiling we disable the memusagestat generation in this
|
|
|
|
|
# situation.
|
|
|
|
|
ifneq ($(cross-compiling),yes)
|
2000-06-20 06:36:03 +00:00
|
|
|
# If the gd library is available we build the `memusagestat' program.
|
1999-10-04 04:37:58 +00:00
|
|
|
ifneq ($(LIBGD),no)
|
2006-05-19 16:48:27 +00:00
|
|
|
others: $(objpfx)memusage
|
2019-04-24 13:32:22 +02:00
|
|
|
others += memusagestat
|
2004-12-15 18:44:54 +00:00
|
|
|
install-bin = memusagestat
|
|
|
|
|
install-bin-script += memusage
|
2000-08-24 08:58:23 +00:00
|
|
|
generated += memusagestat memusage
|
2000-08-24 12:39:25 +00:00
|
|
|
extra-objs += memusagestat.o
|
2002-09-18 00:15:25 +00:00
|
|
|
|
2013-10-30 13:20:52 +10:00
|
|
|
# The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
|
2002-09-18 00:15:25 +00:00
|
|
|
# The directory specified by --with-headers usually contains only the basic
|
|
|
|
|
# kernel interface headers, not something like libgd. So the simplest thing
|
|
|
|
|
# is to presume that the standard system headers will be ok for this file.
|
|
|
|
|
$(objpfx)memusagestat.o: sysincludes = # nothing
|
1999-10-04 04:37:58 +00:00
|
|
|
endif
|
2001-01-30 01:45:30 +00:00
|
|
|
endif
|
1999-10-04 04:37:58 +00:00
|
|
|
|
|
|
|
|
# Another goal which can be used to override the configure decision.
|
2000-06-20 06:36:03 +00:00
|
|
|
.PHONY: do-memusagestat
|
|
|
|
|
do-memusagestat: $(objpfx)memusagestat
|
1999-10-04 04:37:58 +00:00
|
|
|
|
2000-06-20 06:36:03 +00:00
|
|
|
memusagestat-modules = memusagestat
|
2014-11-19 12:13:54 +05:30
|
|
|
|
|
|
|
|
cpp-srcs-left := $(memusagestat-modules)
|
|
|
|
|
lib := memusagestat
|
2017-05-08 15:52:26 -04:00
|
|
|
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
|
2014-11-19 12:13:54 +05:30
|
|
|
|
2019-04-24 13:32:22 +02:00
|
|
|
LDLIBS-memusagestat = $(libgd-LDFLAGS) -lgd -lpng -lz -lm
|
1999-10-04 04:37:58 +00:00
|
|
|
|
2014-03-06 22:35:33 +00:00
|
|
|
ifeq ($(run-built-tests),yes)
|
|
|
|
|
ifeq (yes,$(build-shared))
|
|
|
|
|
ifneq ($(PERL),no)
|
|
|
|
|
tests-special += $(objpfx)tst-mtrace.out
|
2017-06-02 11:59:28 +02:00
|
|
|
tests-special += $(objpfx)tst-dynarray-mem.out
|
|
|
|
|
tests-special += $(objpfx)tst-dynarray-fail-mem.out
|
2014-03-06 22:35:33 +00:00
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
1996-12-08 08:01:13 +00:00
|
|
|
include ../Rules
|
|
|
|
|
|
2017-12-11 13:11:16 -08:00
|
|
|
CFLAGS-mcheck-init.c += $(PIC-ccflag)
|
|
|
|
|
CFLAGS-obstack.c += $(uses-callbacks)
|
2005-02-22 09:53:18 +00:00
|
|
|
|
1996-12-20 01:39:50 +00:00
|
|
|
$(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
|
|
|
|
|
-rm -f $@
|
1998-09-21 14:34:13 +00:00
|
|
|
$(patsubst %/,cd % &&,$(objpfx)) \
|
|
|
|
|
$(LN_S) $(<F) $(@F)
|
1996-12-20 01:39:50 +00:00
|
|
|
|
|
|
|
|
lib: $(objpfx)libmcheck.a
|
|
|
|
|
|
2012-10-24 00:08:46 +00:00
|
|
|
ifeq ($(run-built-tests),yes)
|
2000-07-10 13:52:21 +00:00
|
|
|
ifeq (yes,$(build-shared))
|
2001-02-19 12:36:27 +00:00
|
|
|
ifneq ($(PERL),no)
|
2000-07-23 01:23:29 +00:00
|
|
|
$(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
|
2014-06-06 22:19:27 +00:00
|
|
|
$(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
|
2020-10-01 15:42:38 +02:00
|
|
|
'$(run-program-env)' '$(test-program-prefix-after-env)'; \
|
2014-02-21 21:48:08 +00:00
|
|
|
$(evaluate-test)
|
2000-07-10 13:52:21 +00:00
|
|
|
endif
|
2000-08-25 09:02:59 +00:00
|
|
|
endif
|
2001-02-19 12:36:27 +00:00
|
|
|
endif
|
2000-07-07 03:02:14 +00:00
|
|
|
|
2005-04-27 01:39:11 +00:00
|
|
|
tst-mcheck-ENV = MALLOC_CHECK_=3
|
2012-09-05 21:49:00 +05:30
|
|
|
tst-malloc-usable-ENV = MALLOC_CHECK_=3
|
2016-12-31 23:32:17 +05:30
|
|
|
tst-malloc-usable-static-ENV = $(tst-malloc-usable-ENV)
|
2016-12-31 23:33:27 +05:30
|
|
|
tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
|
|
|
|
|
tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
|
2005-04-27 01:39:11 +00:00
|
|
|
|
2019-08-08 19:09:43 -04:00
|
|
|
tst-mxfast-ENV = GLIBC_TUNABLES=glibc.malloc.tcache_count=0:glibc.malloc.mxfast=0
|
|
|
|
|
|
2017-07-06 13:37:30 -04:00
|
|
|
ifeq ($(experimental-malloc),yes)
|
|
|
|
|
CPPFLAGS-malloc.c += -DUSE_TCACHE=1
|
|
|
|
|
else
|
|
|
|
|
CPPFLAGS-malloc.c += -DUSE_TCACHE=0
|
|
|
|
|
endif
|
1997-01-28 03:59:29 +00:00
|
|
|
# Uncomment this for test releases. For public releases it is too expensive.
|
2002-01-29 07:54:51 +00:00
|
|
|
#CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
|
1997-09-27 00:21:42 +00:00
|
|
|
|
2006-05-19 16:48:27 +00:00
|
|
|
sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
|
|
|
|
|
|
1997-09-27 00:21:42 +00:00
|
|
|
$(objpfx)mtrace: mtrace.pl
|
1997-10-12 04:05:44 +00:00
|
|
|
rm -f $@.new
|
1997-09-27 00:21:42 +00:00
|
|
|
sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
|
2012-11-09 22:13:45 +00:00
|
|
|
-e 's|@VERSION@|$(version)|' \
|
|
|
|
|
-e 's|@PKGVERSION@|$(PKGVERSION)|' \
|
|
|
|
|
-e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
|
1999-10-05 01:55:45 +00:00
|
|
|
&& rm -f $@ && mv $@.new $@ && chmod +x $@
|
|
|
|
|
|
2000-06-20 06:36:03 +00:00
|
|
|
$(objpfx)memusage: memusage.sh
|
1999-10-05 01:55:45 +00:00
|
|
|
rm -f $@.new
|
2021-05-12 07:45:33 +05:30
|
|
|
sed -e 's|@VERSION@|$(version)|' -e 's|@SLIBDIR@|$(sLIBdir)|' \
|
|
|
|
|
-e 's|@BINDIR@|$(bindir)|' -e 's|@PKGVERSION@|$(PKGVERSION)|' \
|
2012-11-09 22:13:45 +00:00
|
|
|
-e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
|
1999-10-05 01:55:45 +00:00
|
|
|
&& rm -f $@ && mv $@.new $@ && chmod +x $@
|
|
|
|
|
|
1999-10-04 22:59:43 +00:00
|
|
|
|
|
|
|
|
# The implementation uses `dlsym'
|
2014-05-16 21:38:08 +00:00
|
|
|
$(objpfx)libmemusage.so: $(libdl)
|
2002-01-29 07:54:51 +00:00
|
|
|
|
|
|
|
|
# Extra dependencies
|
|
|
|
|
$(foreach o,$(all-object-suffixes),$(objpfx)malloc$(o)): arena.c hooks.c
|
2016-08-02 17:01:02 +02:00
|
|
|
|
|
|
|
|
# Compile the tests with a flag which suppresses the mallopt call in
|
|
|
|
|
# the test skeleton.
|
|
|
|
|
$(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
|
2016-08-26 22:40:27 +02:00
|
|
|
|
|
|
|
|
$(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
|
|
|
|
|
$(objpfx)tst-interpose-thread: \
|
|
|
|
|
$(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
|
2020-12-23 13:04:45 +05:30
|
|
|
$(objpfx)tst-interpose-thread-mcheck: \
|
|
|
|
|
$(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
|
2016-08-26 22:40:27 +02:00
|
|
|
$(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
|
|
|
|
|
$(objpfx)tst-interpose-static-thread: \
|
|
|
|
|
$(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
|
2017-06-02 11:59:28 +02:00
|
|
|
|
|
|
|
|
tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace
|
|
|
|
|
$(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
|
|
|
|
|
$(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
|
|
|
|
|
$(evaluate-test)
|
|
|
|
|
|
|
|
|
|
tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace
|
|
|
|
|
$(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
|
|
|
|
|
$(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
|
|
|
|
|
$(evaluate-test)
|
2017-09-28 11:05:18 -06:00
|
|
|
|
|
|
|
|
$(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
|
2017-11-15 11:39:01 +01:00
|
|
|
$(objpfx)tst-malloc_info: $(shared-thread-library)
|
2019-05-08 15:29:13 +02:00
|
|
|
$(objpfx)tst-mallocfork2: $(shared-thread-library)
|
2020-12-23 13:04:45 +05:30
|
|
|
$(objpfx)tst-malloc-tcache-leak-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-malloc_info-mcheck: $(shared-thread-library)
|
|
|
|
|
$(objpfx)tst-mallocfork2-mcheck: $(shared-thread-library)
|