elf: Fix _dl_debug_vdprintf to work before self-relocation
[glibc.git] / stdio-common / Makefile
blobe88a9cea29244caefe85471014c9270b1f7dca6c
1 # Copyright (C) 1991-2023 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 # <https://www.gnu.org/licenses/>.
19 # Specific makefile for stdio-common.
21 subdir := stdio-common
23 include ../Makeconfig
25 headers := \
26 bits/printf-ldbl.h \
27 bits/stdio_lim.h \
28 printf.h \
29 stdio_ext.h \
30 # headers
32 routines := \
33 _itoa \
34 _itowa \
35 asprintf \
36 ctermid \
37 cuserid \
38 dprintf \
39 flockfile \
40 fprintf \
41 fscanf \
42 ftrylockfile \
43 funlockfile \
44 gentempfd \
45 getline \
46 getw \
47 grouping_iterator \
48 iovfscanf \
49 isoc23_fscanf \
50 isoc23_scanf \
51 isoc23_sscanf \
52 isoc23_vfscanf \
53 isoc23_vscanf \
54 isoc23_vsscanf \
55 isoc99_fscanf \
56 isoc99_scanf \
57 isoc99_sscanf \
58 isoc99_vfscanf \
59 isoc99_vscanf \
60 isoc99_vsscanf \
61 itoa-digits \
62 itoa-udigits \
63 itowa-digits \
64 perror \
65 printf \
66 printf-prs \
67 printf_buffer_as_file \
68 printf_buffer_done \
69 printf_buffer_flush \
70 printf_buffer_pad_1 \
71 printf_buffer_putc_1 \
72 printf_buffer_puts_1 \
73 printf_buffer_to_file \
74 printf_buffer_write \
75 printf_fp \
76 printf_fphex \
77 printf_function_invoke \
78 printf_size \
79 psiginfo \
80 psignal \
81 putw \
82 reg-modifier \
83 reg-printf \
84 reg-type \
85 remove \
86 rename \
87 renameat \
88 renameat2 \
89 scanf \
90 snprintf \
91 sprintf \
92 sscanf \
93 tempnam \
94 tempname \
95 tmpfile \
96 tmpfile64 \
97 tmpnam \
98 tmpnam_r \
99 translated_number_width \
100 vfprintf \
101 vfprintf-internal \
102 vfscanf \
103 vfscanf-internal \
104 vfwprintf \
105 vfwprintf-internal \
106 vfwscanf \
107 vfwscanf-internal \
108 vprintf \
109 wprintf_buffer_as_file \
110 wprintf_buffer_done \
111 wprintf_buffer_flush \
112 wprintf_buffer_pad_1 \
113 wprintf_buffer_putc_1 \
114 wprintf_buffer_puts_1 \
115 wprintf_buffer_to_file \
116 wprintf_buffer_write \
117 wprintf_function_invoke \
118 # routines
120 # Exclude fortified routines from being built with _FORTIFY_SOURCE
121 routines_no_fortify += \
122 asprintf \
123 dprintf \
124 fprintf \
125 printf \
126 snprintf \
127 sprintf \
128 vfprintf \
129 vfwprintf \
130 vprintf \
131 # routines_no_fortify
133 aux := \
134 errlist \
135 errlist-data \
136 errname \
137 fxprintf \
138 printf-parsemb \
139 printf-parsewc \
140 siglist \
141 # aux
143 tests := \
144 bug-vfprintf-nargs \
145 bug1 \
146 bug3 \
147 bug4 \
148 bug5 \
149 bug6 \
150 bug7 \
151 bug8 \
152 bug9 \
153 bug10 \
154 bug11 \
155 bug12 \
156 bug13 \
157 bug14 \
158 bug16 \
159 bug17 \
160 bug18 \
161 bug18a \
162 bug19 \
163 bug19a \
164 bug2 \
165 bug20 \
166 bug21 \
167 bug22 \
168 bug23 \
169 bug24 \
170 bug25 \
171 bug26 \
172 bug27 \
173 bug28 \
174 bug29 \
175 errnobug \
176 scanf1 \
177 scanf2 \
178 scanf3 \
179 scanf4 \
180 scanf5 \
181 scanf7 \
182 scanf8 \
183 scanf9 \
184 scanf10 \
185 scanf11 \
186 scanf12 \
187 scanf13 \
188 scanf14 \
189 scanf15 \
190 scanf16 \
191 scanf17 \
192 scanf18 \
193 scanf19 \
194 temptest \
195 test-fseek \
196 test-fwrite \
197 test-popen \
198 test-strerr \
199 test-vfprintf \
200 test_rdwr \
201 tfformat \
202 tiformat \
203 tllformat \
204 tst-bz11319 \
205 tst-bz11319-fortify2 \
206 tst-cookie \
207 tst-dprintf-length \
208 tst-fdopen \
209 tst-ferror \
210 tst-fgets \
211 tst-fileno \
212 tst-fmemopen \
213 tst-fmemopen2 \
214 tst-fmemopen3 \
215 tst-fmemopen4 \
216 tst-fphex \
217 tst-fphex-wide \
218 tst-fseek \
219 tst-fwrite \
220 tst-gets \
221 tst-grouping \
222 tst-grouping2 \
223 tst-grouping3 \
224 tst-long-dbl-fphex \
225 tst-memstream-string \
226 tst-obprintf \
227 tst-perror \
228 tst-popen \
229 tst-popen2 \
230 tst-printf-binary \
231 tst-printf-bz18872 \
232 tst-printf-bz25691 \
233 tst-printf-fp-free \
234 tst-printf-fp-leak \
235 tst-printf-intn \
236 tst-printf-oct \
237 tst-printf-round \
238 tst-printfsz \
239 tst-put-error \
240 tst-renameat2 \
241 tst-rndseek \
242 tst-scanf-binary-c11 \
243 tst-scanf-binary-c2x \
244 tst-scanf-binary-gnu11 \
245 tst-scanf-binary-gnu89 \
246 tst-scanf-intn \
247 tst-scanf-round \
248 tst-scanf-to_inpunct \
249 tst-setvbuf1 \
250 tst-sprintf \
251 tst-sprintf-errno \
252 tst-sprintf2 \
253 tst-sprintf3 \
254 tst-sscanf \
255 tst-swprintf \
256 tst-swscanf \
257 tst-tmpnam \
258 tst-ungetc \
259 tst-unlockedio \
260 tst-vfprintf-mbs-prec \
261 tst-vfprintf-user-type \
262 tst-vfprintf-width-i18n \
263 tst-vfprintf-width-prec \
264 tst-vfprintf-width-prec-alloc \
265 tst-wc-printf \
266 tstdiomisc \
267 tstgetln \
268 tstscanf \
269 xbug \
270 # tests
272 tests-container += \
273 tst-popen3
274 # tests-container
276 generated += \
277 errlist-data-aux-shared.S \
278 errlist-data-aux.S \
279 siglist-aux-shared.S \
280 siglist-aux.S \
281 # generated
283 tests-internal = \
284 tst-grouping_iterator \
285 # tests-internal
287 test-srcs = \
288 tst-printf \
289 tst-printfsz-islongdouble \
290 tst-unbputc \
291 # test-srcs
293 ifeq ($(run-built-tests),yes)
294 tests-special += \
295 $(objpfx)tst-printf-bz18872-mem.out \
296 $(objpfx)tst-printf-bz25691-mem.out \
297 $(objpfx)tst-printf-fp-free-mem.out \
298 $(objpfx)tst-printf-fp-leak-mem.out \
299 $(objpfx)tst-printf.out \
300 $(objpfx)tst-printfsz-islongdouble.out \
301 $(objpfx)tst-setvbuf1-cmp.out \
302 $(objpfx)tst-unbputc.out \
303 $(objpfx)tst-vfprintf-width-prec-mem.out \
304 # tests-special
306 generated += \
307 tst-printf-bz18872-mem.out \
308 tst-printf-bz18872.c \
309 tst-printf-bz18872.mtrace \
310 tst-printf-bz25691-mem.out \
311 tst-printf-bz25691.mtrace \
312 tst-printf-fp-free-mem.out \
313 tst-printf-fp-free.mtrace \
314 tst-printf-fp-leak-mem.out \
315 tst-printf-fp-leak.mtrace \
316 tst-vfprintf-width-prec-mem.out \
317 tst-vfprintf-width-prec.mtrace \
318 # generated
319 endif # $(run-built-tests)
321 tests-special += $(objpfx)tst-errno-manual.out
323 include ../Rules
325 # The errlist.c is built in two phases because compiler might reorder the
326 # compat_symbol directive prior the object itself and on binutils older
327 # than 2.29 it might generate object sizes different than the expected ones.
328 $(objpfx)errlist-data-aux-shared.S: errlist-data-gen.c
329 $(make-target-directory)
330 $(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S
332 $(objpfx)errlist-data-aux.S: errlist-data-gen.c
333 $(make-target-directory)
334 $(compile-command.c) $(pie-default) $(no-stack-protector) -S
336 ifndef no_deps
337 -include $(objpfx)errlist-data-aux.S.d $(objpfx)errlist-data-aux-shared.S.d
338 endif
340 $(objpfx)errlist-data.os: $(objpfx)errlist-data-aux-shared.S
341 $(addprefix $(objpfx)errlist-data, $(object-suffixes-noshared)): \
342 $(objpfx)errlist-data-aux.S
344 $(objpfx)siglist-aux-shared.S: siglist-gen.c
345 $(make-target-directory)
346 $(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S
348 $(objpfx)siglist-aux.S: siglist-gen.c
349 $(make-target-directory)
350 $(compile-command.c) $(pie-default) $(no-stack-protector) -S
352 ifndef no_deps
353 -include $(objpfx)siglist-aux.S.d $(objpfx)siglist-aux-shared.S.d
354 endif
356 $(objpfx)siglist.os: $(objpfx)siglist-aux-shared.S
357 $(addprefix $(objpfx)siglist, $(object-suffixes-noshared)): \
358 $(objpfx)siglist-aux.S
360 ifeq ($(run-built-tests),yes)
361 LOCALES := \
362 de_DE.ISO-8859-1 \
363 de_DE.UTF-8 \
364 en_US.ISO-8859-1 \
365 fa_IR.UTF-8 \
366 hi_IN.UTF-8 \
367 ja_JP.EUC-JP \
368 ps_AF.UTF-8 \
369 tg_TJ.UTF-8 \
370 # LOCALES
371 include ../gen-locales.mk
373 $(objpfx)bug14.out: $(gen-locales)
374 $(objpfx)scanf13.out: $(gen-locales)
375 $(objpfx)test-vfprintf.out: $(gen-locales)
376 $(objpfx)tst-grouping.out: $(gen-locales)
377 $(objpfx)tst-grouping2.out: $(gen-locales)
378 $(objpfx)tst-grouping_iterator.out: $(gen-locales)
379 $(objpfx)tst-sprintf.out: $(gen-locales)
380 $(objpfx)tst-sscanf.out: $(gen-locales)
381 $(objpfx)tst-swprintf.out: $(gen-locales)
382 $(objpfx)tst-vfprintf-mbs-prec.out: $(gen-locales)
383 $(objpfx)tst-vfprintf-width-i18n.out: $(gen-locales)
384 $(objpfx)tst-grouping3.out: $(gen-locales)
385 $(objpfx)tst-scanf-to_inpunct.out: $(gen-locales)
386 endif
388 tst-printf-bz18872-ENV = MALLOC_TRACE=$(objpfx)tst-printf-bz18872.mtrace \
389 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
390 tst-vfprintf-width-prec-ENV = \
391 MALLOC_TRACE=$(objpfx)tst-vfprintf-width-prec.mtrace \
392 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
393 tst-printf-bz25691-ENV = \
394 MALLOC_TRACE=$(objpfx)tst-printf-bz25691.mtrace \
395 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
396 tst-printf-fp-free-ENV = \
397 MALLOC_TRACE=$(objpfx)tst-printf-fp-free.mtrace \
398 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
399 tst-printf-fp-leak-ENV = \
400 MALLOC_TRACE=$(objpfx)tst-printf-fp-leak.mtrace \
401 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
403 $(objpfx)tst-unbputc.out: tst-unbputc.sh $(objpfx)tst-unbputc
404 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
405 $(evaluate-test)
407 $(objpfx)tst-printf.out: tst-printf.sh $(objpfx)tst-printf
408 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \
409 $(evaluate-test)
411 $(objpfx)tst-printfsz-islongdouble.out: \
412 tst-printfsz-islongdouble.sh $(objpfx)tst-printfsz-islongdouble
413 $(SHELL) $^ '$(test-program-prefix)' $@; \
414 $(evaluate-test)
416 # We generate this source because it requires a printf invocation with
417 # 10K arguments.
418 $(objpfx)tst-printf-bz18872.c: tst-printf-bz18872.sh
419 rm -f $@ && $(BASH) $^ > $@.new && mv $@.new $@
421 $(objpfx)tst-%-mem.out: $(objpfx)tst-%.out
422 $(common-objpfx)malloc/mtrace $(objpfx)tst-$*.mtrace > $@; \
423 $(evaluate-test)
425 errlist-h = $(firstword $(wildcard $(addsuffix /errlist.h,$(sysdirs) .)))
427 $(objpfx)tst-errno-manual.out: tst-errno-manual.py \
428 $(errlist-h) \
429 $(..)manual/errno.texi
430 $(PYTHON) tst-errno-manual.py -m $(..)manual/errno.texi \
431 -e $(errlist-h) > $@; \
432 $(evaluate-test)
434 CFLAGS-vfprintf.c += -Wno-uninitialized
435 CFLAGS-vfwprintf.c += -Wno-uninitialized
437 CFLAGS-tmpfile.c += -fexceptions
438 CFLAGS-tmpfile64.c += -fexceptions
439 CFLAGS-tempname.c += -fexceptions
440 CFLAGS-psignal.c += -fexceptions
441 CFLAGS-vprintf.c += -fexceptions
442 CFLAGS-cuserid.c += -fexceptions
444 CFLAGS-vfprintf.c += -fexceptions
445 CFLAGS-fprintf.c += -fexceptions
446 CFLAGS-printf.c += -fexceptions
447 CFLAGS-vfwprintf.c += -fexceptions
448 CFLAGS-vfscanf.c += -fexceptions
449 CFLAGS-vfwscanf.c += -fexceptions
450 CFLAGS-fscanf.c += -fexceptions
451 CFLAGS-scanf.c += -fexceptions
452 CFLAGS-isoc99_vfscanf.c += -fexceptions
453 CFLAGS-isoc99_vscanf.c += -fexceptions
454 CFLAGS-isoc99_fscanf.c += -fexceptions
455 CFLAGS-isoc99_scanf.c += -fexceptions
456 CFLAGS-isoc23_vfscanf.c += -fexceptions
457 CFLAGS-isoc23_vscanf.c += -fexceptions
458 CFLAGS-isoc23_fscanf.c += -fexceptions
459 CFLAGS-isoc23_scanf.c += -fexceptions
461 CFLAGS-dprintf.c += $(config-cflags-wno-ignored-attributes)
463 # Called during static library initialization, so turn stack-protection
464 # off for non-shared builds.
465 CFLAGS-_itoa.o = $(no-stack-protector)
466 CFLAGS-_itoa.op = $(no-stack-protector)
468 # scanf18.c and scanf19.c test a deprecated extension which is no
469 # longer visible under most conformance levels; see the source files
470 # for more detail.
471 CFLAGS-scanf18.c += -std=gnu89
472 CFLAGS-scanf19.c += -std=gnu89
474 CFLAGS-bug3.c += -DOBJPFX=\"$(objpfx)\"
475 CFLAGS-bug4.c += -DOBJPFX=\"$(objpfx)\"
476 CFLAGS-bug5.c += -DOBJPFX=\"$(objpfx)\"
477 CFLAGS-test-fseek.c += -DOBJPFX=\"$(objpfx)\"
478 CFLAGS-test-popen.c += -DOBJPFX=\"$(objpfx)\"
479 CFLAGS-test_rdwr.c += -DOBJPFX=\"$(objpfx)\"
481 # tst-gets.c tests a deprecated function.
482 CFLAGS-tst-gets.c += -Wno-deprecated-declarations
484 # BZ #11319 was first fixed for regular vdprintf, then reopened because
485 # the fortified version had the same bug.
486 CFLAGS-tst-bz11319-fortify2.c += $(no-fortify-source),-D_FORTIFY_SOURCE=2
488 CFLAGS-tst-memstream-string.c += -fno-builtin-fprintf
490 # Some versions of GCC supported for building glibc do not support -std=c2x, so
491 # the test for that version uses -std=c11 and then _ISOC2X_SOURCE is defined in
492 # the test as needed.
493 CFLAGS-tst-scanf-binary-c11.c += -std=c11 -DOBJPFX=\"$(objpfx)\"
494 CFLAGS-tst-scanf-binary-c2x.c += -std=c11 -DOBJPFX=\"$(objpfx)\"
495 CFLAGS-tst-scanf-binary-gnu11.c += -std=gnu11 -DOBJPFX=\"$(objpfx)\"
496 CFLAGS-tst-scanf-binary-gnu89.c += -std=gnu89 -DOBJPFX=\"$(objpfx)\"
498 CPPFLAGS += $(libio-mtsafe)
500 $(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
501 $(test-program-cmd) > $@ 2>&1; \
502 $(evaluate-test)
504 $(objpfx)tst-setvbuf1-cmp.out: tst-setvbuf1.expect $(objpfx)tst-setvbuf1.out
505 cmp $^ > $@; \
506 $(evaluate-test)
508 $(objpfx)tst-printf-round: $(libm)
509 $(objpfx)tst-scanf-round: $(libm)