Blame malloc/Makefile

Packit Service 82fcde
# Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
# This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
# The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
# modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
# License as published by the Free Software Foundation; either
Packit Service 82fcde
# version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
# The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
# Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
# You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
# License along with the GNU C Library; if not, see
Packit Service 82fcde
# <http://www.gnu.org/licenses/>.
Packit Service 82fcde
Packit Service 82fcde
#
Packit Service 82fcde
#	Makefile for malloc routines
Packit Service 82fcde
#
Packit Service 82fcde
subdir	:= malloc
Packit Service 82fcde
Packit Service 82fcde
include ../Makeconfig
Packit Service 82fcde
Packit Service 82fcde
dist-headers := malloc.h
Packit Service 82fcde
headers := $(dist-headers) obstack.h mcheck.h
Packit Service 82fcde
tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
Packit Service 82fcde
	 tst-mcheck tst-mallocfork tst-trim1 \
Packit Service 82fcde
	 tst-malloc-usable tst-realloc tst-reallocarray tst-posix_memalign \
Packit Service 82fcde
	 tst-pvalloc tst-memalign tst-mallopt \
Packit Service 82fcde
	 tst-malloc-backtrace tst-malloc-thread-exit \
Packit Service 82fcde
	 tst-malloc-thread-fail tst-malloc-fork-deadlock \
Packit Service 82fcde
	 tst-mallocfork2 \
Packit Service 82fcde
	 tst-interpose-nothread \
Packit Service 82fcde
	 tst-interpose-thread \
Packit Service 82fcde
	 tst-alloc_buffer \
Packit Service 82fcde
	 tst-malloc-tcache-leak \
Packit Service 82fcde
	 tst-malloc_info \
Packit Service 82fcde
	 tst-malloc-too-large \
Packit Service 82fcde
	 tst-malloc-stats-cancellation \
Packit Service 82fcde
Packit Service 82fcde
tests-static := \
Packit Service 82fcde
	 tst-interpose-static-nothread \
Packit Service 82fcde
	 tst-interpose-static-thread \
Packit Service 82fcde
	 tst-malloc-usable-static \
Packit Service 82fcde
Packit Service 82fcde
tests-internal := tst-mallocstate tst-scratch_buffer
Packit Service 82fcde
Packit Service 82fcde
# The dynarray framework is only available inside glibc.
Packit Service 82fcde
tests-internal += \
Packit Service 82fcde
	 tst-dynarray \
Packit Service 82fcde
	 tst-dynarray-fail \
Packit Service 82fcde
	 tst-dynarray-at-fail \
Packit Service 82fcde
Packit Service 82fcde
ifneq (no,$(have-tunables))
Packit Service 1c5418
tests += tst-malloc-usable-tunables
Packit Service 82fcde
tests-static += tst-malloc-usable-static-tunables
Packit Service 82fcde
endif
Packit Service 82fcde
Packit Service 82fcde
tests += $(tests-static)
Packit Service 82fcde
test-srcs = tst-mtrace
Packit Service 82fcde
Packit Service 82fcde
routines = malloc morecore mcheck mtrace obstack reallocarray \
Packit Service 82fcde
  scratch_buffer_grow scratch_buffer_grow_preserve \
Packit Service 82fcde
  scratch_buffer_set_array_size \
Packit Service 82fcde
  dynarray_at_failure \
Packit Service 82fcde
  dynarray_emplace_enlarge \
Packit Service 82fcde
  dynarray_finalize \
Packit Service 82fcde
  dynarray_resize \
Packit Service 82fcde
  dynarray_resize_clear \
Packit Service 82fcde
  alloc_buffer_alloc_array \
Packit Service 82fcde
  alloc_buffer_allocate \
Packit Service 82fcde
  alloc_buffer_copy_bytes  \
Packit Service 82fcde
  alloc_buffer_copy_string \
Packit Service 82fcde
  alloc_buffer_create_failure \
Packit Service 82fcde
Packit Service 82fcde
install-lib := libmcheck.a
Packit Service 82fcde
non-lib.a := libmcheck.a
Packit Service 82fcde
Packit Service 82fcde
# Additional library.
Packit Service 82fcde
extra-libs = libmemusage
Packit Service 82fcde
extra-libs-others = $(extra-libs)
Packit Service 82fcde
Packit Service 82fcde
# Helper objects for some tests.
Packit Service 82fcde
extra-tests-objs += \
Packit Service 82fcde
  tst-interpose-aux-nothread.o \
Packit Service 82fcde
  tst-interpose-aux-thread.o \
Packit Service 82fcde
Packit Service 82fcde
test-extras = \
Packit Service 82fcde
  tst-interpose-aux-nothread \
Packit Service 82fcde
  tst-interpose-aux-thread \
Packit Service 82fcde
Packit Service 82fcde
libmemusage-routines = memusage
Packit Service 82fcde
libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)tst-malloc-backtrace: $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
Packit Service 82fcde
Packit Service 82fcde
# Export the __malloc_initialize_hook variable to libc.so.
Packit Service 82fcde
LDFLAGS-tst-mallocstate = -rdynamic
Packit Service 82fcde
Packit Service 82fcde
# These should be removed by `make clean'.
Packit Service 82fcde
extra-objs = mcheck-init.o libmcheck.a
Packit Service 82fcde
others-extras = mcheck-init.o
Packit Service 82fcde
Packit Service 82fcde
# Include the cleanup handler.
Packit Service 82fcde
aux := set-freeres thread-freeres
Packit Service 82fcde
Packit Service 82fcde
# The Perl script to analyze the output of the mtrace functions.
Packit Service 82fcde
ifneq ($(PERL),no)
Packit Service 82fcde
install-bin-script = mtrace
Packit Service 82fcde
generated += mtrace
Packit Service 82fcde
Packit Service 82fcde
# The Perl script will print addresses and to do this nicely we must know
Packit Service 82fcde
# whether we are on a 32 or 64 bit machine.
Packit Service 82fcde
ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
Packit Service 82fcde
address-width=10
Packit Service 82fcde
else
Packit Service 82fcde
address-width=18
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
Packit Service 82fcde
# Unless we get a test for the availability of libgd which also works
Packit Service 82fcde
# for cross-compiling we disable the memusagestat generation in this
Packit Service 82fcde
# situation.
Packit Service 82fcde
ifneq ($(cross-compiling),yes)
Packit Service 82fcde
# If the gd library is available we build the `memusagestat' program.
Packit Service 82fcde
ifneq ($(LIBGD),no)
Packit Service 82fcde
others: $(objpfx)memusage
Packit Service 82fcde
install-bin = memusagestat
Packit Service 82fcde
install-bin-script += memusage
Packit Service 82fcde
generated += memusagestat memusage
Packit Service 82fcde
extra-objs += memusagestat.o
Packit Service 82fcde
Packit Service 82fcde
# The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
Packit Service 82fcde
# The directory specified by --with-headers usually contains only the basic
Packit Service 82fcde
# kernel interface headers, not something like libgd.  So the simplest thing
Packit Service 82fcde
# is to presume that the standard system headers will be ok for this file.
Packit Service 82fcde
$(objpfx)memusagestat.o: sysincludes = # nothing
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
Packit Service 82fcde
# Another goal which can be used to override the configure decision.
Packit Service 82fcde
.PHONY: do-memusagestat
Packit Service 82fcde
do-memusagestat: $(objpfx)memusagestat
Packit Service 82fcde
Packit Service 82fcde
memusagestat-modules = memusagestat
Packit Service 82fcde
Packit Service 82fcde
cpp-srcs-left := $(memusagestat-modules)
Packit Service 82fcde
lib := memusagestat
Packit Service 82fcde
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit Service 82fcde
Packit Service 1c5418
$(objpfx)memusagestat: $(memusagestat-modules:%=$(objpfx)%.o)
Packit Service 1c5418
	$(LINK.o) -o $@ $^ $(libgd-LDFLAGS) -lgd -lpng -lz -lm
Packit Service 82fcde
Packit Service 82fcde
ifeq ($(run-built-tests),yes)
Packit Service 82fcde
ifeq (yes,$(build-shared))
Packit Service 82fcde
ifneq ($(PERL),no)
Packit Service 82fcde
tests-special += $(objpfx)tst-mtrace.out
Packit Service 82fcde
tests-special += $(objpfx)tst-dynarray-mem.out
Packit Service 82fcde
tests-special += $(objpfx)tst-dynarray-fail-mem.out
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
Packit Service 82fcde
include ../Rules
Packit Service 82fcde
Packit Service 82fcde
CFLAGS-mcheck-init.c += $(PIC-ccflag)
Packit Service 82fcde
CFLAGS-obstack.c += $(uses-callbacks)
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
Packit Service 82fcde
	-rm -f $@
Packit Service 82fcde
	$(patsubst %/,cd % &&,$(objpfx)) \
Packit Service 82fcde
	$(LN_S) $(
Packit Service 82fcde
Packit Service 82fcde
lib: $(objpfx)libmcheck.a
Packit Service 82fcde
Packit Service 82fcde
ifeq ($(run-built-tests),yes)
Packit Service 82fcde
ifeq (yes,$(build-shared))
Packit Service 82fcde
ifneq ($(PERL),no)
Packit Service 82fcde
$(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
Packit Service 82fcde
	$(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
Packit Service 82fcde
		 '$(run-program-env)' '$(test-program-prefix-after-env)' > $@; \
Packit Service 82fcde
	$(evaluate-test)
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
endif
Packit Service 82fcde
Packit Service 82fcde
tst-mcheck-ENV = MALLOC_CHECK_=3
Packit Service 82fcde
tst-malloc-usable-ENV = MALLOC_CHECK_=3
Packit Service 82fcde
tst-malloc-usable-static-ENV = $(tst-malloc-usable-ENV)
Packit Service 82fcde
tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
Packit Service 82fcde
tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
Packit Service 82fcde
Packit Service 82fcde
ifeq ($(experimental-malloc),yes)
Packit Service 82fcde
CPPFLAGS-malloc.c += -DUSE_TCACHE=1
Packit Service 82fcde
else
Packit Service 82fcde
CPPFLAGS-malloc.c += -DUSE_TCACHE=0
Packit Service 82fcde
endif
Packit Service 82fcde
# Uncomment this for test releases.  For public releases it is too expensive.
Packit Service 82fcde
#CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
Packit Service 82fcde
Packit Service 82fcde
sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)mtrace: mtrace.pl
Packit Service 82fcde
	rm -f $@.new
Packit Service 82fcde
	sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
Packit Service 82fcde
	    -e 's|@VERSION@|$(version)|' \
Packit Service 82fcde
	    -e 's|@PKGVERSION@|$(PKGVERSION)|' \
Packit Service 82fcde
	    -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
Packit Service 82fcde
	&& rm -f $@ && mv $@.new $@ && chmod +x $@
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)memusage: memusage.sh
Packit Service 82fcde
	rm -f $@.new
Packit Service 82fcde
	sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \
Packit Service 82fcde
	    -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \
Packit Service 82fcde
	    -e 's|@PKGVERSION@|$(PKGVERSION)|' \
Packit Service 82fcde
	    -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
Packit Service 82fcde
	&& rm -f $@ && mv $@.new $@ && chmod +x $@
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
# The implementation uses `dlsym'
Packit Service 82fcde
$(objpfx)libmemusage.so: $(libdl)
Packit Service 82fcde
Packit Service 82fcde
# Extra dependencies
Packit Service 82fcde
$(foreach o,$(all-object-suffixes),$(objpfx)malloc$(o)): arena.c hooks.c
Packit Service 82fcde
Packit Service 82fcde
# Compile the tests with a flag which suppresses the mallopt call in
Packit Service 82fcde
# the test skeleton.
Packit Service 82fcde
$(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
Packit Service 82fcde
$(objpfx)tst-interpose-thread: \
Packit Service 82fcde
  $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
Packit Service 82fcde
$(objpfx)tst-interpose-static-thread: \
Packit Service 82fcde
  $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
Packit Service 82fcde
Packit Service 82fcde
tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace
Packit Service 82fcde
$(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
Packit Service 82fcde
	$(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
Packit Service 82fcde
	$(evaluate-test)
Packit Service 82fcde
Packit Service 82fcde
tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace
Packit Service 82fcde
$(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
Packit Service 82fcde
	$(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
Packit Service 82fcde
	$(evaluate-test)
Packit Service 82fcde
Packit Service 82fcde
$(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
Packit Service 82fcde
$(objpfx)tst-malloc_info: $(shared-thread-library)