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