2be09a
commit 23645707f12f2dd9d80b51effb2d9618a7b65565
2be09a
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
2be09a
Date:   Wed Dec 8 11:21:26 2021 +0530
2be09a
2be09a
    Replace --enable-static-pie with --disable-default-pie
2be09a
    
2be09a
    Build glibc programs and tests as PIE by default and enable static-pie
2be09a
    automatically if the architecture and toolchain supports it.
2be09a
    
2be09a
    Also add a new configuration option --disable-default-pie to prevent
2be09a
    building programs as PIE.
2be09a
    
2be09a
    Only the following architectures now have PIE disabled by default
2be09a
    because they do not work at the moment.  hppa, ia64, alpha and csky
2be09a
    don't work because the linker is unable to handle a pcrel relocation
2be09a
    generated from PIE objects.  The microblaze compiler is currently
2be09a
    failing with an ICE.  GNU hurd tries to enable static-pie, which does
2be09a
    not work and hence fails.  All these targets have default PIE disabled
2be09a
    at the moment and I have left it to the target maintainers to enable PIE
2be09a
    on their targets.
2be09a
    
2be09a
    build-many-glibcs runs clean for all targets.  I also tested x86_64 on
2be09a
    Fedora and Ubuntu, to verify that the default build as well as
2be09a
    --disable-default-pie work as expected with both system toolchains.
2be09a
    
2be09a
    Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
2be09a
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2be09a
2be09a
diff --git a/INSTALL b/INSTALL
2be09a
index 02dcf6b1ca3a4c43..d6d93ec9be4262d7 100644
2be09a
--- a/INSTALL
2be09a
+++ b/INSTALL
2be09a
@@ -111,16 +111,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
2be09a
      systems support shared libraries; you need ELF support and
2be09a
      (currently) the GNU linker.
2be09a
 
2be09a
-'--enable-static-pie'
2be09a
-     Enable static position independent executable (static PIE) support.
2be09a
-     Static PIE is similar to static executable, but can be loaded at
2be09a
-     any address without help from a dynamic linker.  All static
2be09a
-     programs as well as static tests are built as static PIE, except
2be09a
-     for those marked with no-pie.  The resulting glibc can be used with
2be09a
-     the GCC option, -static-pie, which is available with GCC 8 or
2be09a
-     above, to create static PIE. This option also implies that glibc
2be09a
-     programs and tests are created as dynamic position independent
2be09a
-     executables (PIE) by default.
2be09a
+'--disable-default-pie'
2be09a
+     Don't build glibc programs and the testsuite as position
2be09a
+     independent executables (PIE). By default, glibc programs and tests
2be09a
+     are created as position independent executables on targets that
2be09a
+     support it.  If the toolchain and architecture support it, static
2be09a
+     executables are built as static PIE and the resulting glibc can be
2be09a
+     used with the GCC option, -static-pie, which is available with GCC
2be09a
+     8 or above, to create static PIE.
2be09a
 
2be09a
 '--enable-cet'
2be09a
 '--enable-cet=permissive'
2be09a
diff --git a/Makeconfig b/Makeconfig
2be09a
index 2fa0884b4eee5e53..8bc5540292c7b6fa 100644
2be09a
--- a/Makeconfig
2be09a
+++ b/Makeconfig
2be09a
@@ -1,4 +1,5 @@
2be09a
 # Copyright (C) 1991-2021 Free Software Foundation, Inc.
2be09a
+# Copyright (C) The GNU Toolchain Authors.
2be09a
 # This file is part of the GNU C Library.
2be09a
 
2be09a
 # The GNU C Library is free software; you can redistribute it and/or
2be09a
@@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
2be09a
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
2be09a
 endif
2be09a
 
2be09a
-ifeq (yes,$(enable-static-pie))
2be09a
+ifeq (no,$(build-pie-default))
2be09a
+pie-default = $(no-pie-ccflag)
2be09a
+else # build-pie-default
2be09a
 pic-default = -DPIC
2be09a
 # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
2be09a
 pie-default = $(pie-ccflag)
2be09a
+
2be09a
+ifeq (yes,$(enable-static-pie))
2be09a
 ifeq (yes,$(have-static-pie))
2be09a
-default-pie-ldflag = -static-pie
2be09a
+static-pie-ldflag = -static-pie
2be09a
 else
2be09a
 # Static PIE can't have dynamic relocations in read-only segments since
2be09a
 # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
2be09a
 # for PIE to support exception.
2be09a
-default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
2be09a
-endif
2be09a
-endif
2be09a
+static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
2be09a
+endif # have-static-pie
2be09a
+endif # enable-static-pie
2be09a
+endif # build-pie-default
2be09a
 
2be09a
 # If lazy relocations are disabled, add the -z now flag.  Use
2be09a
 # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
2be09a
@@ -444,7 +450,7 @@ endif
2be09a
 # Command for statically linking programs with the C library.
2be09a
 ifndef +link-static
2be09a
 +link-static-before-inputs = -nostdlib -nostartfiles -static \
2be09a
-	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
2be09a
+	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
2be09a
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
2be09a
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
2be09a
 	      $(+preinit) $(+prectorT)
2be09a
@@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
2be09a
 +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
2be09a
 +link-printers-tests = $(+link-pie-printers-tests)
2be09a
 else  # not build-pie-default
2be09a
-+link-before-inputs = -nostdlib -nostartfiles \
2be09a
++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
2be09a
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
2be09a
 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
2be09a
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
2be09a
@@ -1047,6 +1053,7 @@ PIC-ccflag = -fPIC
2be09a
 endif
2be09a
 # This can be changed by a sysdep makefile
2be09a
 pie-ccflag = -fpie
2be09a
+no-pie-ccflag = -fno-pie
2be09a
 # This one should always stay like this unless there is a very good reason.
2be09a
 PIE-ccflag = -fPIE
2be09a
 ifeq (yes,$(build-profile))
2be09a
diff --git a/config.h.in b/config.h.in
2be09a
index 8b45a3a61d774714..458342887e4e9380 100644
2be09a
--- a/config.h.in
2be09a
+++ b/config.h.in
2be09a
@@ -277,6 +277,9 @@
2be09a
 /* Build glibc with tunables support.  */
2be09a
 #define HAVE_TUNABLES 0
2be09a
 
2be09a
+/* Define if PIE is unsupported.  */
2be09a
+#undef PIE_UNSUPPORTED
2be09a
+
2be09a
 /* Define if static PIE is supported.  */
2be09a
 #undef SUPPORT_STATIC_PIE
2be09a
 
2be09a
diff --git a/config.make.in b/config.make.in
2be09a
index cbf59114b0b9ae4f..e8630a8d0ccf874d 100644
2be09a
--- a/config.make.in
2be09a
+++ b/config.make.in
2be09a
@@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
2be09a
 
2be09a
 # Configuration options.
2be09a
 build-shared = @shared@
2be09a
-build-pic-default= @libc_cv_pic_default@
2be09a
-build-pie-default= @libc_cv_pie_default@
2be09a
-cc-pie-default= @libc_cv_cc_pie_default@
2be09a
 build-profile = @profile@
2be09a
 build-static-nss = @static_nss@
2be09a
 cross-compiling = @cross_compiling@
2be09a
diff --git a/configure b/configure
2be09a
index 9619c10991d04362..e9d2b1f398c4dba0 100755
2be09a
--- a/configure
2be09a
+++ b/configure
2be09a
@@ -596,9 +596,6 @@ DEFINES
2be09a
 static_nss
2be09a
 profile
2be09a
 libc_cv_multidir
2be09a
-libc_cv_pie_default
2be09a
-libc_cv_cc_pie_default
2be09a
-libc_cv_pic_default
2be09a
 shared
2be09a
 static
2be09a
 ldd_rewrite_script
2be09a
@@ -767,7 +764,7 @@ with_nonshared_cflags
2be09a
 enable_sanity_checks
2be09a
 enable_shared
2be09a
 enable_profile
2be09a
-enable_static_pie
2be09a
+enable_default_pie
2be09a
 enable_timezone_tools
2be09a
 enable_hardcoded_path_in_tests
2be09a
 enable_hidden_plt
2be09a
@@ -1423,8 +1420,8 @@ Optional Features:
2be09a
                           in special situations) [default=yes]
2be09a
   --enable-shared         build shared library [default=yes if GNU ld]
2be09a
   --enable-profile        build profiled library [default=no]
2be09a
-  --enable-static-pie     enable static PIE support and use it in the
2be09a
-                          testsuite [default=no]
2be09a
+  --disable-default-pie   Do not build glibc programs and the testsuite as PIE
2be09a
+                          [default=no]
2be09a
   --disable-timezone-tools
2be09a
                           do not install timezone tools [default=install]
2be09a
   --enable-hardcoded-path-in-tests
2be09a
@@ -3408,11 +3405,11 @@ else
2be09a
   profile=no
2be09a
 fi
2be09a
 
2be09a
-# Check whether --enable-static-pie was given.
2be09a
-if test "${enable_static_pie+set}" = set; then :
2be09a
-  enableval=$enable_static_pie; static_pie=$enableval
2be09a
+# Check whether --enable-default-pie was given.
2be09a
+if test "${enable_default_pie+set}" = set; then :
2be09a
+  enableval=$enable_default_pie; default_pie=$enableval
2be09a
 else
2be09a
-  static_pie=no
2be09a
+  default_pie=yes
2be09a
 fi
2be09a
 
2be09a
 # Check whether --enable-timezone-tools was given.
2be09a
@@ -6912,7 +6909,8 @@ rm -f conftest.*
2be09a
 fi
2be09a
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
2be09a
 $as_echo "$libc_cv_pic_default" >&6; }
2be09a
-
2be09a
+config_vars="$config_vars
2be09a
+build-pic-default = $libc_cv_pic_default"
2be09a
 
2be09a
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
2be09a
 $as_echo_n "checking whether -fPIE is default... " >&6; }
2be09a
@@ -6932,17 +6930,37 @@ rm -f conftest.*
2be09a
 fi
2be09a
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
2be09a
 $as_echo "$libc_cv_cc_pie_default" >&6; }
2be09a
-libc_cv_pie_default=$libc_cv_cc_pie_default
2be09a
-
2be09a
-
2be09a
-
2be09a
-# Set the `multidir' variable by grabbing the variable from the compiler.
2be09a
-# We do it once and save the result in a generated makefile.
2be09a
-libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
2be09a
-
2be09a
+config_vars="$config_vars
2be09a
+cc-pie-default = $libc_cv_cc_pie_default"
2be09a
 
2be09a
-if test "$static_pie" = yes; then
2be09a
-  # Check target support for static PIE
2be09a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
2be09a
+$as_echo_n "checking if we can build programs as PIE... " >&6; }
2be09a
+if test "x$default_pie" != xno; then
2be09a
+  # Disable build-pie-default if target does not support it.
2be09a
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
2be09a
+/* end confdefs.h.  */
2be09a
+#ifdef PIE_UNSUPPORTED
2be09a
+# error PIE is not supported
2be09a
+#endif
2be09a
+_ACEOF
2be09a
+if ac_fn_c_try_compile "$LINENO"; then :
2be09a
+  libc_cv_pie_default=yes
2be09a
+else
2be09a
+  libc_cv_pie_default=no
2be09a
+fi
2be09a
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
2be09a
+fi
2be09a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
2be09a
+$as_echo "$libc_cv_pie_default" >&6; }
2be09a
+config_vars="$config_vars
2be09a
+build-pie-default = $libc_cv_pie_default"
2be09a
+
2be09a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
2be09a
+$as_echo_n "checking if we can build static PIE programs... " >&6; }
2be09a
+libc_cv_static_pie=$libc_cv_pie_default
2be09a
+if test "x$libc_cv_pie_default" != xno \
2be09a
+   -a "$libc_cv_no_dynamic_linker" = yes; then
2be09a
+  # Enable static-pie if available
2be09a
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
2be09a
 /* end confdefs.h.  */
2be09a
 #ifndef SUPPORT_STATIC_PIE
2be09a
@@ -6950,22 +6968,25 @@ if test "$static_pie" = yes; then
2be09a
 #endif
2be09a
 _ACEOF
2be09a
 if ac_fn_c_try_compile "$LINENO"; then :
2be09a
-
2be09a
+  libc_cv_static_pie=yes
2be09a
 else
2be09a
-  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
2be09a
+  libc_cv_static_pie=no
2be09a
 fi
2be09a
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
2be09a
-  # The linker must support --no-dynamic-linker.
2be09a
-  if test "$libc_cv_no_dynamic_linker" != yes; then
2be09a
-    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
2be09a
-  fi
2be09a
-  # Default to PIE.
2be09a
-  libc_cv_pie_default=yes
2be09a
-  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
2be09a
+  if test "$libc_cv_static_pie" = "yes"; then
2be09a
+    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
2be09a
 
2be09a
+  fi
2be09a
 fi
2be09a
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
2be09a
+$as_echo "$libc_cv_static_pie" >&6; }
2be09a
 config_vars="$config_vars
2be09a
-enable-static-pie = $static_pie"
2be09a
+enable-static-pie = $libc_cv_static_pie"
2be09a
+
2be09a
+# Set the `multidir' variable by grabbing the variable from the compiler.
2be09a
+# We do it once and save the result in a generated makefile.
2be09a
+libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
2be09a
+
2be09a
 
2be09a
 
2be09a
 
2be09a
diff --git a/configure.ac b/configure.ac
2be09a
index 34ecbba540546337..79f6822d29ce21cf 100644
2be09a
--- a/configure.ac
2be09a
+++ b/configure.ac
2be09a
@@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
2be09a
 			     [build profiled library @<:@default=no@:>@]),
2be09a
 	      [profile=$enableval],
2be09a
 	      [profile=no])
2be09a
-AC_ARG_ENABLE([static-pie],
2be09a
-	      AS_HELP_STRING([--enable-static-pie],
2be09a
-			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
2be09a
-	      [static_pie=$enableval],
2be09a
-	      [static_pie=no])
2be09a
+AC_ARG_ENABLE([default-pie],
2be09a
+	      AS_HELP_STRING([--disable-default-pie],
2be09a
+			     [Do not build glibc programs and the testsuite as PIE @<:@default=no@:>@]),
2be09a
+	      [default_pie=$enableval],
2be09a
+	      [default_pie=yes])
2be09a
 AC_ARG_ENABLE([timezone-tools],
2be09a
 	      AS_HELP_STRING([--disable-timezone-tools],
2be09a
 			     [do not install timezone tools @<:@default=install@:>@]),
2be09a
@@ -1856,7 +1856,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
2be09a
   libc_cv_pic_default=no
2be09a
 fi
2be09a
 rm -f conftest.*])
2be09a
-AC_SUBST(libc_cv_pic_default)
2be09a
+LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
2be09a
 
2be09a
 AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
2be09a
 [libc_cv_cc_pie_default=yes
2be09a
@@ -1869,30 +1869,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
2be09a
   libc_cv_cc_pie_default=no
2be09a
 fi
2be09a
 rm -f conftest.*])
2be09a
-libc_cv_pie_default=$libc_cv_cc_pie_default
2be09a
-AC_SUBST(libc_cv_cc_pie_default)
2be09a
-AC_SUBST(libc_cv_pie_default)
2be09a
+LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
2be09a
+
2be09a
+AC_MSG_CHECKING(if we can build programs as PIE)
2be09a
+if test "x$default_pie" != xno; then
2be09a
+  # Disable build-pie-default if target does not support it.
2be09a
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
2be09a
+# error PIE is not supported
2be09a
+#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
2be09a
+fi
2be09a
+AC_MSG_RESULT($libc_cv_pie_default)
2be09a
+LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
2be09a
+
2be09a
+AC_MSG_CHECKING(if we can build static PIE programs)
2be09a
+libc_cv_static_pie=$libc_cv_pie_default
2be09a
+if test "x$libc_cv_pie_default" != xno \
2be09a
+   -a "$libc_cv_no_dynamic_linker" = yes; then
2be09a
+  # Enable static-pie if available
2be09a
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
2be09a
+# error static PIE is not supported
2be09a
+#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
2be09a
+  if test "$libc_cv_static_pie" = "yes"; then
2be09a
+    AC_DEFINE(ENABLE_STATIC_PIE)
2be09a
+  fi
2be09a
+fi
2be09a
+AC_MSG_RESULT($libc_cv_static_pie)
2be09a
+LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
2be09a
 
2be09a
 # Set the `multidir' variable by grabbing the variable from the compiler.
2be09a
 # We do it once and save the result in a generated makefile.
2be09a
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
2be09a
 AC_SUBST(libc_cv_multidir)
2be09a
 
2be09a
-if test "$static_pie" = yes; then
2be09a
-  # Check target support for static PIE
2be09a
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
2be09a
-# error static PIE is not supported
2be09a
-#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
2be09a
-  # The linker must support --no-dynamic-linker.
2be09a
-  if test "$libc_cv_no_dynamic_linker" != yes; then
2be09a
-    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
2be09a
-  fi
2be09a
-  # Default to PIE.
2be09a
-  libc_cv_pie_default=yes
2be09a
-  AC_DEFINE(ENABLE_STATIC_PIE)
2be09a
-fi
2be09a
-LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
2be09a
-
2be09a
 AC_SUBST(profile)
2be09a
 AC_SUBST(static_nss)
2be09a
 
2be09a
diff --git a/manual/install.texi b/manual/install.texi
2be09a
index 46f73b538d3fee6f..1320ac69b3c645f2 100644
2be09a
--- a/manual/install.texi
2be09a
+++ b/manual/install.texi
2be09a
@@ -141,15 +141,13 @@ Don't build shared libraries even if it is possible.  Not all systems
2be09a
 support shared libraries; you need ELF support and (currently) the GNU
2be09a
 linker.
2be09a
 
2be09a
-@item --enable-static-pie
2be09a
-Enable static position independent executable (static PIE) support.
2be09a
-Static PIE is similar to static executable, but can be loaded at any
2be09a
-address without help from a dynamic linker.  All static programs as
2be09a
-well as static tests are built as static PIE, except for those marked
2be09a
-with no-pie.  The resulting glibc can be used with the GCC option,
2be09a
--static-pie, which is available with GCC 8 or above, to create static
2be09a
-PIE.  This option also implies that glibc programs and tests are created
2be09a
-as dynamic position independent executables (PIE) by default.
2be09a
+@item --disable-default-pie
2be09a
+Don't build glibc programs and the testsuite as position independent
2be09a
+executables (PIE).  By default, glibc programs and tests are created as
2be09a
+position independent executables on targets that support it.  If the toolchain
2be09a
+and architecture support it, static executables are built as static PIE and the
2be09a
+resulting glibc can be used with the GCC option, -static-pie, which is
2be09a
+available with GCC 8 or above, to create static PIE.
2be09a
 
2be09a
 @item --enable-cet
2be09a
 @itemx --enable-cet=permissive
2be09a
diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
2be09a
index 86537fa8005cfd3d..2fd82a5d054c51ca 100755
2be09a
--- a/scripts/build-many-glibcs.py
2be09a
+++ b/scripts/build-many-glibcs.py
2be09a
@@ -1,6 +1,7 @@
2be09a
 #!/usr/bin/python3
2be09a
 # Build many configurations of glibc.
2be09a
 # Copyright (C) 2016-2021 Free Software Foundation, Inc.
2be09a
+# Copyright (C) The GNU Toolchain Authors.
2be09a
 # This file is part of the GNU C Library.
2be09a
 #
2be09a
 # The GNU C Library is free software; you can redistribute it and/or
2be09a
@@ -435,15 +436,15 @@ class Context(object):
2be09a
                                                '--disable-experimental-malloc',
2be09a
                                                '--disable-build-nscd',
2be09a
                                                '--disable-nscd']},
2be09a
-                                      {'variant': 'static-pie',
2be09a
-                                       'cfg': ['--enable-static-pie']},
2be09a
-                                      {'variant': 'x32-static-pie',
2be09a
+                                      {'variant': 'no-pie',
2be09a
+                                       'cfg': ['--disable-default-pie']},
2be09a
+                                      {'variant': 'x32-no-pie',
2be09a
                                        'ccopts': '-mx32',
2be09a
-                                       'cfg': ['--enable-static-pie']},
2be09a
-                                      {'variant': 'static-pie',
2be09a
+                                       'cfg': ['--disable-default-pie']},
2be09a
+                                      {'variant': 'no-pie',
2be09a
                                        'arch': 'i686',
2be09a
                                        'ccopts': '-m32 -march=i686',
2be09a
-                                       'cfg': ['--enable-static-pie']},
2be09a
+                                       'cfg': ['--disable-default-pie']},
2be09a
                                       {'variant': 'disable-multi-arch',
2be09a
                                        'arch': 'i686',
2be09a
                                        'ccopts': '-m32 -march=i686',
2be09a
diff --git a/sysdeps/alpha/configure b/sysdeps/alpha/configure
2be09a
index 464b5965276dca19..3d665d96f2b40c4e 100644
2be09a
--- a/sysdeps/alpha/configure
2be09a
+++ b/sysdeps/alpha/configure
2be09a
@@ -5,4 +5,9 @@
2be09a
 # symbols in a position independent way.
2be09a
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
2be09a
 
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
 # work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/alpha/configure.ac b/sysdeps/alpha/configure.ac
2be09a
index 38e52e71ac2a5bc0..8f9a39ed2e4a29cb 100644
2be09a
--- a/sysdeps/alpha/configure.ac
2be09a
+++ b/sysdeps/alpha/configure.ac
2be09a
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2be09a
 # With required gcc+binutils, we can always access static and hidden
2be09a
 # symbols in a position independent way.
2be09a
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
 # work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
2be09a
index 19acb084fb43d9ea..27464eb707ebd6c6 100644
2be09a
--- a/sysdeps/csky/configure
2be09a
+++ b/sysdeps/csky/configure
2be09a
@@ -2,3 +2,10 @@
2be09a
  # Local configure fragment for sysdeps/csky.
2be09a
 
2be09a
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
2be09a
+
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
2be09a
index 5656b665da698d05..8e008249094d9e5a 100644
2be09a
--- a/sysdeps/csky/configure.ac
2be09a
+++ b/sysdeps/csky/configure.ac
2be09a
@@ -2,3 +2,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2be09a
 # Local configure fragment for sysdeps/csky.
2be09a
 
2be09a
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
2be09a
index 2cfe6cbea14549d0..cf5acf966dad67ba 100644
2be09a
--- a/sysdeps/hppa/configure
2be09a
+++ b/sysdeps/hppa/configure
2be09a
@@ -30,3 +30,10 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
2be09a
 cat >>confdefs.h <<_ACEOF
2be09a
 #define ASM_LINE_SEP $libc_cv_asm_line_sep
2be09a
 _ACEOF
2be09a
+
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
2be09a
index 1ec417b9474c3382..3e1c35bbd992f548 100644
2be09a
--- a/sysdeps/hppa/configure.ac
2be09a
+++ b/sysdeps/hppa/configure.ac
2be09a
@@ -19,3 +19,8 @@ else
2be09a
 fi
2be09a
 rm -f conftest*])
2be09a
 AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
2be09a
index 1ef70921bc5266db..748cb526012adeb8 100644
2be09a
--- a/sysdeps/ia64/configure
2be09a
+++ b/sysdeps/ia64/configure
2be09a
@@ -3,4 +3,9 @@
2be09a
 
2be09a
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
2be09a
 
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
 # work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
2be09a
index 3bae9fc5e1a3ff45..8e5fba32c3ec8bfc 100644
2be09a
--- a/sysdeps/ia64/configure.ac
2be09a
+++ b/sysdeps/ia64/configure.ac
2be09a
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2be09a
 dnl It is always possible to access static and hidden symbols in an
2be09a
 dnl position independent way.
2be09a
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
2be09a
+
2be09a
+# PIE builds fail on binutils 2.37 and earlier, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
 # work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
2be09a
index 8d0702ad438d1c0a..3303e5dff8ef5ecf 100644
2be09a
--- a/sysdeps/mach/hurd/configure
2be09a
+++ b/sysdeps/mach/hurd/configure
2be09a
@@ -49,3 +49,9 @@ fi
2be09a
 
2be09a
 # Hurd has libpthread as a separate library.
2be09a
 pthread_in_libc=no
2be09a
+
2be09a
+# Hurd build needs to be updated to support static pie, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
2be09a
index 82d085af33701aa2..022c2eff79fc0d08 100644
2be09a
--- a/sysdeps/mach/hurd/configure.ac
2be09a
+++ b/sysdeps/mach/hurd/configure.ac
2be09a
@@ -29,3 +29,8 @@ fi
2be09a
 
2be09a
 # Hurd has libpthread as a separate library.
2be09a
 pthread_in_libc=no
2be09a
+
2be09a
+# Hurd build needs to be updated to support static pie, see:
2be09a
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
2be09a
new file mode 100755
2be09a
index 0000000000000000..e6652562d212b688
2be09a
--- /dev/null
2be09a
+++ b/sysdeps/microblaze/configure
2be09a
@@ -0,0 +1,8 @@
2be09a
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
2be09a
+ # Local configure fragment for sysdeps/microblaze.
2be09a
+
2be09a
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
2be09a
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
2be09a
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
2be09a
+
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
2be09a
new file mode 100644
2be09a
index 0000000000000000..1c58f70a7bdfebcb
2be09a
--- /dev/null
2be09a
+++ b/sysdeps/microblaze/configure.ac
2be09a
@@ -0,0 +1,7 @@
2be09a
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2be09a
+# Local configure fragment for sysdeps/microblaze.
2be09a
+
2be09a
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
2be09a
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
2be09a
+AC_DEFINE(PIE_UNSUPPORTED)
2be09a
+# work around problem with autoconf and empty lines at the end of files
2be09a
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
2be09a
index 1be9a3db2ca12216..12c2c1b085fd4ae2 100644
2be09a
--- a/sysdeps/sparc/Makefile
2be09a
+++ b/sysdeps/sparc/Makefile
2be09a
@@ -2,6 +2,7 @@
2be09a
 long-double-fcts = yes
2be09a
 
2be09a
 pie-ccflag = -fPIE
2be09a
+no-pie-ccflag = -fno-PIE
2be09a
 
2be09a
 ifeq ($(subdir),gmon)
2be09a
 sysdep_routines += sparc-mcount