riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
[glibc.git] / libio / Makefile
blob287ec11338f48c02225295a1f8b34cc34554a237
1 # Copyright (C) 1995-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 libio.
21 subdir := libio
23 include ../Makeconfig
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
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 \
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 \
49 __fbufsize __freading __fwriting __freadable __fwritable __flbf \
50 __fpurge __fpending __fsetlocking \
52 libc_fatal fmemopen oldfmemopen vtables
54 gen-as-const-headers += libio-macros.sym
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 swprintf \
64 vasprintf \
65 vsnprintf \
66 vswprintf \
67 vwprintf \
68 wprintf \
69 # routines_no_fortify
71 tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
72 tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-ext2 \
73 tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \
74 tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof \
75 tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
76 tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \
77 tst-mmap2-eofsync tst-mmap-offend bug-fopena+ bug-wfflush \
78 bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \
79 tst-memstream1 tst-memstream2 tst-memstream3 tst-memstream4 \
80 tst-wmemstream1 tst-wmemstream2 tst-wmemstream3 tst-wmemstream4 \
81 tst-wmemstream5 bug-memstream1 bug-wmemstream1 \
82 tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \
83 tst-fwrite-error tst-ftell-partial-wide tst-ftell-active-handler \
84 tst-ftell-append tst-fputws tst-bz22415 tst-fgetc-after-eof \
85 tst-sprintf-ub tst-sprintf-chk-ub tst-bz24051 tst-bz24153 \
86 tst-wfile-sync tst-bz28828 tst-getdelim
88 tests-internal = tst-vtables tst-vtables-interposed
90 ifeq (yes,$(build-shared))
91 # Add test-fopenloc only if shared library is enabled since it depends on
92 # shared localedata objects.
93 tests += tst-fopenloc
94 # Add tst-bz24228 only if shared library is enabled since it can never meet its
95 # objective with static linking because the relevant code just is not there.
96 tests += tst-bz24228
97 endif
98 test-srcs = test-freopen
100 ifeq ($(build-shared),yes)
101 routines += oldiofopen oldiofdopen oldiofclose oldiopopen oldpclose \
102 oldtmpfile oldiofgetpos oldiofgetpos64 oldiofsetpos \
103 oldiofsetpos64
104 endif
106 ifeq (yes,$(libc-reentrant))
107 routines += clearerr_u feof_u ferror_u fputc_u getc_u getchar_u \
108 iofflush_u putc_u putchar_u peekc iofread_u iofwrite_u iofgets_u \
109 iofputs_u
110 endif
112 CPPFLAGS += $(libio-mtsafe)
114 # Support for exception handling.
115 CFLAGS-fileops.c += -fexceptions
116 CFLAGS-fputc.c += -fexceptions
117 CFLAGS-fputwc.c += -fexceptions
118 CFLAGS-freopen64.c += -fexceptions
119 CFLAGS-freopen.c += -fexceptions
120 CFLAGS-fseek.c += -fexceptions
121 CFLAGS-fseeko64.c += -fexceptions
122 CFLAGS-fseeko.c += -fexceptions
123 CFLAGS-ftello64.c += -fexceptions
124 CFLAGS-ftello.c += -fexceptions
125 CFLAGS-fwide.c += -fexceptions
126 CFLAGS-genops.c += -fexceptions
127 CFLAGS-getc.c += -fexceptions
128 CFLAGS-getchar.c += -fexceptions
129 CFLAGS-getwc.c += -fexceptions
130 CFLAGS-getwchar.c += -fexceptions
131 CFLAGS-iofclose.c += -fexceptions
132 CFLAGS-iofflush.c += -fexceptions $(config-cflags-wno-ignored-attributes)
133 CFLAGS-iofgetpos64.c += -fexceptions
134 CFLAGS-iofgetpos.c += -fexceptions
135 CFLAGS-iofgets.c += -fexceptions
136 CFLAGS-iofgetws.c += -fexceptions
137 CFLAGS-iofputs.c += -fexceptions $(config-cflags-wno-ignored-attributes)
138 CFLAGS-iofputws.c += -fexceptions
139 CFLAGS-iofread.c += -fexceptions
140 CFLAGS-iofsetpos64.c += -fexceptions
141 CFLAGS-iofsetpos.c += -fexceptions
142 CFLAGS-ioftell.c += -fexceptions
143 CFLAGS-iofwrite.c += -fexceptions $(config-cflags-wno-ignored-attributes)
144 CFLAGS-iogetdelim.c += -fexceptions
145 CFLAGS-iogetline.c += -fexceptions
146 CFLAGS-iogets.c += -fexceptions
147 CFLAGS-iogetwline.c += -fexceptions
148 CFLAGS-ioputs.c += -fexceptions
149 CFLAGS-ioseekoff.c += -fexceptions
150 CFLAGS-ioseekpos.c += -fexceptions
151 CFLAGS-iosetbuffer.c += -fexceptions
152 CFLAGS-iosetvbuf.c += -fexceptions
153 CFLAGS-ioungetc.c += -fexceptions
154 CFLAGS-ioungetwc.c += -fexceptions
155 CFLAGS-oldfileops.c += -fexceptions
156 CFLAGS-oldiofclose.c += -fexceptions
157 CFLAGS-oldiofgetpos64.c += -fexceptions
158 CFLAGS-oldiofgetpos.c += -fexceptions
159 CFLAGS-oldiofsetpos64.c += -fexceptions
160 CFLAGS-oldiofsetpos.c += -fexceptions
161 CFLAGS-peekc.c += -fexceptions
162 CFLAGS-putc.c += -fexceptions
163 CFLAGS-putchar.c += -fexceptions
164 CFLAGS-putwc.c += -fexceptions
165 CFLAGS-putwchar.c += -fexceptions
166 CFLAGS-rewind.c += -fexceptions
167 CFLAGS-wfileops.c += -fexceptions
168 CFLAGS-wgenops.c += -fexceptions
169 CFLAGS-oldiofopen.c += -fexceptions
170 CFLAGS-iofopen.c += -fexceptions
171 CFLAGS-iofopen64.c += -fexceptions
172 CFLAGS-oldtmpfile.c += -fexceptions
173 CFLAGS-fileno.c += $(config-cflags-wno-ignored-attributes)
174 CFLAGS-feof_u.c += $(config-cflags-wno-ignored-attributes)
175 CFLAGS-ferror_u.c += $(config-cflags-wno-ignored-attributes)
176 CFLAGS-getc_u.c += $(config-cflags-wno-ignored-attributes)
177 CFLAGS-iofflush_u.c += $(config-cflags-wno-ignored-attributes)
178 CFLAGS-putc_u.c += $(config-cflags-wno-ignored-attributes)
179 CFLAGS-iofgets_u.c += $(config-cflags-wno-ignored-attributes)
180 CFLAGS-iofputs_u.c += $(config-cflags-wno-ignored-attributes)
181 # XXX Do we need filedoalloc and wfiledoalloc? Others?
183 # Prevent fortification as these are built with -O0
184 CFLAGS-tst-bz24051.c += $(no-fortify-source)
185 CFLAGS-tst-bz24153.c += $(no-fortify-source)
187 CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
189 # These test cases intentionally use overlapping arguments
190 CFLAGS-tst-sprintf-ub.c += -Wno-restrict $(no-fortify-source)
191 CFLAGS-tst-sprintf-chk-ub.c += -Wno-restrict $(no-fortify-source)
193 LDFLAGS-tst-bz24228 = -Wl,--version-script=tst-bz24228.map
195 tst_wprintf2-ARGS = "Some Text"
197 test-fmemopen-ENV = MALLOC_TRACE=$(objpfx)test-fmemopen.mtrace \
198 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
199 tst-fopenloc-ENV = MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace \
200 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
201 tst-bz22415-ENV = MALLOC_TRACE=$(objpfx)tst-bz22415.mtrace \
202 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
203 tst-bz24228-ENV = MALLOC_TRACE=$(objpfx)tst-bz24228.mtrace \
204 LD_PRELOAD=$(common-objpfx)/malloc/libc_malloc_debug.so
206 generated += test-fmemopen.mtrace test-fmemopen.check
207 generated += tst-fopenloc.mtrace tst-fopenloc.check
208 generated += tst-bz22415.mtrace tst-bz22415.check
210 aux := fileops genops stdfiles stdio strops
212 ifeq ($(build-shared),yes)
213 generated += tst-bz24228.mtrace tst-bz24228.check
214 aux += oldfileops oldstdfiles
215 endif
217 shared-only-routines = oldiofopen oldiofdopen oldiofclose oldfileops \
218 oldstdfiles oldiopopen oldpclose oldtmpfile \
219 oldiofgetpos oldiofgetpos64 oldiofsetpos \
220 oldiofsetpos64
222 ifeq ($(run-built-tests),yes)
223 tests-special += $(objpfx)test-freopen.out $(objpfx)test-fmemopen-mem.out \
224 $(objpfx)tst-bz22415-mem.out
225 ifeq (yes,$(build-shared))
226 # Run tst-fopenloc-cmp.out and tst-openloc-mem.out only if shared
227 # library is enabled since they depend on tst-fopenloc.out.
228 tests-special += $(objpfx)tst-fopenloc-cmp.out $(objpfx)tst-fopenloc-mem.out \
229 $(objpfx)tst-bz24228-mem.out
230 endif
232 tests += tst-cleanup-default tst-cleanup-default-static
233 tests-static += tst-cleanup-default-static
234 tests-special += $(objpfx)tst-cleanup-default-cmp.out $(objpfx)tst-cleanup-default-static-cmp.out
235 LDFLAGS-tst-cleanup-default = -Wl,--gc-sections
236 LDFLAGS-tst-cleanup-default-static = -Wl,--gc-sections
238 ifeq ($(have-gnu-retain)$(have-z-start-stop-gc),yesyes)
239 tests += tst-cleanup-start-stop-gc tst-cleanup-start-stop-gc-static \
240 tst-cleanup-nostart-stop-gc tst-cleanup-nostart-stop-gc-static
241 tests-static += tst-cleanup-start-stop-gc-static tst-cleanup-nostart-stop-gc-static
242 tests-special += $(objpfx)tst-cleanup-start-stop-gc-cmp.out \
243 $(objpfx)tst-cleanup-start-stop-gc-static-cmp.out \
244 $(objpfx)tst-cleanup-nostart-stop-gc-cmp.out \
245 $(objpfx)tst-cleanup-nostart-stop-gc-static-cmp.out
246 LDFLAGS-tst-cleanup-start-stop-gc := -Wl,--gc-sections,-z,start-stop-gc
247 LDFLAGS-tst-cleanup-start-stop-gc-static := -Wl,--gc-sections,-z,start-stop-gc
248 LDFLAGS-tst-cleanup-nostart-stop-gc := -Wl,--gc-sections,-z,nostart-stop-gc
249 LDFLAGS-tst-cleanup-nostart-stop-gc-static := -Wl,--gc-sections,-z,nostart-stop-gc
250 endif
251 endif
253 include ../Rules
255 ifeq ($(run-built-tests),yes)
256 LOCALES := de_DE.ISO-8859-1 de_DE.UTF-8 en_US.ISO-8859-1 en_US.UTF-8 \
257 ja_JP.EUC-JP ja_JP.UTF-8
258 include ../gen-locales.mk
260 $(objpfx)bug-ftell.out: $(gen-locales)
261 $(objpfx)bug-ungetwc1.out: $(gen-locales)
262 $(objpfx)bug-ungetwc2.out: $(gen-locales)
263 $(objpfx)tst-fgetwc.out: $(gen-locales)
264 $(objpfx)tst-fgetws.out: $(gen-locales)
265 $(objpfx)tst-fopenloc.out: $(gen-locales)
266 $(objpfx)tst-fputws.out: $(gen-locales)
267 $(objpfx)tst-fseek.out: $(gen-locales)
268 $(objpfx)tst-ftell-active-handler.out: $(gen-locales)
269 $(objpfx)tst-ftell-append.out: $(gen-locales)
270 $(objpfx)tst-ftell-partial-wide.out: $(gen-locales)
271 $(objpfx)tst-setvbuf1.out: $(gen-locales)
272 $(objpfx)tst-swscanf.out: $(gen-locales)
273 $(objpfx)tst-ungetwc1.out: $(gen-locales)
274 $(objpfx)tst-ungetwc2.out: $(gen-locales)
275 $(objpfx)tst-widetext.out: $(gen-locales)
276 $(objpfx)tst_wprintf2.out: $(gen-locales)
277 $(objpfx)tst-wfile-sync.out: $(gen-locales)
278 endif
280 define gen-tst-cleanup
281 $(objpfx)tst-cleanup-$1-cmp.out: tst-cleanup.exp $(objpfx)tst-cleanup-$1.out
282 cmp $$^ > $$@; $$(evaluate-test)
283 endef
285 $(foreach t,default default-static start-stop-gc start-stop-gc-static nostart-stop-gc nostart-stop-gc-static, \
286 $(eval $(call gen-tst-cleanup,$(t))))
288 $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen
289 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)' \
290 $(common-objpfx)libio/; \
291 $(evaluate-test)
293 $(objpfx)tst-fopenloc-cmp.out: ../iconvdata/testdata/ISO-8859-1..UTF8 \
294 $(objpfx)tst-fopenloc.out
295 cmp $^ > $@; \
296 $(evaluate-test)
298 $(objpfx)test-fmemopen-mem.out: $(objpfx)test-fmemopen.out
299 $(common-objpfx)malloc/mtrace $(objpfx)test-fmemopen.mtrace > $@; \
300 $(evaluate-test)
302 $(objpfx)tst-fopenloc-mem.out: $(objpfx)tst-fopenloc.out
303 $(common-objpfx)malloc/mtrace $(objpfx)tst-fopenloc.mtrace > $@; \
304 $(evaluate-test)
306 $(objpfx)tst-bz22415-mem.out: $(objpfx)tst-bz22415.out
307 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz22415.mtrace > $@; \
308 $(evaluate-test)
310 $(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
311 $(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
312 $(evaluate-test)