a50cd9a
Author: Florian Weimer <fweimer@redhat.com>
a50cd9a
Date:   Wed Jul 4 11:34:36 2018 +0200
a50cd9a
a50cd9a
    Add --with-nonshared-cflags option to configure
a50cd9a
a50cd9a
Submitted upstream:
a50cd9a
a50cd9a
  https://sourceware.org/ml/libc-alpha/2018-07/msg00071.html
a50cd9a
a50cd9a
diff --git a/INSTALL b/INSTALL
a50cd9a
index 0a22aa7d01e6e87b..0f80d9d615db6d42 100644
a50cd9a
--- a/INSTALL
a50cd9a
+++ b/INSTALL
a50cd9a
@@ -90,6 +90,15 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
a50cd9a
      library will still be usable, but functionality may be lost--for
a50cd9a
      example, you can't build a shared libc with old binutils.
a50cd9a
 
a50cd9a
+'--with-nonshared-cflags=CFLAGS'
a50cd9a
+     Use additional compiler flags CFLAGS to build the parts of the
a50cd9a
+     library which are always statically linked into applications and
a50cd9a
+     libraries even with shared linking (that is, the object files
a50cd9a
+     contained in 'lib*_nonshared.a' libraries).  The build process will
a50cd9a
+     automatically use the appropriate flags, but this option can be
a50cd9a
+     used to set additional flags required for building applications and
a50cd9a
+     libraries, to match local policy.
a50cd9a
+
a50cd9a
 '--disable-shared'
a50cd9a
      Don't build shared libraries even if it is possible.  Not all
a50cd9a
      systems support shared libraries; you need ELF support and
a50cd9a
diff --git a/Makeconfig b/Makeconfig
a50cd9a
index 608ffe648c80c724..b0b27f0113ac18b8 100644
a50cd9a
--- a/Makeconfig
a50cd9a
+++ b/Makeconfig
a50cd9a
@@ -1038,7 +1038,7 @@ object-suffixes-for-libc += .oS
a50cd9a
 # Must build the routines as PIC, though, because they can end up in (users')
a50cd9a
 # shared objects.  We don't want to use CFLAGS-os because users may, for
a50cd9a
 # example, make that processor-specific.
a50cd9a
-CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag)
a50cd9a
+CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag) $(extra-nonshared-cflags)
a50cd9a
 CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
a50cd9a
 libtype.oS = lib%_nonshared.a
a50cd9a
 endif
a50cd9a
diff --git a/config.make.in b/config.make.in
a50cd9a
index d9891b2cd8ec3fbf..a6fe48d31f4d2725 100644
a50cd9a
--- a/config.make.in
a50cd9a
+++ b/config.make.in
a50cd9a
@@ -110,6 +110,7 @@ BUILD_CC = @BUILD_CC@
a50cd9a
 CFLAGS = @CFLAGS@
a50cd9a
 CPPFLAGS-config = @CPPFLAGS@
a50cd9a
 CPPUNDEFS = @CPPUNDEFS@
a50cd9a
+extra-nonshared-cflags = @extra_nonshared_cflags@
a50cd9a
 ASFLAGS-config = @ASFLAGS_config@
a50cd9a
 AR = @AR@
a50cd9a
 NM = @NM@
a50cd9a
diff --git a/configure b/configure
a50cd9a
index ef1830221522b7a5..fec0efff8216addd 100755
a50cd9a
--- a/configure
a50cd9a
+++ b/configure
a50cd9a
@@ -684,6 +684,7 @@ force_install
a50cd9a
 bindnow
a50cd9a
 hardcoded_path_in_tests
a50cd9a
 enable_timezone_tools
a50cd9a
+extra_nonshared_cflags
a50cd9a
 use_default_link
a50cd9a
 sysheaders
a50cd9a
 ac_ct_CXX
a50cd9a
@@ -762,6 +763,7 @@ with_binutils
a50cd9a
 with_selinux
a50cd9a
 with_headers
a50cd9a
 with_default_link
a50cd9a
+with_nonshared_cflags
a50cd9a
 enable_sanity_checks
a50cd9a
 enable_shared
a50cd9a
 enable_profile
a50cd9a
@@ -1479,6 +1481,8 @@ Optional Packages:
a50cd9a
   --with-headers=PATH     location of system headers to use (for example
a50cd9a
                           /usr/src/linux/include) [default=compiler default]
a50cd9a
   --with-default-link     do not use explicit linker scripts
a50cd9a
+  --with-nonshared-cflags=FLAGS
a50cd9a
+                          build nonshared libraries with additional FLAGS
a50cd9a
   --with-cpu=CPU          select code for CPU variant
a50cd9a
 
a50cd9a
 Some influential environment variables:
a50cd9a
@@ -3336,6 +3340,16 @@ else
a50cd9a
 fi
a50cd9a
 
a50cd9a
 
a50cd9a
+
a50cd9a
+# Check whether --with-nonshared-cflags was given.
a50cd9a
+if test "${with_nonshared_cflags+set}" = set; then :
a50cd9a
+  withval=$with_nonshared_cflags; extra_nonshared_cflags=$withval
a50cd9a
+else
a50cd9a
+  extra_nonshared_cflags=
a50cd9a
+fi
a50cd9a
+
a50cd9a
+
a50cd9a
+
a50cd9a
 # Check whether --enable-sanity-checks was given.
a50cd9a
 if test "${enable_sanity_checks+set}" = set; then :
a50cd9a
   enableval=$enable_sanity_checks; enable_sanity=$enableval
a50cd9a
diff --git a/configure.ac b/configure.ac
a50cd9a
index dc517017f588626a..154185d70de38928 100644
a50cd9a
--- a/configure.ac
a50cd9a
+++ b/configure.ac
a50cd9a
@@ -154,6 +154,14 @@ AC_ARG_WITH([default-link],
a50cd9a
 	    [use_default_link=$withval],
a50cd9a
 	    [use_default_link=default])
a50cd9a
 
a50cd9a
+dnl Additional build flags injection.
a50cd9a
+AC_ARG_WITH([nonshared-cflags],
a50cd9a
+	    AC_HELP_STRING([--with-nonshared-cflags=FLAGS],
a50cd9a
+			   [build nonshared libraries with additional FLAGS]),
a50cd9a
+	    [extra_nonshared_cflags=$withval],
a50cd9a
+	    [extra_nonshared_cflags=])
a50cd9a
+AC_SUBST(extra_nonshared_cflags)
a50cd9a
+
a50cd9a
 AC_ARG_ENABLE([sanity-checks],
a50cd9a
 	      AC_HELP_STRING([--disable-sanity-checks],
a50cd9a
 			     [really do not use threads (should not be used except in special situations) @<:@default=yes@:>@]),
a50cd9a
diff --git a/manual/install.texi b/manual/install.texi
a50cd9a
index 422da1447eb4dc68..eaf0cd09e7501b96 100644
a50cd9a
--- a/manual/install.texi
a50cd9a
+++ b/manual/install.texi
a50cd9a
@@ -117,6 +117,15 @@ problem and suppress these constructs, so that the library will still be
a50cd9a
 usable, but functionality may be lost---for example, you can't build a
a50cd9a
 shared libc with old binutils.
a50cd9a
 
a50cd9a
+@item --with-nonshared-cflags=@var{cflags}
a50cd9a
+Use additional compiler flags @var{cflags} to build the parts of the
a50cd9a
+library which are always statically linked into applications and
a50cd9a
+libraries even with shared linking (that is, the object files contained
a50cd9a
+in @file{lib*_nonshared.a} libraries).  The build process will
a50cd9a
+automatically use the appropriate flags, but this option can be used to
a50cd9a
+set additional flags required for building applications and libraries,
a50cd9a
+to match local policy.
a50cd9a
+
a50cd9a
 @c disable static doesn't work currently
a50cd9a
 @c @item --disable-static
a50cd9a
 @c Don't build static libraries.  Static libraries aren't that useful these