regex: fix uninitialized memory access
[glibc.git] / malloc / Makefile
blob7d54bad866f63cb8a23a1a1bb6eb793e92572ff8
1 # Copyright (C) 1991-2018 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 \
36 tst-alloc_buffer \
37 tst-malloc-tcache-leak \
38 tst-malloc_info \
39 tst-malloc-too-large \
40 tst-malloc-stats-cancellation \
42 tests-static := \
43 tst-interpose-static-nothread \
44 tst-interpose-static-thread \
45 tst-malloc-usable-static \
47 tests-internal := tst-mallocstate tst-scratch_buffer
49 # The dynarray framework is only available inside glibc.
50 tests-internal += \
51 tst-dynarray \
52 tst-dynarray-fail \
53 tst-dynarray-at-fail \
55 ifneq (no,$(have-tunables))
56 tests += tst-malloc-usable-tunables
57 tests-static += tst-malloc-usable-static-tunables
58 endif
60 tests += $(tests-static)
61 test-srcs = tst-mtrace
63 routines = malloc morecore mcheck mtrace obstack reallocarray \
64 scratch_buffer_grow scratch_buffer_grow_preserve \
65 scratch_buffer_set_array_size \
66 dynarray_at_failure \
67 dynarray_emplace_enlarge \
68 dynarray_finalize \
69 dynarray_resize \
70 dynarray_resize_clear \
71 alloc_buffer_alloc_array \
72 alloc_buffer_allocate \
73 alloc_buffer_copy_bytes \
74 alloc_buffer_copy_string \
75 alloc_buffer_create_failure \
77 install-lib := libmcheck.a
78 non-lib.a := libmcheck.a
80 # Additional library.
81 extra-libs = libmemusage
82 extra-libs-others = $(extra-libs)
84 # Helper objects for some tests.
85 extra-tests-objs += \
86 tst-interpose-aux-nothread.o \
87 tst-interpose-aux-thread.o \
89 test-extras = \
90 tst-interpose-aux-nothread \
91 tst-interpose-aux-thread \
93 libmemusage-routines = memusage
94 libmemusage-inhibit-o = $(filter-out .os,$(object-suffixes))
96 $(objpfx)tst-malloc-backtrace: $(shared-thread-library)
97 $(objpfx)tst-malloc-thread-exit: $(shared-thread-library)
98 $(objpfx)tst-malloc-thread-fail: $(shared-thread-library)
99 $(objpfx)tst-malloc-fork-deadlock: $(shared-thread-library)
100 $(objpfx)tst-malloc-stats-cancellation: $(shared-thread-library)
102 # Export the __malloc_initialize_hook variable to libc.so.
103 LDFLAGS-tst-mallocstate = -rdynamic
105 # These should be removed by `make clean'.
106 extra-objs = mcheck-init.o libmcheck.a
107 others-extras = mcheck-init.o
109 # Include the cleanup handler.
110 aux := set-freeres thread-freeres
112 # The Perl script to analyze the output of the mtrace functions.
113 ifneq ($(PERL),no)
114 install-bin-script = mtrace
115 generated += mtrace
117 # The Perl script will print addresses and to do this nicely we must know
118 # whether we are on a 32 or 64 bit machine.
119 ifneq ($(findstring wordsize-32,$(config-sysdirs)),)
120 address-width=10
121 else
122 address-width=18
123 endif
124 endif
126 # Unless we get a test for the availability of libgd which also works
127 # for cross-compiling we disable the memusagestat generation in this
128 # situation.
129 ifneq ($(cross-compiling),yes)
130 # If the gd library is available we build the `memusagestat' program.
131 ifneq ($(LIBGD),no)
132 others: $(objpfx)memusage
133 install-bin = memusagestat
134 install-bin-script += memusage
135 generated += memusagestat memusage
136 extra-objs += memusagestat.o
138 # The configure.ac check for libgd and its headers did not use $SYSINCLUDES.
139 # The directory specified by --with-headers usually contains only the basic
140 # kernel interface headers, not something like libgd. So the simplest thing
141 # is to presume that the standard system headers will be ok for this file.
142 $(objpfx)memusagestat.o: sysincludes = # nothing
143 endif
144 endif
146 # Another goal which can be used to override the configure decision.
147 .PHONY: do-memusagestat
148 do-memusagestat: $(objpfx)memusagestat
150 memusagestat-modules = memusagestat
152 cpp-srcs-left := $(memusagestat-modules)
153 lib := memusagestat
154 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
156 $(objpfx)memusagestat: $(memusagestat-modules:%=$(objpfx)%.o)
157 $(LINK.o) -o $@ $^ $(libgd-LDFLAGS) -lgd -lpng -lz -lm
159 ifeq ($(run-built-tests),yes)
160 ifeq (yes,$(build-shared))
161 ifneq ($(PERL),no)
162 tests-special += $(objpfx)tst-mtrace.out
163 tests-special += $(objpfx)tst-dynarray-mem.out
164 tests-special += $(objpfx)tst-dynarray-fail-mem.out
165 endif
166 endif
167 endif
169 include ../Rules
171 CFLAGS-mcheck-init.c += $(PIC-ccflag)
172 CFLAGS-obstack.c += $(uses-callbacks)
174 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
175 -rm -f $@
176 $(patsubst %/,cd % &&,$(objpfx)) \
177 $(LN_S) $(<F) $(@F)
179 lib: $(objpfx)libmcheck.a
181 ifeq ($(run-built-tests),yes)
182 ifeq (yes,$(build-shared))
183 ifneq ($(PERL),no)
184 $(objpfx)tst-mtrace.out: tst-mtrace.sh $(objpfx)tst-mtrace
185 $(SHELL) $< $(common-objpfx) '$(test-program-prefix-before-env)' \
186 '$(run-program-env)' '$(test-program-prefix-after-env)' > $@; \
187 $(evaluate-test)
188 endif
189 endif
190 endif
192 tst-mcheck-ENV = MALLOC_CHECK_=3
193 tst-malloc-usable-ENV = MALLOC_CHECK_=3
194 tst-malloc-usable-static-ENV = $(tst-malloc-usable-ENV)
195 tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
196 tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
198 ifeq ($(experimental-malloc),yes)
199 CPPFLAGS-malloc.c += -DUSE_TCACHE=1
200 else
201 CPPFLAGS-malloc.c += -DUSE_TCACHE=0
202 endif
203 # Uncomment this for test releases. For public releases it is too expensive.
204 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
206 sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
208 $(objpfx)mtrace: mtrace.pl
209 rm -f $@.new
210 sed -e 's|@PERL@|$(PERL)|' -e 's|@XXX@|$(address-width)|' \
211 -e 's|@VERSION@|$(version)|' \
212 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
213 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
214 && rm -f $@ && mv $@.new $@ && chmod +x $@
216 $(objpfx)memusage: memusage.sh
217 rm -f $@.new
218 sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \
219 -e 's|@SLIBDIR@|$(sLIBdir)|' -e 's|@BINDIR@|$(bindir)|' \
220 -e 's|@PKGVERSION@|$(PKGVERSION)|' \
221 -e 's|@REPORT_BUGS_TO@|$(REPORT_BUGS_TO)|' $^ > $@.new \
222 && rm -f $@ && mv $@.new $@ && chmod +x $@
225 # The implementation uses `dlsym'
226 $(objpfx)libmemusage.so: $(libdl)
228 # Extra dependencies
229 $(foreach o,$(all-object-suffixes),$(objpfx)malloc$(o)): arena.c hooks.c
231 # Compile the tests with a flag which suppresses the mallopt call in
232 # the test skeleton.
233 $(tests:%=$(objpfx)%.o): CPPFLAGS += -DTEST_NO_MALLOPT
235 $(objpfx)tst-interpose-nothread: $(objpfx)tst-interpose-aux-nothread.o
236 $(objpfx)tst-interpose-thread: \
237 $(objpfx)tst-interpose-aux-thread.o $(shared-thread-library)
238 $(objpfx)tst-interpose-static-nothread: $(objpfx)tst-interpose-aux-nothread.o
239 $(objpfx)tst-interpose-static-thread: \
240 $(objpfx)tst-interpose-aux-thread.o $(static-thread-library)
242 tst-dynarray-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray.mtrace
243 $(objpfx)tst-dynarray-mem.out: $(objpfx)tst-dynarray.out
244 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray.mtrace > $@; \
245 $(evaluate-test)
247 tst-dynarray-fail-ENV = MALLOC_TRACE=$(objpfx)tst-dynarray-fail.mtrace
248 $(objpfx)tst-dynarray-fail-mem.out: $(objpfx)tst-dynarray-fail.out
249 $(common-objpfx)malloc/mtrace $(objpfx)tst-dynarray-fail.mtrace > $@; \
250 $(evaluate-test)
252 $(objpfx)tst-malloc-tcache-leak: $(shared-thread-library)
253 $(objpfx)tst-malloc_info: $(shared-thread-library)