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