Debian Codegraph @

libio/Makefile

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # Copyright (C) 1995-2026 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.
17
18 #
19 # Specific makefile for libio.
20 #
21 subdir := libio
22
23 include ../Makeconfig
24
25 headers := stdio.h \
26 bits/stdio.h bits/stdio2.h bits/stdio2-decl.h bits/stdio-ldbl.h \
27 bits/types/FILE.h bits/types/__FILE.h bits/types/struct_FILE.h \
28 bits/types/__fpos_t.h bits/types/__fpos64_t.h \
29 bits/types/cookie_io_functions_t.h
30
31 routines := \
32 filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \
33 iofopncook iofputs iofread iofsetpos ioftell wfiledoalloc \
34 iofwrite iogetdelim iogetline iogets iopadn iopopen ioputs \
35 ioseekoff ioseekpos iosetbuffer iosetvbuf ioungetc \
36 iovsprintf iovsscanf \
37 iofgetpos64 iofopen64 iofsetpos64 \
38 fputwc fputwc_u getwc getwc_u getwchar getwchar_u iofgetws iofgetws_u \
39 iofputws iofputws_u iogetwline iowpadn ioungetwc putwc putwc_u \
40 putwchar putwchar_u putchar putchar_u fwprintf swprintf vwprintf \
41 wprintf wscanf fwscanf vwscanf vswprintf iovswscanf swscanf wgenops \
42 wstrops wfileops iofwide fwide wmemstream \
43 \
44 clearerr feof ferror fileno fputc freopen fseek getc getchar \
45 memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \
46 iovdprintf vscanf vsnprintf obprintf fcloseall fseeko ftello \
47 freopen64 fseeko64 ftello64 \
48 \
49 __fbufsize __freading __fwriting __freadable __fwritable __flbf \
50 __fpurge __fpending __fsetlocking \
51 \
52 libc_fatal fmemopen oldfmemopen vtables
53
54 gen-as-const-headers += libio-macros.sym
55
56 # Exclude fortified routines from being built with _FORTIFY_SOURCE
57 routines_no_fortify += \
58 fwprintf \
59 iofgets \
60 iofgets_u \
61 iofgetws \
62 iofgetws_u \
63 iovdprintf \
64 swprintf \
65 vasprintf \
66 vsnprintf \
67 vswprintf \
68 vwprintf \
69 wprintf \
70 # routines_no_fortify
71
72 tests = \
73 bug-fopena+ \
74 bug-fseek \
75 bug-ftell \
76 bug-memstream1 \
77 bug-mmap-fflush \
78 bug-rewind \
79 bug-rewind2 \
80 bug-ungetc \
81 bug-ungetc2 \
82 bug-ungetc3 \
83 bug-ungetc4 \
84 bug-ungetwc1 \
85 bug-ungetwc2 \
86 bug-wfflush \
•87 bug-wgenops-bz33998 \
88 bug-wmemstream1 \
89 bug-wsetpos \
90 test-fmemopen \
91 test-fputs-unbuffered-full \
92 test-fputws-unbuffered-full \
93 tst-asprintf-null \
94 tst-atime \
95 tst-bz22415 \
96 tst-bz24051 \
97 tst-bz24153 \
98 tst-bz28828 \
99 tst-closeall \
100 tst-eof \
101 tst-ext \
102 tst-ext2 \
103 tst-fclose-unopened \
104 tst-fclose-unopened2 \
105 tst-fdopen-seek-failure \
106 tst-fflush \
107 tst-fflush-NULL \
108 tst-fgetc-after-eof \
109 tst-fgetwc \
110 tst-fgetws \
111 tst-fopenloc2 \
112 tst-fputws \
113 tst-freopen \
114 tst-fseek \
115 tst-ftell-active-handler \
116 tst-ftell-append \
117 tst-ftell-partial-wide \
118 tst-fwrite-error \
119 tst-getdelim \
120 tst-memstream1 \
121 tst-memstream2 \
122 tst-memstream3 \
123 tst-memstream4 \
124 tst-mmap-eofsync \
125 tst-mmap-fflushsync \
126 tst-mmap-offend \
127 tst-mmap-setvbuf \
128 tst-mmap2-eofsync \
129 tst-popen-fork \
130 tst-popen1 \
131 tst-setvbuf1 \
132 tst-sprintf-chk-ub \
133 tst-sprintf-ub \
134 tst-sscanf \
135 tst-stdio-static \
136 tst-swscanf \
137 tst-ungetwc1 \
138 tst-ungetwc2 \
139 tst-wfile-sync \
140 tst-widetext \
141 tst-wmemstream1 \
142 tst-wmemstream2 \
143 tst-wmemstream3 \
144 tst-wmemstream4 \
145 tst-wmemstream5 \
146 tst_getwc \
147 tst_putwc \
148 tst_swprintf \
149 tst_swscanf \
150 tst_wprintf \
151 tst_wprintf2 \
152 tst_wscanf \
153 # tests
154
155 tests-static += tst-stdio-static
156
157 $(objpfx)tst-popen-fork: $(shared-thread-library)
158
159 tests-internal = tst-vtables tst-vtables-interposed
160
161 ifeq (yes,$(build-shared))
162 # Add test-fopenloc only if shared library is enabled since it depends on
163 # shared localedata objects.
164 tests += tst-fopenloc
165 # Add tst-bz24228 only if shared library is enabled since it can never meet its
166 # objective with static linking because the relevant code just is not there.
167 tests += tst-bz24228
168 endif
169 test-srcs = test-freopen
170
171 ifeq ($(build-shared),yes)
172 routines += oldiofopen oldiofdopen oldiofclose oldiopopen oldpclose \
173 oldtmpfile oldiofgetpos oldiofgetpos64 oldiofsetpos \
174 oldiofsetpos64
175 endif
176
177 ifeq (yes,$(libc-reentrant))
178 routines += clearerr_u feof_u ferror_u fputc_u getc_u getchar_u \
179 iofflush_u putc_u putchar_u peekc iofread_u iofwrite_u iofgets_u \
180 iofputs_u
181 endif
182
183 CPPFLAGS += $(libio-mtsafe)
184
185 # Support for exception handling.
186 CFLAGS-fileops.c += -fexceptions
187 CFLAGS-fputc.c += -fexceptions
188 CFLAGS-fputwc.c += -fexceptions
189 CFLAGS-freopen64.c += -fexceptions
190 CFLAGS-freopen.c += -fexceptions
191 CFLAGS-fseek.c += -fexceptions
192 CFLAGS-fseeko64.c += -fexceptions
193 CFLAGS-fseeko.c += -fexceptions
194 CFLAGS-ftello64.c += -fexceptions
195 CFLAGS-ftello.c += -fexceptions
196 CFLAGS-fwide.c += -fexceptions
197 CFLAGS-genops.c += -fexceptions
198 CFLAGS-getc.c += -fexceptions
199 CFLAGS-getchar.c += -fexceptions
200 CFLAGS-getwc.c += -fexceptions
201 CFLAGS-getwchar.c += -fexceptions
202 CFLAGS-iofclose.c += -fexceptions
203 CFLAGS-iofflush.c += -fexceptions
204 CFLAGS-iofgetpos64.c += -fexceptions
205 CFLAGS-iofgetpos.c += -fexceptions
206 CFLAGS-iofgets.c += -fexceptions
207 CFLAGS-iofgetws.c += -fexceptions
208 CFLAGS-iofputs.c += -fexceptions
209 CFLAGS-iofputws.c += -fexceptions
210 CFLAGS-iofread.c += -fexceptions
211 CFLAGS-iofsetpos64.c += -fexceptions
212 CFLAGS-iofsetpos.c += -fexceptions
213 CFLAGS-ioftell.c += -fexceptions
214 CFLAGS-iofwrite.c += -fexceptions
215 CFLAGS-iogetdelim.c += -fexceptions
216 CFLAGS-iogetline.c += -fexceptions
217 CFLAGS-iogets.c += -fexceptions
218 CFLAGS-iogetwline.c += -fexceptions
219 CFLAGS-ioputs.c += -fexceptions
220 CFLAGS-ioseekoff.c += -fexceptions
221 CFLAGS-ioseekpos.c += -fexceptions
222 CFLAGS-iosetbuffer.c += -fexceptions
223 CFLAGS-iosetvbuf.c += -fexceptions
224 CFLAGS-ioungetc.c += -fexceptions
225 CFLAGS-ioungetwc.c += -fexceptions
226 CFLAGS-oldfileops.c += -fexceptions
227 CFLAGS-oldiofclose.c += -fexceptions
228 CFLAGS-oldiofgetpos64.c += -fexceptions
229 CFLAGS-oldiofgetpos.c += -fexceptions
230 CFLAGS-oldiofsetpos64.c += -fexceptions
231 CFLAGS-oldiofsetpos.c += -fexceptions
232 CFLAGS-peekc.c += -fexceptions
233 CFLAGS-putc.c += -fexceptions
234 CFLAGS-putchar.c += -fexceptions
235 CFLAGS-putwc.c += -fexceptions
236 CFLAGS-putwchar.c += -fexceptions
237 CFLAGS-rewind.c += -fexceptions
238 CFLAGS-wfileops.c += -fexceptions
239 CFLAGS-wgenops.c += -fexceptions
240 CFLAGS-oldiofopen.c += -fexceptions
241 CFLAGS-iofopen.c += -fexceptions
242 CFLAGS-iofopen64.c += -fexceptions
243 CFLAGS-oldtmpfile.c += -fexceptions
244 # XXX Do we need filedoalloc and wfiledoalloc? Others?
245
246 # Prevent fortification as these are built with -O0
247 CFLAGS-tst-bz24051.c += $(no-fortify-source)
248 CFLAGS-tst-bz24153.c += $(no-fortify-source)
249
250 CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
251
252 # These test cases intentionally use overlapping arguments
253 CFLAGS-tst-sprintf-ub.c += $(test-config-cflags-wno-restrict) \
254 $(no-fortify-source)
255 CFLAGS-tst-sprintf-chk-ub.c += $(test-config-cflags-wno-restrict) \
256 $(no-fortify-source)
257
258 LDFLAGS-tst-bz24228 = -Wl,--version-script=tst-bz24228.map
259
260 tst_wprintf2-ARGS = "Some Text"
261
262 tst-fclose-unopened2-ENV = \
263 MALLOC_TRACE=$(objpfx)tst-fclose-unopened2.mtrace \
264 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
265 test-fmemopen-ENV = MALLOC_TRACE=$(objpfx)test-fmemopen.mtrace \
266 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
267 tst-fdopen-seek-failure-ENV = \
268 MALLOC_TRACE=$(objpfx)tst-fdopen-seek-failure.mtrace \
269 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
270 tst-fopenloc-ENV = MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace \
271 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
272 tst-bz22415-ENV = MALLOC_TRACE=$(objpfx)tst-bz22415.mtrace \
273 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
274 tst-bz24228-ENV = MALLOC_TRACE=$(objpfx)tst-bz24228.mtrace \
275 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
276
277 aux := fileops genops stdfiles stdio strops
278
279 ifeq ($(run-built-tests),yes)
280 ifeq ($(build-shared),yes)
281 ifneq ($(PERL),no)
282 generated += \
283 test-fmemopen.check \
284 test-fmemopen.mtrace \
285 tst-bz22415.check \
286 tst-bz22415.mtrace \
287 tst-bz24228.check \
288 tst-bz24228.mtrace \
289 tst-fclose-unopened2.check \
290 tst-fclose-unopened2.mtrace \
291 tst-fdopen-seek-failure.check \
292 tst-fdopen-seek-failure.mtrace \
293 tst-fopenloc.check \
294 tst-fopenloc.mtrace \
295 # generated
296 endif
297 endif
298 endif
299
300 ifeq ($(build-shared),yes)
301 aux += oldfileops oldstdfiles
302 tests += \
303 tst-fopen-compat \
304 tst-stderr-compat \
305 # tests
306 tests-2.0 += \
307 tst-fopen-compat \
308 tst-stderr-compat \
309 # tests-2.0
310
311 tst-fopen-compat-ARGS = tst-fopen-compat.c
312 # Disable PIE to trigger copy relocation.
313 CFLAGS-tst-fopen-compat.c += -fno-pie
314 tst-fopen-compat-no-pie = yes
315 endif
316
317 shared-only-routines = oldiofopen oldiofdopen oldiofclose oldfileops \
318 oldstdfiles oldiopopen oldpclose oldtmpfile \
319 oldiofgetpos oldiofgetpos64 oldiofsetpos \
320 oldiofsetpos64
321
322 ifeq ($(run-built-tests),yes)
323 tests-special += \
324 $(objpfx)test-freopen.out \
325 # tests-special
326 ifeq (yes,$(build-shared))
327 # Run tst-fopenloc-cmp.out and tst-openloc-mem.out only if shared
328 # library is enabled since they depend on tst-fopenloc.out.
329 tests-special += $(objpfx)tst-fopenloc-cmp.out
330 ifeq ($(build-shared),yes)
331 ifneq ($(PERL),no)
332 tests-special += \
333 $(objpfx)test-fmemopen-mem.out \
334 $(objpfx)tst-bz22415-mem.out \
335 $(objpfx)tst-bz24228-mem.out \
336 $(objpfx)tst-fclose-unopened2-mem.out \
337 $(objpfx)tst-fdopen-seek-failure-mem.out \
338 $(objpfx)tst-fopenloc-mem.out \
339 # tests-special
340 endif
341 endif
342 endif
343
344 tests += \
345 tst-cleanup-default \
346 tst-cleanup-default-static \
347 # tests
348 tests-static += tst-cleanup-default-static
349 tests-special += $(objpfx)tst-cleanup-default-cmp.out $(objpfx)tst-cleanup-default-static-cmp.out
350 LDFLAGS-tst-cleanup-default = -Wl,--gc-sections
351 LDFLAGS-tst-cleanup-default-static = -Wl,--gc-sections
352
353 ifeq ($(have-gnu-retain)$(have-z-start-stop-gc),yesyes)
354 tests += \
355 tst-cleanup-nostart-stop-gc \
356 tst-cleanup-nostart-stop-gc-static \
357 tst-cleanup-start-stop-gc \
358 tst-cleanup-start-stop-gc-static \
359 # tests
360 tests-static += \
361 tst-cleanup-nostart-stop-gc-static \
362 tst-cleanup-start-stop-gc-static \
363 # tests-static
364 tests-special += $(objpfx)tst-cleanup-start-stop-gc-cmp.out \
365 $(objpfx)tst-cleanup-start-stop-gc-static-cmp.out \
366 $(objpfx)tst-cleanup-nostart-stop-gc-cmp.out \
367 $(objpfx)tst-cleanup-nostart-stop-gc-static-cmp.out
368 LDFLAGS-tst-cleanup-start-stop-gc := -Wl,--gc-sections,-z,start-stop-gc
369 LDFLAGS-tst-cleanup-start-stop-gc-static := -Wl,--gc-sections,-z,start-stop-gc
370 LDFLAGS-tst-cleanup-nostart-stop-gc := -Wl,--gc-sections,-z,nostart-stop-gc
371 LDFLAGS-tst-cleanup-nostart-stop-gc-static := -Wl,--gc-sections,-z,nostart-stop-gc
372 endif
373 endif
374
375 include ../Rules
376
377 ifeq ($(run-built-tests),yes)
378 LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ISO-8859-1 en_US.UTF-8 \
379 ja_JP.EUC-JP ja_JP.UTF-8
380 include ../gen-locales.mk
381
382 $(objpfx)bug-ftell.out: $(gen-locales)
383 $(objpfx)bug-ungetwc1.out: $(gen-locales)
384 $(objpfx)bug-ungetwc2.out: $(gen-locales)
385 $(objpfx)tst-fgetwc.out: $(gen-locales)
386 $(objpfx)tst-fgetws.out: $(gen-locales)
387 $(objpfx)tst-fopenloc.out: $(gen-locales)
388 $(objpfx)tst-fputws.out: $(gen-locales)
389 $(objpfx)tst-fseek.out: $(gen-locales)
390 $(objpfx)tst-ftell-active-handler.out: $(gen-locales)
391 $(objpfx)tst-ftell-append.out: $(gen-locales)
392 $(objpfx)tst-ftell-partial-wide.out: $(gen-locales)
393 $(objpfx)tst-setvbuf1.out: $(gen-locales)
394 $(objpfx)tst-swscanf.out: $(gen-locales)
395 $(objpfx)tst-ungetwc1.out: $(gen-locales)
396 $(objpfx)tst-ungetwc2.out: $(gen-locales)
397 $(objpfx)tst-widetext.out: $(gen-locales)
398 $(objpfx)tst_wprintf2.out: $(gen-locales)
399 $(objpfx)tst-wfile-sync.out: $(gen-locales)
400 endif
401
402 define gen-tst-cleanup
403 $(objpfx)tst-cleanup-$1-cmp.out: tst-cleanup.exp $(objpfx)tst-cleanup-$1.out
404 cmp $$^ > $$@; $$(evaluate-test)
405 endef
406
407 $(foreach t,default default-static start-stop-gc start-stop-gc-static nostart-stop-gc nostart-stop-gc-static, \
408 $(eval $(call gen-tst-cleanup,$(t))))
409
410 $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen
411 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)' \
412 $(common-objpfx)libio/; \
413 $(evaluate-test)
414
415 $(objpfx)tst-fopenloc-cmp.out: ../iconvdata/testdata/ISO-8859-1..UTF8 \
416 $(objpfx)tst-fopenloc.out
417 cmp $^ > $@; \
418 $(evaluate-test)
419
420 $(objpfx)test-fmemopen-mem.out: $(objpfx)test-fmemopen.out
421 $(common-objpfx)malloc/mtrace $(objpfx)test-fmemopen.mtrace > $@; \
422 $(evaluate-test)
423
424 $(objpfx)tst-fclose-unopened2-mem.out: $(objpfx)tst-fclose-unopened2.out
425 $(common-objpfx)malloc/mtrace \
426 $(objpfx)tst-fclose-unopened2.mtrace > $@; \
427 $(evaluate-test)
428
429 $(objpfx)tst-fdopen-seek-failure-mem.out: $(objpfx)tst-fdopen-seek-failure.out
430 $(common-objpfx)malloc/mtrace \
431 $(objpfx)tst-fdopen-seek-failure.mtrace > $@; \
432 $(evaluate-test)
433
434 $(objpfx)tst-fopenloc-mem.out: $(objpfx)tst-fopenloc.out
435 $(common-objpfx)malloc/mtrace $(objpfx)tst-fopenloc.mtrace > $@; \
436 $(evaluate-test)
437
438 $(objpfx)tst-bz22415-mem.out: $(objpfx)tst-bz22415.out
439 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz22415.mtrace > $@; \
440 $(evaluate-test)
441
442 $(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
443 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
444 $(evaluate-test)
445
446 # Test stdio.o with "strip --strip-unneeded".
447 $(objpfx)tst-stdio-static: $(objpfx)stdio-stripped.o
448
449 $(objpfx)stdio-stripped.o: $(objpfx)stdio.o
450 $(STRIP) --strip-unneeded -o $@ $<