Add crt1-2.0.o for glibc 2.0 compatibility tests
[glibc.git] / Makeconfig
blob61ff1d0d9bdc2f5c74b80e28a3c70dfc54f75eba
1 # Copyright (C) 1991-2024 Free Software Foundation, Inc.
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
20 #       Makefile configuration options for the GNU C library.
22 ifneq (,)
23 This makefile requires GNU Make.
24 endif
26 all: # Make this the default goal
28 ifneq "$(origin +included-Makeconfig)" "file"
30 +included-Makeconfig := yes
32 ifdef subdir
33 .. := ../
34 endif
36 # $(common-objdir) is the place to put objects and
37 # such that are not specific to a single subdir.
38 ifdef objdir
39 objpfx := $(patsubst %//,%/,$(objdir)/$(subdir)/)
40 common-objpfx = $(objdir)/
41 common-objdir = $(objdir)
42 else
43 $(error objdir must be defined by the build-directory Makefile)
44 endif
46 # Did we request 'make -s' run? "yes" or "no".
47 # Starting from make-4.4 MAKEFLAGS now contains long
48 # options like '--shuffle'. To detect presence of 's'
49 # we pick first word with short options. Long options
50 # are guaranteed to come after whitespace. We use '-'
51 # prefix to always have a word before long options
52 # even if no short options were passed.
53 # Typical MAKEFLAGS values to watch for:
54 #   "rs --shuffle=42" (silent)
55 #   " --shuffle" (not silent)
56 ifeq ($(findstring s, $(firstword -$(MAKEFLAGS))),)
57 silent-make := no
58 else
59 silent-make := yes
60 endif
62 # Root of the sysdeps tree.
63 sysdep_dir := $(..)sysdeps
64 export sysdep_dir := $(sysdep_dir)
66 # Get the values defined by options to `configure'.
67 include $(common-objpfx)config.make
69 # What flags to give to sources which call user provided callbacks
70 uses-callbacks = -fexceptions
72 # What flags to give to tests which test stack alignment
73 stack-align-test-flags =
75 # Complete path to sysdep dirs.
76 # `configure' writes a definition of `config-sysdirs' in `config.make'.
77 sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))
79 +sysdep_dirs = $(sysdirs)
80 ifdef objdir
81 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
82 endif
84 # Run config.status to update config.make and config.h.  We don't show the
85 # dependence of config.h to Make, because it is only touched when it
86 # changes and so config.status would be run every time; the dependence of
87 # config.make should suffice to force regeneration and re-exec, and the new
88 # image will notice if config.h changed.
89 $(common-objpfx)config.make: $(common-objpfx)config.status \
90                              $(..)config.make.in $(..)config.h.in
91         cd $(<D); $(SHELL) $(<F)
93 # Find all the sysdeps configure fragments, to make sure we re-run
94 # configure when any of them changes.
95 $(common-objpfx)config.status: $(..)version.h $(..)configure \
96                                $(foreach dir,$(sysdirs),\
97                                          $(wildcard $(dir)/Implies) \
98                                          $(patsubst %.ac,%,\
99                                                     $(firstword $(wildcard \
100  $(addprefix $(dir)/,configure configure.ac))))) \
101                                $(patsubst %.ac,%,\
102  $(wildcard $(..)sysdeps/*/preconfigure $(..)sysdeps/*/preconfigure.ac))
103         @cd $(@D); if test -f $(@F); then exec $(SHELL) $(@F) --recheck; else \
104          echo The GNU C library has not been configured. >&2; \
105          echo Run \`configure\' to configure it before building. >&2; \
106          echo Try \`configure --help\' for more details. >&2; \
107          exit 1; fi
109 # We don't want CPPFLAGS to be exported to the command running configure.
110 unexport CPPFLAGS
112 # Get the user's configuration parameters.
113 ifneq ($(wildcard $(..)configparms),)
114 include $(..)configparms
115 endif
116 ifneq ($(objpfx),)
117 ifneq ($(wildcard $(common-objpfx)configparms),)
118 include $(common-objpfx)configparms
119 endif
120 endif
122 ####
123 ####    These are the configuration variables.  You can define values for
124 ####    the variables below in the file `configparms'.
125 ####    Do NOT edit this file.
126 ####
129 # Common prefix for machine-independent installation directories.
130 ifeq ($(origin prefix),undefined) # ifndef would override explicit empty value.
131 prefix = /usr/local
132 endif
134 # Decide whether we shall build the programs or not.  We always do this
135 # unless the user tells us (in configparms) or we are building for a
136 # standalone target.
137 ifndef build-programs
138 ifneq ($(config-os),none)
139 build-programs=yes
140 else
141 build-programs=no
142 endif
143 endif
145 # Common prefix for machine-dependent installation directories.
146 ifeq ($(origin exec_prefix),undefined)
147 exec_prefix = $(prefix)
148 endif
150 # Where to install the library and object files.
151 ifndef libdir
152 libdir = $(exec_prefix)/lib
153 endif
154 inst_libdir = $(install_root)$(libdir)
156 # Where to install the shared library.
157 ifndef slibdir
158 slibdir = $(exec_prefix)/lib
159 endif
160 inst_slibdir = $(install_root)$(slibdir)
162 # Where to install the dynamic linker.
163 ifndef rtlddir
164 rtlddir = $(slibdir)
165 endif
166 inst_rtlddir = $(install_root)$(rtlddir)
168 # Prefix to put on files installed in $(libdir).  For libraries `libNAME.a',
169 # the prefix is spliced between `lib' and the name, so the linker switch
170 # `-l$(libprefix)NAME' finds the library; for other files the prefix is
171 # just prepended to the whole file name.
172 ifeq ($(origin libprefix),undefined)
173 libprefix =
174 endif
176 # Where to install the header files.
177 ifndef includedir
178 includedir = $(prefix)/include
179 endif
180 inst_includedir = $(install_root)$(includedir)
182 # Where to install machine-independent data files.
183 # These are the timezone database, and the locale database.
184 ifndef datadir
185 datadir = $(prefix)/share
186 endif
187 inst_datadir = $(install_root)$(datadir)
189 # Where to install the timezone data files (which are machine-independent).
190 ifndef zonedir
191 zonedir = $(datadir)/zoneinfo
192 endif
193 inst_zonedir = $(install_root)$(zonedir)
195 # Where to install the compiled binary locale archive and compiled
196 # binary locale files.
197 ifndef complocaledir
198 complocaledir = $(libdir)/locale
199 endif
200 inst_complocaledir = $(install_root)$(complocaledir)
202 # Where to install the message catalog data files (which are
203 # machine-independent).
204 ifndef localedir
205 localedir = $(datadir)/locale
206 endif
207 inst_localedir = $(install_root)$(localedir)
209 # Where to install the locale charmap source files.
210 ifndef i18ndir
211 i18ndir = $(datadir)/i18n
212 endif
213 inst_i18ndir = $(install_root)$(i18ndir)
215 # Where to install the shared object for charset transformation.
216 ifndef gconvdir
217 gconvdir = $(libdir)/gconv
218 endif
219 inst_gconvdir = $(install_root)$(gconvdir)
221 # Where to install programs.
222 ifndef bindir
223 bindir = $(exec_prefix)/bin
224 endif
225 inst_bindir = $(install_root)$(bindir)
227 # Where to install internal programs.
228 ifndef libexecdir
229 libexecdir = $(exec_prefix)/libexec
230 endif
231 inst_libexecdir = $(install_root)$(libexecdir)
233 # Where to install administrative programs.
234 ifndef rootsbindir
235 rootsbindir = $(exec_prefix)/sbin
236 endif
237 inst_rootsbindir = $(install_root)$(rootsbindir)
239 ifndef sbindir
240 sbindir = $(exec_prefix)/sbin
241 endif
242 inst_sbindir = $(install_root)$(sbindir)
244 # Where to install the Info files.
245 ifndef infodir
246 infodir = $(prefix)/info
247 endif
248 inst_infodir = $(install_root)$(infodir)
250 # Where to install audit libraries.
251 ifndef auditdir
252 auditdir = $(libdir)/audit
253 endif
254 inst_auditdir = $(install_root)$(auditdir)
256 # Where to install default configuration files.  These include the local
257 # timezone specification and network data base files.
258 ifndef sysconfdir
259 sysconfdir = $(prefix)/etc
260 endif
261 inst_sysconfdir = $(install_root)$(sysconfdir)
263 # Directory for the database files and Makefile for nss_db.
264 ifndef vardbdir
265 vardbdir = $(localstatedir)/db
266 endif
267 inst_vardbdir = $(install_root)$(vardbdir)
269 # Where to install the "localtime" timezone file; this is the file whose
270 # contents $(localtime) specifies.  If this is a relative pathname, it is
271 # relative to $(zonedir).  It is a good idea to put this somewhere
272 # other than there, so the zoneinfo directory contains only universal data,
273 # localizing the configuration data elsewhere.
274 ifndef localtime-file
275 localtime-file = $(sysconfdir)/localtime
276 endif
278 # What to use for leap second specifications in compiling the default
279 # timezone files.  Set this to `/dev/null' for no leap second handling as
280 # 1003.1 requires, or to `leapseconds' for proper leap second handling.
281 # Both zone flavors are always available as `posix/ZONE' and `right/ZONE'.
282 # This variable determines the default: if it's `/dev/null',
283 # ZONE==posix/ZONE; if it's `leapseconds', ZONE==right/ZONE.
284 ifndef leapseconds
285 leapseconds = /dev/null
286 endif
288 # What timezone's DST rules should be used when a POSIX-style TZ
289 # environment variable doesn't specify any rules.  For 1003.1 compliance
290 # this timezone must use rules that are as U.S. federal law defines DST.
291 # Run `make -C time echo-zonenames' to see a list of available zone names.
292 # This setting can be changed with `zic -p TIMEZONE' at any time.
293 # If you want POSIX.1 compatibility, use `America/New_York'.
294 ifndef posixrules
295 posixrules = America/New_York
296 endif
298 # Where to install the "posixrules" timezone file; this is file
299 # whose contents $(posixrules) specifies.  If this is a relative
300 # pathname, it is relative to $(zonedir).
301 ifndef posixrules-file
302 posixrules-file = posixrules
303 endif
306 # Directory where your system's native header files live.
307 # This is used on Unix systems to generate some GNU libc header files.
308 ifndef sysincludedir
309 sysincludedir = /usr/include
310 endif
313 # Commands to install files.
314 ifndef INSTALL_DATA
315 INSTALL_DATA = $(INSTALL) -m 644
316 endif
317 ifndef INSTALL_SCRIPT
318 INSTALL_SCRIPT = $(INSTALL)
319 endif
320 ifndef INSTALL_PROGRAM
321 INSTALL_PROGRAM = $(INSTALL)
322 endif
323 ifndef INSTALL
324 INSTALL = install
325 endif
328 # The name of the C compiler.
329 # If you've got GCC, and it works, use it.
330 ifeq ($(origin CC),default)
331 CC := gcc
332 endif
334 # The name of the C compiler to use for compilations of programs to run on
335 # the host that is building the library.  If you set CC to a
336 # cross-compiler, you must set this to the normal compiler.
337 ifndef BUILD_CC
338 BUILD_CC = $(CC)
339 endif
341 # Default flags to pass the C compiler.
342 ifndef default_cflags
343 ifeq ($(release),stable)
344 default_cflags := -g -O2
345 else
346 default_cflags := -g -O
347 endif
348 endif
350 # Flags to pass the C compiler when assembling preprocessed assembly code
351 # (`.S' files).
352 ifndef asm-CPPFLAGS
353 asm-CPPFLAGS =
354 endif
356 # Must be supported by the linker.
357 no-whole-archive = -Wl,--no-whole-archive
358 whole-archive = -Wl,--whole-archive
360 # Installed name of the startup code.
361 # The ELF convention is that the startfile is called crt1.o
362 start-installed-name = crt1.o
363 # Similar to crt1.o, but without _IO_stdin_used.
364 start-name-2.0 = crt1-2.0.o
365 # On systems that do not need a special startfile for statically linked
366 # binaries, simply set it to the normal name.
367 ifndef static-start-installed-name
368 static-start-installed-name = $(start-installed-name)
369 endif
371 ifeq (yes,$(enable-static-pie))
372 # Link with rcrt1.o, instead of crt1.o, to call _dl_relocate_static_pie
373 # to relocate static PIE.
374 real-static-start-installed-name = r$(static-start-installed-name)
375 else
376 real-static-start-installed-name = $(static-start-installed-name)
377 endif
379 relro-LDFLAGS = -Wl,-z,relro
380 LDFLAGS.so += $(relro-LDFLAGS)
381 LDFLAGS-rtld += $(relro-LDFLAGS)
383 # Linker options to enable and disable DT_RELR.
384 ifeq ($(have-dt-relr),yes)
385 dt-relr-ldflag = -Wl,-z,pack-relative-relocs
386 no-dt-relr-ldflag = -Wl,-z,nopack-relative-relocs
387 else
388 dt-relr-ldflag =
389 no-dt-relr-ldflag =
390 endif
392 ifeq (no,$(build-pie-default))
393 pie-default = $(no-pie-ccflag)
394 else # build-pie-default
395 pic-default = -DPIC
396 # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
397 pie-default = $(pie-ccflag)
399 ifeq (yes,$(enable-static-pie))
400 static-pie-dt-relr-ldflag = $(dt-relr-ldflag)
401 ifeq (yes,$(have-static-pie))
402 static-pie-ldflag = -static-pie
403 else
404 # Static PIE can't have dynamic relocations in read-only segments since
405 # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
406 # for PIE to support exception.
407 static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
408 endif # have-static-pie
409 endif # enable-static-pie
410 endif # build-pie-default
412 # If lazy relocations are disabled, add the -z now flag.  Use
413 # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
414 # test modules.
415 ifeq ($(bind-now),yes)
416 LDFLAGS-lib.so += -Wl,-z,now
417 # Extra flags for dynamically linked non-test main programs.
418 link-extra-flags += -Wl,-z,now
419 endif
421 # Command to run after every final link (executable or shared object).
422 # This is invoked with $(call after-link,...), so it should operate on
423 # the file $1.  This can be set to do some sort of post-processing on
424 # binaries, or to perform some sort of static sanity check.
425 ifndef after-link
426 after-link =
427 endif
429 # Additional libraries to link into every test.
430 link-extra-libs-tests = $(libsupport)
432 # Command for linking PIE programs with the C library.
433 ifndef +link-pie
434 +link-pie-before-inputs = $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
435              $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
436              -Wl,-O1 -nostdlib -nostartfiles \
437              $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
438              $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
439              $(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \
440              $(+preinit) $(+prectorS)
441 +link-pie-before-libc = -o $@ $(+link-pie-before-inputs) \
442              $(filter-out $(addprefix $(csu-objpfx),start.o \
443                                                     S$(start-installed-name))\
444                           $(+preinit) $(link-extra-libs) \
445                           $(common-objpfx)libc% $(+postinit),$^) \
446              $(link-extra-libs)
447 +link-pie-after-libc = $(+postctorS) $(+postinit)
448 define +link-pie
449 $(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
450   $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
451 $(call after-link,$@)
452 endef
453 define +link-pie-tests
454 $(CC) $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
455   $(+link-pie-after-libc)
456 $(call after-link,$@)
457 endef
458 define +link-pie-printers-tests
459 $(CC) $(+link-pie-before-libc) $(built-rtld-LDFLAGS) \
460   $(link-libc-printers-tests) $(+link-pie-after-libc)
461 $(call after-link,$@)
462 endef
463 endif
464 # Command for statically linking programs with the C library.
465 ifndef +link-static
466 +link-static-before-inputs = -nostdlib -nostartfiles -static \
467               $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
468               $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(static-pie-dt-relr-ldflag)) \
469               $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
470               $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
471               $(+preinit) $(+prectorT)
472 +link-static-before-libc = -o $@ $(+link-static-before-inputs) \
473               $(filter-out $(addprefix $(csu-objpfx),start.o \
474                                                      $(start-installed-name))\
475                            $(+preinit) $(link-extra-libs-static) \
476                            $(common-objpfx)libc% $(+postinit),$^) \
477               $(link-extra-libs-static)
478 +link-static-after-libc = $(+postctorT) $(+postinit)
479 define +link-static
480 $(CC) $(+link-static-before-libc) $(link-extra-flags) $(link-libc-static) \
481   $(+link-static-after-libc)
482 $(call after-link,$@)
483 endef
484 define +link-static-tests
485 $(CC) $(+link-static-before-libc) $(link-libc-static-tests) \
486   $(+link-static-after-libc)
487 $(call after-link,$@)
488 endef
489 endif
490 # Commands for linking programs with the C library.
491 ifndef +link
492 ifeq (yes,$(build-shared))
493 ifeq (yes,$(cc-pie-default))
494 no-pie-ldflag = -no-pie
495 endif
496 ifeq (yes,$(build-pie-default))
497 +link = $(+link-pie)
498 +link-tests = $(+link-pie-tests)
499 +link-tests-before-inputs = $(+link-pie-before-inputs) $(rtld-tests-LDFLAGS)
500 +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
501 +link-printers-tests = $(+link-pie-printers-tests)
502 else  # not build-pie-default
503 +link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
504               $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
505               $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
506               $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
507               $(+preinit) $(+prector)
508 +link-before-libc = -o $@ $(+link-before-inputs) \
509               $(filter-out $(addprefix $(csu-objpfx),start.o \
510                                                      $(start-installed-name))\
511                            $(+preinit) $(link-extra-libs) \
512                            $(common-objpfx)libc% $(+postinit),$^) \
513               $(link-extra-libs)
514 +link-after-libc = $(+postctor) $(+postinit)
515 define +link
516 $(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
517   $(link-extra-flags) $(link-libc) $(+link-after-libc)
518 $(call after-link,$@)
519 endef
520 +link-tests-before-inputs = $(+link-before-inputs) $(rtld-tests-LDFLAGS)
521 +link-tests-after-inputs = $(link-libc-tests) $(+link-after-libc)
522 define +link-tests
523 $(CC) $(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
524                      $(+link-after-libc)
525 $(call after-link,$@)
526 endef
527 define +link-printers-tests
528 $(CC) $(+link-before-libc) $(built-rtld-LDFLAGS) $(link-libc-printers-tests) \
529                      $(+link-after-libc)
530 $(call after-link,$@)
531 endef
532 endif  # build-pie-default
533 else  # build-static
534 +link = $(+link-static)
535 +link-tests = $(+link-static-tests)
536 +link-tests-before-inputs = $(+link-static-before-inputs)
537 +link-tests-after-inputs = $(link-libc-static-tests) $(+link-static-after-libc)
538 +link-printers-tests = $(+link-static-tests)
539 endif  # build-shared
540 endif  # +link
542 # Command for linking test programs with crt1.o from glibc 2.0.
543 +link-2.0-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
544               $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
545               $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
546               $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-name-2.0)) \
547               $(+preinit) $(+prector)
548 +link-2.0-before-libc = -o $@ $(+link-2.0-before-inputs) \
549               $(filter-out $(addprefix $(csu-objpfx),start.o \
550                                                      $(start-name-2.0))\
551                            $(+preinit) $(link-extra-libs) \
552                            $(common-objpfx)libc% $(+postinit),$^) \
553               $(link-extra-libs)
554 +link-after-libc = $(+postctor) $(+postinit)
555 define +link-2.0-tests
556 $(CC) $(+link-2.0-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
557   $(+link-after-libc)
558 $(call after-link,$@)
559 endef
561 # The pretty printer test programs need to be compiled without optimizations
562 # so they won't confuse gdb.  We could use either the 'GCC optimize' pragma
563 # or the 'optimize' function attribute to achieve this; however, at least on
564 # ARM, gcc always produces different debugging symbols when invoked with
565 # a -O greater than 0 than when invoked with -O0, regardless of anything else
566 # we're using to suppress optimizations.  Therefore, we need to explicitly pass
567 # -O0 to it through CFLAGS. As a result, any fortification needs to be disabled
568 # as it needs -O greater than 0.
569 # Additionally, the build system will try to -include $(common-objpfx)/config.h
570 # when compiling the tests, which will throw an error if some special macros
571 # (such as __OPTIMIZE__ and IS_IN_build) aren't defined.  To avoid this, we
572 # tell gcc to define IS_IN_build.
573 CFLAGS-printers-tests := -O0 -ggdb3 -DIS_IN_build $(no-fortify-source)
575 ifeq (yes,$(build-shared))
576 # These indicate whether to link using the built ld.so or the installed one.
577 installed-rtld-LDFLAGS = -Wl,-dynamic-linker=$(rtlddir)/$(rtld-installed-name)
578 built-rtld-LDFLAGS = -Wl,-dynamic-linker=$(elf-objpfx)ld.so
580 ifndef rtld-LDFLAGS
581 rtld-LDFLAGS = $(installed-rtld-LDFLAGS)
582 endif
584 ifndef rtld-tests-LDFLAGS
585 ifeq (yes,$(build-hardcoded-path-in-tests))
586 rtld-tests-LDFLAGS = $(built-rtld-LDFLAGS)
587 else
588 rtld-tests-LDFLAGS = $(installed-rtld-LDFLAGS)
589 endif  # build-hardcoded-path-in-tests
590 endif  # rtld-tests-LDFLAGS
592 endif  # build-shared
594 ifndef link-libc
595 ifeq (yes,$(build-shared))
596 # We need the versioned name of libc.so in the deps of $(others) et al
597 # so that the symlink to libc.so is created before anything tries to
598 # run the linked programs.
599 link-libc-rpath = -Wl,-rpath=$(rpath-link)
600 link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
602 # For programs which are not tests, $(link-libc-rpath-link) is added
603 # directly in $(+link), $(+link-pie) above, so that -Wl,-rpath-link
604 # comes before the expansion of LDLIBS-* and affects libraries added
605 # there.  For shared objects, -Wl,-rpath-link is added via
606 # $(build-shlib-helper) and $(build-module-helper) in Makerules (also
607 # before the expansion of LDLIBS-* variables).
609 # Tests use -Wl,-rpath instead of -Wl,-rpath-link for
610 # build-hardcoded-path-in-tests.
611 ifeq (yes,$(build-hardcoded-path-in-tests))
612 link-libc-tests-rpath-link = $(link-libc-rpath)
613 link-test-modules-rpath-link = $(link-libc-rpath)
614 else
615 link-libc-tests-rpath-link = $(link-libc-rpath-link)
616 link-test-modules-rpath-link =
617 endif  # build-hardcoded-path-in-tests
619 link-libc-between-gnulib = $(common-objpfx)libc.so$(libc.so-version) \
620                            $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
621                            -Wl,--as-needed $(elf-objpfx)ld.so \
622                            -Wl,--no-as-needed
623 link-libc = $(link-libc-between-gnulib) $(gnulib)
625 link-libc-tests-after-rpath-link = $(gnulib-tests) $(link-libc-between-gnulib) $(gnulib-tests)
626 link-libc-tests = $(link-libc-tests-rpath-link) \
627                   $(link-libc-tests-after-rpath-link)
628 # Pretty printer test programs always require rpath instead of rpath-link.
629 link-libc-printers-tests = $(link-libc-rpath) \
630                            $(link-libc-tests-after-rpath-link)
632 # This is how to find at build-time things that will be installed there.
633 rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
634 rpath-link = \
635 $(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
636 else  # build-static
637 link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
638 link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
639 endif  # build-shared
640 endif  # link-libc
642 # Differences in the linkers on the various platforms.
643 LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
644 LDFLAGS-soname-fname = -Wl,-soname,$(@F)
645 LDFLAGS-rdynamic = -rdynamic
646 LDFLAGS-Bsymbolic = -Bsymbolic
648 # Choose the default search path for the dynamic linker based on
649 # where we will install libraries.
650 ifneq ($(libdir),$(slibdir))
651 default-rpath = $(slibdir):$(libdir)
652 else
653 default-rpath = $(libdir)
654 endif
656 ifndef link-extra-libs
657 link-extra-libs = $(LDLIBS-$(@F))
658 link-extra-libs-static = $(link-extra-libs)
659 endif
661 # The static libraries.
662 link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
663 link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
665 # How to link against libgcc.  Some libgcc functions, such as those
666 # for "long long" arithmetic or software floating point, can always be
667 # built without use of C library headers and do not have any global
668 # state so can safely be linked statically into any executable or
669 # shared library requiring them; these functions are in libgcc.a.
670 # Other functions, relating to exception handling, may require C
671 # library headers to build and it may not be safe to have more than
672 # one copy of them in a process; these functions are only in
673 # libgcc_s.so and libgcc_eh.a.
675 # To avoid circular dependencies when bootstrapping, it is desirable
676 # to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
677 # glibc functionality (in particular, thread cancellation) requires
678 # exception handling, this is implemented through dlopen of libgcc_s
679 # to avoid unnecessary dependencies on libgcc_s by programs not using
680 # that functionality; executables built with glibc do not use
681 # exception handling other than through thread cancellation.
683 # Undefined references to functions from libgcc_eh or libgcc_s may
684 # arise for code built with -fexceptions.  In the case of statically
685 # linked programs installed by glibc, unwinding will never actually
686 # occur at runtime and the use of elf/static-stubs.c to resolve these
687 # references is safe.  In the case of statically linked test programs
688 # and test programs built with -fexceptions, unwinding may occur in
689 # some cases and it is preferable to link with libgcc_eh or libgcc_s
690 # so that the testing is as similar as possible to how programs will
691 # be built with the installed glibc.
693 # Some architectures have architecture-specific systems for exception
694 # handling that may involve undefined references to
695 # architecture-specific functions.  On those architectures,
696 # gnulib-arch and static-gnulib-arch may be defined in sysdeps
697 # makefiles to use additional libraries for linking executables and
698 # shared libraries built by glibc.
699 ifndef gnulib
700 ifneq ($(have-cc-with-libunwind),yes)
701   libunwind =
702 else
703   libunwind = -lunwind
704 endif
705 libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
706 gnulib-arch =
707 gnulib = -lgcc $(gnulib-arch)
708 gnulib-tests := -lgcc $(libgcc_eh)
709 static-gnulib-arch =
710 # By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
711 # statically link programs.  When --disable-shared is used, we use
712 # -lgcc_eh since elf/static-stubs.o isn't sufficient.
713 ifeq (yes,$(build-shared))
714 static-gnulib = -lgcc $(static-gnulib-arch)
715 else
716 static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
717 endif
718 static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
719 libc.so-gnulib := -lgcc
720 endif
721 +preinit = $(addprefix $(csu-objpfx),crti.o)
722 +postinit = $(addprefix $(csu-objpfx),crtn.o)
723 +prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
724 +postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
725 # Variants of the two previous definitions for linking PIE programs.
726 +prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
727 +postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
728 # Variants of the two previous definitions for statically linking programs.
729 static-prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
730 static-postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
731 ifeq (yes,$(enable-static-pie))
732 # Static PIE must use PIE variants.
733 +prectorT = $(if $($(@F)-no-pie),$(static-prector),$(+prectorS))
734 +postctorT = $(if $($(@F)-no-pie),$(static-postctor),$(+postctorS))
735 else
736 +prectorT = $(static-prector)
737 +postctorT =$(static-postctor)
738 endif
739 csu-objpfx = $(common-objpfx)csu/
740 elf-objpfx = $(common-objpfx)elf/
742 # A command that, prepended to the name and arguments of a program,
743 # and run on the build system, causes that program with those
744 # arguments to be run on the host for which the library is built.
745 ifndef test-wrapper
746 test-wrapper =
747 endif
748 # Likewise, but the name of the program is preceded by
749 # <variable>=<value> assignments for environment variables.
750 ifndef test-wrapper-env
751 test-wrapper-env = $(test-wrapper) env
752 endif
753 # Likewise, but the program's environment will be empty except for any
754 # explicit <variable>=<value> assignments preceding the program name.
755 ifndef test-wrapper-env-only
756 test-wrapper-env-only = $(test-wrapper) env -i
757 endif
759 # Whether to run test programs built for the library's host system.
760 ifndef run-built-tests
761 ifeq (yes|,$(cross-compiling)|$(test-wrapper))
762 run-built-tests = no
763 else
764 run-built-tests = yes
765 endif
766 endif
768 # Whether to stop immediately when a test fails.  Nonempty means to
769 # stop, empty means not to stop.
770 ifndef stop-on-test-failure
771 stop-on-test-failure =
772 endif
774 # How to run a program we just linked with our library.
775 # The program binary is assumed to be $(word 2,$^).
776 built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
777 rtld-prefix = $(elf-objpfx)$(rtld-installed-name)                             \
778               --library-path                                                  \
779               $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
780 ifeq (yes,$(build-shared))
781 comma = ,
782 sysdep-library-path = \
783 $(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
784                                        $(filter -Wl$(comma)-rpath-link=%,\
785                                                 $(sysdep-LDFLAGS)))))
786 # $(run-via-rtld-prefix) is a command that, when prepended to the name
787 # of a program built with the newly built library, produces a command
788 # that, executed on the host for which the library is built, runs that
789 # program.  For tests listed in tests-static or xtests-static, it is
790 # empty.
791 run-via-rtld-prefix =                                                         \
792   $(if $(strip $(filter $(notdir $(built-program-file)),                      \
793                         $(tests-static) $(xtests-static))),, $(rtld-prefix))
794 else
795 run-via-rtld-prefix =
796 endif
797 # $(run-program-env) is the default environment variable settings to
798 # use when running a program built with the newly built library.
799 run-program-env = GCONV_PATH=$(common-objpfx)iconvdata \
800                   LOCPATH=$(common-objpfx)localedata LC_ALL=C
801 # $(run-program-prefix) is a command that, when prepended to the name
802 # of a program built with the newly built library, produces a command
803 # that, executed on the build system on which "make" is run, runs that
804 # program.  $(run-program-prefix-before-env) and
805 # $(run-program-prefix-after-env) are similar, but separate parts
806 # before and after a list of environment variables.
807 run-program-prefix-before-env = $(test-wrapper-env)
808 run-program-prefix-after-env = $(run-via-rtld-prefix)
809 run-program-prefix = $(run-program-prefix-before-env) $(run-program-env) \
810                      $(run-program-prefix-after-env)
811 # $(built-program-cmd) is a command that, executed on the build system
812 # on which "make" is run, runs the newly built program that is the
813 # second dependency of the makefile target in which
814 # $(built-program-cmd) is used.  $(built-program-cmd-before-env) and
815 # $(built-program-cmd-after-env) are similar, before and after a list
816 # of environment variables.
817 built-program-cmd-before-env = $(test-wrapper-env)
818 built-program-cmd-after-env = $(run-via-rtld-prefix) $(built-program-file)
819 built-program-cmd = $(built-program-cmd-before-env) $(run-program-env) \
820                     $(built-program-cmd-after-env)
821 # $(host-built-program-cmd) is a command that, executed on the host
822 # for which the library is built, runs the newly built program that is
823 # the second dependency of the makefile target in which
824 # $(host-built-program-cmd) is used.
825 host-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
826 # $(ld-library-path) is the common content to be set in LD_LIBRARY_PATH
827 # for running static binaries that may load dynamic objects.
828 ld-library-path = $(objpfx):$(common-objpfx)$(addprefix :,$(sysdep-ld-library-path))
830 ifndef LD
831 LD := ld -X
832 endif
834 # $(test-via-rtld-prefix) is a command that, when prepended to the name
835 # of a test program built with the newly built library, produces a command
836 # that, executed on the host for which the library is built, runs that
837 # program.  For tests listed in tests-static or xtests-static as well
838 # as when test programs are hardcoded to the newly built libraries, it
839 # is empty.
841 # $(test-program-prefix) is a command that, when prepended to the name
842 # of a test program built with the newly built library, produces a command
843 # that, executed on the build system on which "make" is run, runs that
844 # test program.  $(test-program-prefix-before-env) and
845 # $(test-program-prefix-after-env) are similar, before and after a
846 # list of environment variables.
848 # $(test-program-cmd) is a command that, executed on the build system
849 # on which "make" is run, runs the newly built test program that is the
850 # second dependency of the makefile target in which
851 # $(test-program-cmd) is used.  $(test-program-cmd-before-env) and
852 # $(test-program-cmd-after-env) are similar, before and after a list
853 # of environment variables.
855 # $(host-test-program-cmd) is a command that, executed on the host
856 # for which the library is built, runs the newly built test program that
857 # is the second dependency of the makefile target in which
858 # $(host-test-program-cmd) is used.
860 ifeq (yes,$(build-hardcoded-path-in-tests))
861 test-via-rtld-prefix =
862 test-program-prefix-before-env = $(test-wrapper-env)
863 test-program-prefix-after-env =
864 test-program-prefix = $(test-program-prefix-before-env) $(run-program-env) \
865                       $(test-program-prefix-after-env)
866 test-program-cmd-before-env = $(test-wrapper-env)
867 test-program-cmd-after-env = $(built-program-file)
868 test-program-cmd = $(test-program-cmd-before-env) $(run-program-env) \
869                    $(test-program-cmd-after-env)
870 host-test-program-cmd = $(built-program-file)
871 else
872 test-via-rtld-prefix = $(run-via-rtld-prefix)
873 test-program-prefix-before-env = $(run-program-prefix-before-env)
874 test-program-prefix-after-env = $(run-program-prefix-after-env)
875 test-program-prefix = $(run-program-prefix)
876 test-program-cmd-before-env = $(built-program-cmd-before-env)
877 test-program-cmd-after-env = $(built-program-cmd-after-env)
878 test-program-cmd = $(built-program-cmd)
879 host-test-program-cmd = $(host-built-program-cmd)
880 endif
882 # Extra flags to pass to GCC.
883 +gccwarn := -Wall -Wwrite-strings -Wundef
884 ifeq ($(enable-werror),yes)
885 +gccwarn += -Werror
886 endif
887 +gccwarn-c = -Wstrict-prototypes -Wold-style-definition
889 # We do not depend on the address of constants in different files to be
890 # actually different, so allow the compiler to merge them all.
891 +merge-constants = -fmerge-all-constants
893 # We have to assume that glibc functions are called in any rounding
894 # mode and also change the rounding mode in a few functions. So,
895 # disable any optimization that assume default rounding mode.
896 +math-flags = -frounding-math
898 # Logically only "libnldbl", "nonlib" and "testsuite" should be using
899 # -fno-math-errno. However due to GCC bug #88576, only "libm" can use
900 # -fno-math-errno.
901 +extra-math-flags = $(if $(filter libm,$(in-module)),-fno-math-errno,-fmath-errno)
903 # Use 64 bit time_t support for installed programs
904 installed-modules = nonlib nscd ldconfig locale_programs \
905                     iconvprogs libnss_files libnss_compat libnss_db libnss_hesiod \
906                     libutil libpcprofile libnsl
907 +extra-time-flags = $(if $(filter $(installed-modules),\
908                            $(in-module)),-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64)
910 # We might want to compile with some stack-protection flag.
911 ifneq ($(stack-protector),)
912 +stack-protector=$(stack-protector)
913 endif
915 # Some routines are unsafe to build with stack-protection since they're called
916 # before the stack check guard is set up.  Provide a way to disable stack
917 # protector.  The first argument is the extension (.o, .os, .oS) and the second
918 # is a list of routines that this path should be applied to.
919 define elide-stack-protector
920 $(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector))
921 endef
923 # We might want to compile with fortify-source
924 ifneq ($(fortify-source),)
925 +fortify-source=$(fortify-source)
926 endif
928 # Some routine can't be fortified like the ones used by fortify
929 define elide-fortify-source
930 $(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-fortify-source))
931 endef
933 # The program that makes Emacs-style TAGS files.
934 ETAGS   := etags
936 # The `xgettext' program for producing .pot files from sources.
937 ifndef XGETTEXT
938 XGETTEXT = xgettext
939 endif
941 # The `m4' macro processor; this is used by sysdeps/sparc/Makefile (and
942 # perhaps others) to preprocess assembly code in some cases.
943 M4 = m4
945 # To force installation of files even if they are older than the
946 # installed files.  This variable is included in the dependency list
947 # of all installation targets.
948 ifeq ($(force-install),yes)
949 +force = force-install
950 else
951 +force =
952 endif
954 ####
955 #### End of configuration variables.
956 ####
958 # This tells some versions of GNU make before 3.63 not to export all variables.
959 .NOEXPORT:
961 # We want to echo the commands we're running without
962 # umpteen zillion filenames along with it (we use `...' instead)
963 # but we don't want this echoing done when the user has said
964 # he doesn't want to see commands echoed by using -s.
965 ifeq ($(silent-make),yes)                       # if -s
966 +cmdecho        := echo >/dev/null
967 else                                            # not -s
968 +cmdecho        := echo
969 endif                                           # -s
971 # These are the flags given to the compiler to tell
972 # it what sort of optimization and/or debugging output to do.
973 ifndef  +cflags
974 # If `CFLAGS' was defined, use that.
975 ifdef           CFLAGS
976 +cflags := $(filter-out -I%,$(CFLAGS))
977 endif           # CFLAGS
978 endif   # +cflags
980 # If none of the above worked, default to "-g -O".
981 ifeq    "$(strip $(+cflags))" ""
982 +cflags := $(default_cflags)
983 endif   # $(+cflags) == ""
985 # Force building with -fno-common because hidden_def, compat_symbol
986 # and other constructs do not work for common symbols (and would
987 # otherwise require specifying __attribute__ ((nocommon)) on a
988 # case-by-case basis).
989 +cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags) \
990            $(+stack-protector) -fno-common
991 +gcc-nowarn := -w
993 # We must filter out elf because the early bootstrap of the dynamic loader
994 # cannot be fortified. Likewise we exclude dlfcn because it is entangled
995 # with the loader. We must filter out csu because early startup, like the
996 # loader, cannot be fortified. Lastly debug is the fortification routines
997 # themselves and they cannot be fortified.
998 do-fortify = $(filter-out elf dlfcn csu debug,$(subdir))
999 ifeq ($(do-fortify),$(subdir))
1000 +cflags += $(+fortify-source)
1001 else
1002 +cflags += $(no-fortify-source)
1003 endif
1005 # Each sysdeps directory can contain header files that both will be
1006 # used to compile and will be installed.  Each can also contain an
1007 # include/ subdirectory, whose header files will be used to compile
1008 # but will not be installed, and will take precedence over the
1009 # installed files.  This mirrors the top-level include/ subdirectory.
1010 +sysdep-includes := $(foreach dir,$(+sysdep_dirs),\
1011                               $(addprefix -I,$(wildcard $(dir)/include) $(dir)))
1013 # These are flags given to the C compiler to tell it to look for
1014 # include files (including ones given in angle brackets) in the parent
1015 # library source directory, in the include directory, and in the
1016 # current directory.
1017 +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
1018             $(+sysdep-includes) $(includes) \
1019             $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
1021 # Since libio has several internal header files, we use a -I instead
1022 # of many little headers in the include directory.
1023 libio-include = -I$(..)libio
1025 # List of non-library modules that we build.
1026 built-modules = iconvprogs iconvdata ldconfig libmemusage \
1027                 libpcprofile librpcsvc locale-programs \
1028                 memusagestat nonlib nscd extramodules libnldbl libsupport \
1029                 testsuite testsuite-internal
1031 in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
1032                                     $(libof-$(<F)) \
1033                                     $(libof-$(@F)) \
1034                                     libc))
1036 # Build ld.so, libc.so and libpthread.so with -ftls-model=initial-exec
1037 tls-model = $(if $(filter libpthread rtld \
1038                           libc,$(in-module)),-ftls-model=initial-exec,)
1040 module-cppflags-real = -include $(common-objpfx)libc-modules.h \
1041                        -DMODULE_NAME=$(in-module)
1043 # We don't need libc-modules.h and the MODULE_NAME definition for .v.i
1044 # files.  These targets don't (and will likely never need to) use the IS_IN
1045 # facility.  In fact, shlib-versions should not use it because that will
1046 # create a circular dependency as libc-modules.h is generated from
1047 # shlib-versions.
1048 module-cppflags = $(if $(filter %.mk.i %.v.i,$(@F)),,$(module-cppflags-real))
1050 # These are the variables that the implicit compilation rules use.
1051 # Note that we can't use -std=* in CPPFLAGS, because it overrides
1052 # the implicit -lang-asm and breaks cpp behavior for .S files--notably
1053 # it causes cpp to stop predefining __ASSEMBLER__.
1054 CPPFLAGS = $(config-extra-cppflags) $(CPPFLAGS-config) \
1055            $($(subdir)-CPPFLAGS) \
1056            $(+includes) $(defines) $(module-cppflags) \
1057            -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
1058            $(CPPFLAGS-$(suffix $@)) \
1059            $(foreach lib,$(libof-$(basename $(@F))) \
1060                          $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
1061            $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F))) \
1062            -DTOP_NAMESPACE=glibc
1064 override CFLAGS = -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
1065                   $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
1066                   $(+extra-math-flags) $(+extra-time-flags) \
1067                   $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
1068                   $(CFLAGS-$(@F)) $(tls-model) \
1069                   $(foreach lib,$(libof-$(basename $(@F))) \
1070                                 $(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
1071 # Use our copies of cstdlib and cmath.
1072 override CXXFLAGS = -I$(common-objpfx) $(c++-sysincludes) \
1073                     $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
1074                     $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
1076 # If everything is compiled with -fPIC (implicitly) we must tell this by
1077 # defining the PIC symbol.
1078 ifeq (yes,$(build-pic-default))
1079 pic-default = -DPIC
1080 endif
1082 # Enable object files for different versions of the library.
1083 # Various things use $(object-suffixes) to know what all to make.
1084 # The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX})
1085 # to pass different flags for each flavor.
1086 libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
1087 # .op may be added to all-object-suffixes below.
1088 all-object-suffixes := .o .os .oS
1089 object-suffixes :=
1090 CPPFLAGS-.o = $(pic-default)
1091 # libc.a must be compiled with -fPIE/-fpie for static PIE.
1092 CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) $(pie-default)
1093 CFLAGS-.o += $(call elide-fortify-source,.o,$(routines_no_fortify))
1094 CFLAGS-.o += $(call elide-fortify-source,_chk.o,$(routines_no_fortify))
1095 libtype.o := lib%.a
1096 object-suffixes += .o
1097 ifeq (yes,$(build-shared))
1098 # Under --enable-shared, we will build a shared library of PIC objects.
1099 # The PIC object files are named foo.os.
1100 object-suffixes += .os
1101 pic-cppflags = -DPIC -DSHARED
1102 CPPFLAGS-.os = $(pic-cppflags)
1103 CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
1104 CFLAGS-.os += $(call elide-fortify-source,.os,$(routines_no_fortify))
1105 CFLAGS-.os += $(call elide-fortify-source,_chk.os,$(routines_no_fortify))
1106 libtype.os := lib%_pic.a
1107 # This can be changed by a sysdep makefile
1108 pic-ccflag = -fPIC
1109 # This one should always stay like this unless there is a very good reason.
1110 PIC-ccflag = -fPIC
1111 endif
1112 # This can be changed by a sysdep makefile
1113 pie-ccflag = -fPIE
1114 no-pie-ccflag = -fno-pie
1115 # This one should always stay like this unless there is a very good reason.
1116 PIE-ccflag = -fPIE
1117 ifeq (yes,$(build-profile))
1118 # Under --enable-profile, we will build a static library of profiled objects.
1119 # The profiled object files are named foo.op.
1120 all-object-suffixes += .op
1121 object-suffixes += .op
1122 CPPFLAGS-.op = -DPROF $(pic-default)
1123 # libc_p.a must be compiled with -fPIE/-fpie for static PIE.
1124 CFLAGS-.op = -pg $(pie-default)
1125 CFLAGS-.op += $(call elide-fortify-source,.op,$(routines_no_fortify))
1126 CFLAGS-.op += $(call elide-fortify-source,_chk.op,$(routines_no_fortify))
1127 libtype.op = lib%_p.a
1128 endif
1130 # Convenience variable for when we want to treat shared-library cases
1131 # differently from the rest.
1132 object-suffixes-noshared := $(filter-out .os,$(object-suffixes))
1134 object-suffixes-for-libc := $(object-suffixes)
1136 ifeq (yes,$(build-shared))
1137 # Build special library that contains the static-only routines for libc.
1138 object-suffixes-for-libc += .oS
1140 # Must build the routines as PIC, though, because they can end up in (users')
1141 # shared objects.  We don't want to use CFLAGS-os because users may, for
1142 # example, make that processor-specific.
1143 CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag) $(extra-nonshared-cflags)
1144 CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
1145 libtype.oS = lib%_nonshared.a
1146 endif
1148 # The assembler can generate debug information too.
1149 ifndef ASFLAGS
1150 ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
1151 endif
1152 override ASFLAGS += -Werror=undef $(ASFLAGS-config) $(asflags-cpu)
1154 ifndef BUILD_CC
1155 BUILD_CC = $(CC)
1156 endif
1158 move-if-change = $(SHELL) $(..)scripts/move-if-change
1160 -include $(common-objpfx)sysd-sorted
1161 subdirs = $(sorted-subdirs)
1162 subdir-srcdirs = $(foreach dir,$(subdirs),\
1163                            $(firstword $($(dir)-srcdir) $(..)$(dir)))
1165 # This is a pair of implicit rules to preprocess a file with # comments,
1166 # %ifdef et al, based on config.h settings or other %include'd files.
1167 # We use chained rules instead of a pipeline here so that we can properly
1168 # check the exit status of cpp rather than using its bad output when there
1169 # is a preprocessing error.  Another rule should depend on the output file
1170 # `FOO.v', and along with that `FOO.v.i' should be given dependencies
1171 # listing both its input files, and any header files that it may reference
1172 # (but no commands).
1173 %.v.i: $(common-objpfx)config.h $(..)Makeconfig
1174         sed '/^[        ]*%/!s/#.*$$//;/^[      ]*$$/d;s/^[     ]*%/#/' \
1175             $(filter-out FORCE %.h $(..)Makeconfig,$^) \
1176         | $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - \
1177                    > $@T
1178         mv -f $@T $@
1179 %.v: %.v.i
1180         sed '/^[        ]*#/d;/^[       ]*$$/d' $< > $@T
1181         mv -f $@T $@
1183 ifeq (yes, $(build-shared))
1185 # To generate a header to support more than one ABI for different
1186 # architecture variants, the CPU/Makefile defines abi-variants to be a
1187 # list of names for those variants (e.g. 32 64), and, for each variant,
1188 # defines abi-$(variant)-condition to be the condition for those options
1189 # to use in a C #if condition.  abi-includes may be defined to a list of
1190 # headers to include in the generated header, if the default does not
1191 # suffice.  default-abi is defined to be the ABI for the current glibc
1192 # build.
1194 ifndef abi-includes
1195 abi-includes := bits/wordsize.h
1196 endif
1198 # Process the shlib-versions file, which tells us what shared library
1199 # version numbers to use when we install shared objects on this system.
1200 # We need to wait until $(subdirs) is complete.
1201 ifeq ($(sysd-sorted-done),t)
1202 -include $(common-objpfx)soversions.mk
1203 ifndef avoid-generated
1204 $(common-objpfx)shlib-versions.v.i: \
1205         $(wildcard $(+sysdep_dirs:=/shlib-versions) \
1206                    $(subdir-srcdirs:=/shlib-versions)) \
1207         $(..)shlib-versions
1209 $(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
1210                               $(common-objpfx)shlib-versions.v
1211         $(AWK) -f $^ > $@T
1212         mv -f $@T $@
1213 $(common-objpfx)soversions.mk: $(common-objpfx)soversions.i $(..)Makeconfig
1214         (while read which lib number setname; do \
1215            eval seen_$$which=1; \
1216            test x"$$which" = xDEFAULT || continue; \
1217            case $$number in \
1218              [0-9]*) echo "$$lib.so-version=.$$number"; \
1219                      echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
1220              *)      echo "$$lib.so-version=$$number"; \
1221                      echo "all-sonames+=$$lib=\$$($$lib.so-version)";;\
1222            esac; \
1223          done; \
1224          echo soversions.mk-done = t;) < $< > $@T; exit 0
1225         mv -f $@T $@
1226 endif
1227 endif
1229 postclean-generated += soversions.mk soversions.i \
1230                        shlib-versions.v shlib-versions.v.i
1232 before-compile += $(common-objpfx)libc-modules.h
1233 common-generated += libc-modules.h libc-modules.stmp
1234 ifeq ($(soversions.mk-done),t)
1235 # Generate a header with macro definitions for use with the IS_IN macro.
1236 # These are the possible values for the MODULE_NAME macro defined when building
1237 # sources, to identify which module the translation unit is going to be built
1238 # into.
1239 $(common-objpfx)libc-modules.h: $(common-objpfx)libc-modules.stmp; @:
1240 $(common-objpfx)libc-modules.stmp: $(..)scripts/gen-libc-modules.awk \
1241                                    $(common-objpfx)soversions.i
1242         $(AWK) -v buildlist="$(subst -,_,$(built-modules))" -f $^ > ${@:stmp=T}
1243         $(move-if-change) ${@:stmp=T} ${@:stmp=h}
1244         touch $@
1246 endif
1248 # Build the tunables list header early since it could be used by any module in
1249 # glibc.
1250 before-compile += $(common-objpfx)dl-tunable-list.h
1251 common-generated += dl-tunable-list.h dl-tunable-list.stmp
1253 $(common-objpfx)dl-tunable-list.h: $(common-objpfx)dl-tunable-list.stmp; @:
1254 $(common-objpfx)dl-tunable-list.stmp: \
1255                 $(..)scripts/gen-tunables.awk \
1256                 $(..)elf/dl-tunables.list \
1257                 $(wildcard $(subdirs:%=$(..)%/dl-tunables.list)) \
1258                 $(wildcard $(sysdirs:%=%/dl-tunables.list))
1259         $(AWK) -f $^ > ${@:stmp=T}
1260         $(move-if-change) ${@:stmp=T} ${@:stmp=h}
1261         touch $@
1263 # Dump the GCC macros used by the default compiler flags to a header
1264 # file, so that they can be inspected when using different compiler
1265 # flags.  Add the GCCMACRO prefix to make these macro names unique.
1266 $(common-objpfx)gcc-macros.h.in: $(common-objpfx)config.status
1267         $(CC) $(CFLAGS) $(CPPFLAGS) -E -dM -x c -o $@ /dev/null
1268 $(common-objpfx)gcc-macros.h: $(common-objpfx)gcc-macros.h.in
1269         sed 's/^#define /#define GCCMACRO/' < $< > $@
1270 before-compile += $(common-objpfx)gcc-macros.h
1272 # Generate version maps, but wait until sysdep-subdirs is known
1273 ifeq ($(sysd-sorted-done),t)
1274 ifeq ($(build-shared),yes)
1275 -include $(common-objpfx)sysd-versions
1276 -include $(common-objpfx)Versions.mk
1277 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
1278 common-generated += $(version-maps)
1279 postclean-generated += sysd-versions Versions.all abi-versions.h \
1280                        Versions.def Versions.v.i Versions.v Versions.mk
1282 ifndef avoid-generated
1283 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
1284 sysd-versions-force = FORCE
1285 FORCE:
1286 endif
1288 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
1289                               $(common-objpfx)Versions.v
1290         LC_ALL=C $(AWK) -f $^ > $@T
1291         mv -f $@T $@
1293 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
1294                               $(common-objpfx)soversions.i \
1295                               $(common-objpfx)Versions.def
1296         { while read which lib version setname; do \
1297             test x"$$which" = xDEFAULT || continue; \
1298             test -z "$$setname" || echo "$$lib : $$setname"; \
1299           done < $(word 2,$^); \
1300           cat $(word 3,$^); \
1301         } | LC_ALL=C $(AWK) -f $< > $@T
1302         mv -f $@T $@
1303 $(common-objpfx)Versions.mk: $(..)scripts/haveversions.awk \
1304                              $(common-objpfx)Versions.all
1305         $(AWK) -f $^ > $@T
1306         mv -f $@T $@
1307 # See %.v/%.v.i implicit rules in Makeconfig.
1308 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
1309                               $(wildcard $(sysdirs:%=%/Versions)) \
1310                               $(sysd-versions-force)
1311 $(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
1312 $(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
1313                                $(common-objpfx)Versions.v \
1314                                $(..)scripts/versions.awk
1315         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
1316           cat $(word 2,$^) \
1317           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
1318                             -v move_if_change='$(move-if-change)' \
1319                             -f $(word 3,$^); \
1320         ) > $(common-objpfx)sysd-versionsT
1321         mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
1322         touch $@
1323 endif # avoid-generated
1324 endif # $(build-shared) = yes
1326 -include $(common-objpfx)time64-compat.mk
1327 postclean-generated += time64-compat.mk
1329 $(common-objpfx)time64-compat.mk: $(common-objpfx)time64-compat.mk.i \
1330                                   $(sysd-versions-force)
1331         sed '/^[        ]*#/d;/^[       ]*$$/d' $< > $@T
1332         mv -f $@T $@
1333 $(common-objpfx)time64-compat.mk.i: $(..)Makeconfig
1334         printf "#include <time64-compat.h>\n#ifdef TIME64_NON_DEFAULT\nhave-time64-compat = yes\n#endif" \
1335         | $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - > $@T
1336         mv -f $@T $@
1339 endif # sysd-sorted-done
1341 # The name under which the run-time dynamic linker is installed.
1342 # We are currently going for the convention that `/lib/ld.so.1'
1343 # names the SVR4/ELF ABI-compliant dynamic linker.
1344 ifndef rtld-installed-name
1345 ifdef ld.so-version
1346 rtld-installed-name = $(ld.so-version)
1347 else
1348 rtld-installed-name = ld.so.1
1349 endif
1350 endif
1352 ifndef rtld-version-installed-name
1353 rtld-version-installed-name = ld-$(version).so
1354 endif
1356 endif # build-shared
1359 ifeq ($(build-shared),yes)
1360 libm = $(common-objpfx)math/libm.so$(libm.so-version)
1361 libmvec = $(common-objpfx)mathvec/libmvec.so$(libmvec.so-version)
1362 else
1363 libm = $(common-objpfx)math/libm.a
1364 libmvec = $(common-objpfx)mathvec/libmvec.a
1365 endif
1367 ifeq ($(build-shared),yes)
1368 libsupport = $(common-objpfx)support/libsupport_nonshared.a
1369 else
1370 libsupport = $(common-objpfx)support/libsupport.a
1371 endif
1373 # This is a partial list of subdirectories containing the library source.
1374 # The order is more or less arbitrary.  The sorting step will take care of the
1375 # dependencies and generate sorted-subdirs dynamically.
1376 all-subdirs = csu assert ctype locale intl catgets math setjmp signal       \
1377               stdlib stdio-common libio malloc string wcsmbs time dirent    \
1378               posix io termios resource misc socket sysvipc gmon            \
1379               gnulib iconv iconvdata wctype manual po argp                  \
1380               localedata timezone rt conform debug mathvec support          \
1381               dlfcn elf
1383 ifndef avoid-generated
1384 # sysd-sorted itself will contain rules making the sysd-sorted target
1385 # depend on Depend files.  But if you just added a Depend file to an
1386 # existing directory not in all-subdirs, then sysd-sorted needs to
1387 # be regenerated, so it depends on existing $(sorted-subdirs:=/Depend) files.
1388 all-Depend-files := $(wildcard $(sort \
1389                         $(foreach dir,$(all-subdirs),\
1390                                   $(firstword $($(dir)-srcdir) \
1391                                   $(..)$(dir))/Depend) \
1392                         $(sorted-subdirs:=/Depend)))
1393 $(common-objpfx)sysd-sorted: $(..)scripts/gen-sorted.awk \
1394                              $(common-objpfx)config.make $(..)Makeconfig \
1395                              $(wildcard $(sysdirs:=/Subdirs)) \
1396                              $(all-Depend-files)
1397         $(AWK) -f $< \
1398                -v subdirs='$(all-subdirs)' \
1399                -v srcpfx='$(..)' \
1400                $(filter %/Subdirs %/Depend,$^) > $@-tmp
1401         mv -f $@-tmp $@
1402 $(all-Depend-files): ;
1403 endif
1405 # This gives partial TARGET:SOURCE pattern pairs to have rules
1406 # emitted into sysd-rules.  A sysdeps Makeconfig fragment can
1407 # add its own special object file prefix to this list with e.g. foo-%:%
1408 # to have foo-*.? compiled from *.? using $(foo-CPPFLAGS).
1409 sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%
1411 # Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
1412 sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
1413 ifneq (,$(sysdep-makeconfigs))
1414 include $(sysdep-makeconfigs)
1415 endif
1417 # Compute just the target patterns.  Makeconfig has set sysd-rules-patterns.
1418 sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
1419                                          $(firstword $(subst :, ,$p))))
1421 # $(libpthread-routines-var) and $(librt-routines-var) are the make
1422 # variable to which pthread routines need to be added to land in the
1423 # right library.
1424 ifeq ($(pthread-in-libc),yes)
1425 libpthread-routines-var = routines
1426 librt-routines-var = routines
1427 libanl-routines-var = routines
1428 else
1429 libpthread-routines-var = libpthread-routines
1430 librt-routines-var = librt-routines
1431 libanl-routines-var = libanl-routines
1432 endif
1434 # A sysdeps Makeconfig fragment may set libc-reentrant to yes.
1435 ifeq (yes,$(libc-reentrant))
1436 defines += -D_LIBC_REENTRANT
1438 libio-mtsafe = -D_IO_MTSAFE_IO
1439 endif
1441 # The name to give to a test in test results summaries.
1442 test-name = $(strip $(patsubst %.out, %, $(patsubst $(common-objpfx)%, %, $@)))
1444 # Likewise, in XFAIL variable names.
1445 test-xfail-name = $(strip $(patsubst %.out, %, $(patsubst $(objpfx)%, %, $@)))
1447 # Command to output a test status line (such as PASS: test-name).  If
1448 # test-xfail-$(test-xfail-name) has a nonempty value, the status will be
1449 # XPASS or XFAIL rather than PASS or FAIL.
1450 evaluate-test = $(..)scripts/evaluate-test.sh $(test-name) $$? \
1451                   $(if $(test-xfail-$(test-xfail-name)),true,false) \
1452                   $(if $(stop-on-test-failure),true,false) \
1453                   > $(common-objpfx)$(test-name).test-result
1455 endif # Makeconfig not yet included
1457 # Local Variables:
1458 # mode: makefile
1459 # End: