Fix struct sigaltstack namespace (bug 21517).
[glibc.git] / malloc / Makefile
blobaf025cbb243647f88853680aa4cc0e77bd565294
1 # Copyright (C) 1991-2017 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 # <http://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-mcheck tst-mallocfork tst-trim1 \
29 tst-malloc-usable tst-realloc tst-reallocarray tst-posix_memalign \
30 tst-pvalloc 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-interpose-nothread \
35 tst-interpose-thread \
37 tests-static := \
38 tst-interpose-static-nothread \
39 tst-interpose-static-thread \
40 tst-malloc-usable-static \
42 tests-internal := tst-mallocstate tst-scratch_buffer
44 # The dynarray framework is only available inside glibc.
45 tests-internal += \
46 tst-dynarray \
47 tst-dynarray-fail \
48 tst-dynarray-at-fail \
50 ifneq (no,$(have-tunables))
51 tests += tst-malloc-usable-tunables
52 tests-static += tst-malloc-usable-static-tunables
53 endif
55 tests += $(tests-static)
56 test-srcs = tst-mtrace tst-dynarray tst-dynarray-fail
58 routines = malloc morecore mcheck mtrace obstack reallocarray \
59 scratch_buffer_grow scratch_buffer_grow_preserve \
60 scratch_buffer_set_array_size \
61 dynarray_at_failure \
62 dynarray_emplace_enlarge \
63 dynarray_finalize \
64 dynarray_resize \
65 dynarray_resize_clear \
67 install-lib := libmcheck.a
68 non-lib.a := libmcheck.a
70 # Additional library.
71 extra-libs = libmemusage
72 extra-libs-others = $(extra-libs)
74 # Helper objects for some tests.
75 extra-tests-objs += \
76 tst-interpose-aux-nothread.o \
77 tst-interpose-aux-thread.o \
79 test-extras = \
80 tst-interpose-aux-nothread \
81 tst-interpose-aux-thread \
83 libmemusage-routines = memusage
84 libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
86 $(objpfx)tst-malloc-backtrace: $(shared-thread-library)
87 $(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
88 $(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
89 $(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
91 # Export the __malloc_initialize_hook variable to libc.so.
92 LDFLAGS-tst-mallocstate = -rdynamic
94 # These should be removed by `make clean'.
95 extra-objs = mcheck-init.o libmcheck.a
97 # Include the cleanup handler.
98 aux := set-freeres thread-freeres
100 # The Perl script to analyze the output of the mtrace functions.
101 ifneq ($(PERL),no)
102 install-bin-script = mtrace
103 generated += mtrace
105 # The Perl script will print addresses and to do this nicely we must know
106 # whether we are on a 32 or 64 bit machine.
107 ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
108 address-width=10
109 else
110 address-width=18
111 endif
112 endif
114 # Unless we get a test for the availability of libgd which also works
115 # for cross-compiling we disable the memusagestat generation in this
116 # situation.
117 ifneq ($(cross-compiling),yes)
118 # If the gd library is available we build the `memusagestat' program.
119 ifneq ($(LIBGD),no)
120 others: $(objpfx)memusage
121 install-bin = memusagestat
122 install-bin-script += memusage
123 generated += memusagestat memusage
124 extra-objs += memusagestat.o
126 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
127 # The directory specified by --with-headers usually contains only the basic
128 # kernel interface headers, not something like libgd. So the simplest thing
129 # is to presume that the standard system headers will be ok for this file.
130 $(objpfx)memusagestat.o: sysincludes = # nothing
131 endif
132 endif
134 # Another goal which can be used to override the configure decision.
135 .PHONY: do-memusagestat
136 do-memusagestat: $(objpfx)memusagestat
138 memusagestat-modules = memusagestat
140 cpp-srcs-left := $(memusagestat-modules)
141 lib := memusagestat
142 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
144 $(objpfx)memusagestat: $(memusagestat-modules:%=$(objpfx)%.o)
145 $(LINK.o) -o $@ $^ $(libgd-LDFLAGS) -lgd -lpng -lz -lm
147 ifeq ($(run-built-tests),yes)
148 ifeq (yes,$(build-shared))
149 ifneq ($(PERL),no)
150 tests-special += $(objpfx)tst-mtrace.out
151 tests-special += $(objpfx)tst-dynarray-mem.out
152 tests-special += $(objpfx)tst-dynarray-fail-mem.out
153 endif
154 endif
155 endif
157 include ../Rules
159 CFLAGS-mcheck-init.c = $(PIC-ccflag)
160 CFLAGS-obstack.c = $(uses-callbacks)
162 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
163 -rm -f $@
164 $(patsubst %/,cd % &&,$(objpfx)) \
165 $(LN_S) $(<F) $(@F)
167 lib: $(objpfx)libmcheck.a
169 ifeq ($(run-built-tests),yes)
170 ifeq (yes,$(build-shared))
171 ifneq ($(PERL),no)
172 $(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
173 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
174 '$(run-program-env)' '$(test-program-prefix-after-env)' ; \
175 $(evaluate-test)
176 endif
177 endif
178 endif
180 tst-mcheck-ENV = MALLOC_CHECK_=3
181 tst-malloc-usable-ENV = MALLOC_CHECK_=3
182 tst-malloc-usable-static-ENV = $(tst-malloc-usable-ENV)
183 tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
184 tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
186 # Uncomment this for test releases. For public releases it is too expensive.
187 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
189 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
191 $(objpfx)mtrace: mtrace.pl
192 rm -f $@.new
193 sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
194 -e 's|@VERSION@|$(version)|' \
195 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
196 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
197 && rm -f $@ && mv $@.new $@ && chmod +x $@
199 $(objpfx)memusage: memusage.sh
200 rm -f $@.new
201 sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \
202 -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \
203 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
204 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
205 && rm -f $@ && mv $@.new $@ && chmod +x $@
208 # The implementation uses `dlsym'
209 $(objpfx)libmemusage.so: $(libdl)
211 # Extra dependencies
212 $(foreach o,$(all-object-suffixes),$(objpfx)malloc$(o)): arena.c hooks.c
214 # Compile the tests with a flag which suppresses the mallopt call in
215 # the test skeleton.
216 $(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
218 $(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
219 $(objpfx)tst-interpose-thread: \
220 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
221 $(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
222 $(objpfx)tst-interpose-static-thread: \
223 $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
225 tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace
226 $(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
227 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
228 $(evaluate-test)
230 tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace
231 $(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
232 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
233 $(evaluate-test)