93dc2d
commit 9ba202c78f0aa39f49929eee63c367847da72ee4
93dc2d
Author: Florian Weimer <fweimer@redhat.com>
93dc2d
Date:   Fri Jan 14 20:16:05 2022 +0100
93dc2d
93dc2d
    Add --with-rtld-early-cflags configure option
93dc2d
    
93dc2d
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
93dc2d
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
93dc2d
93dc2d
Conflicts:
93dc2d
	INSTALL
93dc2d
	configure
93dc2d
	manual/install.texi
93dc2d
	  (Missing --with-timeout-factor downstream.)
93dc2d
93dc2d
diff --git a/INSTALL b/INSTALL
93dc2d
index d6d93ec9be4262d7..d8d4e9f155f56616 100644
93dc2d
--- a/INSTALL
93dc2d
+++ b/INSTALL
93dc2d
@@ -106,6 +106,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
93dc2d
      particular case and potentially change debugging information and
93dc2d
      metadata only).
93dc2d
 
93dc2d
+'--with-rtld-early-cflags=CFLAGS'
93dc2d
+     Use additional compiler flags CFLAGS to build the early startup
93dc2d
+     code of the dynamic linker.  These flags can be used to enable
93dc2d
+     early dynamic linker diagnostics to run on CPUs which are not
93dc2d
+     compatible with the rest of the GNU C Library, for example, due to
93dc2d
+     compiler flags which target a later instruction set architecture
93dc2d
+     (ISA).
93dc2d
+
93dc2d
 '--disable-shared'
93dc2d
      Don't build shared libraries even if it is possible.  Not all
93dc2d
      systems support shared libraries; you need ELF support and
93dc2d
diff --git a/config.make.in b/config.make.in
93dc2d
index e8630a8d0ccf874d..6d43e691f7823262 100644
93dc2d
--- a/config.make.in
93dc2d
+++ b/config.make.in
93dc2d
@@ -110,6 +110,7 @@ CFLAGS = @CFLAGS@
93dc2d
 CPPFLAGS-config = @CPPFLAGS@
93dc2d
 CPPUNDEFS = @CPPUNDEFS@
93dc2d
 extra-nonshared-cflags = @extra_nonshared_cflags@
93dc2d
+rtld-early-cflags = @rtld_early_cflags@
93dc2d
 ASFLAGS-config = @ASFLAGS_config@
93dc2d
 AR = @AR@
93dc2d
 NM = @NM@
93dc2d
diff --git a/configure b/configure
93dc2d
index e9d2b1f398c4dba0..03f4e59e754b5463 100755
93dc2d
--- a/configure
93dc2d
+++ b/configure
93dc2d
@@ -681,6 +681,7 @@ force_install
93dc2d
 bindnow
93dc2d
 hardcoded_path_in_tests
93dc2d
 enable_timezone_tools
93dc2d
+rtld_early_cflags
93dc2d
 extra_nonshared_cflags
93dc2d
 use_default_link
93dc2d
 sysheaders
93dc2d
@@ -761,6 +762,7 @@ with_selinux
93dc2d
 with_headers
93dc2d
 with_default_link
93dc2d
 with_nonshared_cflags
93dc2d
+with_rtld_early_cflags
93dc2d
 enable_sanity_checks
93dc2d
 enable_shared
93dc2d
 enable_profile
93dc2d
@@ -1479,6 +1481,8 @@ Optional Packages:
93dc2d
   --with-default-link     do not use explicit linker scripts
93dc2d
   --with-nonshared-cflags=CFLAGS
93dc2d
                           build nonshared libraries with additional CFLAGS
93dc2d
+  --with-rtld-early-cflags=CFLAGS
93dc2d
+                          build early initialization with additional CFLAGS
93dc2d
   --with-cpu=CPU          select code for CPU variant
93dc2d
 
93dc2d
 Some influential environment variables:
93dc2d
@@ -3383,6 +3387,16 @@ fi
93dc2d
 
93dc2d
 
93dc2d
 
93dc2d
+# Check whether --with-rtld-early-cflags was given.
93dc2d
+if test "${with_rtld_early_cflags+set}" = set; then :
93dc2d
+  withval=$with_rtld_early_cflags; rtld_early_cflags=$withval
93dc2d
+else
93dc2d
+  rtld_early_cflags=
93dc2d
+fi
93dc2d
+
93dc2d
+
93dc2d
+
93dc2d
+
93dc2d
 # Check whether --enable-sanity-checks was given.
93dc2d
 if test "${enable_sanity_checks+set}" = set; then :
93dc2d
   enableval=$enable_sanity_checks; enable_sanity=$enableval
93dc2d
diff --git a/configure.ac b/configure.ac
93dc2d
index 79f6822d29ce21cf..eb9431875fae1b0e 100644
93dc2d
--- a/configure.ac
93dc2d
+++ b/configure.ac
93dc2d
@@ -162,6 +162,12 @@ AC_ARG_WITH([nonshared-cflags],
93dc2d
 	    [extra_nonshared_cflags=$withval],
93dc2d
 	    [extra_nonshared_cflags=])
93dc2d
 AC_SUBST(extra_nonshared_cflags)
93dc2d
+AC_ARG_WITH([rtld-early-cflags],
93dc2d
+	    AS_HELP_STRING([--with-rtld-early-cflags=CFLAGS],
93dc2d
+			   [build early initialization with additional CFLAGS]),
93dc2d
+	    [rtld_early_cflags=$withval],
93dc2d
+	    [rtld_early_cflags=])
93dc2d
+AC_SUBST(rtld_early_cflags)
93dc2d
 
93dc2d
 AC_ARG_ENABLE([sanity-checks],
93dc2d
 	      AS_HELP_STRING([--disable-sanity-checks],
93dc2d
diff --git a/elf/Makefile b/elf/Makefile
93dc2d
index 52aafc89cec835ab..778e393395fc5248 100644
93dc2d
--- a/elf/Makefile
93dc2d
+++ b/elf/Makefile
93dc2d
@@ -152,6 +152,14 @@ CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os))
93dc2d
 CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os))
93dc2d
 CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))
93dc2d
 
93dc2d
+# Add the requested compiler flags to the early startup code.
93dc2d
+CFLAGS-dl-printf.os += $(rtld-early-cflags)
93dc2d
+CFLAGS-dl-sysdep.os += $(rtld-early-cflags)
93dc2d
+CFLAGS-dl-tunables.os += $(rtld-early-cflags)
93dc2d
+CFLAGS-dl-write.os += $(rtld-early-cflags)
93dc2d
+CFLAGS-dl-writev.os += $(rtld-early-cflags)
93dc2d
+CFLAGS-rtld.os += $(rtld-early-cflags)
93dc2d
+
93dc2d
 ifeq ($(unwind-find-fde),yes)
93dc2d
 routines += unwind-dw2-fde-glibc
93dc2d
 shared-only-routines += unwind-dw2-fde-glibc
93dc2d
diff --git a/manual/install.texi b/manual/install.texi
93dc2d
index 1320ac69b3c645f2..816b77a0a25a88a7 100644
93dc2d
--- a/manual/install.texi
93dc2d
+++ b/manual/install.texi
93dc2d
@@ -131,6 +131,13 @@ that the objects in @file{libc_nonshared.a} are compiled with this flag
93dc2d
 (although this will not affect the generated code in this particular
93dc2d
 case and potentially change debugging information and metadata only).
93dc2d
 
93dc2d
+@item --with-rtld-early-cflags=@var{cflags}
93dc2d
+Use additional compiler flags @var{cflags} to build the early startup
93dc2d
+code of the dynamic linker.  These flags can be used to enable early
93dc2d
+dynamic linker diagnostics to run on CPUs which are not compatible with
93dc2d
+the rest of @theglibc{}, for example, due to compiler flags which target
93dc2d
+a later instruction set architecture (ISA).
93dc2d
+
93dc2d
 @c disable static doesn't work currently
93dc2d
 @c @item --disable-static
93dc2d
 @c Don't build static libraries.  Static libraries aren't that useful these