* manual/socket.texi: Document MTASC-safety properties.
[jlayton/glibc.git] / Makeconfig
index 9f134cc137771db7bc6ea8d0c5784387b6333eb5..1908f275a9b7d8b6dd16de9e1c4e63d817ed8fe3 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright (C) 1991-2003,2004,2005,2006,2007,2008,2009
-#      Free Software Foundation, Inc.
+# Copyright (C) 1991-2014 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -13,9 +12,8 @@
 # Lesser General Public License for more details.
 
 # You should have received a copy of the GNU Lesser General Public
-# License along with the GNU C Library; if not, write to the Free
-# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA.
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
 
 #
 #      Makefile configuration options for the GNU C library.
@@ -34,31 +32,6 @@ ifdef subdir
 .. := ../
 endif
 
-# If config.make exists, the source directory was configured,
-# so don't try to be clever and find another directory to build in.
-ifneq (,$(wildcard $(..)config.make))
-ARCH =
-machine =
-else   # Not configured.
-ifndef ARCH
-ifdef machine
-ARCH = $(machine)
-endif # machine
-endif # ARCH
-endif # config.make
-
-# Directory for object files and libc.a.  If this is not defined, the
-# object files live in the subdirectories where their sources live, and
-# libc.a lives in the parent directory (this probably doesn't work any
-# more).
-ifdef ARCH
-ifeq ($(filter /%,$(ARCH)),)
-objdir := $(..)$(ARCH)
-else
-objdir = $(ARCH)
-endif
-endif
-
 # $(common-objdir) is the place to put objects and
 # such that are not specific to a single subdir.
 ifdef objdir
@@ -66,15 +39,7 @@ objpfx := $(patsubst %//,%/,$(objdir)/$(subdir)/)
 common-objpfx = $(objdir)/
 common-objdir = $(objdir)
 else
-objpfx :=
-ifdef ..
-common-objpfx = $(..)
-common-objdir = ..
-else
-# This is a kludge.  make wizards might grok.
-common-objpfx = sysdeps/../
-common-objdir = .
-endif
+objdir must be defined by the build-directory Makefile.
 endif
 
 # Root of the sysdeps tree.
@@ -90,15 +55,6 @@ uses-callbacks = $(exceptions)
 # What flags to give to tests which test stack alignment
 stack-align-test-flags =
 
-# We have a special subdir for each binary format.
-# For now, only ELF is fully supported.
-ifeq ($(elf),yes)
-binfmt-subdir = elf
-else
-# This is probably better than nothing.
-binfmt-subdir = aout
-endif
-
 # Complete path to sysdep dirs.
 # `configure' writes a definition of `config-sysdirs' in `config.make'.
 sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))
@@ -132,12 +88,16 @@ $(common-objpfx)config.status: $(..)version.h $(..)configure \
                                         $(wildcard $(dir)/Implies) \
                                         $(patsubst %.in,%,\
                                                    $(firstword $(wildcard \
- $(addprefix $(dir)/,configure configure.in))))) \
+ $(addprefix $(dir)/,configure configure.ac))))) \
+                              $(patsubst %.in,%,\
+ $(wildcard $(..)sysdeps/*/preconfigure $(..)sysdeps/*/preconfigure.ac)) \
                               $(patsubst %.in,%,\
                                          $(foreach add-on,$(add-ons),\
                                                    $(firstword $(wildcard \
  $(addprefix $(firstword $(filter /%,$(add-on)) $(..)$(add-on))/,\
-            configure configure.in)))))
+            configure configure.ac))) \
+ $(wildcard $(addprefix $(firstword $(filter /%,$(add-on)) $(..)$(add-on))/,\
+                       sysdeps/*/preconfigure sysdeps/*/preconfigure.ac))))
        @cd $(@D); if test -f $(@F); then exec $(SHELL) $(@F) --recheck; else \
         echo The GNU C library has not been configured. >&2; \
         echo Run \`configure\' to configure it before building. >&2; \
@@ -191,12 +151,18 @@ libdir = $(exec_prefix)/lib
 endif
 inst_libdir = $(install_root)$(libdir)
 
-# Where to install the shared library and dynamic linker.
+# Where to install the shared library.
 ifndef slibdir
 slibdir = $(exec_prefix)/lib
 endif
 inst_slibdir = $(install_root)$(slibdir)
 
+# Where to install the dynamic linker.
+ifndef rtlddir
+rtlddir = $(slibdir)
+endif
+inst_rtlddir = $(install_root)$(rtlddir)
+
 # Prefix to put on files installed in $(libdir).  For libraries `libNAME.a',
 # the prefix is spliced between `lib' and the name, so the linker switch
 # `-l$(libprefix)NAME' finds the library; for other files the prefix is
@@ -278,6 +244,12 @@ infodir = $(prefix)/info
 endif
 inst_infodir = $(install_root)$(infodir)
 
+# Where to install audit libraries.
+ifndef auditdir
+auditdir = $(libdir)/audit
+endif
+inst_auditdir = $(install_root)$(auditdir)
+
 # Where to install default configuration files.  These include the local
 # timezone specification and network data base files.
 ifndef sysconfdir
@@ -285,12 +257,11 @@ sysconfdir = $(prefix)/etc
 endif
 inst_sysconfdir = $(install_root)$(sysconfdir)
 
-# What timezone should be the installed default (e.g., US/Eastern).
-# Run `make -C time echo-zonenames' to see a list of available zone names.
-# The local timezone can be changed with `zic -l TIMEZONE' at any time.
-ifndef localtime
-localtime = Factory
+# Directory for the database files and Makefile for nss_db.
+ifndef vardbdir
+vardbdir = $(localstatedir)/db
 endif
+inst_vardbdir = $(install_root)$(vardbdir)
 
 # Where to install the "localtime" timezone file; this is the file whose
 # contents $(localtime) specifies.  If this is a relative pathname, it is
@@ -299,7 +270,6 @@ endif
 # localizing the configuration data elsewhere.
 ifndef localtime-file
 localtime-file = $(sysconfdir)/localtime
-inst_localtime-file = $(install_root)$(localtime-file)
 endif
 
 # What to use for leap second specifications in compiling the default
@@ -382,27 +352,23 @@ ifndef asm-CPPFLAGS
 asm-CPPFLAGS =
 endif
 
-# ELF always supports init/fini sections
-ifeq ($(elf),yes)
-have-initfini = yes
-endif
+as-needed := -Wl,--as-needed
+no-as-needed := -Wl,--no-as-needed
+
+# Must be supported by the linker.
+no-whole-archive = -Wl,--no-whole-archive
+whole-archive = -Wl,--whole-archive
 
 # Installed name of the startup code.
-ifneq ($(have-initfini),yes)
-# When not having init/fini, there is just one startfile, called crt0.o.
-start-installed-name = crt0.o
-else
-# On systems having init/fini, crt0.o is called crt1.o, and there are
-# some additional bizarre files.
+# The ELF convention is that the startfile is called crt1.o
 start-installed-name = crt1.o
-endif
 # On systems that do not need a special startfile for statically linked
 # binaries, simply set it to the normal name.
 ifndef static-start-installed-name
 static-start-installed-name = $(start-installed-name)
 endif
 
-ifeq (yesyesyes,$(build-shared)$(elf)$(have-z-combreloc))
+ifeq (yesyes,$(build-shared)$(have-z-combreloc))
 combreloc-LDFLAGS = -Wl,-z,combreloc
 LDFLAGS.so += $(combreloc-LDFLAGS)
 LDFLAGS-rtld += $(combreloc-LDFLAGS)
@@ -421,90 +387,111 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
 endif
 
-# Command for linking programs with the C library.
-ifndef +link
-+link = $(CC) -nostdlib -nostartfiles -o $@ \
-             $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
-             $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
-             $(addprefix $(csu-objpfx),$(start-installed-name)) \
-             $(+preinit) $(+prector) \
-             $(filter-out $(addprefix $(csu-objpfx),start.o \
-                                                    $(start-installed-name))\
-                          $(+preinit) $(link-extra-libs) \
-                          $(common-objpfx)libc% $(+postinit),$^) \
-             $(link-extra-libs) $(link-libc) $(+postctor) $(+postinit)
-endif
 # Command for linking PIE programs with the C library.
 ifndef +link-pie
-+link-pie = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
-            $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
++link-pie-before-libc = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
+            $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
             $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
             $(addprefix $(csu-objpfx),S$(start-installed-name)) \
             $(+preinit) $(+prectorS) \
             $(filter-out $(addprefix $(csu-objpfx),start.o \
-            S$(start-installed-name))\
-            $(+preinit) $(link-extra-libs) \
-            $(common-objpfx)libc% $(+postinit),$^) \
-            $(link-extra-libs) $(link-libc) $(+postctorS) $(+postinit)
+                                                   S$(start-installed-name))\
+                         $(+preinit) $(link-extra-libs) \
+                         $(common-objpfx)libc% $(+postinit),$^) \
+            $(link-extra-libs)
++link-pie-after-libc = $(+postctorS) $(+postinit)
++link-pie = $(+link-pie-before-libc) $(rtld-LDFLAGS) $(link-libc) \
+           $(+link-pie-after-libc)
++link-pie-tests = $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) \
+                 $(link-libc-tests) $(+link-pie-after-libc)
 endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
-+link-static = $(CC) -nostdlib -nostartfiles -static -o $@ \
++link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
              $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
              $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
-             $(+preinit) $(+prector) \
+             $(+preinit) $(+prectorT) \
              $(filter-out $(addprefix $(csu-objpfx),start.o \
                                                     $(start-installed-name))\
                           $(+preinit) $(link-extra-libs-static) \
                           $(common-objpfx)libc% $(+postinit),$^) \
-             $(link-extra-libs-static) $(link-libc-static) $(+postctor) $(+postinit)
-endif
-# Command for statically linking bounded-pointer programs with the C library.
-ifndef +link-bounded
-+link-bounded = $(CC) -nostdlib -nostartfiles -static -fbounded-pointers -o $@ \
-             $(sysdep-LDFLAGS) $(LDFLAGS)  \
-             $(addprefix $(csu-objpfx),b$(static-start-installed-name)) \
+             $(link-extra-libs-static)
++link-static-after-libc = $(+postctorT) $(+postinit)
++link-static = $(+link-static-before-libc) $(link-libc-static) \
+              $(+link-static-after-libc)
++link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
+                    $(+link-static-after-libc)
+endif
+# Commands for linking programs with the C library.
+ifndef +link
+ifeq (yes,$(build-shared))
++link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
+             $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
+             $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
+             $(addprefix $(csu-objpfx),$(start-installed-name)) \
              $(+preinit) $(+prector) \
-             $(filter-out $(addprefix $(csu-objpfx),start.ob \
+             $(filter-out $(addprefix $(csu-objpfx),start.o \
                                                     $(start-installed-name))\
-                          $(+preinit) $(link-extra-libs-bounded) \
+                          $(+preinit) $(link-extra-libs) \
                           $(common-objpfx)libc% $(+postinit),$^) \
-             $(link-extra-libs-bounded) $(link-libc-bounded) $(+postctor) $(+postinit)
+             $(link-extra-libs)
++link-after-libc = $(+postctor) $(+postinit)
++link = $(+link-before-libc) $(rtld-LDFLAGS) $(link-libc) \
+       $(+link-after-libc)
++link-tests = $(+link-before-libc) $(rtld-tests-LDFLAGS) \
+             $(link-libc-tests) $(+link-after-libc)
+else
++link = $(+link-static)
++link-tests = $(+link-static-tests)
+endif
+endif
+ifeq (yes,$(build-shared))
+ifndef rtld-LDFLAGS
+rtld-LDFLAGS = -Wl,-dynamic-linker=$(rtlddir)/$(rtld-installed-name)
+endif
+ifndef rtld-tests-LDFLAGS
+ifeq (yes,$(build-hardcoded-path-in-tests))
+rtld-tests-LDFLAGS = -Wl,-dynamic-linker=$(common-objpfx)elf/ld.so
+else
+rtld-tests-LDFLAGS = $(rtld-LDFLAGS)
 endif
-ifndef config-LDFLAGS
-ifeq (yesyes,$(build-shared)$(elf))
-config-LDFLAGS = -Wl,-dynamic-linker=$(slibdir)/$(rtld-installed-name)
 endif
 endif
 ifndef link-libc
 ifeq (yes,$(build-shared))
-ifeq ($(elf),yes)
 # We need the versioned name of libc.so in the deps of $(others) et al
 # so that the symlink to libc.so is created before anything tries to
 # run the linked programs.
-link-libc = -Wl,-rpath-link=$(rpath-link) \
-           $(common-objpfx)libc.so$(libc.so-version) \
-           $(common-objpfx)$(patsubst %,$(libtype.oS),c) $(gnulib)
+link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
+ifeq (yes,$(build-hardcoded-path-in-tests))
+link-libc-tests-rpath-link = -Wl,-rpath=$(rpath-link)
+else
+link-libc-tests-rpath-link = $(link-libc-rpath-link)
+endif
+link-libc-before-gnulib = $(common-objpfx)libc.so$(libc.so-version) \
+                         $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
+                         $(as-needed) $(common-objpfx)elf/ld.so \
+                         $(no-as-needed)
+link-libc = $(link-libc-rpath-link) $(link-libc-before-gnulib) $(gnulib)
+link-libc-tests = $(link-libc-tests-rpath-link) \
+                 $(link-libc-before-gnulib) $(gnulib-tests)
 # This is how to find at build-time things that will be installed there.
 rpath-dirs = math elf dlfcn nss nis rt resolv crypt
-endif
 rpath-link = \
 $(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
-elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
 else
-nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
-resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
 link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
+link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
 endif
 endif
 
+elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
+
 # Differences in the linkers on the various platforms.
-ifeq ($(elf),yes)
 LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
 LDFLAGS-soname-fname = -Wl,-soname,$(@F)
 LDFLAGS-rdynamic = -rdynamic
 LDFLAGS-Bsymbolic = -Bsymbolic
-endif
 
 # Choose the default search path for the dynamic linker based on
 # where we will install libraries.
@@ -517,75 +504,179 @@ endif
 ifndef link-extra-libs
 link-extra-libs = $(LDLIBS-$(@F))
 link-extra-libs-static = $(link-extra-libs)
-link-extra-libs-bounded = $(link-extra-libs)
 endif
 
 # The static libraries.
-ifeq (yes,$(build-static))
-link-libc-static = $(common-objpfx)libc.a $(static-gnulib) $(common-objpfx)libc.a
-else
-ifeq (yes,$(build-shared))
-# We can try to link the programs with lib*_pic.a...
-link-libc-static = $(static-gnulib) $(common-objpfx)libc_pic.a
-endif
-endif
-link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a
-
+link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
+link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
+
+# How to link against libgcc.  Some libgcc functions, such as those
+# for "long long" arithmetic or software floating point, can always be
+# built without use of C library headers and do not have any global
+# state so can safely be linked statically into any executable or
+# shared library requiring them; these functions are in libgcc.a.
+# Other functions, relating to exception handling, may require C
+# library headers to build and it may not be safe to have more than
+# one copy of them in a process; these functions are only in
+# libgcc_s.so and libgcc_eh.a.
+#
+# To avoid circular dependencies when bootstrapping, it is desirable
+# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
+# glibc functionality (in particular, thread cancellation) requires
+# exception handling, this is implemented through dlopen of libgcc_s
+# to avoid unnecessary dependencies on libgcc_s by programs not using
+# that functionality; executables built with glibc do not use
+# exception handling other than through thread cancellation.
+#
+# Undefined references to functions from libgcc_eh or libgcc_s may
+# arise for code built with -fexceptions.  In the case of statically
+# linked programs installed by glibc, unwinding will never actually
+# occur at runtime and the use of elf/static-stubs.c to resolve these
+# references is safe.  In the case of statically linked test programs
+# and test programs built with -fexceptions, unwinding may occur in
+# some cases and it is preferable to link with libgcc_eh or libgcc_s
+# so that the testing is as similar as possible to how programs will
+# be built with the installed glibc.
+#
+# Some architectures have architecture-specific systems for exception
+# handling that may involve undefined references to
+# architecture-specific functions.  On those architectures,
+# gnulib-arch and static-gnulib-arch may be defined in sysdeps
+# makefiles to use additional libraries for linking executables and
+# shared libraries built by glibc.
 ifndef gnulib
 ifneq ($(have-cc-with-libunwind),yes)
   libunwind =
 else
   libunwind = -lunwind
 endif
-ifneq ($(have-as-needed),yes)
- libgcc_eh := -lgcc_eh $(libunwind)
+libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
+gnulib-arch =
+gnulib = -lgcc $(gnulib-arch)
+gnulib-tests := -lgcc $(libgcc_eh)
+static-gnulib-arch =
+# By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
+# statically link programs.  When --disable-shared is used, we use
+# -lgcc_eh since elf/static-stubs.o isn't sufficient.
+ifeq (yes,$(build-shared))
+static-gnulib = -lgcc $(static-gnulib-arch)
 else
- libgcc_eh := -Wl,--as-needed -lgcc_s$(libgcc_s_suffix) $(libunwind) -Wl,--no-as-needed
+static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
 endif
-gnulib := -lgcc $(libgcc_eh)
-static-gnulib := -lgcc -lgcc_eh $(libunwind)
+static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
 libc.so-gnulib := -lgcc
 endif
-ifeq ($(elf),yes)
 +preinit = $(addprefix $(csu-objpfx),crti.o)
 +postinit = $(addprefix $(csu-objpfx),crtn.o)
-+prector = `$(CC) --print-file-name=crtbegin.o`
-+postctor = `$(CC) --print-file-name=crtend.o`
++prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
++postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
 # Variants of the two previous definitions for linking PIE programs.
-+prectorS = `$(CC) --print-file-name=crtbeginS.o`
-+postctorS = `$(CC) --print-file-name=crtendS.o`
++prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
++postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
+# Variants of the two previous definitions for statically linking programs.
++prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
++postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
 +interp = $(addprefix $(elf-objpfx),interp.os)
-endif
 csu-objpfx = $(common-objpfx)csu/
 elf-objpfx = $(common-objpfx)elf/
 
+# A command that, prepended to the name and arguments of a program,
+# and run on the build system, causes that program with those
+# arguments to be run on the host for which the library is built.
+ifndef test-wrapper
+test-wrapper =
+endif
+# Likewise, but the name of the program is preceded by
+# <variable>=<value> assignments for environment variables.
+ifndef test-wrapper-env
+test-wrapper-env = $(test-wrapper) env
+endif
+
+# Whether to run test programs built for the library's host system.
+ifndef run-built-tests
+ifeq (yes|,$(cross-compiling)|$(test-wrapper))
+run-built-tests = no
+else
+run-built-tests = yes
+endif
+endif
+
 # How to run a program we just linked with our library.
 # The program binary is assumed to be $(word 2,$^).
 built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
-ifeq (yesyes,$(build-shared)$(elf))
+rtld-prefix = $(elf-objpfx)$(rtld-installed-name)                            \
+             --library-path                                                  \
+             $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
+ifeq (yes,$(build-shared))
 comma = ,
 sysdep-library-path = \
 $(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
                                       $(filter -Wl$(comma)-rpath-link=%,\
                                                $(sysdep-LDFLAGS)))))
-run-program-prefix = $(if $(filter $(notdir $(built-program-file)),\
-                                  $(tests-static) $(xtests-static)),, \
-                         $(elf-objpfx)$(rtld-installed-name) \
-                         --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)))
+# $(run-via-rtld-prefix) is a command that, when prepended to the name
+# of a program built with the newly built library, produces a command
+# that, executed on the host for which the library is built, runs that
+# program.  For tests listed in tests-static or xtests-static, it is
+# empty.
+run-via-rtld-prefix =                                                        \
+  $(if $(strip $(filter $(notdir $(built-program-file)),                     \
+                       $(tests-static) $(xtests-static))),, $(rtld-prefix))
 else
-run-program-prefix =
-endif
-# Never use $(run-program-prefix) for the statically-linked %-bp test programs
-built-program-cmd = $(patsubst %,$(run-program-prefix),\
-                       $(filter-out %-bp,$(built-program-file))) \
-                   $(built-program-file)
+run-via-rtld-prefix =
+endif
+# $(run-program-prefix) is a command that, when prepended to the name
+# of a program built with the newly built library, produces a command
+# that, executed on the build system on which "make" is run, runs that
+# program.
+run-program-prefix = $(test-wrapper) $(run-via-rtld-prefix)
+# $(built-program-cmd) is a command that, executed on the build system
+# on which "make" is run, runs the newly built program that is the
+# second dependency of the makefile target in which
+# $(built-program-cmd) is used.
+built-program-cmd = $(test-wrapper) \
+                   $(run-via-rtld-prefix) $(built-program-file)
+# $(host-built-program-cmd) is a command that, executed on the host
+# for which the library is built, runs the newly built program that is
+# the second dependency of the makefile target in which
+# $(host-built-program-cmd) is used.
+host-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
 
 ifndef LD
 LD := ld -X
 endif
 
-ifndef RANLIB
-RANLIB = ranlib
+# $(test-via-rtld-prefix) is a command that, when prepended to the name
+# of a test program built with the newly built library, produces a command
+# that, executed on the host for which the library is built, runs that
+# program.  For tests listed in tests-static or xtests-static as well
+# as when test programs are hardcoded to the newly built libraries, it
+# is empty.
+
+# $(test-program-prefix) is a command that, when prepended to the name
+# of a test program built with the newly built library, produces a command
+# that, executed on the build system on which "make" is run, runs that
+# test program.
+
+# $(test-program-cmd) is a command that, executed on the build system
+# on which "make" is run, runs the newly built test program that is the
+# second dependency of the makefile target in which
+# $(test-program-cmd) is used.
+
+# $(host-test-program-cmd) is a command that, executed on the host
+# for which the library is built, runs the newly built test program that
+# is the second dependency of the makefile target in which
+# $(host-test-program-cmd) is used.
+
+ifeq (yes,$(build-hardcoded-path-in-tests))
+test-via-rtld-prefix =
+test-program-prefix = $(test-wrapper)
+test-program-cmd = $(test-wrapper) $(built-program-file)
+host-test-program-cmd = $(built-program-file)
+else
+test-via-rtld-prefix = $(run-via-rtld-prefix)
+test-program-prefix = $(run-program-prefix)
+test-program-cmd = $(built-program-cmd)
+host-test-program-cmd = $(host-built-program-cmd)
 endif
 
 # Extra flags to pass to GCC.
@@ -600,6 +691,11 @@ endif
 # actually different, so allow the compiler to merge them all.
 +merge-constants = -fmerge-all-constants
 
+# We have to assume that glibc functions are called in any rounding
+# mode and also change the rounding mode in a few functions. So,
+# disable any optimization that assume default rounding mode.
++math-flags = -frounding-math
+
 # This is the program that generates makefile dependencies from C source files.
 # The -MP flag tells GCC >= 3.2 (which we now require) to produce dummy
 # targets for headers so that removed headers don't break the build.
@@ -659,17 +755,24 @@ ifeq      "$(strip $(+cflags))" ""
 +cflags        := $(default_cflags)
 endif  # $(+cflags) == ""
 
-+cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants)
++cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags)
 +gcc-nowarn := -w
 
 # Don't duplicate options if we inherited variables from the parent.
 +cflags        := $(sort $(+cflags))
 
+# Each sysdeps directory can contain header files that both will be
+# used to compile and will be installed.  Each can also contain an
+# include/ subdirectory, whose header files will be used to compile
+# but will not be installed, and will take precedence over the
+# installed files.  This mirrors the top-level include/ subdirectory.
++sysdep-includes := $(foreach dir,$(+sysdep_dirs),\
+                             $(addprefix -I,$(wildcard $(dir)/include) $(dir)))
+
 # These are flags given to the C compiler to tell it to look for
 # include files (including ones given in angle brackets) in the parent
 # library source directory, in the include directory, and in the
 # current directory.
-+sysdep-includes = $(addprefix -I,$(+sysdep_dirs))
 +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
            $(+sysdep-includes) $(includes) \
            $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
@@ -682,16 +785,19 @@ libio-include = -I$(..)libio
 # Note that we can't use -std=* in CPPFLAGS, because it overrides
 # the implicit -lang-asm and breaks cpp behavior for .S files--notably
 # it causes cpp to stop predefining __ASSEMBLER__.
-CPPFLAGS = $($(subdir)-CPPFLAGS) $(+includes) $(defines) \
+CPPFLAGS = $(CPPUNDEFS) $(CPPFLAGS-config) $($(subdir)-CPPFLAGS) \
+          $(+includes) $(defines) \
           -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
           $(CPPFLAGS-$(suffix $@)) \
           $(foreach lib,$(libof-$(basename $(@F))) \
-                        $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
+                        $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
           $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
-override CFLAGS        = -std=gnu99 $(gnu89-inline-CFLAGS) \
+override CFLAGS        = -std=gnu99 $(gnu89-inline-CFLAGS) $(config-extra-cflags) \
                  $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
                  $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
-                 $(CFLAGS-$(@F))
+                 $(CFLAGS-$(@F)) \
+                 $(foreach lib,$(libof-$(basename $(@F))) \
+                               $(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
 override CXXFLAGS = $(c++-sysincludes) \
                    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
                    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
@@ -707,14 +813,12 @@ endif
 # The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX})
 # to pass different flags for each flavor.
 libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
-all-object-suffixes := .o .os .op .og .ob .oS
+all-object-suffixes := .o .os .op .og .oS
 object-suffixes :=
 CPPFLAGS-.o = $(pic-default)
 CFLAGS-.o = $(filter %frame-pointer,$(+cflags))
-ifeq (yes,$(build-static))
 libtype.o := lib%.a
 object-suffixes += .o
-endif
 ifeq (yes,$(build-shared))
 # Under --enable-shared, we will build a shared library of PIC objects.
 # The PIC object files are named foo.os.
@@ -739,29 +843,10 @@ CPPFLAGS-.op = -DPROF $(pic-default)
 CFLAGS-.op = -pg
 libtype.op = lib%_p.a
 endif
-ifeq (yes,$(build-omitfp))
-# Under --enable-omitfp, we build the library optimized without
-# debugging information using -fomit-frame-pointer, and build an extra
-# library with debugging information.  The debuggable objects are named foo.og.
-object-suffixes += .og
-CPPFLAGS-.og = $(pic-default)
-CFLAGS-.og = -g
-CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) -g0 -O99 -fomit-frame-pointer -D__USE_STRING_INLINES
-CFLAGS-.os += -g0 -O99 -fomit-frame-pointer -D__USE_STRING_INLINES
-libtype.og = lib%_g.a
-endif
-
-bppfx = BP-
-ifeq (yes,$(build-bounded))
-# Under --enable-bounded, we build the library with `-fbounded-pointers -g'
-# to runtime bounds checking.  The bounded-pointer objects are named foo.ob.
-# We disable sibling-call optimizations so that stack traces will be complete
-# and thus aid debugging, since after all, BPs are a debugging tool.
-object-suffixes += .ob
-CPPFLAGS-.ob = -fbounded-pointers $(pic-default)
-CFLAGS-.ob = -g -O2 -fno-optimize-sibling-calls -fno-strict-aliasing
-libtype.ob = lib%_b.a
-endif
+
+# Convenience variable for when we want to treat shared-library cases
+# differently from the rest.
+object-suffixes-noshared := $(filter-out .os,$(object-suffixes))
 
 object-suffixes-for-libc := $(object-suffixes)
 
@@ -779,11 +864,7 @@ endif
 
 # The assembler can generate debug information too.
 ifndef ASFLAGS
-ifeq ($(have-cpp-asm-debuginfo),yes)
-ASFLAGS := $(filter -g%,$(CFLAGS))
-else
-ASFLAGS :=
-endif
+ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
 endif
 ASFLAGS += $(ASFLAGS-config) $(asflags-cpu)
 
@@ -798,8 +879,6 @@ subdirs = $(sorted-subdirs)
 subdir-srcdirs = $(foreach dir,$(subdirs),\
                           $(firstword $($(dir)-srcdir) $(..)$(dir)))
 
-ifeq (yes, $(build-shared))
-
 # This is a pair of implicit rules to preprocess a file with # comments,
 # %ifdef et al, based on config.h settings or other %include'd files.
 # We use chained rules instead of a pipeline here so that we can properly
@@ -818,6 +897,21 @@ ifeq (yes, $(build-shared))
        sed '/^[        ]*#/d;/^[       ]*$$/d' $< > $@T
        mv -f $@T $@
 
+ifeq (yes, $(build-shared))
+
+# To generate a header to support more than one ABI for different
+# architecture variants, the CPU/Makefile defines abi-variants to be a
+# list of names for those variants (e.g. 32 64), and, for each variant,
+# defines abi-$(variant)-condition to be the condition for those options
+# to use in a C #if condition.  abi-includes may be defined to a list of
+# headers to include in the generated header, if the default does not
+# suffice.  default-abi is defined to be the ABI for the current glibc
+# build.
+
+ifndef abi-includes
+abi-includes := bits/wordsize.h
+endif
+
 # Process the shlib-versions file, which tells us what shared library
 # version numbers to use when we install shared objects on this system.
 # We need to wait until $(subdirs) is complete.
@@ -843,24 +937,17 @@ $(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
               -f $^ > $@T
        mv -f $@T $@
 $(common-objpfx)soversions.mk: $(common-objpfx)soversions.i $(..)Makeconfig
-       (seen_DEFAULT=0; seen_WORDSIZE32=0; seen_WORDSIZE64=0; \
-        while read which lib number setname; do \
+       (while read which lib number setname; do \
           eval seen_$$which=1; \
           test x"$$which" != xABI || echo abi-name = "$$lib"; \
           test x"$$which" = xDEFAULT || continue; \
           case $$number in \
             [0-9]*) echo "$$lib.so-version=.$$number"; \
                     echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
-            *)      echo "$$lib.so-version=$$number"; \
+            *)      echo "$$lib.so-version=\$$(if \$$(abi-$(default-abi)-$$lib-soname),\$$(abi-$(default-abi)-$$lib-soname),$$number)"; \
                     echo "all-sonames+=$$lib=\$$($$lib.so-version)";;\
           esac; \
         done; \
-        case "$$seen_DEFAULT$$seen_WORDSIZE32$$seen_WORDSIZE64" in \
-          100) echo biarch = no;; \
-          101) echo biarch = 32;; \
-          ?1?) echo biarch = 64;; \
-          *) echo >&2 BUG; exit 2;; \
-        esac; \
         echo soversions.mk-done = t;) < $< > $@T; exit 0
        mv -f $@T $@
 endif
@@ -877,8 +964,31 @@ $(common-objpfx)gnu/lib-names.h: $(common-objpfx)gnu/lib-names.stmp; @:
 $(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
                                    $(common-objpfx)soversions.i
        $(make-target-directory)
-       @rm -f ${@:stmp=T} $@
-       LC_ALL=C $(AWK) -f $^ > ${@:stmp=T}
+       { \
+        echo '/* This file is automatically generated.';\
+        echo '   It defines macros to allow user program to find the shared'; \
+        echo '   library files which come as part of GNU libc.  */'; \
+        echo '#ifndef __GNU_LIB_NAMES_H'; \
+        echo '#define __GNU_LIB_NAMES_H        1'; \
+        echo ''; \
+        $(if $(abi-includes), \
+         $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
+         echo '';) \
+        $(if $(abi-variants), \
+        $(foreach v,$(abi-variants),\
+        $(if $(abi-$(v)-condition),\
+        echo '#if $(abi-$(v)-condition)'; \
+        ($(foreach s,$(all-sonames), \
+          $(if $(abi-$(v)-$(firstword $(subst =, ,$(s)))-soname),\
+            echo $(firstword $(subst =, ,$(s)))=$(abi-$(v)-$(firstword $(subst =, ,$(s)))-soname);, \
+            echo $(s);))) \
+        | LC_ALL=C $(AWK) -v multi=1 -f $(firstword $^) | LC_ALL=C sort;) \
+        $(if $(abi-$(v)-condition),echo '#endif';)), \
+        ($(foreach s,$(all-sonames), echo $(s);)) \
+        | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort;) \
+        echo ''; \
+        echo '#endif   /* gnu/lib-names.h */'; \
+       } >  ${@:stmp=T}
        $(move-if-change) ${@:stmp=T} ${@:stmp=h}
        touch $@
 endif
@@ -903,28 +1013,16 @@ endif
 endif # build-shared
 
 
-ifeq ($(elf),yes)
-dlfcn = dlfcn
 ifeq ($(build-shared),yes)
 libdl = $(common-objpfx)dlfcn/libdl.so$(libdl.so-version)
 else
 libdl = $(common-objpfx)dlfcn/libdl.a
 endif
-else
-ifneq (,$(findstring aix,$(config-os)))
+
 ifeq ($(build-shared),yes)
-dlfcn = dlfcn
-libdl = $(common-objpfx)dlfcn/libdl.so$(libdl.so-version)
+libm = $(common-objpfx)math/libm.so$(libm.so-version)
 else
-# No libdl without shared libs on AIX
-dlfcn =
-libdl =
-endif
-else
-# No ELF, no AIX - no libdl, at least for now.
-dlfcn =
-libdl =
-endif
+libm = $(common-objpfx)math/libm.a
 endif
 
 # These are the subdirectories containing the library source.  The order
@@ -934,13 +1032,19 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal        \
              stdlib stdio-common libio malloc string wcsmbs time dirent    \
              grp pwd posix io termios resource misc socket sysvipc gmon    \
              gnulib iconv iconvdata wctype manual shadow gshadow po argp   \
-             crypt nss localedata timezone rt conform debug                \
-             $(add-on-subdirs) $(dlfcn) $(binfmt-subdir)
+             crypt localedata timezone rt conform debug                    \
+             $(add-on-subdirs) dlfcn elf
 
 ifndef avoid-generated
-all-Depend-files := $(wildcard $(foreach dir,$(all-subdirs),\
-                                        $(firstword $($(dir)-srcdir) \
-                                                    $(..)$(dir))/Depend))
+# sysd-sorted itself will contain rules making the sysd-sorted target
+# depend on Depend files.  But if you just added a Depend file to an
+# existing directory not in all-subdirs, then sysd-sorted needs to
+# be regenerated, so it depends on existing $(sorted-subdirs:=/Depend) files.
+all-Depend-files := $(wildcard $(sort \
+                       $(foreach dir,$(all-subdirs),\
+                                 $(firstword $($(dir)-srcdir) \
+                                 $(..)$(dir))/Depend) \
+                       $(sorted-subdirs:=/Depend)))
 $(common-objpfx)sysd-sorted: $(..)scripts/gen-sorted.awk \
                             $(common-objpfx)config.make $(..)Makeconfig \
                             $(wildcard $(sysdirs:=/Subdirs)) \
@@ -957,7 +1061,7 @@ endif
 # emitted into sysd-rules.  A sysdeps Makeconfig fragment can
 # add its own special object file prefix to this list with e.g. foo-%:%
 # to have foo-*.? compiled from *.? using $(foo-CPPFLAGS).
-sysd-rules-patterns := %:% rtld-%:% m_%:s_%
+sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%
 
 # Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
 sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
@@ -966,8 +1070,15 @@ include $(sysdep-makeconfigs)
 endif
 
 # Compute just the target patterns.  Makeconfig has set sysd-rules-patterns.
-sysd-rules-targets := $(foreach p,$(sysd-rules-patterns),\
-                               $(firstword $(subst :, ,$p)))
+sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
+                                        $(firstword $(subst :, ,$p))))
+
+# A sysdeps Makeconfig fragment may set libc-reentrant to yes.
+ifeq (yes,$(libc-reentrant))
+defines += -D_LIBC_REENTRANT
+
+libio-mtsafe = -D_IO_MTSAFE_IO
+endif
 
 endif # Makeconfig not yet included