Debian Codegraph @

libio/Makefile

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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-wmemstream1 \
88 bug-wsetpos \
89 test-fmemopen \
90 test-fputs-unbuffered-full \
91 test-fputws-unbuffered-full \
92 tst-asprintf-null \
93 tst-atime \
94 tst-bz22415 \
95 tst-bz24051 \
96 tst-bz24153 \
97 tst-bz28828 \
98 tst-closeall \
99 tst-eof \
100 tst-ext \
101 tst-ext2 \
102 tst-fclose-unopened \
103 tst-fclose-unopened2 \
104 tst-fdopen-seek-failure \
105 tst-fflush \
106 tst-fflush-NULL \
107 tst-fgetc-after-eof \
108 tst-fgetwc \
109 tst-fgetws \
110 tst-fopenloc2 \
111 tst-fputws \
112 tst-freopen \
113 tst-fseek \
114 tst-ftell-active-handler \
115 tst-ftell-append \
116 tst-ftell-partial-wide \
117 tst-fwrite-error \
118 tst-getdelim \
119 tst-memstream1 \
120 tst-memstream2 \
121 tst-memstream3 \
122 tst-memstream4 \
123 tst-mmap-eofsync \
124 tst-mmap-fflushsync \
125 tst-mmap-offend \
126 tst-mmap-setvbuf \
127 tst-mmap2-eofsync \
128 tst-popen-fork \
129 tst-popen1 \
130 tst-setvbuf1 \
131 tst-sprintf-chk-ub \
132 tst-sprintf-ub \
133 tst-sscanf \
134 tst-stdio-static \
135 tst-swscanf \
136 tst-ungetwc1 \
137 tst-ungetwc2 \
138 tst-wfile-sync \
139 tst-widetext \
140 tst-wmemstream1 \
141 tst-wmemstream2 \
142 tst-wmemstream3 \
143 tst-wmemstream4 \
144 tst-wmemstream5 \
145 tst_getwc \
146 tst_putwc \
147 tst_swprintf \
148 tst_swscanf \
149 tst_wprintf \
150 tst_wprintf2 \
151 tst_wscanf \
152 # tests
153
154 tests-static += tst-stdio-static
155
156 $(objpfx)tst-popen-fork: $(shared-thread-library)
157
158 tests-internal = tst-vtables tst-vtables-interposed
159
160 ifeq (yes,$(build-shared))
161 # Add test-fopenloc only if shared library is enabled since it depends on
162 # shared localedata objects.
163 tests += tst-fopenloc
164 # Add tst-bz24228 only if shared library is enabled since it can never meet its
165 # objective with static linking because the relevant code just is not there.
166 tests += tst-bz24228
167 endif
168 test-srcs = test-freopen
169
170 ifeq ($(build-shared),yes)
171 routines += oldiofopen oldiofdopen oldiofclose oldiopopen oldpclose \
172 oldtmpfile oldiofgetpos oldiofgetpos64 oldiofsetpos \
173 oldiofsetpos64
174 endif
175
176 ifeq (yes,$(libc-reentrant))
177 routines += clearerr_u feof_u ferror_u fputc_u getc_u getchar_u \
178 iofflush_u putc_u putchar_u peekc iofread_u iofwrite_u iofgets_u \
179 iofputs_u
180 endif
181
182 CPPFLAGS += $(libio-mtsafe)
183
184 # Support for exception handling.
185 CFLAGS-fileops.c += -fexceptions
186 CFLAGS-fputc.c += -fexceptions
187 CFLAGS-fputwc.c += -fexceptions
188 CFLAGS-freopen64.c += -fexceptions
189 CFLAGS-freopen.c += -fexceptions
190 CFLAGS-fseek.c += -fexceptions
191 CFLAGS-fseeko64.c += -fexceptions
192 CFLAGS-fseeko.c += -fexceptions
193 CFLAGS-ftello64.c += -fexceptions
194 CFLAGS-ftello.c += -fexceptions
195 CFLAGS-fwide.c += -fexceptions
196 CFLAGS-genops.c += -fexceptions
197 CFLAGS-getc.c += -fexceptions
198 CFLAGS-getchar.c += -fexceptions
199 CFLAGS-getwc.c += -fexceptions
200 CFLAGS-getwchar.c += -fexceptions
201 CFLAGS-iofclose.c += -fexceptions
202 CFLAGS-iofflush.c += -fexceptions
203 CFLAGS-iofgetpos64.c += -fexceptions
204 CFLAGS-iofgetpos.c += -fexceptions
205 CFLAGS-iofgets.c += -fexceptions
206 CFLAGS-iofgetws.c += -fexceptions
207 CFLAGS-iofputs.c += -fexceptions
208 CFLAGS-iofputws.c += -fexceptions
209 CFLAGS-iofread.c += -fexceptions
210 CFLAGS-iofsetpos64.c += -fexceptions
211 CFLAGS-iofsetpos.c += -fexceptions
212 CFLAGS-ioftell.c += -fexceptions
213 CFLAGS-iofwrite.c += -fexceptions
214 CFLAGS-iogetdelim.c += -fexceptions
215 CFLAGS-iogetline.c += -fexceptions
216 CFLAGS-iogets.c += -fexceptions
217 CFLAGS-iogetwline.c += -fexceptions
218 CFLAGS-ioputs.c += -fexceptions
219 CFLAGS-ioseekoff.c += -fexceptions
220 CFLAGS-ioseekpos.c += -fexceptions
221 CFLAGS-iosetbuffer.c += -fexceptions
222 CFLAGS-iosetvbuf.c += -fexceptions
223 CFLAGS-ioungetc.c += -fexceptions
224 CFLAGS-ioungetwc.c += -fexceptions
225 CFLAGS-oldfileops.c += -fexceptions
226 CFLAGS-oldiofclose.c += -fexceptions
227 CFLAGS-oldiofgetpos64.c += -fexceptions
228 CFLAGS-oldiofgetpos.c += -fexceptions
229 CFLAGS-oldiofsetpos64.c += -fexceptions
230 CFLAGS-oldiofsetpos.c += -fexceptions
231 CFLAGS-peekc.c += -fexceptions
232 CFLAGS-putc.c += -fexceptions
233 CFLAGS-putchar.c += -fexceptions
234 CFLAGS-putwc.c += -fexceptions
235 CFLAGS-putwchar.c += -fexceptions
236 CFLAGS-rewind.c += -fexceptions
237 CFLAGS-wfileops.c += -fexceptions
238 CFLAGS-wgenops.c += -fexceptions
239 CFLAGS-oldiofopen.c += -fexceptions
240 CFLAGS-iofopen.c += -fexceptions
241 CFLAGS-iofopen64.c += -fexceptions
242 CFLAGS-oldtmpfile.c += -fexceptions
243 # XXX Do we need filedoalloc and wfiledoalloc? Others?
244
245 # Prevent fortification as these are built with -O0
246 CFLAGS-tst-bz24051.c += $(no-fortify-source)
247 CFLAGS-tst-bz24153.c += $(no-fortify-source)
248
249 CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
250
251 # These test cases intentionally use overlapping arguments
252 CFLAGS-tst-sprintf-ub.c += $(test-config-cflags-wno-restrict) \
253 $(no-fortify-source)
254 CFLAGS-tst-sprintf-chk-ub.c += $(test-config-cflags-wno-restrict) \
255 $(no-fortify-source)
256
257 LDFLAGS-tst-bz24228 = -Wl,--version-script=tst-bz24228.map
258
259 tst_wprintf2-ARGS = "Some Text"
260
261 tst-fclose-unopened2-ENV = \
262 MALLOC_TRACE=$(objpfx)tst-fclose-unopened2.mtrace \
263 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
264 test-fmemopen-ENV = MALLOC_TRACE=$(objpfx)test-fmemopen.mtrace \
265 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
266 tst-fdopen-seek-failure-ENV = \
267 MALLOC_TRACE=$(objpfx)tst-fdopen-seek-failure.mtrace \
268 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
269 tst-fopenloc-ENV = MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace \
270 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
271 tst-bz22415-ENV = MALLOC_TRACE=$(objpfx)tst-bz22415.mtrace \
272 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
273 tst-bz24228-ENV = MALLOC_TRACE=$(objpfx)tst-bz24228.mtrace \
274 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
275
276 aux := fileops genops stdfiles stdio strops
277
278 ifeq ($(run-built-tests),yes)
279 ifeq ($(build-shared),yes)
280 ifneq ($(PERL),no)
281 generated += \
282 test-fmemopen.check \
283 test-fmemopen.mtrace \
284 tst-bz22415.check \
285 tst-bz22415.mtrace \
286 tst-bz24228.check \
287 tst-bz24228.mtrace \
288 tst-fclose-unopened2.check \
289 tst-fclose-unopened2.mtrace \
290 tst-fdopen-seek-failure.check \
291 tst-fdopen-seek-failure.mtrace \
292 tst-fopenloc.check \
293 tst-fopenloc.mtrace \
294 # generated
295 endif
296 endif
297 endif
298
299 ifeq ($(build-shared),yes)
300 aux += oldfileops oldstdfiles
301 tests += \
302 tst-fopen-compat \
303 tst-stderr-compat \
304 # tests
305 tests-2.0 += \
306 tst-fopen-compat \
307 tst-stderr-compat \
308 # tests-2.0
309
310 tst-fopen-compat-ARGS = tst-fopen-compat.c
311 # Disable PIE to trigger copy relocation.
312 CFLAGS-tst-fopen-compat.c += -fno-pie
313 tst-fopen-compat-no-pie = yes
314 endif
315
316 shared-only-routines = oldiofopen oldiofdopen oldiofclose oldfileops \
317 oldstdfiles oldiopopen oldpclose oldtmpfile \
318 oldiofgetpos oldiofgetpos64 oldiofsetpos \
319 oldiofsetpos64
320
321 ifeq ($(run-built-tests),yes)
322 tests-special += \
323 $(objpfx)test-freopen.out \
324 # tests-special
325 ifeq (yes,$(build-shared))
326 # Run tst-fopenloc-cmp.out and tst-openloc-mem.out only if shared
327 # library is enabled since they depend on tst-fopenloc.out.
328 tests-special += $(objpfx)tst-fopenloc-cmp.out
329 ifeq ($(build-shared),yes)
330 ifneq ($(PERL),no)
331 tests-special += \
332 $(objpfx)test-fmemopen-mem.out \
333 $(objpfx)tst-bz22415-mem.out \
334 $(objpfx)tst-bz24228-mem.out \
335 $(objpfx)tst-fclose-unopened2-mem.out \
336 $(objpfx)tst-fdopen-seek-failure-mem.out \
337 $(objpfx)tst-fopenloc-mem.out \
338 # tests-special
339 endif
340 endif
341 endif
342
343 tests += \
344 tst-cleanup-default \
345 tst-cleanup-default-static \
346 # tests
347 tests-static += tst-cleanup-default-static
348 tests-special += $(objpfx)tst-cleanup-default-cmp.out $(objpfx)tst-cleanup-default-static-cmp.out
349 LDFLAGS-tst-cleanup-default = -Wl,--gc-sections
350 LDFLAGS-tst-cleanup-default-static = -Wl,--gc-sections
351
352 ifeq ($(have-gnu-retain)$(have-z-start-stop-gc),yesyes)
353 tests += \
354 tst-cleanup-nostart-stop-gc \
355 tst-cleanup-nostart-stop-gc-static \
356 tst-cleanup-start-stop-gc \
357 tst-cleanup-start-stop-gc-static \
358 # tests
359 tests-static += \
360 tst-cleanup-nostart-stop-gc-static \
361 tst-cleanup-start-stop-gc-static \
362 # tests-static
363 tests-special += $(objpfx)tst-cleanup-start-stop-gc-cmp.out \
364 $(objpfx)tst-cleanup-start-stop-gc-static-cmp.out \
365 $(objpfx)tst-cleanup-nostart-stop-gc-cmp.out \
366 $(objpfx)tst-cleanup-nostart-stop-gc-static-cmp.out
367 LDFLAGS-tst-cleanup-start-stop-gc := -Wl,--gc-sections,-z,start-stop-gc
368 LDFLAGS-tst-cleanup-start-stop-gc-static := -Wl,--gc-sections,-z,start-stop-gc
369 LDFLAGS-tst-cleanup-nostart-stop-gc := -Wl,--gc-sections,-z,nostart-stop-gc
370 LDFLAGS-tst-cleanup-nostart-stop-gc-static := -Wl,--gc-sections,-z,nostart-stop-gc
371 endif
372 endif
373
374 include ../Rules
375
376 ifeq ($(run-built-tests),yes)
377 LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ISO-8859-1 en_US.UTF-8 \
378 ja_JP.EUC-JP ja_JP.UTF-8
379 include ../gen-locales.mk
380
381 $(objpfx)bug-ftell.out: $(gen-locales)
382 $(objpfx)bug-ungetwc1.out: $(gen-locales)
383 $(objpfx)bug-ungetwc2.out: $(gen-locales)
384 $(objpfx)tst-fgetwc.out: $(gen-locales)
385 $(objpfx)tst-fgetws.out: $(gen-locales)
386 $(objpfx)tst-fopenloc.out: $(gen-locales)
387 $(objpfx)tst-fputws.out: $(gen-locales)
388 $(objpfx)tst-fseek.out: $(gen-locales)
389 $(objpfx)tst-ftell-active-handler.out: $(gen-locales)
390 $(objpfx)tst-ftell-append.out: $(gen-locales)
391 $(objpfx)tst-ftell-partial-wide.out: $(gen-locales)
392 $(objpfx)tst-setvbuf1.out: $(gen-locales)
393 $(objpfx)tst-swscanf.out: $(gen-locales)
394 $(objpfx)tst-ungetwc1.out: $(gen-locales)
395 $(objpfx)tst-ungetwc2.out: $(gen-locales)
396 $(objpfx)tst-widetext.out: $(gen-locales)
397 $(objpfx)tst_wprintf2.out: $(gen-locales)
398 $(objpfx)tst-wfile-sync.out: $(gen-locales)
399 endif
400
401 define gen-tst-cleanup
402 $(objpfx)tst-cleanup-$1-cmp.out: tst-cleanup.exp $(objpfx)tst-cleanup-$1.out
403 cmp $$^ > $$@; $$(evaluate-test)
404 endef
405
406 $(foreach t,default default-static start-stop-gc start-stop-gc-static nostart-stop-gc nostart-stop-gc-static, \
407 $(eval $(call gen-tst-cleanup,$(t))))
408
409 $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen
410 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)' \
411 $(common-objpfx)libio/; \
412 $(evaluate-test)
413
414 $(objpfx)tst-fopenloc-cmp.out: ../iconvdata/testdata/ISO-8859-1..UTF8 \
415 $(objpfx)tst-fopenloc.out
416 cmp $^ > $@; \
417 $(evaluate-test)
418
419 $(objpfx)test-fmemopen-mem.out: $(objpfx)test-fmemopen.out
420 $(common-objpfx)malloc/mtrace $(objpfx)test-fmemopen.mtrace > $@; \
421 $(evaluate-test)
422
423 $(objpfx)tst-fclose-unopened2-mem.out: $(objpfx)tst-fclose-unopened2.out
424 $(common-objpfx)malloc/mtrace \
425 $(objpfx)tst-fclose-unopened2.mtrace > $@; \
426 $(evaluate-test)
427
428 $(objpfx)tst-fdopen-seek-failure-mem.out: $(objpfx)tst-fdopen-seek-failure.out
429 $(common-objpfx)malloc/mtrace \
430 $(objpfx)tst-fdopen-seek-failure.mtrace > $@; \
431 $(evaluate-test)
432
433 $(objpfx)tst-fopenloc-mem.out: $(objpfx)tst-fopenloc.out
434 $(common-objpfx)malloc/mtrace $(objpfx)tst-fopenloc.mtrace > $@; \
435 $(evaluate-test)
436
437 $(objpfx)tst-bz22415-mem.out: $(objpfx)tst-bz22415.out
438 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz22415.mtrace > $@; \
439 $(evaluate-test)
440
441 $(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
442 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
443 $(evaluate-test)
444
445 # Test stdio.o with "strip --strip-unneeded".
446 $(objpfx)tst-stdio-static: $(objpfx)stdio-stripped.o
447
448 $(objpfx)stdio-stripped.o: $(objpfx)stdio.o
449 $(STRIP) --strip-unneeded -o $@ $<