public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Replace --enable-static-pie with --disable-default-pie
@ 2021-12-07  8:26 Siddhesh Poyarekar
  2021-12-07 16:06 ` Florian Weimer
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-07  8:26 UTC (permalink / raw)
  To: libc-alpha; +Cc: fweimer

Build glibc programs and tests as PIE by default and enable static-pie
automatically if the architecture and toolchain supports it.

Also add a new configuration option --disable-default-pie to prevent
building programs as PIE.

Only the following architectures now have PIE disabled by default
because they do not work at the moment.  hppa, ia64 and csky don't work
because the linker is unable to handle a pcrel relocation generated from
PIE objects.  The microblaze compiler is currently failing with an ICE.
GNU hurd tries to enable static-pie, which does not work and hence
fails.  It could be made to work, but I've left the enabling for the
Hurd maintainer.  build-many-glibcs runs clean for all targets now;
following are the failures before disabling PIE for these targets.  I
also tested x86_64 on Fedora and Ubuntu, to verify that the default
build as well as --disable-default-pie work as expected with both system
toolchains.

FAIL: glibcs-microblazeel-linux-gnu check
ICE

FAIL: glibcs-csky-linux-gnuabiv2-soft check
build-many-2/build/glibcs/csky-linux-gnuabiv2-soft/glibc/math/test-tgmath2.o: in function `main':
build-many-2/src/glibc/math/../support/test-driver.c:124:(.text.startup+0x24): relocation truncated to fit: R_CKCORE_PCREL_IMM18BY2 against `.text'

FAIL: glibcs-csky-linux-gnuabiv2 check
/tmp/ccaEAi1b.s: Assembler messages:
/tmp/ccaEAi1b.s:409254: Error: pcrel offset for branch to <unknown> too far (0xfffffffffffc44a1)
make[3]: *** [../o-iterator.mk:9: build-many-2/build/glibcs/csky-linux-gnuabiv2/glibc/math/test-tgmath3-fma.o] Error 1

FAIL: glibcs-ia64-linux-gnu build
build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `_dl_aux_init':
build-many-2/src/glibc/elf/dl-support.c:254:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `setup_vdso':
build-many-2/src/glibc/elf/setup-vdso.h:108:(.text+0x1092): relocation truncated to fit: GPREL22 against `.text'

FAIL: glibcs-microblaze-linux-gnu check
ICE

FAIL: glibcs-hppa-linux-gnu check
build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot reach 0000004f_retNum6056+0, recompile with -ffunction-sections
build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot handle R_PARISC_PCREL17F for retNum6056
build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: final link failed: bad value

FAIL: glibcs-i686-gnu build
build-many-2/install/compilers/i686-gnu/lib/gcc/i686-glibc-gnu/11.2.1/../../../../i686-glibc-gnu/bin/ld: cannot find build-many-2/build/glibcs/i686-gnu/glibc/csu/rcrt0.o: No such file or directory
collect2: error: ld returned 1 exit status
make[3]: *** [../Rules:269: build-many-2/build/glibcs/i686-gnu/glibc/support/test-run-command] Error 1

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
 INSTALL                         | 19 ++++----
 Makeconfig                      | 21 ++++++---
 NEWS                            | 12 +++++
 config.h.in                     |  3 ++
 config.make.in                  |  3 --
 configure                       | 83 +++++++++++++++++++++------------
 configure.ac                    | 56 ++++++++++++----------
 manual/install.texi             | 17 ++++---
 scripts/build-many-glibcs.py    | 12 ++---
 sysdeps/csky/configure          |  6 +++
 sysdeps/csky/configure.ac       |  4 ++
 sysdeps/hppa/configure          |  6 +++
 sysdeps/hppa/configure.ac       |  4 ++
 sysdeps/ia64/configure          |  4 ++
 sysdeps/ia64/configure.ac       |  3 ++
 sysdeps/mach/hurd/configure     |  5 ++
 sysdeps/mach/hurd/configure.ac  |  4 ++
 sysdeps/microblaze/configure    |  7 +++
 sysdeps/microblaze/configure.ac |  6 +++
 sysdeps/sparc/Makefile          |  1 +
 20 files changed, 186 insertions(+), 90 deletions(-)
 create mode 100755 sysdeps/microblaze/configure
 create mode 100644 sysdeps/microblaze/configure.ac

diff --git a/INSTALL b/INSTALL
index 02dcf6b1ca..56d2a31dad 100644
--- a/INSTALL
+++ b/INSTALL
@@ -111,16 +111,15 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
      systems support shared libraries; you need ELF support and
      (currently) the GNU linker.
 
-'--enable-static-pie'
-     Enable static position independent executable (static PIE) support.
-     Static PIE is similar to static executable, but can be loaded at
-     any address without help from a dynamic linker.  All static
-     programs as well as static tests are built as static PIE, except
-     for those marked with no-pie.  The resulting glibc can be used with
-     the GCC option, -static-pie, which is available with GCC 8 or
-     above, to create static PIE. This option also implies that glibc
-     programs and tests are created as dynamic position independent
-     executables (PIE) by default.
+'--disable-default-pie'
+     Don't build glibc programs and tests in the testsuite as position
+     independent executables (PIE). By default, glibc programs and tests
+     are created as position independent executables.  If the toolchain
+     and architecture supports it, static executable are built as static
+     PIE and the resulting glibc can be used with the GCC option,
+     -static-pie, which is available with GCC 8 or above, to create
+     static PIE. PIE is not enabled by default on i686 GNU/Hurd, HPPA,
+     IA64, CSKY and Microblaze targets.
 
 '--enable-cet'
 '--enable-cet=permissive'
diff --git a/Makeconfig b/Makeconfig
index 3fa2f13003..775bf12b65 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1,4 +1,5 @@
 # Copyright (C) 1991-2021 Free Software Foundation, Inc.
+# Copyright (C) The GNU Toolchain Authors.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
 endif
 
-ifeq (yes,$(enable-static-pie))
+ifeq (no,$(build-pie-default))
+pie-default = $(no-pie-ccflag)
+else # build-pie-default
 pic-default = -DPIC
 # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
 pie-default = $(pie-ccflag)
+
+ifeq (yes,$(enable-static-pie))
 ifeq (yes,$(have-static-pie))
-default-pie-ldflag = -static-pie
+static-pie-ldflag = -static-pie
 else
 # Static PIE can't have dynamic relocations in read-only segments since
 # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
 # for PIE to support exception.
-default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
-endif
-endif
+static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
+endif # have-static-pie
+endif # enable-static-pie
+endif # build-pie-default
 
 # If lazy relocations are disabled, add the -z now flag.  Use
 # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
@@ -444,7 +450,7 @@ endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
 +link-static-before-inputs = -nostdlib -nostartfiles -static \
-	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
+	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
 	      $(+preinit) $(+prectorT)
@@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
 +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
 +link-printers-tests = $(+link-pie-printers-tests)
 else  # not build-pie-default
-+link-before-inputs = -nostdlib -nostartfiles \
++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
@@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
 endif
 # This can be changed by a sysdep makefile
 pie-ccflag = -fpie
+no-pie-ccflag = -fno-pie
 # This one should always stay like this unless there is a very good reason.
 PIE-ccflag = -fPIE
 ifeq (yes,$(build-profile))
diff --git a/NEWS b/NEWS
index f10971b180..f12f3ffde4 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,14 @@ Major new features:
   to be used by compilers for optimizing usage of 'memcmp' when its
   return value is only used for its boolean status.
 
+* All programs and tests in glibc are now built as position independent
+  executables (PIE) by default on architectures that support it.  Further, if
+  static-pie is available in the toolchain and the architecture, it is also
+  enabled and static programs also built as executable.  A new option
+  --disable-default-pie has been added to disable this behavior and get a
+  non-PIE build.  Default PIE is not supported on GNU Hurd, HPPA, IA64, CSKY
+  and Microblaze targets.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The r_version update in the debugger interface makes the glibc binary
@@ -80,6 +88,10 @@ Deprecated and removed features, and other changes affecting compatibility:
 
 * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
 
+* The --enable-static-pie option is no longer available.  The glibc build
+  configuration script now automatically detects static-pie support in the
+  toolchain and architecture and enables it if available.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/config.h.in b/config.h.in
index 0a6f57b006..acce608373 100644
--- a/config.h.in
+++ b/config.h.in
@@ -265,6 +265,9 @@
 /* Build glibc with tunables support.  */
 #define HAVE_TUNABLES 0
 
+/* Define if PIE is unsupported.  */
+#undef PIE_UNSUPPORTED
+
 /* Define if static PIE is supported.  */
 #undef SUPPORT_STATIC_PIE
 
diff --git a/config.make.in b/config.make.in
index cbf59114b0..e8630a8d0c 100644
--- a/config.make.in
+++ b/config.make.in
@@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
 
 # Configuration options.
 build-shared = @shared@
-build-pic-default= @libc_cv_pic_default@
-build-pie-default= @libc_cv_pie_default@
-cc-pie-default= @libc_cv_cc_pie_default@
 build-profile = @profile@
 build-static-nss = @static_nss@
 cross-compiling = @cross_compiling@
diff --git a/configure b/configure
index 2f9adca064..4dce154938 100755
--- a/configure
+++ b/configure
@@ -596,9 +596,6 @@ DEFINES
 static_nss
 profile
 libc_cv_multidir
-libc_cv_pie_default
-libc_cv_cc_pie_default
-libc_cv_pic_default
 shared
 static
 ldd_rewrite_script
@@ -767,7 +764,7 @@ with_nonshared_cflags
 enable_sanity_checks
 enable_shared
 enable_profile
-enable_static_pie
+enable_default_pie
 enable_timezone_tools
 enable_hardcoded_path_in_tests
 enable_hidden_plt
@@ -1423,8 +1420,8 @@ Optional Features:
                           in special situations) [default=yes]
   --enable-shared         build shared library [default=yes if GNU ld]
   --enable-profile        build profiled library [default=no]
-  --enable-static-pie     enable static PIE support and use it in the
-                          testsuite [default=no]
+  --disable-default-pie   Do not build glibc programs and tests in the
+                          testsuite as PIE [default=no]
   --disable-timezone-tools
                           do not install timezone tools [default=install]
   --enable-hardcoded-path-in-tests
@@ -3408,11 +3405,11 @@ else
   profile=no
 fi
 
-# Check whether --enable-static-pie was given.
-if test "${enable_static_pie+set}" = set; then :
-  enableval=$enable_static_pie; static_pie=$enableval
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; default_pie=$enableval
 else
-  static_pie=no
+  default_pie=yes
 fi
 
 # Check whether --enable-timezone-tools was given.
@@ -6959,7 +6956,8 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
 $as_echo "$libc_cv_pic_default" >&6; }
-
+config_vars="$config_vars
+build-pic-default = $libc_cv_pic_default"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
 $as_echo_n "checking whether -fPIE is default... " >&6; }
@@ -6979,17 +6977,37 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
 $as_echo "$libc_cv_cc_pie_default" >&6; }
-libc_cv_pie_default=$libc_cv_cc_pie_default
-
-
-
-# Set the `multidir' variable by grabbing the variable from the compiler.
-# We do it once and save the result in a generated makefile.
-libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
-
+config_vars="$config_vars
+cc-pie-default = $libc_cv_cc_pie_default"
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
+$as_echo_n "checking if we can build programs as PIE... " >&6; }
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libc_cv_pie_default=yes
+else
+  libc_cv_pie_default=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
+$as_echo "$libc_cv_pie_default" >&6; }
+config_vars="$config_vars
+build-pie-default = $libc_cv_pie_default"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
+$as_echo_n "checking if we can build static PIE programs... " >&6; }
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #ifndef SUPPORT_STATIC_PIE
@@ -6997,22 +7015,25 @@ if test "$static_pie" = yes; then
 #endif
 _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
-
+  libc_cv_static_pie=yes
 else
-  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
+  libc_cv_static_pie=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
+  if test "$libc_cv_static_pie" = "yes"; then
+    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
 
+  fi
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
+$as_echo "$libc_cv_static_pie" >&6; }
 config_vars="$config_vars
-enable-static-pie = $static_pie"
+enable-static-pie = $libc_cv_static_pie"
+
+# Set the `multidir' variable by grabbing the variable from the compiler.
+# We do it once and save the result in a generated makefile.
+libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
+
 
 
 
diff --git a/configure.ac b/configure.ac
index 7eb4239359..55d3162a4d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
 			     [build profiled library @<:@default=no@:>@]),
 	      [profile=$enableval],
 	      [profile=no])
-AC_ARG_ENABLE([static-pie],
-	      AS_HELP_STRING([--enable-static-pie],
-			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
-	      [static_pie=$enableval],
-	      [static_pie=no])
+AC_ARG_ENABLE([default-pie],
+	      AS_HELP_STRING([--disable-default-pie],
+			     [Do not build glibc programs and tests in the testsuite as PIE @<:@default=no@:>@]),
+	      [default_pie=$enableval],
+	      [default_pie=yes])
 AC_ARG_ENABLE([timezone-tools],
 	      AS_HELP_STRING([--disable-timezone-tools],
 			     [do not install timezone tools @<:@default=install@:>@]),
@@ -1839,7 +1839,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_pic_default=no
 fi
 rm -f conftest.*])
-AC_SUBST(libc_cv_pic_default)
+LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
 
 AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
 [libc_cv_cc_pie_default=yes
@@ -1852,30 +1852,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_cc_pie_default=no
 fi
 rm -f conftest.*])
-libc_cv_pie_default=$libc_cv_cc_pie_default
-AC_SUBST(libc_cv_cc_pie_default)
-AC_SUBST(libc_cv_pie_default)
+LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
+
+AC_MSG_CHECKING(if we can build programs as PIE)
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
+fi
+AC_MSG_RESULT($libc_cv_pie_default)
+LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
+
+AC_MSG_CHECKING(if we can build static PIE programs)
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
+# error static PIE is not supported
+#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
+  if test "$libc_cv_static_pie" = "yes"; then
+    AC_DEFINE(ENABLE_STATIC_PIE)
+  fi
+fi
+AC_MSG_RESULT($libc_cv_static_pie)
+LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
 
 # Set the `multidir' variable by grabbing the variable from the compiler.
 # We do it once and save the result in a generated makefile.
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
 AC_SUBST(libc_cv_multidir)
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
-# error static PIE is not supported
-#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  AC_DEFINE(ENABLE_STATIC_PIE)
-fi
-LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
-
 AC_SUBST(profile)
 AC_SUBST(static_nss)
 
diff --git a/manual/install.texi b/manual/install.texi
index 46f73b538d..dff20fefa1 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -141,15 +141,14 @@ Don't build shared libraries even if it is possible.  Not all systems
 support shared libraries; you need ELF support and (currently) the GNU
 linker.
 
-@item --enable-static-pie
-Enable static position independent executable (static PIE) support.
-Static PIE is similar to static executable, but can be loaded at any
-address without help from a dynamic linker.  All static programs as
-well as static tests are built as static PIE, except for those marked
-with no-pie.  The resulting glibc can be used with the GCC option,
--static-pie, which is available with GCC 8 or above, to create static
-PIE.  This option also implies that glibc programs and tests are created
-as dynamic position independent executables (PIE) by default.
+@item --disable-default-pie
+Don't build glibc programs and tests in the testsuite as position independent
+executables (PIE).  By default, glibc programs and tests are created as
+position independent executables.  If the toolchain and architecture supports
+it, static executable are built as static PIE and the resulting glibc can be
+used with the GCC option, -static-pie, which is available with GCC 8 or above,
+to create static PIE.  PIE is not enabled by default on i686 GNU/Hurd, HPPA,
+IA64, CSKY and Microblaze targets.
 
 @item --enable-cet
 @itemx --enable-cet=permissive
diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 6ae2172956..89bd06881f 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -437,15 +437,15 @@ class Context(object):
                                                '--disable-experimental-malloc',
                                                '--disable-build-nscd',
                                                '--disable-nscd']},
-                                      {'variant': 'static-pie',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'x32-static-pie',
+                                      {'variant': 'no-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'x32-no-pie',
                                        'ccopts': '-mx32',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'static-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'no-pie',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
-                                       'cfg': ['--enable-static-pie']},
+                                       'cfg': ['--disable-default-pie']},
                                       {'variant': 'disable-multi-arch',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
index 19acb084fb..08caa633b1 100644
--- a/sysdeps/csky/configure
+++ b/sysdeps/csky/configure
@@ -2,3 +2,9 @@
  # Local configure fragment for sysdeps/csky.
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
+
+
+# PIE builds don't work.
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
index 5656b665da..9613c68338 100644
--- a/sysdeps/csky/configure.ac
+++ b/sysdeps/csky/configure.ac
@@ -2,3 +2,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/csky.
 
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds don't work.
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
index 2cfe6cbea1..1a0530ef9f 100644
--- a/sysdeps/hppa/configure
+++ b/sysdeps/hppa/configure
@@ -30,3 +30,9 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
 cat >>confdefs.h <<_ACEOF
 #define ASM_LINE_SEP $libc_cv_asm_line_sep
 _ACEOF
+
+
+# PIE builds don't work.
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
index 1ec417b947..3aa5cde7ce 100644
--- a/sysdeps/hppa/configure.ac
+++ b/sysdeps/hppa/configure.ac
@@ -19,3 +19,7 @@ else
 fi
 rm -f conftest*])
 AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
+
+# PIE builds don't work.
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
index 1ef70921bc..c13b11d5af 100644
--- a/sysdeps/ia64/configure
+++ b/sysdeps/ia64/configure
@@ -3,4 +3,8 @@
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
+
+# PIE builds don't work.
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
index 3bae9fc5e1..8f16c49d4d 100644
--- a/sysdeps/ia64/configure.ac
+++ b/sysdeps/ia64/configure.ac
@@ -4,4 +4,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 dnl It is always possible to access static and hidden symbols in an
 dnl position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds don't work.
+AC_DEFINE(PIE_UNSUPPORTED)
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
index 8d0702ad43..1192a5261d 100644
--- a/sysdeps/mach/hurd/configure
+++ b/sysdeps/mach/hurd/configure
@@ -49,3 +49,8 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# PIE builds don't work.
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
index 82d085af33..115d809cec 100644
--- a/sysdeps/mach/hurd/configure.ac
+++ b/sysdeps/mach/hurd/configure.ac
@@ -29,3 +29,7 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# PIE builds don't work.
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
new file mode 100755
index 0000000000..2805a4568d
--- /dev/null
+++ b/sysdeps/microblaze/configure
@@ -0,0 +1,7 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/microblaze.
+
+# PIE builds don't work.
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
new file mode 100644
index 0000000000..3dce7167db
--- /dev/null
+++ b/sysdeps/microblaze/configure.ac
@@ -0,0 +1,6 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/microblaze.
+
+# PIE builds don't work.
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 1be9a3db2c..12c2c1b085 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -2,6 +2,7 @@
 long-double-fcts = yes
 
 pie-ccflag = -fPIE
+no-pie-ccflag = -fno-PIE
 
 ifeq ($(subdir),gmon)
 sysdep_routines += sparc-mcount
-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
@ 2021-12-07 16:06 ` Florian Weimer
  2021-12-07 16:21   ` Siddhesh Poyarekar
  2021-12-07 18:52 ` Joseph Myers
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: Florian Weimer @ 2021-12-07 16:06 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

* Siddhesh Poyarekar:

> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
>
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
>
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64 and csky don't work
> because the linker is unable to handle a pcrel relocation generated from
> PIE objects.  The microblaze compiler is currently failing with an ICE.
> GNU hurd tries to enable static-pie, which does not work and hence
> fails.  It could be made to work, but I've left the enabling for the
> Hurd maintainer.  build-many-glibcs runs clean for all targets now;
> following are the failures before disabling PIE for these targets.  I
> also tested x86_64 on Fedora and Ubuntu, to verify that the default
> build as well as --disable-default-pie work as expected with both system
> toolchains.

I see a “make check” failure on alpha:

/home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc.o: in function `do_test':
/home/bmg/src/glibc/math/test-misc.c:391:(.text+0x780): relocation truncated to fit: GPREL16 against `.rodata.cst16'
/home/bmg/src/glibc/math/test-misc.c:400:(.text+0x87c): relocation truncated to fit: GPREL16 against `.rodata.cst16'
/home/bmg/src/glibc/math/test-misc.c:705:(.text+0xda0): relocation truncated to fit: GPREL16 against `.rodata.cst16'
/home/bmg/src/glibc/math/test-misc.c:714:(.text+0xe90): relocation truncated to fit: GPREL16 against `.rodata.cst16'
collect2: error: ld returned 1 exit status
make[3]: *** [../Rules:230: /home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc] Error 1

This is with default build-many-glibcs.py.

The NEWS entry should mention that --enable-static-pie is now ignored
(and no longer necessary).

Thanks,
Florian


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07 16:06 ` Florian Weimer
@ 2021-12-07 16:21   ` Siddhesh Poyarekar
  2021-12-07 16:30     ` Florian Weimer
  0 siblings, 1 reply; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-07 16:21 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha

On 12/7/21 21:36, Florian Weimer wrote:
> * Siddhesh Poyarekar:
> 
>> Build glibc programs and tests as PIE by default and enable static-pie
>> automatically if the architecture and toolchain supports it.
>>
>> Also add a new configuration option --disable-default-pie to prevent
>> building programs as PIE.
>>
>> Only the following architectures now have PIE disabled by default
>> because they do not work at the moment.  hppa, ia64 and csky don't work
>> because the linker is unable to handle a pcrel relocation generated from
>> PIE objects.  The microblaze compiler is currently failing with an ICE.
>> GNU hurd tries to enable static-pie, which does not work and hence
>> fails.  It could be made to work, but I've left the enabling for the
>> Hurd maintainer.  build-many-glibcs runs clean for all targets now;
>> following are the failures before disabling PIE for these targets.  I
>> also tested x86_64 on Fedora and Ubuntu, to verify that the default
>> build as well as --disable-default-pie work as expected with both system
>> toolchains.
> 
> I see a “make check” failure on alpha:
> 
> /home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc.o: in function `do_test':
> /home/bmg/src/glibc/math/test-misc.c:391:(.text+0x780): relocation truncated to fit: GPREL16 against `.rodata.cst16'
> /home/bmg/src/glibc/math/test-misc.c:400:(.text+0x87c): relocation truncated to fit: GPREL16 against `.rodata.cst16'
> /home/bmg/src/glibc/math/test-misc.c:705:(.text+0xda0): relocation truncated to fit: GPREL16 against `.rodata.cst16'
> /home/bmg/src/glibc/math/test-misc.c:714:(.text+0xe90): relocation truncated to fit: GPREL16 against `.rodata.cst16'
> collect2: error: ld returned 1 exit status
> make[3]: *** [../Rules:230: /home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc] Error 1
> 
> This is with default build-many-glibcs.py.

My alpha `compilers` build had failed despite manually rebasing the 
binutils and gcc release branches.  That's similar to the hppa failure 
where the linker isn't able to handle a relative relocation.  I'll 
disable PIE for alpha too.

> The NEWS entry should mention that --enable-static-pie is now ignored
> (and no longer necessary).

I did mention it...

>  Deprecated and removed features, and other changes affecting compatibility:
>  
>  * The r_version update in the debugger interface makes the glibc binary
> @@ -80,6 +88,10 @@ Deprecated and removed features, and other changes affecting compatibility:
>  
>  * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
>  
> +* The --enable-static-pie option is no longer available.  The glibc build
> +  configuration script now automatically detects static-pie support in the
> +  toolchain and architecture and enables it if available.
> +
>  Changes to build and runtime requirements:
>  
>    [Add changes to build and runtime requirements here]

... but I just noticed the "Changes to build and runtime requirements" 
section.  Should I just consolidate the NEWS note into this section instead?

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07 16:21   ` Siddhesh Poyarekar
@ 2021-12-07 16:30     ` Florian Weimer
  0 siblings, 0 replies; 17+ messages in thread
From: Florian Weimer @ 2021-12-07 16:30 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha

* Siddhesh Poyarekar:

> On 12/7/21 21:36, Florian Weimer wrote:
>> * Siddhesh Poyarekar:
>> 
>>> Build glibc programs and tests as PIE by default and enable static-pie
>>> automatically if the architecture and toolchain supports it.
>>>
>>> Also add a new configuration option --disable-default-pie to prevent
>>> building programs as PIE.
>>>
>>> Only the following architectures now have PIE disabled by default
>>> because they do not work at the moment.  hppa, ia64 and csky don't work
>>> because the linker is unable to handle a pcrel relocation generated from
>>> PIE objects.  The microblaze compiler is currently failing with an ICE.
>>> GNU hurd tries to enable static-pie, which does not work and hence
>>> fails.  It could be made to work, but I've left the enabling for the
>>> Hurd maintainer.  build-many-glibcs runs clean for all targets now;
>>> following are the failures before disabling PIE for these targets.  I
>>> also tested x86_64 on Fedora and Ubuntu, to verify that the default
>>> build as well as --disable-default-pie work as expected with both system
>>> toolchains.
>> I see a “make check” failure on alpha:
>> /home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc.o: in
>> function `do_test':
>> /home/bmg/src/glibc/math/test-misc.c:391:(.text+0x780): relocation truncated to fit: GPREL16 against `.rodata.cst16'
>> /home/bmg/src/glibc/math/test-misc.c:400:(.text+0x87c): relocation truncated to fit: GPREL16 against `.rodata.cst16'
>> /home/bmg/src/glibc/math/test-misc.c:705:(.text+0xda0): relocation truncated to fit: GPREL16 against `.rodata.cst16'
>> /home/bmg/src/glibc/math/test-misc.c:714:(.text+0xe90): relocation truncated to fit: GPREL16 against `.rodata.cst16'
>> collect2: error: ld returned 1 exit status
>> make[3]: *** [../Rules:230: /home/bmg/build/glibcs/alpha-linux-gnu/glibc/math/test-misc] Error 1
>> This is with default build-many-glibcs.py.
>
> My alpha `compilers` build had failed despite manually rebasing the
> binutils and gcc release branches.  That's similar to the hppa failure 
> where the linker isn't able to handle a relative relocation.  I'll
> disable PIE for alpha too.

Thanks.

>> The NEWS entry should mention that --enable-static-pie is now ignored
>> (and no longer necessary).
>
> I did mention it...

Ah, okay, sorry.

Florian


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
  2021-12-07 16:06 ` Florian Weimer
@ 2021-12-07 18:52 ` Joseph Myers
  2021-12-07 20:13 ` Adhemerval Zanella
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 17+ messages in thread
From: Joseph Myers @ 2021-12-07 18:52 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: libc-alpha, fweimer

On Tue, 7 Dec 2021, Siddhesh Poyarekar via Libc-alpha wrote:

> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)

"don't work" isn't very helpful information.  For each such comment, 
please include the URL of a bug report (existing or new; against GCC, 
binutils or glibc as appropriate) for the actual problem seen, as well as 
mentioning "as of GCC 11" or "as of binutils 2.37" or similar in the 
comment, to make it easy for someone to check in future if the issue is 
known to be fixed.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
  2021-12-07 16:06 ` Florian Weimer
  2021-12-07 18:52 ` Joseph Myers
@ 2021-12-07 20:13 ` Adhemerval Zanella
  2021-12-08  4:34   ` Siddhesh Poyarekar
  2021-12-08  6:39 ` [PATCH v2] " Siddhesh Poyarekar
  2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
  4 siblings, 1 reply; 17+ messages in thread
From: Adhemerval Zanella @ 2021-12-07 20:13 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: fweimer



On 07/12/2021 05:26, Siddhesh Poyarekar via Libc-alpha wrote:
> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
> 
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
> 
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64 and csky don't work
> because the linker is unable to handle a pcrel relocation generated from
> PIE objects.  The microblaze compiler is currently failing with an ICE.
> GNU hurd tries to enable static-pie, which does not work and hence
> fails.  It could be made to work, but I've left the enabling for the
> Hurd maintainer.  build-many-glibcs runs clean for all targets now;
> following are the failures before disabling PIE for these targets.  I
> also tested x86_64 on Fedora and Ubuntu, to verify that the default
> build as well as --disable-default-pie work as expected with both system
> toolchains.
> 
> FAIL: glibcs-microblazeel-linux-gnu check
> ICE
> 
> FAIL: glibcs-csky-linux-gnuabiv2-soft check
> build-many-2/build/glibcs/csky-linux-gnuabiv2-soft/glibc/math/test-tgmath2.o: in function `main':
> build-many-2/src/glibc/math/../support/test-driver.c:124:(.text.startup+0x24): relocation truncated to fit: R_CKCORE_PCREL_IMM18BY2 against `.text'
> 
> FAIL: glibcs-csky-linux-gnuabiv2 check
> /tmp/ccaEAi1b.s: Assembler messages:
> /tmp/ccaEAi1b.s:409254: Error: pcrel offset for branch to <unknown> too far (0xfffffffffffc44a1)
> make[3]: *** [../o-iterator.mk:9: build-many-2/build/glibcs/csky-linux-gnuabiv2/glibc/math/test-tgmath3-fma.o] Error 1
> 
> FAIL: glibcs-ia64-linux-gnu build
> build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `_dl_aux_init':
> build-many-2/src/glibc/elf/dl-support.c:254:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
> build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `setup_vdso':
> build-many-2/src/glibc/elf/setup-vdso.h:108:(.text+0x1092): relocation truncated to fit: GPREL22 against `.text'
> 
> FAIL: glibcs-microblaze-linux-gnu check
> ICE
> 
> FAIL: glibcs-hppa-linux-gnu check
> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot reach 0000004f_retNum6056+0, recompile with -ffunction-sections
> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot handle R_PARISC_PCREL17F for retNum6056
> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: final link failed: bad value
> 
> FAIL: glibcs-i686-gnu build
> build-many-2/install/compilers/i686-gnu/lib/gcc/i686-glibc-gnu/11.2.1/../../../../i686-glibc-gnu/bin/ld: cannot find build-many-2/build/glibcs/i686-gnu/glibc/csu/rcrt0.o: No such file or directory
> collect2: error: ld returned 1 exit status
> make[3]: *** [../Rules:269: build-many-2/build/glibcs/i686-gnu/glibc/support/test-run-command] Error 1
> 
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
> ---
>  INSTALL                         | 19 ++++----
>  Makeconfig                      | 21 ++++++---
>  NEWS                            | 12 +++++
>  config.h.in                     |  3 ++
>  config.make.in                  |  3 --
>  configure                       | 83 +++++++++++++++++++++------------
>  configure.ac                    | 56 ++++++++++++----------
>  manual/install.texi             | 17 ++++---
>  scripts/build-many-glibcs.py    | 12 ++---
>  sysdeps/csky/configure          |  6 +++
>  sysdeps/csky/configure.ac       |  4 ++
>  sysdeps/hppa/configure          |  6 +++
>  sysdeps/hppa/configure.ac       |  4 ++
>  sysdeps/ia64/configure          |  4 ++
>  sysdeps/ia64/configure.ac       |  3 ++
>  sysdeps/mach/hurd/configure     |  5 ++
>  sysdeps/mach/hurd/configure.ac  |  4 ++
>  sysdeps/microblaze/configure    |  7 +++
>  sysdeps/microblaze/configure.ac |  6 +++
>  sysdeps/sparc/Makefile          |  1 +
>  20 files changed, 186 insertions(+), 90 deletions(-)
>  create mode 100755 sysdeps/microblaze/configure
>  create mode 100644 sysdeps/microblaze/configure.ac
> 
> diff --git a/INSTALL b/INSTALL
> index 02dcf6b1ca..56d2a31dad 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -111,16 +111,15 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
>       systems support shared libraries; you need ELF support and
>       (currently) the GNU linker.
>  
> -'--enable-static-pie'
> -     Enable static position independent executable (static PIE) support.
> -     Static PIE is similar to static executable, but can be loaded at
> -     any address without help from a dynamic linker.  All static
> -     programs as well as static tests are built as static PIE, except
> -     for those marked with no-pie.  The resulting glibc can be used with
> -     the GCC option, -static-pie, which is available with GCC 8 or
> -     above, to create static PIE. This option also implies that glibc
> -     programs and tests are created as dynamic position independent
> -     executables (PIE) by default.
> +'--disable-default-pie'
> +     Don't build glibc programs and tests in the testsuite as position

'tests in the testsuite' sounds redundat, maybe only 'testsuite'.

> +     independent executables (PIE). By default, glibc programs and tests

Double space after period.

> +     are created as position independent executables.  If the toolchain
> +     and architecture supports it, static executable are built as static

I think it should be 'support' here and I also think it should be 'executables'.

> +     PIE and the resulting glibc can be used with the GCC option,
> +     -static-pie, which is available with GCC 8 or above, to create
> +     static PIE. PIE is not enabled by default on i686 GNU/Hurd, HPPA,
> +     IA64, CSKY and Microblaze targets.

Maybe not to reference which architecture are not supported? Otherwise we
will need to keep in sync and add a mark it should be updated.

>  
>  '--enable-cet'
>  '--enable-cet=permissive'
> diff --git a/Makeconfig b/Makeconfig
> index 3fa2f13003..775bf12b65 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -1,4 +1,5 @@
>  # Copyright (C) 1991-2021 Free Software Foundation, Inc.
> +# Copyright (C) The GNU Toolchain Authors.
>  # This file is part of the GNU C Library.
>  
>  # The GNU C Library is free software; you can redistribute it and/or

Can we re-license the file?

> @@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
>  LDFLAGS-rtld += $(hashstyle-LDFLAGS)
>  endif
>  
> -ifeq (yes,$(enable-static-pie))
> +ifeq (no,$(build-pie-default))
> +pie-default = $(no-pie-ccflag)
> +else # build-pie-default
>  pic-default = -DPIC
>  # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
>  pie-default = $(pie-ccflag)
> +
> +ifeq (yes,$(enable-static-pie))
>  ifeq (yes,$(have-static-pie))
> -default-pie-ldflag = -static-pie
> +static-pie-ldflag = -static-pie
>  else
>  # Static PIE can't have dynamic relocations in read-only segments since
>  # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
>  # for PIE to support exception.
> -default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
> -endif
> -endif
> +static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
> +endif # have-static-pie
> +endif # enable-static-pie
> +endif # build-pie-default
>  
>  # If lazy relocations are disabled, add the -z now flag.  Use
>  # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
> @@ -444,7 +450,7 @@ endif
>  # Command for statically linking programs with the C library.
>  ifndef +link-static
>  +link-static-before-inputs = -nostdlib -nostartfiles -static \
> -	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
> +	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
>  	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
>  	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
>  	      $(+preinit) $(+prectorT)
> @@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
>  +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
>  +link-printers-tests = $(+link-pie-printers-tests)
>  else  # not build-pie-default
> -+link-before-inputs = -nostdlib -nostartfiles \
> ++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
>  	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
>  	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
>  	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
> @@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
>  endif
>  # This can be changed by a sysdep makefile
>  pie-ccflag = -fpie
> +no-pie-ccflag = -fno-pie
>  # This one should always stay like this unless there is a very good reason.
>  PIE-ccflag = -fPIE
>  ifeq (yes,$(build-profile))
> diff --git a/NEWS b/NEWS
> index f10971b180..f12f3ffde4 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -68,6 +68,14 @@ Major new features:
>    to be used by compilers for optimizing usage of 'memcmp' when its
>    return value is only used for its boolean status.
>  
> +* All programs and tests in glibc are now built as position independent
> +  executables (PIE) by default on architectures that support it.  Further, if

Maybe state that if both architecture and toolchain support it.

> +  static-pie is available in the toolchain and the architecture, it is also
> +  enabled and static programs also built as executable.  A new option

Maybe 'are also'?  And state that --enable-static-pie is not replaced with
--disable-default-pie.

> +  --disable-default-pie has been added to disable this behavior and get a
> +  non-PIE build.  Default PIE is not supported on GNU Hurd, HPPA, IA64, CSKY
> +  and Microblaze targets.
> +
>  Deprecated and removed features, and other changes affecting compatibility:
>  
>  * The r_version update in the debugger interface makes the glibc binary
> @@ -80,6 +88,10 @@ Deprecated and removed features, and other changes affecting compatibility:
>  
>  * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
>  
> +* The --enable-static-pie option is no longer available.  The glibc build
> +  configuration script now automatically detects static-pie support in the
> +  toolchain and architecture and enables it if available.
> +
>  Changes to build and runtime requirements:
>  
>    [Add changes to build and runtime requirements here]
> diff --git a/config.h.in b/config.h.in
> index 0a6f57b006..acce608373 100644
> --- a/config.h.in
> +++ b/config.h.in
> @@ -265,6 +265,9 @@
>  /* Build glibc with tunables support.  */
>  #define HAVE_TUNABLES 0
>  
> +/* Define if PIE is unsupported.  */
> +#undef PIE_UNSUPPORTED
> +
>  /* Define if static PIE is supported.  */
>  #undef SUPPORT_STATIC_PIE
>  
> diff --git a/config.make.in b/config.make.in
> index cbf59114b0..e8630a8d0c 100644
> --- a/config.make.in
> +++ b/config.make.in
> @@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
>  
>  # Configuration options.
>  build-shared = @shared@
> -build-pic-default= @libc_cv_pic_default@
> -build-pie-default= @libc_cv_pie_default@
> -cc-pie-default= @libc_cv_cc_pie_default@
>  build-profile = @profile@
>  build-static-nss = @static_nss@
>  cross-compiling = @cross_compiling@
> diff --git a/configure b/configure
> index 2f9adca064..4dce154938 100755
> --- a/configure
> +++ b/configure
> @@ -596,9 +596,6 @@ DEFINES
>  static_nss
>  profile
>  libc_cv_multidir
> -libc_cv_pie_default
> -libc_cv_cc_pie_default
> -libc_cv_pic_default
>  shared
>  static
>  ldd_rewrite_script
> @@ -767,7 +764,7 @@ with_nonshared_cflags
>  enable_sanity_checks
>  enable_shared
>  enable_profile
> -enable_static_pie
> +enable_default_pie
>  enable_timezone_tools
>  enable_hardcoded_path_in_tests
>  enable_hidden_plt
> @@ -1423,8 +1420,8 @@ Optional Features:
>                            in special situations) [default=yes]
>    --enable-shared         build shared library [default=yes if GNU ld]
>    --enable-profile        build profiled library [default=no]
> -  --enable-static-pie     enable static PIE support and use it in the
> -                          testsuite [default=no]
> +  --disable-default-pie   Do not build glibc programs and tests in the
> +                          testsuite as PIE [default=no]
>    --disable-timezone-tools
>                            do not install timezone tools [default=install]
>    --enable-hardcoded-path-in-tests
> @@ -3408,11 +3405,11 @@ else
>    profile=no
>  fi
>  
> -# Check whether --enable-static-pie was given.
> -if test "${enable_static_pie+set}" = set; then :
> -  enableval=$enable_static_pie; static_pie=$enableval
> +# Check whether --enable-default-pie was given.
> +if test "${enable_default_pie+set}" = set; then :
> +  enableval=$enable_default_pie; default_pie=$enableval
>  else
> -  static_pie=no
> +  default_pie=yes
>  fi
>  
>  # Check whether --enable-timezone-tools was given.
> @@ -6959,7 +6956,8 @@ rm -f conftest.*
>  fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
>  $as_echo "$libc_cv_pic_default" >&6; }
> -
> +config_vars="$config_vars
> +build-pic-default = $libc_cv_pic_default"
>  
>  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
>  $as_echo_n "checking whether -fPIE is default... " >&6; }
> @@ -6979,17 +6977,37 @@ rm -f conftest.*
>  fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
>  $as_echo "$libc_cv_cc_pie_default" >&6; }
> -libc_cv_pie_default=$libc_cv_cc_pie_default
> -
> -
> -
> -# Set the `multidir' variable by grabbing the variable from the compiler.
> -# We do it once and save the result in a generated makefile.
> -libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
> -
> +config_vars="$config_vars
> +cc-pie-default = $libc_cv_cc_pie_default"
>  
> -if test "$static_pie" = yes; then
> -  # Check target support for static PIE
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
> +$as_echo_n "checking if we can build programs as PIE... " >&6; }
> +if test "x$default_pie" != xno; then
> +  # Disable build-pie-default if target does not support it.
> +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +#ifdef PIE_UNSUPPORTED
> +# error PIE is not supported
> +#endif
> +_ACEOF
> +if ac_fn_c_try_compile "$LINENO"; then :
> +  libc_cv_pie_default=yes
> +else
> +  libc_cv_pie_default=no
> +fi
> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
> +$as_echo "$libc_cv_pie_default" >&6; }
> +config_vars="$config_vars
> +build-pie-default = $libc_cv_pie_default"
> +
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
> +$as_echo_n "checking if we can build static PIE programs... " >&6; }
> +libc_cv_static_pie=$libc_cv_pie_default
> +if test "x$libc_cv_pie_default" != xno \
> +   -a "$libc_cv_no_dynamic_linker" = yes; then
> +  # Enable static-pie if available
>    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>  /* end confdefs.h.  */
>  #ifndef SUPPORT_STATIC_PIE
> @@ -6997,22 +7015,25 @@ if test "$static_pie" = yes; then
>  #endif
>  _ACEOF
>  if ac_fn_c_try_compile "$LINENO"; then :
> -
> +  libc_cv_static_pie=yes
>  else
> -  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
> +  libc_cv_static_pie=no
>  fi
>  rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> -  # The linker must support --no-dynamic-linker.
> -  if test "$libc_cv_no_dynamic_linker" != yes; then
> -    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
> -  fi
> -  # Default to PIE.
> -  libc_cv_pie_default=yes
> -  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
> +  if test "$libc_cv_static_pie" = "yes"; then
> +    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
>  
> +  fi
>  fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
> +$as_echo "$libc_cv_static_pie" >&6; }
>  config_vars="$config_vars
> -enable-static-pie = $static_pie"
> +enable-static-pie = $libc_cv_static_pie"
> +
> +# Set the `multidir' variable by grabbing the variable from the compiler.
> +# We do it once and save the result in a generated makefile.
> +libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
> +
>  
>  
>  
> diff --git a/configure.ac b/configure.ac
> index 7eb4239359..55d3162a4d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
>  			     [build profiled library @<:@default=no@:>@]),
>  	      [profile=$enableval],
>  	      [profile=no])
> -AC_ARG_ENABLE([static-pie],
> -	      AS_HELP_STRING([--enable-static-pie],
> -			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
> -	      [static_pie=$enableval],
> -	      [static_pie=no])
> +AC_ARG_ENABLE([default-pie],
> +	      AS_HELP_STRING([--disable-default-pie],
> +			     [Do not build glibc programs and tests in the testsuite as PIE @<:@default=no@:>@]),

Maybe just 'tests' or 'testsuite'.

> +	      [default_pie=$enableval],
> +	      [default_pie=yes])
>  AC_ARG_ENABLE([timezone-tools],
>  	      AS_HELP_STRING([--disable-timezone-tools],
>  			     [do not install timezone tools @<:@default=install@:>@]),
> @@ -1839,7 +1839,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>    libc_cv_pic_default=no
>  fi
>  rm -f conftest.*])
> -AC_SUBST(libc_cv_pic_default)
> +LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
>  
>  AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
>  [libc_cv_cc_pie_default=yes
> @@ -1852,30 +1852,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>    libc_cv_cc_pie_default=no
>  fi
>  rm -f conftest.*])
> -libc_cv_pie_default=$libc_cv_cc_pie_default
> -AC_SUBST(libc_cv_cc_pie_default)
> -AC_SUBST(libc_cv_pie_default)
> +LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
> +
> +AC_MSG_CHECKING(if we can build programs as PIE)
> +if test "x$default_pie" != xno; then
> +  # Disable build-pie-default if target does not support it.
> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
> +# error PIE is not supported
> +#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
> +fi
> +AC_MSG_RESULT($libc_cv_pie_default)
> +LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
> +
> +AC_MSG_CHECKING(if we can build static PIE programs)
> +libc_cv_static_pie=$libc_cv_pie_default
> +if test "x$libc_cv_pie_default" != xno \
> +   -a "$libc_cv_no_dynamic_linker" = yes; then
> +  # Enable static-pie if available
> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
> +# error static PIE is not supported
> +#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
> +  if test "$libc_cv_static_pie" = "yes"; then
> +    AC_DEFINE(ENABLE_STATIC_PIE)
> +  fi
> +fi
> +AC_MSG_RESULT($libc_cv_static_pie)
> +LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
>  
>  # Set the `multidir' variable by grabbing the variable from the compiler.
>  # We do it once and save the result in a generated makefile.
>  libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
>  AC_SUBST(libc_cv_multidir)
>  
> -if test "$static_pie" = yes; then
> -  # Check target support for static PIE
> -  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
> -# error static PIE is not supported
> -#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
> -  # The linker must support --no-dynamic-linker.
> -  if test "$libc_cv_no_dynamic_linker" != yes; then
> -    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
> -  fi
> -  # Default to PIE.
> -  libc_cv_pie_default=yes
> -  AC_DEFINE(ENABLE_STATIC_PIE)
> -fi
> -LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
> -
>  AC_SUBST(profile)
>  AC_SUBST(static_nss)
>  
> diff --git a/manual/install.texi b/manual/install.texi
> index 46f73b538d..dff20fefa1 100644
> --- a/manual/install.texi
> +++ b/manual/install.texi
> @@ -141,15 +141,14 @@ Don't build shared libraries even if it is possible.  Not all systems
>  support shared libraries; you need ELF support and (currently) the GNU
>  linker.
>  
> -@item --enable-static-pie
> -Enable static position independent executable (static PIE) support.
> -Static PIE is similar to static executable, but can be loaded at any
> -address without help from a dynamic linker.  All static programs as
> -well as static tests are built as static PIE, except for those marked
> -with no-pie.  The resulting glibc can be used with the GCC option,
> --static-pie, which is available with GCC 8 or above, to create static
> -PIE.  This option also implies that glibc programs and tests are created
> -as dynamic position independent executables (PIE) by default.
> +@item --disable-default-pie
> +Don't build glibc programs and tests in the testsuite as position independent
> +executables (PIE).  By default, glibc programs and tests are created as
> +position independent executables.  If the toolchain and architecture supports
> +it, static executable are built as static PIE and the resulting glibc can be
> +used with the GCC option, -static-pie, which is available with GCC 8 or above,
> +to create static PIE.  PIE is not enabled by default on i686 GNU/Hurd, HPPA,
> +IA64, CSKY and Microblaze targets.
>  
>  @item --enable-cet
>  @itemx --enable-cet=permissive
> diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
> index 6ae2172956..89bd06881f 100755
> --- a/scripts/build-many-glibcs.py
> +++ b/scripts/build-many-glibcs.py
> @@ -437,15 +437,15 @@ class Context(object):
>                                                 '--disable-experimental-malloc',
>                                                 '--disable-build-nscd',
>                                                 '--disable-nscd']},
> -                                      {'variant': 'static-pie',
> -                                       'cfg': ['--enable-static-pie']},
> -                                      {'variant': 'x32-static-pie',
> +                                      {'variant': 'no-pie',
> +                                       'cfg': ['--disable-default-pie']},
> +                                      {'variant': 'x32-no-pie',
>                                         'ccopts': '-mx32',
> -                                       'cfg': ['--enable-static-pie']},
> -                                      {'variant': 'static-pie',
> +                                       'cfg': ['--disable-default-pie']},
> +                                      {'variant': 'no-pie',
>                                         'arch': 'i686',
>                                         'ccopts': '-m32 -march=i686',
> -                                       'cfg': ['--enable-static-pie']},
> +                                       'cfg': ['--disable-default-pie']},
>                                        {'variant': 'disable-multi-arch',
>                                         'arch': 'i686',
>                                         'ccopts': '-m32 -march=i686',
> diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
> index 19acb084fb..08caa633b1 100644
> --- a/sysdeps/csky/configure
> +++ b/sysdeps/csky/configure
> @@ -2,3 +2,9 @@
>   # Local configure fragment for sysdeps/csky.
>  
>  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
> +
> +
> +# PIE builds don't work.
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
> index 5656b665da..9613c68338 100644
> --- a/sysdeps/csky/configure.ac
> +++ b/sysdeps/csky/configure.ac
> @@ -2,3 +2,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  # Local configure fragment for sysdeps/csky.
>  
>  AC_DEFINE(PI_STATIC_AND_HIDDEN)
> +
> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
> index 2cfe6cbea1..1a0530ef9f 100644
> --- a/sysdeps/hppa/configure
> +++ b/sysdeps/hppa/configure
> @@ -30,3 +30,9 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
>  cat >>confdefs.h <<_ACEOF
>  #define ASM_LINE_SEP $libc_cv_asm_line_sep
>  _ACEOF
> +
> +
> +# PIE builds don't work.
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
> index 1ec417b947..3aa5cde7ce 100644
> --- a/sysdeps/hppa/configure.ac
> +++ b/sysdeps/hppa/configure.ac
> @@ -19,3 +19,7 @@ else
>  fi
>  rm -f conftest*])
>  AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
> +
> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
> index 1ef70921bc..c13b11d5af 100644
> --- a/sysdeps/ia64/configure
> +++ b/sysdeps/ia64/configure
> @@ -3,4 +3,8 @@
>  
>  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
>  
> +
> +# PIE builds don't work.
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
> index 3bae9fc5e1..8f16c49d4d 100644
> --- a/sysdeps/ia64/configure.ac
> +++ b/sysdeps/ia64/configure.ac
> @@ -4,4 +4,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  dnl It is always possible to access static and hidden symbols in an
>  dnl position independent way.
>  AC_DEFINE(PI_STATIC_AND_HIDDEN)
> +
> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
> index 8d0702ad43..1192a5261d 100644
> --- a/sysdeps/mach/hurd/configure
> +++ b/sysdeps/mach/hurd/configure
> @@ -49,3 +49,8 @@ fi
>  
>  # Hurd has libpthread as a separate library.
>  pthread_in_libc=no
> +
> +# PIE builds don't work.
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
> index 82d085af33..115d809cec 100644
> --- a/sysdeps/mach/hurd/configure.ac
> +++ b/sysdeps/mach/hurd/configure.ac
> @@ -29,3 +29,7 @@ fi
>  
>  # Hurd has libpthread as a separate library.
>  pthread_in_libc=no
> +
> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
> new file mode 100755
> index 0000000000..2805a4568d
> --- /dev/null
> +++ b/sysdeps/microblaze/configure
> @@ -0,0 +1,7 @@
> +# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
> + # Local configure fragment for sysdeps/microblaze.
> +
> +# PIE builds don't work.
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
> new file mode 100644
> index 0000000000..3dce7167db
> --- /dev/null
> +++ b/sysdeps/microblaze/configure.ac
> @@ -0,0 +1,6 @@
> +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
> +# Local configure fragment for sysdeps/microblaze.
> +
> +# PIE builds don't work.
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
> index 1be9a3db2c..12c2c1b085 100644
> --- a/sysdeps/sparc/Makefile
> +++ b/sysdeps/sparc/Makefile
> @@ -2,6 +2,7 @@
>  long-double-fcts = yes
>  
>  pie-ccflag = -fPIE
> +no-pie-ccflag = -fno-PIE
>  
>  ifeq ($(subdir),gmon)
>  sysdep_routines += sparc-mcount
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] Replace --enable-static-pie with --disable-default-pie
  2021-12-07 20:13 ` Adhemerval Zanella
@ 2021-12-08  4:34   ` Siddhesh Poyarekar
  0 siblings, 0 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-08  4:34 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha; +Cc: fweimer

On 12/8/21 01:43, Adhemerval Zanella wrote:
> 
> 
> On 07/12/2021 05:26, Siddhesh Poyarekar via Libc-alpha wrote:
>> Build glibc programs and tests as PIE by default and enable static-pie
>> automatically if the architecture and toolchain supports it.
>>
>> Also add a new configuration option --disable-default-pie to prevent
>> building programs as PIE.
>>
>> Only the following architectures now have PIE disabled by default
>> because they do not work at the moment.  hppa, ia64 and csky don't work
>> because the linker is unable to handle a pcrel relocation generated from
>> PIE objects.  The microblaze compiler is currently failing with an ICE.
>> GNU hurd tries to enable static-pie, which does not work and hence
>> fails.  It could be made to work, but I've left the enabling for the
>> Hurd maintainer.  build-many-glibcs runs clean for all targets now;
>> following are the failures before disabling PIE for these targets.  I
>> also tested x86_64 on Fedora and Ubuntu, to verify that the default
>> build as well as --disable-default-pie work as expected with both system
>> toolchains.
>>
>> FAIL: glibcs-microblazeel-linux-gnu check
>> ICE
>>
>> FAIL: glibcs-csky-linux-gnuabiv2-soft check
>> build-many-2/build/glibcs/csky-linux-gnuabiv2-soft/glibc/math/test-tgmath2.o: in function `main':
>> build-many-2/src/glibc/math/../support/test-driver.c:124:(.text.startup+0x24): relocation truncated to fit: R_CKCORE_PCREL_IMM18BY2 against `.text'
>>
>> FAIL: glibcs-csky-linux-gnuabiv2 check
>> /tmp/ccaEAi1b.s: Assembler messages:
>> /tmp/ccaEAi1b.s:409254: Error: pcrel offset for branch to <unknown> too far (0xfffffffffffc44a1)
>> make[3]: *** [../o-iterator.mk:9: build-many-2/build/glibcs/csky-linux-gnuabiv2/glibc/math/test-tgmath3-fma.o] Error 1
>>
>> FAIL: glibcs-ia64-linux-gnu build
>> build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `_dl_aux_init':
>> build-many-2/src/glibc/elf/dl-support.c:254:(.text+0x42): relocation truncated to fit: GPREL22 against `.text'
>> build-many-2/build/glibcs/ia64-linux-gnu/glibc/libc.a(dl-support.o): in function `setup_vdso':
>> build-many-2/src/glibc/elf/setup-vdso.h:108:(.text+0x1092): relocation truncated to fit: GPREL22 against `.text'
>>
>> FAIL: glibcs-microblaze-linux-gnu check
>> ICE
>>
>> FAIL: glibcs-hppa-linux-gnu check
>> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot reach 0000004f_retNum6056+0, recompile with -ffunction-sections
>> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: build-many-2/build/glibcs/hppa-linux-gnu/glibc/nptl/tst-audit-threads.o(.text+0x22a58): cannot handle R_PARISC_PCREL17F for retNum6056
>> build-many-2/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/11.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: final link failed: bad value
>>
>> FAIL: glibcs-i686-gnu build
>> build-many-2/install/compilers/i686-gnu/lib/gcc/i686-glibc-gnu/11.2.1/../../../../i686-glibc-gnu/bin/ld: cannot find build-many-2/build/glibcs/i686-gnu/glibc/csu/rcrt0.o: No such file or directory
>> collect2: error: ld returned 1 exit status
>> make[3]: *** [../Rules:269: build-many-2/build/glibcs/i686-gnu/glibc/support/test-run-command] Error 1
>>
>> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
>> ---
>>   INSTALL                         | 19 ++++----
>>   Makeconfig                      | 21 ++++++---
>>   NEWS                            | 12 +++++
>>   config.h.in                     |  3 ++
>>   config.make.in                  |  3 --
>>   configure                       | 83 +++++++++++++++++++++------------
>>   configure.ac                    | 56 ++++++++++++----------
>>   manual/install.texi             | 17 ++++---
>>   scripts/build-many-glibcs.py    | 12 ++---
>>   sysdeps/csky/configure          |  6 +++
>>   sysdeps/csky/configure.ac       |  4 ++
>>   sysdeps/hppa/configure          |  6 +++
>>   sysdeps/hppa/configure.ac       |  4 ++
>>   sysdeps/ia64/configure          |  4 ++
>>   sysdeps/ia64/configure.ac       |  3 ++
>>   sysdeps/mach/hurd/configure     |  5 ++
>>   sysdeps/mach/hurd/configure.ac  |  4 ++
>>   sysdeps/microblaze/configure    |  7 +++
>>   sysdeps/microblaze/configure.ac |  6 +++
>>   sysdeps/sparc/Makefile          |  1 +
>>   20 files changed, 186 insertions(+), 90 deletions(-)
>>   create mode 100755 sysdeps/microblaze/configure
>>   create mode 100644 sysdeps/microblaze/configure.ac
>>
>> diff --git a/INSTALL b/INSTALL
>> index 02dcf6b1ca..56d2a31dad 100644
>> --- a/INSTALL
>> +++ b/INSTALL
>> @@ -111,16 +111,15 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
>>        systems support shared libraries; you need ELF support and
>>        (currently) the GNU linker.
>>   
>> -'--enable-static-pie'
>> -     Enable static position independent executable (static PIE) support.
>> -     Static PIE is similar to static executable, but can be loaded at
>> -     any address without help from a dynamic linker.  All static
>> -     programs as well as static tests are built as static PIE, except
>> -     for those marked with no-pie.  The resulting glibc can be used with
>> -     the GCC option, -static-pie, which is available with GCC 8 or
>> -     above, to create static PIE. This option also implies that glibc
>> -     programs and tests are created as dynamic position independent
>> -     executables (PIE) by default.
>> +'--disable-default-pie'
>> +     Don't build glibc programs and tests in the testsuite as position
> 
> 'tests in the testsuite' sounds redundat, maybe only 'testsuite'.
> 
>> +     independent executables (PIE). By default, glibc programs and tests
> 
> Double space after period.
> 
>> +     are created as position independent executables.  If the toolchain
>> +     and architecture supports it, static executable are built as static
> 
> I think it should be 'support' here and I also think it should be 'executables'.
> 
>> +     PIE and the resulting glibc can be used with the GCC option,
>> +     -static-pie, which is available with GCC 8 or above, to create
>> +     static PIE. PIE is not enabled by default on i686 GNU/Hurd, HPPA,
>> +     IA64, CSKY and Microblaze targets.
> 
> Maybe not to reference which architecture are not supported? Otherwise we
> will need to keep in sync and add a mark it should be updated.

Agreed, I'll drop the target mentions.

> 
>>   
>>   '--enable-cet'
>>   '--enable-cet=permissive'
>> diff --git a/Makeconfig b/Makeconfig
>> index 3fa2f13003..775bf12b65 100644
>> --- a/Makeconfig
>> +++ b/Makeconfig
>> @@ -1,4 +1,5 @@
>>   # Copyright (C) 1991-2021 Free Software Foundation, Inc.
>> +# Copyright (C) The GNU Toolchain Authors.
>>   # This file is part of the GNU C Library.
>>   
>>   # The GNU C Library is free software; you can redistribute it and/or
> 
> Can we re-license the file?

My understanding is that we need to add the GNU Toolchain Authors 
copyright notice every time there is a non-trivial change; my changes 
are not assigned to FSF so the notice is necessary.  Or did I 
misunderstand your question?

> 
>> @@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
>>   LDFLAGS-rtld += $(hashstyle-LDFLAGS)
>>   endif
>>   
>> -ifeq (yes,$(enable-static-pie))
>> +ifeq (no,$(build-pie-default))
>> +pie-default = $(no-pie-ccflag)
>> +else # build-pie-default
>>   pic-default = -DPIC
>>   # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
>>   pie-default = $(pie-ccflag)
>> +
>> +ifeq (yes,$(enable-static-pie))
>>   ifeq (yes,$(have-static-pie))
>> -default-pie-ldflag = -static-pie
>> +static-pie-ldflag = -static-pie
>>   else
>>   # Static PIE can't have dynamic relocations in read-only segments since
>>   # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
>>   # for PIE to support exception.
>> -default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
>> -endif
>> -endif
>> +static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
>> +endif # have-static-pie
>> +endif # enable-static-pie
>> +endif # build-pie-default
>>   
>>   # If lazy relocations are disabled, add the -z now flag.  Use
>>   # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
>> @@ -444,7 +450,7 @@ endif
>>   # Command for statically linking programs with the C library.
>>   ifndef +link-static
>>   +link-static-before-inputs = -nostdlib -nostartfiles -static \
>> -	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
>> +	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
>>   	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
>>   	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
>>   	      $(+preinit) $(+prectorT)
>> @@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
>>   +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
>>   +link-printers-tests = $(+link-pie-printers-tests)
>>   else  # not build-pie-default
>> -+link-before-inputs = -nostdlib -nostartfiles \
>> ++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
>>   	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
>>   	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
>>   	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
>> @@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
>>   endif
>>   # This can be changed by a sysdep makefile
>>   pie-ccflag = -fpie
>> +no-pie-ccflag = -fno-pie
>>   # This one should always stay like this unless there is a very good reason.
>>   PIE-ccflag = -fPIE
>>   ifeq (yes,$(build-profile))
>> diff --git a/NEWS b/NEWS
>> index f10971b180..f12f3ffde4 100644
>> --- a/NEWS
>> +++ b/NEWS
>> @@ -68,6 +68,14 @@ Major new features:
>>     to be used by compilers for optimizing usage of 'memcmp' when its
>>     return value is only used for its boolean status.
>>   
>> +* All programs and tests in glibc are now built as position independent
>> +  executables (PIE) by default on architectures that support it.  Further, if
> 
> Maybe state that if both architecture and toolchain support it.

OK.

> 
>> +  static-pie is available in the toolchain and the architecture, it is also
>> +  enabled and static programs also built as executable.  A new option
> 
> Maybe 'are also'?  And state that --enable-static-pie is not replaced with
> --disable-default-pie.

OK, I assume you mean *now* replaced with.  FWIW, I have also mentioned 
below that --enable-static-pie has been removed, so would it be redundant?

>> +  --disable-default-pie has been added to disable this behavior and get a
>> +  non-PIE build.  Default PIE is not supported on GNU Hurd, HPPA, IA64, CSKY
>> +  and Microblaze targets.
>> +
>>   Deprecated and removed features, and other changes affecting compatibility:
>>   
>>   * The r_version update in the debugger interface makes the glibc binary
>> @@ -80,6 +88,10 @@ Deprecated and removed features, and other changes affecting compatibility:
>>   
>>   * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
>>   
>> +* The --enable-static-pie option is no longer available.  The glibc build
>> +  configuration script now automatically detects static-pie support in the
>> +  toolchain and architecture and enables it if available.
>> +
>>   Changes to build and runtime requirements:
>>   
>>     [Add changes to build and runtime requirements here]
>> diff --git a/config.h.in b/config.h.in
>> index 0a6f57b006..acce608373 100644
>> --- a/config.h.in
>> +++ b/config.h.in
>> @@ -265,6 +265,9 @@
>>   /* Build glibc with tunables support.  */
>>   #define HAVE_TUNABLES 0
>>   
>> +/* Define if PIE is unsupported.  */
>> +#undef PIE_UNSUPPORTED
>> +
>>   /* Define if static PIE is supported.  */
>>   #undef SUPPORT_STATIC_PIE
>>   
>> diff --git a/config.make.in b/config.make.in
>> index cbf59114b0..e8630a8d0c 100644
>> --- a/config.make.in
>> +++ b/config.make.in
>> @@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
>>   
>>   # Configuration options.
>>   build-shared = @shared@
>> -build-pic-default= @libc_cv_pic_default@
>> -build-pie-default= @libc_cv_pie_default@
>> -cc-pie-default= @libc_cv_cc_pie_default@
>>   build-profile = @profile@
>>   build-static-nss = @static_nss@
>>   cross-compiling = @cross_compiling@
>> diff --git a/configure b/configure
>> index 2f9adca064..4dce154938 100755
>> --- a/configure
>> +++ b/configure
>> @@ -596,9 +596,6 @@ DEFINES
>>   static_nss
>>   profile
>>   libc_cv_multidir
>> -libc_cv_pie_default
>> -libc_cv_cc_pie_default
>> -libc_cv_pic_default
>>   shared
>>   static
>>   ldd_rewrite_script
>> @@ -767,7 +764,7 @@ with_nonshared_cflags
>>   enable_sanity_checks
>>   enable_shared
>>   enable_profile
>> -enable_static_pie
>> +enable_default_pie
>>   enable_timezone_tools
>>   enable_hardcoded_path_in_tests
>>   enable_hidden_plt
>> @@ -1423,8 +1420,8 @@ Optional Features:
>>                             in special situations) [default=yes]
>>     --enable-shared         build shared library [default=yes if GNU ld]
>>     --enable-profile        build profiled library [default=no]
>> -  --enable-static-pie     enable static PIE support and use it in the
>> -                          testsuite [default=no]
>> +  --disable-default-pie   Do not build glibc programs and tests in the
>> +                          testsuite as PIE [default=no]
>>     --disable-timezone-tools
>>                             do not install timezone tools [default=install]
>>     --enable-hardcoded-path-in-tests
>> @@ -3408,11 +3405,11 @@ else
>>     profile=no
>>   fi
>>   
>> -# Check whether --enable-static-pie was given.
>> -if test "${enable_static_pie+set}" = set; then :
>> -  enableval=$enable_static_pie; static_pie=$enableval
>> +# Check whether --enable-default-pie was given.
>> +if test "${enable_default_pie+set}" = set; then :
>> +  enableval=$enable_default_pie; default_pie=$enableval
>>   else
>> -  static_pie=no
>> +  default_pie=yes
>>   fi
>>   
>>   # Check whether --enable-timezone-tools was given.
>> @@ -6959,7 +6956,8 @@ rm -f conftest.*
>>   fi
>>   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
>>   $as_echo "$libc_cv_pic_default" >&6; }
>> -
>> +config_vars="$config_vars
>> +build-pic-default = $libc_cv_pic_default"
>>   
>>   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
>>   $as_echo_n "checking whether -fPIE is default... " >&6; }
>> @@ -6979,17 +6977,37 @@ rm -f conftest.*
>>   fi
>>   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
>>   $as_echo "$libc_cv_cc_pie_default" >&6; }
>> -libc_cv_pie_default=$libc_cv_cc_pie_default
>> -
>> -
>> -
>> -# Set the `multidir' variable by grabbing the variable from the compiler.
>> -# We do it once and save the result in a generated makefile.
>> -libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
>> -
>> +config_vars="$config_vars
>> +cc-pie-default = $libc_cv_cc_pie_default"
>>   
>> -if test "$static_pie" = yes; then
>> -  # Check target support for static PIE
>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
>> +$as_echo_n "checking if we can build programs as PIE... " >&6; }
>> +if test "x$default_pie" != xno; then
>> +  # Disable build-pie-default if target does not support it.
>> +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>> +/* end confdefs.h.  */
>> +#ifdef PIE_UNSUPPORTED
>> +# error PIE is not supported
>> +#endif
>> +_ACEOF
>> +if ac_fn_c_try_compile "$LINENO"; then :
>> +  libc_cv_pie_default=yes
>> +else
>> +  libc_cv_pie_default=no
>> +fi
>> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
>> +fi
>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
>> +$as_echo "$libc_cv_pie_default" >&6; }
>> +config_vars="$config_vars
>> +build-pie-default = $libc_cv_pie_default"
>> +
>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
>> +$as_echo_n "checking if we can build static PIE programs... " >&6; }
>> +libc_cv_static_pie=$libc_cv_pie_default
>> +if test "x$libc_cv_pie_default" != xno \
>> +   -a "$libc_cv_no_dynamic_linker" = yes; then
>> +  # Enable static-pie if available
>>     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>>   /* end confdefs.h.  */
>>   #ifndef SUPPORT_STATIC_PIE
>> @@ -6997,22 +7015,25 @@ if test "$static_pie" = yes; then
>>   #endif
>>   _ACEOF
>>   if ac_fn_c_try_compile "$LINENO"; then :
>> -
>> +  libc_cv_static_pie=yes
>>   else
>> -  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
>> +  libc_cv_static_pie=no
>>   fi
>>   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
>> -  # The linker must support --no-dynamic-linker.
>> -  if test "$libc_cv_no_dynamic_linker" != yes; then
>> -    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
>> -  fi
>> -  # Default to PIE.
>> -  libc_cv_pie_default=yes
>> -  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
>> +  if test "$libc_cv_static_pie" = "yes"; then
>> +    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
>>   
>> +  fi
>>   fi
>> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
>> +$as_echo "$libc_cv_static_pie" >&6; }
>>   config_vars="$config_vars
>> -enable-static-pie = $static_pie"
>> +enable-static-pie = $libc_cv_static_pie"
>> +
>> +# Set the `multidir' variable by grabbing the variable from the compiler.
>> +# We do it once and save the result in a generated makefile.
>> +libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
>> +
>>   
>>   
>>   
>> diff --git a/configure.ac b/configure.ac
>> index 7eb4239359..55d3162a4d 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
>>   			     [build profiled library @<:@default=no@:>@]),
>>   	      [profile=$enableval],
>>   	      [profile=no])
>> -AC_ARG_ENABLE([static-pie],
>> -	      AS_HELP_STRING([--enable-static-pie],
>> -			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
>> -	      [static_pie=$enableval],
>> -	      [static_pie=no])
>> +AC_ARG_ENABLE([default-pie],
>> +	      AS_HELP_STRING([--disable-default-pie],
>> +			     [Do not build glibc programs and tests in the testsuite as PIE @<:@default=no@:>@]),
> 
> Maybe just 'tests' or 'testsuite'.

I'll make it 'testsuite' to be consistent with the above.

> 
>> +	      [default_pie=$enableval],
>> +	      [default_pie=yes])
>>   AC_ARG_ENABLE([timezone-tools],
>>   	      AS_HELP_STRING([--disable-timezone-tools],
>>   			     [do not install timezone tools @<:@default=install@:>@]),
>> @@ -1839,7 +1839,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>>     libc_cv_pic_default=no
>>   fi
>>   rm -f conftest.*])
>> -AC_SUBST(libc_cv_pic_default)
>> +LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
>>   
>>   AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
>>   [libc_cv_cc_pie_default=yes
>> @@ -1852,30 +1852,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>>     libc_cv_cc_pie_default=no
>>   fi
>>   rm -f conftest.*])
>> -libc_cv_pie_default=$libc_cv_cc_pie_default
>> -AC_SUBST(libc_cv_cc_pie_default)
>> -AC_SUBST(libc_cv_pie_default)
>> +LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
>> +
>> +AC_MSG_CHECKING(if we can build programs as PIE)
>> +if test "x$default_pie" != xno; then
>> +  # Disable build-pie-default if target does not support it.
>> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
>> +# error PIE is not supported
>> +#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
>> +fi
>> +AC_MSG_RESULT($libc_cv_pie_default)
>> +LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
>> +
>> +AC_MSG_CHECKING(if we can build static PIE programs)
>> +libc_cv_static_pie=$libc_cv_pie_default
>> +if test "x$libc_cv_pie_default" != xno \
>> +   -a "$libc_cv_no_dynamic_linker" = yes; then
>> +  # Enable static-pie if available
>> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
>> +# error static PIE is not supported
>> +#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
>> +  if test "$libc_cv_static_pie" = "yes"; then
>> +    AC_DEFINE(ENABLE_STATIC_PIE)
>> +  fi
>> +fi
>> +AC_MSG_RESULT($libc_cv_static_pie)
>> +LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
>>   
>>   # Set the `multidir' variable by grabbing the variable from the compiler.
>>   # We do it once and save the result in a generated makefile.
>>   libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
>>   AC_SUBST(libc_cv_multidir)
>>   
>> -if test "$static_pie" = yes; then
>> -  # Check target support for static PIE
>> -  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
>> -# error static PIE is not supported
>> -#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
>> -  # The linker must support --no-dynamic-linker.
>> -  if test "$libc_cv_no_dynamic_linker" != yes; then
>> -    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
>> -  fi
>> -  # Default to PIE.
>> -  libc_cv_pie_default=yes
>> -  AC_DEFINE(ENABLE_STATIC_PIE)
>> -fi
>> -LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
>> -
>>   AC_SUBST(profile)
>>   AC_SUBST(static_nss)
>>   
>> diff --git a/manual/install.texi b/manual/install.texi
>> index 46f73b538d..dff20fefa1 100644
>> --- a/manual/install.texi
>> +++ b/manual/install.texi
>> @@ -141,15 +141,14 @@ Don't build shared libraries even if it is possible.  Not all systems
>>   support shared libraries; you need ELF support and (currently) the GNU
>>   linker.
>>   
>> -@item --enable-static-pie
>> -Enable static position independent executable (static PIE) support.
>> -Static PIE is similar to static executable, but can be loaded at any
>> -address without help from a dynamic linker.  All static programs as
>> -well as static tests are built as static PIE, except for those marked
>> -with no-pie.  The resulting glibc can be used with the GCC option,
>> --static-pie, which is available with GCC 8 or above, to create static
>> -PIE.  This option also implies that glibc programs and tests are created
>> -as dynamic position independent executables (PIE) by default.
>> +@item --disable-default-pie
>> +Don't build glibc programs and tests in the testsuite as position independent
>> +executables (PIE).  By default, glibc programs and tests are created as
>> +position independent executables.  If the toolchain and architecture supports
>> +it, static executable are built as static PIE and the resulting glibc can be
>> +used with the GCC option, -static-pie, which is available with GCC 8 or above,
>> +to create static PIE.  PIE is not enabled by default on i686 GNU/Hurd, HPPA,
>> +IA64, CSKY and Microblaze targets.
>>   
>>   @item --enable-cet
>>   @itemx --enable-cet=permissive
>> diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
>> index 6ae2172956..89bd06881f 100755
>> --- a/scripts/build-many-glibcs.py
>> +++ b/scripts/build-many-glibcs.py
>> @@ -437,15 +437,15 @@ class Context(object):
>>                                                  '--disable-experimental-malloc',
>>                                                  '--disable-build-nscd',
>>                                                  '--disable-nscd']},
>> -                                      {'variant': 'static-pie',
>> -                                       'cfg': ['--enable-static-pie']},
>> -                                      {'variant': 'x32-static-pie',
>> +                                      {'variant': 'no-pie',
>> +                                       'cfg': ['--disable-default-pie']},
>> +                                      {'variant': 'x32-no-pie',
>>                                          'ccopts': '-mx32',
>> -                                       'cfg': ['--enable-static-pie']},
>> -                                      {'variant': 'static-pie',
>> +                                       'cfg': ['--disable-default-pie']},
>> +                                      {'variant': 'no-pie',
>>                                          'arch': 'i686',
>>                                          'ccopts': '-m32 -march=i686',
>> -                                       'cfg': ['--enable-static-pie']},
>> +                                       'cfg': ['--disable-default-pie']},
>>                                         {'variant': 'disable-multi-arch',
>>                                          'arch': 'i686',
>>                                          'ccopts': '-m32 -march=i686',
>> diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
>> index 19acb084fb..08caa633b1 100644
>> --- a/sysdeps/csky/configure
>> +++ b/sysdeps/csky/configure
>> @@ -2,3 +2,9 @@
>>    # Local configure fragment for sysdeps/csky.
>>   
>>   $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
>> +
>> +
>> +# PIE builds don't work.
>> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
>> +
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
>> index 5656b665da..9613c68338 100644
>> --- a/sysdeps/csky/configure.ac
>> +++ b/sysdeps/csky/configure.ac
>> @@ -2,3 +2,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>>   # Local configure fragment for sysdeps/csky.
>>   
>>   AC_DEFINE(PI_STATIC_AND_HIDDEN)
>> +
>> +# PIE builds don't work.
>> +AC_DEFINE(PIE_UNSUPPORTED)
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
>> index 2cfe6cbea1..1a0530ef9f 100644
>> --- a/sysdeps/hppa/configure
>> +++ b/sysdeps/hppa/configure
>> @@ -30,3 +30,9 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
>>   cat >>confdefs.h <<_ACEOF
>>   #define ASM_LINE_SEP $libc_cv_asm_line_sep
>>   _ACEOF
>> +
>> +
>> +# PIE builds don't work.
>> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
>> +
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
>> index 1ec417b947..3aa5cde7ce 100644
>> --- a/sysdeps/hppa/configure.ac
>> +++ b/sysdeps/hppa/configure.ac
>> @@ -19,3 +19,7 @@ else
>>   fi
>>   rm -f conftest*])
>>   AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
>> +
>> +# PIE builds don't work.
>> +AC_DEFINE(PIE_UNSUPPORTED)
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
>> index 1ef70921bc..c13b11d5af 100644
>> --- a/sysdeps/ia64/configure
>> +++ b/sysdeps/ia64/configure
>> @@ -3,4 +3,8 @@
>>   
>>   $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
>>   
>> +
>> +# PIE builds don't work.
>> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
>> +
>>   # work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
>> index 3bae9fc5e1..8f16c49d4d 100644
>> --- a/sysdeps/ia64/configure.ac
>> +++ b/sysdeps/ia64/configure.ac
>> @@ -4,4 +4,7 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>>   dnl It is always possible to access static and hidden symbols in an
>>   dnl position independent way.
>>   AC_DEFINE(PI_STATIC_AND_HIDDEN)
>> +
>> +# PIE builds don't work.
>> +AC_DEFINE(PIE_UNSUPPORTED)
>>   # work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
>> index 8d0702ad43..1192a5261d 100644
>> --- a/sysdeps/mach/hurd/configure
>> +++ b/sysdeps/mach/hurd/configure
>> @@ -49,3 +49,8 @@ fi
>>   
>>   # Hurd has libpthread as a separate library.
>>   pthread_in_libc=no
>> +
>> +# PIE builds don't work.
>> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
>> +
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
>> index 82d085af33..115d809cec 100644
>> --- a/sysdeps/mach/hurd/configure.ac
>> +++ b/sysdeps/mach/hurd/configure.ac
>> @@ -29,3 +29,7 @@ fi
>>   
>>   # Hurd has libpthread as a separate library.
>>   pthread_in_libc=no
>> +
>> +# PIE builds don't work.
>> +AC_DEFINE(PIE_UNSUPPORTED)
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
>> new file mode 100755
>> index 0000000000..2805a4568d
>> --- /dev/null
>> +++ b/sysdeps/microblaze/configure
>> @@ -0,0 +1,7 @@
>> +# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
>> + # Local configure fragment for sysdeps/microblaze.
>> +
>> +# PIE builds don't work.
>> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
>> +
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
>> new file mode 100644
>> index 0000000000..3dce7167db
>> --- /dev/null
>> +++ b/sysdeps/microblaze/configure.ac
>> @@ -0,0 +1,6 @@
>> +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>> +# Local configure fragment for sysdeps/microblaze.
>> +
>> +# PIE builds don't work.
>> +AC_DEFINE(PIE_UNSUPPORTED)
>> +# work around problem with autoconf and empty lines at the end of files
>> diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
>> index 1be9a3db2c..12c2c1b085 100644
>> --- a/sysdeps/sparc/Makefile
>> +++ b/sysdeps/sparc/Makefile
>> @@ -2,6 +2,7 @@
>>   long-double-fcts = yes
>>   
>>   pie-ccflag = -fPIE
>> +no-pie-ccflag = -fno-PIE
>>   
>>   ifeq ($(subdir),gmon)
>>   sysdep_routines += sparc-mcount
>>
> 

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2] Replace --enable-static-pie with --disable-default-pie
  2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
                   ` (2 preceding siblings ...)
  2021-12-07 20:13 ` Adhemerval Zanella
@ 2021-12-08  6:39 ` Siddhesh Poyarekar
  2021-12-10 17:35   ` Siddhesh Poyarekar
  2021-12-10 19:28   ` Adhemerval Zanella
  2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
  4 siblings, 2 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-08  6:39 UTC (permalink / raw)
  To: libc-alpha; +Cc: fweimer, adhemerval.zanella

Build glibc programs and tests as PIE by default and enable static-pie
automatically if the architecture and toolchain supports it.

Also add a new configuration option --disable-default-pie to prevent
building programs as PIE.

Only the following architectures now have PIE disabled by default
because they do not work at the moment.  hppa, ia64, alpha and csky
don't work because the linker is unable to handle a pcrel relocation
generated from PIE objects.  The microblaze compiler is currently
failing with an ICE.  GNU hurd tries to enable static-pie, which does
not work and hence fails.  All these targets have default PIE disabled
at the moment and I have left it to the target maintainers to enable PIE
on their targets.

build-many-glibcs runs clean for all targets.  I also tested x86_64 on
Fedora and Ubuntu, to verify that the default build as well as
--disable-default-pie work as expected with both system toolchains.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
---
Changes from v1:
- Filed bugs for build-many-glibcs failures and mentioned them.
- Updated comments and documentation based on review comments.

 INSTALL                         | 18 ++++---
 Makeconfig                      | 21 ++++++---
 NEWS                            | 13 ++++++
 config.h.in                     |  3 ++
 config.make.in                  |  3 --
 configure                       | 83 +++++++++++++++++++++------------
 configure.ac                    | 56 ++++++++++++----------
 manual/install.texi             | 16 +++----
 scripts/build-many-glibcs.py    | 13 +++---
 sysdeps/alpha/configure         |  5 ++
 sysdeps/alpha/configure.ac      |  4 ++
 sysdeps/csky/configure          |  7 +++
 sysdeps/csky/configure.ac       |  5 ++
 sysdeps/hppa/configure          |  7 +++
 sysdeps/hppa/configure.ac       |  5 ++
 sysdeps/ia64/configure          |  5 ++
 sysdeps/ia64/configure.ac       |  4 ++
 sysdeps/mach/hurd/configure     |  6 +++
 sysdeps/mach/hurd/configure.ac  |  5 ++
 sysdeps/microblaze/configure    |  8 ++++
 sysdeps/microblaze/configure.ac |  7 +++
 sysdeps/sparc/Makefile          |  1 +
 22 files changed, 205 insertions(+), 90 deletions(-)
 create mode 100755 sysdeps/microblaze/configure
 create mode 100644 sysdeps/microblaze/configure.ac

diff --git a/INSTALL b/INSTALL
index 02dcf6b1ca..d6d93ec9be 100644
--- a/INSTALL
+++ b/INSTALL
@@ -111,16 +111,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
      systems support shared libraries; you need ELF support and
      (currently) the GNU linker.
 
-'--enable-static-pie'
-     Enable static position independent executable (static PIE) support.
-     Static PIE is similar to static executable, but can be loaded at
-     any address without help from a dynamic linker.  All static
-     programs as well as static tests are built as static PIE, except
-     for those marked with no-pie.  The resulting glibc can be used with
-     the GCC option, -static-pie, which is available with GCC 8 or
-     above, to create static PIE. This option also implies that glibc
-     programs and tests are created as dynamic position independent
-     executables (PIE) by default.
+'--disable-default-pie'
+     Don't build glibc programs and the testsuite as position
+     independent executables (PIE). By default, glibc programs and tests
+     are created as position independent executables on targets that
+     support it.  If the toolchain and architecture support it, static
+     executables are built as static PIE and the resulting glibc can be
+     used with the GCC option, -static-pie, which is available with GCC
+     8 or above, to create static PIE.
 
 '--enable-cet'
 '--enable-cet=permissive'
diff --git a/Makeconfig b/Makeconfig
index 3fa2f13003..775bf12b65 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1,4 +1,5 @@
 # Copyright (C) 1991-2021 Free Software Foundation, Inc.
+# Copyright (C) The GNU Toolchain Authors.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
 endif
 
-ifeq (yes,$(enable-static-pie))
+ifeq (no,$(build-pie-default))
+pie-default = $(no-pie-ccflag)
+else # build-pie-default
 pic-default = -DPIC
 # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
 pie-default = $(pie-ccflag)
+
+ifeq (yes,$(enable-static-pie))
 ifeq (yes,$(have-static-pie))
-default-pie-ldflag = -static-pie
+static-pie-ldflag = -static-pie
 else
 # Static PIE can't have dynamic relocations in read-only segments since
 # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
 # for PIE to support exception.
-default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
-endif
-endif
+static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
+endif # have-static-pie
+endif # enable-static-pie
+endif # build-pie-default
 
 # If lazy relocations are disabled, add the -z now flag.  Use
 # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
@@ -444,7 +450,7 @@ endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
 +link-static-before-inputs = -nostdlib -nostartfiles -static \
-	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
+	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
 	      $(+preinit) $(+prectorT)
@@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
 +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
 +link-printers-tests = $(+link-pie-printers-tests)
 else  # not build-pie-default
-+link-before-inputs = -nostdlib -nostartfiles \
++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
@@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
 endif
 # This can be changed by a sysdep makefile
 pie-ccflag = -fpie
+no-pie-ccflag = -fno-pie
 # This one should always stay like this unless there is a very good reason.
 PIE-ccflag = -fPIE
 ifeq (yes,$(build-profile))
diff --git a/NEWS b/NEWS
index f10971b180..f808764de9 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,15 @@ Major new features:
   to be used by compilers for optimizing usage of 'memcmp' when its
   return value is only used for its boolean status.
 
+* All programs and the testsuite in glibc are now built as position independent
+  executables (PIE) by default on toolchains and architectures that support it.
+  Further, if the toolchain and architecture supports it, even static programs
+  are built as PIE and the resultant glibc can be used to build static PIE
+  executables.  A new option --disable-default-pie has been added to disable
+  this behavior and get a non-PIE build.  This option replaces
+  --enable-static-pie, which no longer has any effect on the build
+  configuration.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The r_version update in the debugger interface makes the glibc binary
@@ -80,6 +89,10 @@ Deprecated and removed features, and other changes affecting compatibility:
 
 * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
 
+* The --enable-static-pie option is no longer available.  The glibc build
+  configuration script now automatically detects static-pie support in the
+  toolchain and architecture and enables it if available.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/config.h.in b/config.h.in
index 0a6f57b006..acce608373 100644
--- a/config.h.in
+++ b/config.h.in
@@ -265,6 +265,9 @@
 /* Build glibc with tunables support.  */
 #define HAVE_TUNABLES 0
 
+/* Define if PIE is unsupported.  */
+#undef PIE_UNSUPPORTED
+
 /* Define if static PIE is supported.  */
 #undef SUPPORT_STATIC_PIE
 
diff --git a/config.make.in b/config.make.in
index cbf59114b0..e8630a8d0c 100644
--- a/config.make.in
+++ b/config.make.in
@@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
 
 # Configuration options.
 build-shared = @shared@
-build-pic-default= @libc_cv_pic_default@
-build-pie-default= @libc_cv_pie_default@
-cc-pie-default= @libc_cv_cc_pie_default@
 build-profile = @profile@
 build-static-nss = @static_nss@
 cross-compiling = @cross_compiling@
diff --git a/configure b/configure
index 2f9adca064..0d295e2913 100755
--- a/configure
+++ b/configure
@@ -596,9 +596,6 @@ DEFINES
 static_nss
 profile
 libc_cv_multidir
-libc_cv_pie_default
-libc_cv_cc_pie_default
-libc_cv_pic_default
 shared
 static
 ldd_rewrite_script
@@ -767,7 +764,7 @@ with_nonshared_cflags
 enable_sanity_checks
 enable_shared
 enable_profile
-enable_static_pie
+enable_default_pie
 enable_timezone_tools
 enable_hardcoded_path_in_tests
 enable_hidden_plt
@@ -1423,8 +1420,8 @@ Optional Features:
                           in special situations) [default=yes]
   --enable-shared         build shared library [default=yes if GNU ld]
   --enable-profile        build profiled library [default=no]
-  --enable-static-pie     enable static PIE support and use it in the
-                          testsuite [default=no]
+  --disable-default-pie   Do not build glibc programs and the testsuite as PIE
+                          [default=no]
   --disable-timezone-tools
                           do not install timezone tools [default=install]
   --enable-hardcoded-path-in-tests
@@ -3408,11 +3405,11 @@ else
   profile=no
 fi
 
-# Check whether --enable-static-pie was given.
-if test "${enable_static_pie+set}" = set; then :
-  enableval=$enable_static_pie; static_pie=$enableval
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; default_pie=$enableval
 else
-  static_pie=no
+  default_pie=yes
 fi
 
 # Check whether --enable-timezone-tools was given.
@@ -6959,7 +6956,8 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
 $as_echo "$libc_cv_pic_default" >&6; }
-
+config_vars="$config_vars
+build-pic-default = $libc_cv_pic_default"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
 $as_echo_n "checking whether -fPIE is default... " >&6; }
@@ -6979,17 +6977,37 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
 $as_echo "$libc_cv_cc_pie_default" >&6; }
-libc_cv_pie_default=$libc_cv_cc_pie_default
-
-
-
-# Set the `multidir' variable by grabbing the variable from the compiler.
-# We do it once and save the result in a generated makefile.
-libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
-
+config_vars="$config_vars
+cc-pie-default = $libc_cv_cc_pie_default"
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
+$as_echo_n "checking if we can build programs as PIE... " >&6; }
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libc_cv_pie_default=yes
+else
+  libc_cv_pie_default=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
+$as_echo "$libc_cv_pie_default" >&6; }
+config_vars="$config_vars
+build-pie-default = $libc_cv_pie_default"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
+$as_echo_n "checking if we can build static PIE programs... " >&6; }
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #ifndef SUPPORT_STATIC_PIE
@@ -6997,22 +7015,25 @@ if test "$static_pie" = yes; then
 #endif
 _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
-
+  libc_cv_static_pie=yes
 else
-  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
+  libc_cv_static_pie=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
+  if test "$libc_cv_static_pie" = "yes"; then
+    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
 
+  fi
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
+$as_echo "$libc_cv_static_pie" >&6; }
 config_vars="$config_vars
-enable-static-pie = $static_pie"
+enable-static-pie = $libc_cv_static_pie"
+
+# Set the `multidir' variable by grabbing the variable from the compiler.
+# We do it once and save the result in a generated makefile.
+libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
+
 
 
 
diff --git a/configure.ac b/configure.ac
index 7eb4239359..b5f89d0bd5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
 			     [build profiled library @<:@default=no@:>@]),
 	      [profile=$enableval],
 	      [profile=no])
-AC_ARG_ENABLE([static-pie],
-	      AS_HELP_STRING([--enable-static-pie],
-			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
-	      [static_pie=$enableval],
-	      [static_pie=no])
+AC_ARG_ENABLE([default-pie],
+	      AS_HELP_STRING([--disable-default-pie],
+			     [Do not build glibc programs and the testsuite as PIE @<:@default=no@:>@]),
+	      [default_pie=$enableval],
+	      [default_pie=yes])
 AC_ARG_ENABLE([timezone-tools],
 	      AS_HELP_STRING([--disable-timezone-tools],
 			     [do not install timezone tools @<:@default=install@:>@]),
@@ -1839,7 +1839,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_pic_default=no
 fi
 rm -f conftest.*])
-AC_SUBST(libc_cv_pic_default)
+LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
 
 AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
 [libc_cv_cc_pie_default=yes
@@ -1852,30 +1852,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_cc_pie_default=no
 fi
 rm -f conftest.*])
-libc_cv_pie_default=$libc_cv_cc_pie_default
-AC_SUBST(libc_cv_cc_pie_default)
-AC_SUBST(libc_cv_pie_default)
+LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
+
+AC_MSG_CHECKING(if we can build programs as PIE)
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
+fi
+AC_MSG_RESULT($libc_cv_pie_default)
+LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
+
+AC_MSG_CHECKING(if we can build static PIE programs)
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
+# error static PIE is not supported
+#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
+  if test "$libc_cv_static_pie" = "yes"; then
+    AC_DEFINE(ENABLE_STATIC_PIE)
+  fi
+fi
+AC_MSG_RESULT($libc_cv_static_pie)
+LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
 
 # Set the `multidir' variable by grabbing the variable from the compiler.
 # We do it once and save the result in a generated makefile.
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
 AC_SUBST(libc_cv_multidir)
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
-# error static PIE is not supported
-#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  AC_DEFINE(ENABLE_STATIC_PIE)
-fi
-LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
-
 AC_SUBST(profile)
 AC_SUBST(static_nss)
 
diff --git a/manual/install.texi b/manual/install.texi
index 46f73b538d..1320ac69b3 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -141,15 +141,13 @@ Don't build shared libraries even if it is possible.  Not all systems
 support shared libraries; you need ELF support and (currently) the GNU
 linker.
 
-@item --enable-static-pie
-Enable static position independent executable (static PIE) support.
-Static PIE is similar to static executable, but can be loaded at any
-address without help from a dynamic linker.  All static programs as
-well as static tests are built as static PIE, except for those marked
-with no-pie.  The resulting glibc can be used with the GCC option,
--static-pie, which is available with GCC 8 or above, to create static
-PIE.  This option also implies that glibc programs and tests are created
-as dynamic position independent executables (PIE) by default.
+@item --disable-default-pie
+Don't build glibc programs and the testsuite as position independent
+executables (PIE).  By default, glibc programs and tests are created as
+position independent executables on targets that support it.  If the toolchain
+and architecture support it, static executables are built as static PIE and the
+resulting glibc can be used with the GCC option, -static-pie, which is
+available with GCC 8 or above, to create static PIE.
 
 @item --enable-cet
 @itemx --enable-cet=permissive
diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 6ae2172956..2f0f435166 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 # Build many configurations of glibc.
 # Copyright (C) 2016-2021 Free Software Foundation, Inc.
+# Copyright (C) The GNU Toolchain Authors.
 # This file is part of the GNU C Library.
 #
 # The GNU C Library is free software; you can redistribute it and/or
@@ -437,15 +438,15 @@ class Context(object):
                                                '--disable-experimental-malloc',
                                                '--disable-build-nscd',
                                                '--disable-nscd']},
-                                      {'variant': 'static-pie',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'x32-static-pie',
+                                      {'variant': 'no-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'x32-no-pie',
                                        'ccopts': '-mx32',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'static-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'no-pie',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
-                                       'cfg': ['--enable-static-pie']},
+                                       'cfg': ['--disable-default-pie']},
                                       {'variant': 'disable-multi-arch',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
diff --git a/sysdeps/alpha/configure b/sysdeps/alpha/configure
index 464b596527..3d665d96f2 100644
--- a/sysdeps/alpha/configure
+++ b/sysdeps/alpha/configure
@@ -5,4 +5,9 @@
 # symbols in a position independent way.
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/alpha/configure.ac b/sysdeps/alpha/configure.ac
index 38e52e71ac..8f9a39ed2e 100644
--- a/sysdeps/alpha/configure.ac
+++ b/sysdeps/alpha/configure.ac
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # With required gcc+binutils, we can always access static and hidden
 # symbols in a position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
index 19acb084fb..27464eb707 100644
--- a/sysdeps/csky/configure
+++ b/sysdeps/csky/configure
@@ -2,3 +2,10 @@
  # Local configure fragment for sysdeps/csky.
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
+
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
index 5656b665da..8e00824909 100644
--- a/sysdeps/csky/configure.ac
+++ b/sysdeps/csky/configure.ac
@@ -2,3 +2,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/csky.
 
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
index 2cfe6cbea1..cf5acf966d 100644
--- a/sysdeps/hppa/configure
+++ b/sysdeps/hppa/configure
@@ -30,3 +30,10 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
 cat >>confdefs.h <<_ACEOF
 #define ASM_LINE_SEP $libc_cv_asm_line_sep
 _ACEOF
+
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
index 1ec417b947..3e1c35bbd9 100644
--- a/sysdeps/hppa/configure.ac
+++ b/sysdeps/hppa/configure.ac
@@ -19,3 +19,8 @@ else
 fi
 rm -f conftest*])
 AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
index 1ef70921bc..748cb52601 100644
--- a/sysdeps/ia64/configure
+++ b/sysdeps/ia64/configure
@@ -3,4 +3,9 @@
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
index 3bae9fc5e1..8e5fba32c3 100644
--- a/sysdeps/ia64/configure.ac
+++ b/sysdeps/ia64/configure.ac
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 dnl It is always possible to access static and hidden symbols in an
 dnl position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
index 8d0702ad43..3303e5dff8 100644
--- a/sysdeps/mach/hurd/configure
+++ b/sysdeps/mach/hurd/configure
@@ -49,3 +49,9 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# Hurd build needs to be updated to support static pie, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
index 82d085af33..022c2eff79 100644
--- a/sysdeps/mach/hurd/configure.ac
+++ b/sysdeps/mach/hurd/configure.ac
@@ -29,3 +29,8 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# Hurd build needs to be updated to support static pie, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
new file mode 100755
index 0000000000..e6652562d2
--- /dev/null
+++ b/sysdeps/microblaze/configure
@@ -0,0 +1,8 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/microblaze.
+
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
new file mode 100644
index 0000000000..1c58f70a7b
--- /dev/null
+++ b/sysdeps/microblaze/configure.ac
@@ -0,0 +1,7 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/microblaze.
+
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 1be9a3db2c..12c2c1b085 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -2,6 +2,7 @@
 long-double-fcts = yes
 
 pie-ccflag = -fPIE
+no-pie-ccflag = -fno-PIE
 
 ifeq ($(subdir),gmon)
 sysdep_routines += sparc-mcount
-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] Replace --enable-static-pie with --disable-default-pie
  2021-12-08  6:39 ` [PATCH v2] " Siddhesh Poyarekar
@ 2021-12-10 17:35   ` Siddhesh Poyarekar
  2021-12-10 19:28   ` Adhemerval Zanella
  1 sibling, 0 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-10 17:35 UTC (permalink / raw)
  To: libc-alpha; +Cc: fweimer, Adhemerval Zanella

On 12/8/21 12:09, Siddhesh Poyarekar via Libc-alpha wrote:
> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
> 
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
> 
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64, alpha and csky
> don't work because the linker is unable to handle a pcrel relocation
> generated from PIE objects.  The microblaze compiler is currently
> failing with an ICE.  GNU hurd tries to enable static-pie, which does
> not work and hence fails.  All these targets have default PIE disabled
> at the moment and I have left it to the target maintainers to enable PIE
> on their targets.
> 
> build-many-glibcs runs clean for all targets.  I also tested x86_64 on
> Fedora and Ubuntu, to verify that the default build as well as
> --disable-default-pie work as expected with both system toolchains.
> 
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
> ---
> Changes from v1:
> - Filed bugs for build-many-glibcs failures and mentioned them.
> - Updated comments and documentation based on review comments.

Adhemerval, had you reviewed the rest of the changes in v1?  If yes then 
I could push this one since changes are mostly in documentation and 
comments.

Thanks,
Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2] Replace --enable-static-pie with --disable-default-pie
  2021-12-08  6:39 ` [PATCH v2] " Siddhesh Poyarekar
  2021-12-10 17:35   ` Siddhesh Poyarekar
@ 2021-12-10 19:28   ` Adhemerval Zanella
  1 sibling, 0 replies; 17+ messages in thread
From: Adhemerval Zanella @ 2021-12-10 19:28 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: fweimer



On 08/12/2021 03:39, Siddhesh Poyarekar wrote:
> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
> 
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
> 
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64, alpha and csky
> don't work because the linker is unable to handle a pcrel relocation
> generated from PIE objects.  The microblaze compiler is currently
> failing with an ICE.  GNU hurd tries to enable static-pie, which does
> not work and hence fails.  All these targets have default PIE disabled
> at the moment and I have left it to the target maintainers to enable PIE
> on their targets.
> 
> build-many-glibcs runs clean for all targets.  I also tested x86_64 on
> Fedora and Ubuntu, to verify that the default build as well as
> --disable-default-pie work as expected with both system toolchains.
> 
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
> Changes from v1:
> - Filed bugs for build-many-glibcs failures and mentioned them.
> - Updated comments and documentation based on review comments.
> 
>  INSTALL                         | 18 ++++---
>  Makeconfig                      | 21 ++++++---
>  NEWS                            | 13 ++++++
>  config.h.in                     |  3 ++
>  config.make.in                  |  3 --
>  configure                       | 83 +++++++++++++++++++++------------
>  configure.ac                    | 56 ++++++++++++----------
>  manual/install.texi             | 16 +++----
>  scripts/build-many-glibcs.py    | 13 +++---
>  sysdeps/alpha/configure         |  5 ++
>  sysdeps/alpha/configure.ac      |  4 ++
>  sysdeps/csky/configure          |  7 +++
>  sysdeps/csky/configure.ac       |  5 ++
>  sysdeps/hppa/configure          |  7 +++
>  sysdeps/hppa/configure.ac       |  5 ++
>  sysdeps/ia64/configure          |  5 ++
>  sysdeps/ia64/configure.ac       |  4 ++
>  sysdeps/mach/hurd/configure     |  6 +++
>  sysdeps/mach/hurd/configure.ac  |  5 ++
>  sysdeps/microblaze/configure    |  8 ++++
>  sysdeps/microblaze/configure.ac |  7 +++
>  sysdeps/sparc/Makefile          |  1 +
>  22 files changed, 205 insertions(+), 90 deletions(-)
>  create mode 100755 sysdeps/microblaze/configure
>  create mode 100644 sysdeps/microblaze/configure.ac
> 
> diff --git a/INSTALL b/INSTALL
> index 02dcf6b1ca..d6d93ec9be 100644
> --- a/INSTALL
> +++ b/INSTALL
> @@ -111,16 +111,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
>       systems support shared libraries; you need ELF support and
>       (currently) the GNU linker.
>  
> -'--enable-static-pie'
> -     Enable static position independent executable (static PIE) support.
> -     Static PIE is similar to static executable, but can be loaded at
> -     any address without help from a dynamic linker.  All static
> -     programs as well as static tests are built as static PIE, except
> -     for those marked with no-pie.  The resulting glibc can be used with
> -     the GCC option, -static-pie, which is available with GCC 8 or
> -     above, to create static PIE. This option also implies that glibc
> -     programs and tests are created as dynamic position independent
> -     executables (PIE) by default.
> +'--disable-default-pie'
> +     Don't build glibc programs and the testsuite as position
> +     independent executables (PIE). By default, glibc programs and tests
> +     are created as position independent executables on targets that
> +     support it.  If the toolchain and architecture support it, static
> +     executables are built as static PIE and the resulting glibc can be
> +     used with the GCC option, -static-pie, which is available with GCC
> +     8 or above, to create static PIE.
>  
>  '--enable-cet'
>  '--enable-cet=permissive'
> diff --git a/Makeconfig b/Makeconfig
> index 3fa2f13003..775bf12b65 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -1,4 +1,5 @@
>  # Copyright (C) 1991-2021 Free Software Foundation, Inc.
> +# Copyright (C) The GNU Toolchain Authors.
>  # This file is part of the GNU C Library.
>  
>  # The GNU C Library is free software; you can redistribute it and/or
> @@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
>  LDFLAGS-rtld += $(hashstyle-LDFLAGS)
>  endif
>  
> -ifeq (yes,$(enable-static-pie))
> +ifeq (no,$(build-pie-default))
> +pie-default = $(no-pie-ccflag)
> +else # build-pie-default
>  pic-default = -DPIC
>  # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
>  pie-default = $(pie-ccflag)
> +
> +ifeq (yes,$(enable-static-pie))
>  ifeq (yes,$(have-static-pie))
> -default-pie-ldflag = -static-pie
> +static-pie-ldflag = -static-pie
>  else
>  # Static PIE can't have dynamic relocations in read-only segments since
>  # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
>  # for PIE to support exception.
> -default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
> -endif
> -endif
> +static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
> +endif # have-static-pie
> +endif # enable-static-pie
> +endif # build-pie-default
>  
>  # If lazy relocations are disabled, add the -z now flag.  Use
>  # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
> @@ -444,7 +450,7 @@ endif
>  # Command for statically linking programs with the C library.
>  ifndef +link-static
>  +link-static-before-inputs = -nostdlib -nostartfiles -static \
> -	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
> +	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
>  	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
>  	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
>  	      $(+preinit) $(+prectorT)
> @@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
>  +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
>  +link-printers-tests = $(+link-pie-printers-tests)
>  else  # not build-pie-default
> -+link-before-inputs = -nostdlib -nostartfiles \
> ++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
>  	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
>  	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
>  	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
> @@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
>  endif
>  # This can be changed by a sysdep makefile
>  pie-ccflag = -fpie
> +no-pie-ccflag = -fno-pie
>  # This one should always stay like this unless there is a very good reason.
>  PIE-ccflag = -fPIE
>  ifeq (yes,$(build-profile))
> diff --git a/NEWS b/NEWS
> index f10971b180..f808764de9 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -68,6 +68,15 @@ Major new features:
>    to be used by compilers for optimizing usage of 'memcmp' when its
>    return value is only used for its boolean status.
>  
> +* All programs and the testsuite in glibc are now built as position independent
> +  executables (PIE) by default on toolchains and architectures that support it.
> +  Further, if the toolchain and architecture supports it, even static programs
> +  are built as PIE and the resultant glibc can be used to build static PIE
> +  executables.  A new option --disable-default-pie has been added to disable
> +  this behavior and get a non-PIE build.  This option replaces
> +  --enable-static-pie, which no longer has any effect on the build
> +  configuration.
> +
>  Deprecated and removed features, and other changes affecting compatibility:
>  
>  * The r_version update in the debugger interface makes the glibc binary
> @@ -80,6 +89,10 @@ Deprecated and removed features, and other changes affecting compatibility:
>  
>  * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
>  
> +* The --enable-static-pie option is no longer available.  The glibc build
> +  configuration script now automatically detects static-pie support in the
> +  toolchain and architecture and enables it if available.
> +
>  Changes to build and runtime requirements:
>  
>    [Add changes to build and runtime requirements here]
> diff --git a/config.h.in b/config.h.in
> index 0a6f57b006..acce608373 100644
> --- a/config.h.in
> +++ b/config.h.in
> @@ -265,6 +265,9 @@
>  /* Build glibc with tunables support.  */
>  #define HAVE_TUNABLES 0
>  
> +/* Define if PIE is unsupported.  */
> +#undef PIE_UNSUPPORTED
> +
>  /* Define if static PIE is supported.  */
>  #undef SUPPORT_STATIC_PIE
>  
> diff --git a/config.make.in b/config.make.in
> index cbf59114b0..e8630a8d0c 100644
> --- a/config.make.in
> +++ b/config.make.in
> @@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
>  
>  # Configuration options.
>  build-shared = @shared@
> -build-pic-default= @libc_cv_pic_default@
> -build-pie-default= @libc_cv_pie_default@
> -cc-pie-default= @libc_cv_cc_pie_default@
>  build-profile = @profile@
>  build-static-nss = @static_nss@
>  cross-compiling = @cross_compiling@
> diff --git a/configure b/configure
> index 2f9adca064..0d295e2913 100755
> --- a/configure
> +++ b/configure
> @@ -596,9 +596,6 @@ DEFINES
>  static_nss
>  profile
>  libc_cv_multidir
> -libc_cv_pie_default
> -libc_cv_cc_pie_default
> -libc_cv_pic_default
>  shared
>  static
>  ldd_rewrite_script
> @@ -767,7 +764,7 @@ with_nonshared_cflags
>  enable_sanity_checks
>  enable_shared
>  enable_profile
> -enable_static_pie
> +enable_default_pie
>  enable_timezone_tools
>  enable_hardcoded_path_in_tests
>  enable_hidden_plt
> @@ -1423,8 +1420,8 @@ Optional Features:
>                            in special situations) [default=yes]
>    --enable-shared         build shared library [default=yes if GNU ld]
>    --enable-profile        build profiled library [default=no]
> -  --enable-static-pie     enable static PIE support and use it in the
> -                          testsuite [default=no]
> +  --disable-default-pie   Do not build glibc programs and the testsuite as PIE
> +                          [default=no]
>    --disable-timezone-tools
>                            do not install timezone tools [default=install]
>    --enable-hardcoded-path-in-tests
> @@ -3408,11 +3405,11 @@ else
>    profile=no
>  fi
>  
> -# Check whether --enable-static-pie was given.
> -if test "${enable_static_pie+set}" = set; then :
> -  enableval=$enable_static_pie; static_pie=$enableval
> +# Check whether --enable-default-pie was given.
> +if test "${enable_default_pie+set}" = set; then :
> +  enableval=$enable_default_pie; default_pie=$enableval
>  else
> -  static_pie=no
> +  default_pie=yes
>  fi
>  
>  # Check whether --enable-timezone-tools was given.
> @@ -6959,7 +6956,8 @@ rm -f conftest.*
>  fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
>  $as_echo "$libc_cv_pic_default" >&6; }
> -
> +config_vars="$config_vars
> +build-pic-default = $libc_cv_pic_default"
>  
>  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
>  $as_echo_n "checking whether -fPIE is default... " >&6; }
> @@ -6979,17 +6977,37 @@ rm -f conftest.*
>  fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
>  $as_echo "$libc_cv_cc_pie_default" >&6; }
> -libc_cv_pie_default=$libc_cv_cc_pie_default
> -
> -
> -
> -# Set the `multidir' variable by grabbing the variable from the compiler.
> -# We do it once and save the result in a generated makefile.
> -libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
> -
> +config_vars="$config_vars
> +cc-pie-default = $libc_cv_cc_pie_default"
>  
> -if test "$static_pie" = yes; then
> -  # Check target support for static PIE
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
> +$as_echo_n "checking if we can build programs as PIE... " >&6; }
> +if test "x$default_pie" != xno; then
> +  # Disable build-pie-default if target does not support it.
> +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h.  */
> +#ifdef PIE_UNSUPPORTED
> +# error PIE is not supported
> +#endif
> +_ACEOF
> +if ac_fn_c_try_compile "$LINENO"; then :
> +  libc_cv_pie_default=yes
> +else
> +  libc_cv_pie_default=no
> +fi
> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
> +$as_echo "$libc_cv_pie_default" >&6; }
> +config_vars="$config_vars
> +build-pie-default = $libc_cv_pie_default"
> +
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
> +$as_echo_n "checking if we can build static PIE programs... " >&6; }
> +libc_cv_static_pie=$libc_cv_pie_default
> +if test "x$libc_cv_pie_default" != xno \
> +   -a "$libc_cv_no_dynamic_linker" = yes; then
> +  # Enable static-pie if available
>    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
>  /* end confdefs.h.  */
>  #ifndef SUPPORT_STATIC_PIE
> @@ -6997,22 +7015,25 @@ if test "$static_pie" = yes; then
>  #endif
>  _ACEOF
>  if ac_fn_c_try_compile "$LINENO"; then :
> -
> +  libc_cv_static_pie=yes
>  else
> -  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
> +  libc_cv_static_pie=no
>  fi
>  rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> -  # The linker must support --no-dynamic-linker.
> -  if test "$libc_cv_no_dynamic_linker" != yes; then
> -    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
> -  fi
> -  # Default to PIE.
> -  libc_cv_pie_default=yes
> -  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
> +  if test "$libc_cv_static_pie" = "yes"; then
> +    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
>  
> +  fi
>  fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
> +$as_echo "$libc_cv_static_pie" >&6; }
>  config_vars="$config_vars
> -enable-static-pie = $static_pie"
> +enable-static-pie = $libc_cv_static_pie"
> +
> +# Set the `multidir' variable by grabbing the variable from the compiler.
> +# We do it once and save the result in a generated makefile.
> +libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
> +
>  
>  
>  
> diff --git a/configure.ac b/configure.ac
> index 7eb4239359..b5f89d0bd5 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -179,11 +179,11 @@ AC_ARG_ENABLE([profile],
>  			     [build profiled library @<:@default=no@:>@]),
>  	      [profile=$enableval],
>  	      [profile=no])
> -AC_ARG_ENABLE([static-pie],
> -	      AS_HELP_STRING([--enable-static-pie],
> -			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
> -	      [static_pie=$enableval],
> -	      [static_pie=no])
> +AC_ARG_ENABLE([default-pie],
> +	      AS_HELP_STRING([--disable-default-pie],
> +			     [Do not build glibc programs and the testsuite as PIE @<:@default=no@:>@]),
> +	      [default_pie=$enableval],
> +	      [default_pie=yes])
>  AC_ARG_ENABLE([timezone-tools],
>  	      AS_HELP_STRING([--disable-timezone-tools],
>  			     [do not install timezone tools @<:@default=install@:>@]),
> @@ -1839,7 +1839,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>    libc_cv_pic_default=no
>  fi
>  rm -f conftest.*])
> -AC_SUBST(libc_cv_pic_default)
> +LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
>  
>  AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
>  [libc_cv_cc_pie_default=yes
> @@ -1852,30 +1852,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
>    libc_cv_cc_pie_default=no
>  fi
>  rm -f conftest.*])
> -libc_cv_pie_default=$libc_cv_cc_pie_default
> -AC_SUBST(libc_cv_cc_pie_default)
> -AC_SUBST(libc_cv_pie_default)
> +LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
> +
> +AC_MSG_CHECKING(if we can build programs as PIE)
> +if test "x$default_pie" != xno; then
> +  # Disable build-pie-default if target does not support it.
> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
> +# error PIE is not supported
> +#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
> +fi
> +AC_MSG_RESULT($libc_cv_pie_default)
> +LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
> +
> +AC_MSG_CHECKING(if we can build static PIE programs)
> +libc_cv_static_pie=$libc_cv_pie_default
> +if test "x$libc_cv_pie_default" != xno \
> +   -a "$libc_cv_no_dynamic_linker" = yes; then
> +  # Enable static-pie if available
> +  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
> +# error static PIE is not supported
> +#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
> +  if test "$libc_cv_static_pie" = "yes"; then
> +    AC_DEFINE(ENABLE_STATIC_PIE)
> +  fi
> +fi
> +AC_MSG_RESULT($libc_cv_static_pie)
> +LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
>  
>  # Set the `multidir' variable by grabbing the variable from the compiler.
>  # We do it once and save the result in a generated makefile.
>  libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
>  AC_SUBST(libc_cv_multidir)
>  
> -if test "$static_pie" = yes; then
> -  # Check target support for static PIE
> -  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
> -# error static PIE is not supported
> -#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
> -  # The linker must support --no-dynamic-linker.
> -  if test "$libc_cv_no_dynamic_linker" != yes; then
> -    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
> -  fi
> -  # Default to PIE.
> -  libc_cv_pie_default=yes
> -  AC_DEFINE(ENABLE_STATIC_PIE)
> -fi
> -LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
> -
>  AC_SUBST(profile)
>  AC_SUBST(static_nss)
>  
> diff --git a/manual/install.texi b/manual/install.texi
> index 46f73b538d..1320ac69b3 100644
> --- a/manual/install.texi
> +++ b/manual/install.texi
> @@ -141,15 +141,13 @@ Don't build shared libraries even if it is possible.  Not all systems
>  support shared libraries; you need ELF support and (currently) the GNU
>  linker.
>  
> -@item --enable-static-pie
> -Enable static position independent executable (static PIE) support.
> -Static PIE is similar to static executable, but can be loaded at any
> -address without help from a dynamic linker.  All static programs as
> -well as static tests are built as static PIE, except for those marked
> -with no-pie.  The resulting glibc can be used with the GCC option,
> --static-pie, which is available with GCC 8 or above, to create static
> -PIE.  This option also implies that glibc programs and tests are created
> -as dynamic position independent executables (PIE) by default.
> +@item --disable-default-pie
> +Don't build glibc programs and the testsuite as position independent
> +executables (PIE).  By default, glibc programs and tests are created as
> +position independent executables on targets that support it.  If the toolchain
> +and architecture support it, static executables are built as static PIE and the
> +resulting glibc can be used with the GCC option, -static-pie, which is
> +available with GCC 8 or above, to create static PIE.
>  
>  @item --enable-cet
>  @itemx --enable-cet=permissive
> diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
> index 6ae2172956..2f0f435166 100755
> --- a/scripts/build-many-glibcs.py
> +++ b/scripts/build-many-glibcs.py
> @@ -1,6 +1,7 @@
>  #!/usr/bin/python3
>  # Build many configurations of glibc.
>  # Copyright (C) 2016-2021 Free Software Foundation, Inc.
> +# Copyright (C) The GNU Toolchain Authors.
>  # This file is part of the GNU C Library.
>  #
>  # The GNU C Library is free software; you can redistribute it and/or
> @@ -437,15 +438,15 @@ class Context(object):
>                                                 '--disable-experimental-malloc',
>                                                 '--disable-build-nscd',
>                                                 '--disable-nscd']},
> -                                      {'variant': 'static-pie',
> -                                       'cfg': ['--enable-static-pie']},
> -                                      {'variant': 'x32-static-pie',
> +                                      {'variant': 'no-pie',
> +                                       'cfg': ['--disable-default-pie']},
> +                                      {'variant': 'x32-no-pie',
>                                         'ccopts': '-mx32',
> -                                       'cfg': ['--enable-static-pie']},
> -                                      {'variant': 'static-pie',
> +                                       'cfg': ['--disable-default-pie']},
> +                                      {'variant': 'no-pie',
>                                         'arch': 'i686',
>                                         'ccopts': '-m32 -march=i686',
> -                                       'cfg': ['--enable-static-pie']},
> +                                       'cfg': ['--disable-default-pie']},
>                                        {'variant': 'disable-multi-arch',
>                                         'arch': 'i686',
>                                         'ccopts': '-m32 -march=i686',
> diff --git a/sysdeps/alpha/configure b/sysdeps/alpha/configure
> index 464b596527..3d665d96f2 100644
> --- a/sysdeps/alpha/configure
> +++ b/sysdeps/alpha/configure
> @@ -5,4 +5,9 @@
>  # symbols in a position independent way.
>  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
>  
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/alpha/configure.ac b/sysdeps/alpha/configure.ac
> index 38e52e71ac..8f9a39ed2e 100644
> --- a/sysdeps/alpha/configure.ac
> +++ b/sysdeps/alpha/configure.ac
> @@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  # With required gcc+binutils, we can always access static and hidden
>  # symbols in a position independent way.
>  AC_DEFINE(PI_STATIC_AND_HIDDEN)
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +AC_DEFINE(PIE_UNSUPPORTED)
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
> index 19acb084fb..27464eb707 100644
> --- a/sysdeps/csky/configure
> +++ b/sysdeps/csky/configure
> @@ -2,3 +2,10 @@
>   # Local configure fragment for sysdeps/csky.
>  
>  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
> +
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
> index 5656b665da..8e00824909 100644
> --- a/sysdeps/csky/configure.ac
> +++ b/sysdeps/csky/configure.ac
> @@ -2,3 +2,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  # Local configure fragment for sysdeps/csky.
>  
>  AC_DEFINE(PI_STATIC_AND_HIDDEN)
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
> index 2cfe6cbea1..cf5acf966d 100644
> --- a/sysdeps/hppa/configure
> +++ b/sysdeps/hppa/configure
> @@ -30,3 +30,10 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
>  cat >>confdefs.h <<_ACEOF
>  #define ASM_LINE_SEP $libc_cv_asm_line_sep
>  _ACEOF
> +
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
> index 1ec417b947..3e1c35bbd9 100644
> --- a/sysdeps/hppa/configure.ac
> +++ b/sysdeps/hppa/configure.ac
> @@ -19,3 +19,8 @@ else
>  fi
>  rm -f conftest*])
>  AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
> index 1ef70921bc..748cb52601 100644
> --- a/sysdeps/ia64/configure
> +++ b/sysdeps/ia64/configure
> @@ -3,4 +3,9 @@
>  
>  $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
>  
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
> index 3bae9fc5e1..8e5fba32c3 100644
> --- a/sysdeps/ia64/configure.ac
> +++ b/sysdeps/ia64/configure.ac
> @@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
>  dnl It is always possible to access static and hidden symbols in an
>  dnl position independent way.
>  AC_DEFINE(PI_STATIC_AND_HIDDEN)
> +
> +# PIE builds fail on binutils 2.37 and earlier, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
> +AC_DEFINE(PIE_UNSUPPORTED)
>  # work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
> index 8d0702ad43..3303e5dff8 100644
> --- a/sysdeps/mach/hurd/configure
> +++ b/sysdeps/mach/hurd/configure
> @@ -49,3 +49,9 @@ fi
>  
>  # Hurd has libpthread as a separate library.
>  pthread_in_libc=no
> +
> +# Hurd build needs to be updated to support static pie, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
> index 82d085af33..022c2eff79 100644
> --- a/sysdeps/mach/hurd/configure.ac
> +++ b/sysdeps/mach/hurd/configure.ac
> @@ -29,3 +29,8 @@ fi
>  
>  # Hurd has libpthread as a separate library.
>  pthread_in_libc=no
> +
> +# Hurd build needs to be updated to support static pie, see:
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
> new file mode 100755
> index 0000000000..e6652562d2
> --- /dev/null
> +++ b/sysdeps/microblaze/configure
> @@ -0,0 +1,8 @@
> +# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
> + # Local configure fragment for sysdeps/microblaze.
> +
> +# gcc 11.2.1 and earlier crash with an internal compiler error, see:
> +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
> +$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
> +
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
> new file mode 100644
> index 0000000000..1c58f70a7b
> --- /dev/null
> +++ b/sysdeps/microblaze/configure.ac
> @@ -0,0 +1,7 @@
> +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
> +# Local configure fragment for sysdeps/microblaze.
> +
> +# gcc 11.2.1 and earlier crash with an internal compiler error, see:
> +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
> +AC_DEFINE(PIE_UNSUPPORTED)
> +# work around problem with autoconf and empty lines at the end of files
> diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
> index 1be9a3db2c..12c2c1b085 100644
> --- a/sysdeps/sparc/Makefile
> +++ b/sysdeps/sparc/Makefile
> @@ -2,6 +2,7 @@
>  long-double-fcts = yes
>  
>  pie-ccflag = -fPIE
> +no-pie-ccflag = -fno-PIE
>  
>  ifeq ($(subdir),gmon)
>  sysdep_routines += sparc-mcount
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
                   ` (3 preceding siblings ...)
  2021-12-08  6:39 ` [PATCH v2] " Siddhesh Poyarekar
@ 2021-12-13  3:02 ` Siddhesh Poyarekar
  2021-12-13 13:22   ` H.J. Lu
                     ` (2 more replies)
  4 siblings, 3 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-13  3:02 UTC (permalink / raw)
  To: libc-alpha

Build glibc programs and tests as PIE by default and enable static-pie
automatically if the architecture and toolchain supports it.

Also add a new configuration option --disable-default-pie to prevent
building programs as PIE.

Only the following architectures now have PIE disabled by default
because they do not work at the moment.  hppa, ia64, alpha and csky
don't work because the linker is unable to handle a pcrel relocation
generated from PIE objects.  The microblaze compiler is currently
failing with an ICE.  GNU hurd tries to enable static-pie, which does
not work and hence fails.  All these targets have default PIE disabled
at the moment and I have left it to the target maintainers to enable PIE
on their targets.

build-many-glibcs runs clean for all targets.  I also tested x86_64 on
Fedora and Ubuntu, to verify that the default build as well as
--disable-default-pie work as expected with both system toolchains.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
 INSTALL                         | 18 ++++---
 Makeconfig                      | 21 ++++++---
 NEWS                            | 13 ++++++
 config.h.in                     |  3 ++
 config.make.in                  |  3 --
 configure                       | 83 +++++++++++++++++++++------------
 configure.ac                    | 56 ++++++++++++----------
 manual/install.texi             | 16 +++----
 scripts/build-many-glibcs.py    | 13 +++---
 sysdeps/alpha/configure         |  5 ++
 sysdeps/alpha/configure.ac      |  4 ++
 sysdeps/csky/configure          |  7 +++
 sysdeps/csky/configure.ac       |  5 ++
 sysdeps/hppa/configure          |  7 +++
 sysdeps/hppa/configure.ac       |  5 ++
 sysdeps/ia64/configure          |  5 ++
 sysdeps/ia64/configure.ac       |  4 ++
 sysdeps/mach/hurd/configure     |  6 +++
 sysdeps/mach/hurd/configure.ac  |  5 ++
 sysdeps/microblaze/configure    |  8 ++++
 sysdeps/microblaze/configure.ac |  7 +++
 sysdeps/sparc/Makefile          |  1 +
 22 files changed, 205 insertions(+), 90 deletions(-)
 create mode 100755 sysdeps/microblaze/configure
 create mode 100644 sysdeps/microblaze/configure.ac

diff --git a/INSTALL b/INSTALL
index 899d7f1ed7..331d405e56 100644
--- a/INSTALL
+++ b/INSTALL
@@ -116,16 +116,14 @@ if 'CFLAGS' is specified it must enable optimization.  For example:
      systems support shared libraries; you need ELF support and
      (currently) the GNU linker.
 
-'--enable-static-pie'
-     Enable static position independent executable (static PIE) support.
-     Static PIE is similar to static executable, but can be loaded at
-     any address without help from a dynamic linker.  All static
-     programs as well as static tests are built as static PIE, except
-     for those marked with no-pie.  The resulting glibc can be used with
-     the GCC option, -static-pie, which is available with GCC 8 or
-     above, to create static PIE. This option also implies that glibc
-     programs and tests are created as dynamic position independent
-     executables (PIE) by default.
+'--disable-default-pie'
+     Don't build glibc programs and the testsuite as position
+     independent executables (PIE). By default, glibc programs and tests
+     are created as position independent executables on targets that
+     support it.  If the toolchain and architecture support it, static
+     executables are built as static PIE and the resulting glibc can be
+     used with the GCC option, -static-pie, which is available with GCC
+     8 or above, to create static PIE.
 
 '--enable-cet'
 '--enable-cet=permissive'
diff --git a/Makeconfig b/Makeconfig
index 3fa2f13003..775bf12b65 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1,4 +1,5 @@
 # Copyright (C) 1991-2021 Free Software Foundation, Inc.
+# Copyright (C) The GNU Toolchain Authors.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -376,19 +377,24 @@ LDFLAGS.so += $(hashstyle-LDFLAGS)
 LDFLAGS-rtld += $(hashstyle-LDFLAGS)
 endif
 
-ifeq (yes,$(enable-static-pie))
+ifeq (no,$(build-pie-default))
+pie-default = $(no-pie-ccflag)
+else # build-pie-default
 pic-default = -DPIC
 # Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
 pie-default = $(pie-ccflag)
+
+ifeq (yes,$(enable-static-pie))
 ifeq (yes,$(have-static-pie))
-default-pie-ldflag = -static-pie
+static-pie-ldflag = -static-pie
 else
 # Static PIE can't have dynamic relocations in read-only segments since
 # static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
 # for PIE to support exception.
-default-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
-endif
-endif
+static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
+endif # have-static-pie
+endif # enable-static-pie
+endif # build-pie-default
 
 # If lazy relocations are disabled, add the -z now flag.  Use
 # LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
@@ -444,7 +450,7 @@ endif
 # Command for statically linking programs with the C library.
 ifndef +link-static
 +link-static-before-inputs = -nostdlib -nostartfiles -static \
-	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(default-pie-ldflag)) \
+	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
 	      $(+preinit) $(+prectorT)
@@ -479,7 +485,7 @@ ifeq (yes,$(build-pie-default))
 +link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
 +link-printers-tests = $(+link-pie-printers-tests)
 else  # not build-pie-default
-+link-before-inputs = -nostdlib -nostartfiles \
++link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
 	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
 	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
 	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
@@ -1040,6 +1046,7 @@ PIC-ccflag = -fPIC
 endif
 # This can be changed by a sysdep makefile
 pie-ccflag = -fpie
+no-pie-ccflag = -fno-pie
 # This one should always stay like this unless there is a very good reason.
 PIE-ccflag = -fPIE
 ifeq (yes,$(build-profile))
diff --git a/NEWS b/NEWS
index bf2b6846fc..d864a7b9d8 100644
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,15 @@ Major new features:
 * A symbolic link to the dynamic linker is now installed under
   /usr/bin/ld.so (or more precisely, '${bindir}/ld.so').
 
+* All programs and the testsuite in glibc are now built as position independent
+  executables (PIE) by default on toolchains and architectures that support it.
+  Further, if the toolchain and architecture supports it, even static programs
+  are built as PIE and the resultant glibc can be used to build static PIE
+  executables.  A new option --disable-default-pie has been added to disable
+  this behavior and get a non-PIE build.  This option replaces
+  --enable-static-pie, which no longer has any effect on the build
+  configuration.
+
 Deprecated and removed features, and other changes affecting compatibility:
 
 * The r_version update in the debugger interface makes the glibc binary
@@ -98,6 +107,10 @@ Deprecated and removed features, and other changes affecting compatibility:
 
 * Intel MPX support (lazy PLT, ld.so profile, and LD_AUDIT) has been removed.
 
+* The --enable-static-pie option is no longer available.  The glibc build
+  configuration script now automatically detects static-pie support in the
+  toolchain and architecture and enables it if available.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/config.h.in b/config.h.in
index 2f5124684e..82ade1cec4 100644
--- a/config.h.in
+++ b/config.h.in
@@ -268,6 +268,9 @@
 /* Build glibc with tunables support.  */
 #define HAVE_TUNABLES 0
 
+/* Define if PIE is unsupported.  */
+#undef PIE_UNSUPPORTED
+
 /* Define if static PIE is supported.  */
 #undef SUPPORT_STATIC_PIE
 
diff --git a/config.make.in b/config.make.in
index cbf59114b0..e8630a8d0c 100644
--- a/config.make.in
+++ b/config.make.in
@@ -90,9 +90,6 @@ static-nss-crypt = @libc_cv_static_nss_crypt@
 
 # Configuration options.
 build-shared = @shared@
-build-pic-default= @libc_cv_pic_default@
-build-pie-default= @libc_cv_pie_default@
-cc-pie-default= @libc_cv_cc_pie_default@
 build-profile = @profile@
 build-static-nss = @static_nss@
 cross-compiling = @cross_compiling@
diff --git a/configure b/configure
index e4d013907c..954bae803e 100755
--- a/configure
+++ b/configure
@@ -596,9 +596,6 @@ DEFINES
 static_nss
 profile
 libc_cv_multidir
-libc_cv_pie_default
-libc_cv_cc_pie_default
-libc_cv_pic_default
 shared
 static
 ldd_rewrite_script
@@ -768,7 +765,7 @@ with_timeoutfactor
 enable_sanity_checks
 enable_shared
 enable_profile
-enable_static_pie
+enable_default_pie
 enable_timezone_tools
 enable_hardcoded_path_in_tests
 enable_hidden_plt
@@ -1424,8 +1421,8 @@ Optional Features:
                           in special situations) [default=yes]
   --enable-shared         build shared library [default=yes if GNU ld]
   --enable-profile        build profiled library [default=no]
-  --enable-static-pie     enable static PIE support and use it in the
-                          testsuite [default=no]
+  --disable-default-pie   Do not build glibc programs and the testsuite as PIE
+                          [default=no]
   --disable-timezone-tools
                           do not install timezone tools [default=install]
   --enable-hardcoded-path-in-tests
@@ -3424,11 +3421,11 @@ else
   profile=no
 fi
 
-# Check whether --enable-static-pie was given.
-if test "${enable_static_pie+set}" = set; then :
-  enableval=$enable_static_pie; static_pie=$enableval
+# Check whether --enable-default-pie was given.
+if test "${enable_default_pie+set}" = set; then :
+  enableval=$enable_default_pie; default_pie=$enableval
 else
-  static_pie=no
+  default_pie=yes
 fi
 
 # Check whether --enable-timezone-tools was given.
@@ -6975,7 +6972,8 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pic_default" >&5
 $as_echo "$libc_cv_pic_default" >&6; }
-
+config_vars="$config_vars
+build-pic-default = $libc_cv_pic_default"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIE is default" >&5
 $as_echo_n "checking whether -fPIE is default... " >&6; }
@@ -6995,17 +6993,37 @@ rm -f conftest.*
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_pie_default" >&5
 $as_echo "$libc_cv_cc_pie_default" >&6; }
-libc_cv_pie_default=$libc_cv_cc_pie_default
-
-
-
-# Set the `multidir' variable by grabbing the variable from the compiler.
-# We do it once and save the result in a generated makefile.
-libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
-
+config_vars="$config_vars
+cc-pie-default = $libc_cv_cc_pie_default"
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build programs as PIE" >&5
+$as_echo_n "checking if we can build programs as PIE... " >&6; }
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libc_cv_pie_default=yes
+else
+  libc_cv_pie_default=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_default" >&5
+$as_echo "$libc_cv_pie_default" >&6; }
+config_vars="$config_vars
+build-pie-default = $libc_cv_pie_default"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can build static PIE programs" >&5
+$as_echo_n "checking if we can build static PIE programs... " >&6; }
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #ifndef SUPPORT_STATIC_PIE
@@ -7013,22 +7031,25 @@ if test "$static_pie" = yes; then
 #endif
 _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
-
+  libc_cv_static_pie=yes
 else
-  as_fn_error $? "the architecture does not support static PIE" "$LINENO" 5
+  libc_cv_static_pie=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    as_fn_error $? "linker support for --no-dynamic-linker needed" "$LINENO" 5
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
+  if test "$libc_cv_static_pie" = "yes"; then
+    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
 
+  fi
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie" >&5
+$as_echo "$libc_cv_static_pie" >&6; }
 config_vars="$config_vars
-enable-static-pie = $static_pie"
+enable-static-pie = $libc_cv_static_pie"
+
+# Set the `multidir' variable by grabbing the variable from the compiler.
+# We do it once and save the result in a generated makefile.
+libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
+
 
 
 
diff --git a/configure.ac b/configure.ac
index a91a7f399c..277d3527d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -186,11 +186,11 @@ AC_ARG_ENABLE([profile],
 			     [build profiled library @<:@default=no@:>@]),
 	      [profile=$enableval],
 	      [profile=no])
-AC_ARG_ENABLE([static-pie],
-	      AS_HELP_STRING([--enable-static-pie],
-			     [enable static PIE support and use it in the testsuite @<:@default=no@:>@]),
-	      [static_pie=$enableval],
-	      [static_pie=no])
+AC_ARG_ENABLE([default-pie],
+	      AS_HELP_STRING([--disable-default-pie],
+			     [Do not build glibc programs and the testsuite as PIE @<:@default=no@:>@]),
+	      [default_pie=$enableval],
+	      [default_pie=yes])
 AC_ARG_ENABLE([timezone-tools],
 	      AS_HELP_STRING([--disable-timezone-tools],
 			     [do not install timezone tools @<:@default=install@:>@]),
@@ -1846,7 +1846,7 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_pic_default=no
 fi
 rm -f conftest.*])
-AC_SUBST(libc_cv_pic_default)
+LIBC_CONFIG_VAR([build-pic-default], [$libc_cv_pic_default])
 
 AC_CACHE_CHECK([whether -fPIE is default], libc_cv_cc_pie_default,
 [libc_cv_cc_pie_default=yes
@@ -1859,30 +1859,38 @@ if eval "${CC-cc} -S conftest.c 2>&AS_MESSAGE_LOG_FD 1>&AS_MESSAGE_LOG_FD"; then
   libc_cv_cc_pie_default=no
 fi
 rm -f conftest.*])
-libc_cv_pie_default=$libc_cv_cc_pie_default
-AC_SUBST(libc_cv_cc_pie_default)
-AC_SUBST(libc_cv_pie_default)
+LIBC_CONFIG_VAR([cc-pie-default], [$libc_cv_cc_pie_default])
+
+AC_MSG_CHECKING(if we can build programs as PIE)
+if test "x$default_pie" != xno; then
+  # Disable build-pie-default if target does not support it.
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifdef PIE_UNSUPPORTED
+# error PIE is not supported
+#endif]])], [libc_cv_pie_default=yes], [libc_cv_pie_default=no])
+fi
+AC_MSG_RESULT($libc_cv_pie_default)
+LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
+
+AC_MSG_CHECKING(if we can build static PIE programs)
+libc_cv_static_pie=$libc_cv_pie_default
+if test "x$libc_cv_pie_default" != xno \
+   -a "$libc_cv_no_dynamic_linker" = yes; then
+  # Enable static-pie if available
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
+# error static PIE is not supported
+#endif]])], [libc_cv_static_pie=yes], [libc_cv_static_pie=no])
+  if test "$libc_cv_static_pie" = "yes"; then
+    AC_DEFINE(ENABLE_STATIC_PIE)
+  fi
+fi
+AC_MSG_RESULT($libc_cv_static_pie)
+LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
 
 # Set the `multidir' variable by grabbing the variable from the compiler.
 # We do it once and save the result in a generated makefile.
 libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory`
 AC_SUBST(libc_cv_multidir)
 
-if test "$static_pie" = yes; then
-  # Check target support for static PIE
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
-# error static PIE is not supported
-#endif]])], , AC_MSG_ERROR([the architecture does not support static PIE]))
-  # The linker must support --no-dynamic-linker.
-  if test "$libc_cv_no_dynamic_linker" != yes; then
-    AC_MSG_ERROR([linker support for --no-dynamic-linker needed])
-  fi
-  # Default to PIE.
-  libc_cv_pie_default=yes
-  AC_DEFINE(ENABLE_STATIC_PIE)
-fi
-LIBC_CONFIG_VAR([enable-static-pie], [$static_pie])
-
 AC_SUBST(profile)
 AC_SUBST(static_nss)
 
diff --git a/manual/install.texi b/manual/install.texi
index fce5155c22..b1afc56f5a 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -146,15 +146,13 @@ Don't build shared libraries even if it is possible.  Not all systems
 support shared libraries; you need ELF support and (currently) the GNU
 linker.
 
-@item --enable-static-pie
-Enable static position independent executable (static PIE) support.
-Static PIE is similar to static executable, but can be loaded at any
-address without help from a dynamic linker.  All static programs as
-well as static tests are built as static PIE, except for those marked
-with no-pie.  The resulting glibc can be used with the GCC option,
--static-pie, which is available with GCC 8 or above, to create static
-PIE.  This option also implies that glibc programs and tests are created
-as dynamic position independent executables (PIE) by default.
+@item --disable-default-pie
+Don't build glibc programs and the testsuite as position independent
+executables (PIE).  By default, glibc programs and tests are created as
+position independent executables on targets that support it.  If the toolchain
+and architecture support it, static executables are built as static PIE and the
+resulting glibc can be used with the GCC option, -static-pie, which is
+available with GCC 8 or above, to create static PIE.
 
 @item --enable-cet
 @itemx --enable-cet=permissive
diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index 6ae2172956..2f0f435166 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 # Build many configurations of glibc.
 # Copyright (C) 2016-2021 Free Software Foundation, Inc.
+# Copyright (C) The GNU Toolchain Authors.
 # This file is part of the GNU C Library.
 #
 # The GNU C Library is free software; you can redistribute it and/or
@@ -437,15 +438,15 @@ class Context(object):
                                                '--disable-experimental-malloc',
                                                '--disable-build-nscd',
                                                '--disable-nscd']},
-                                      {'variant': 'static-pie',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'x32-static-pie',
+                                      {'variant': 'no-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'x32-no-pie',
                                        'ccopts': '-mx32',
-                                       'cfg': ['--enable-static-pie']},
-                                      {'variant': 'static-pie',
+                                       'cfg': ['--disable-default-pie']},
+                                      {'variant': 'no-pie',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
-                                       'cfg': ['--enable-static-pie']},
+                                       'cfg': ['--disable-default-pie']},
                                       {'variant': 'disable-multi-arch',
                                        'arch': 'i686',
                                        'ccopts': '-m32 -march=i686',
diff --git a/sysdeps/alpha/configure b/sysdeps/alpha/configure
index 464b596527..3d665d96f2 100644
--- a/sysdeps/alpha/configure
+++ b/sysdeps/alpha/configure
@@ -5,4 +5,9 @@
 # symbols in a position independent way.
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/alpha/configure.ac b/sysdeps/alpha/configure.ac
index 38e52e71ac..8f9a39ed2e 100644
--- a/sysdeps/alpha/configure.ac
+++ b/sysdeps/alpha/configure.ac
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # With required gcc+binutils, we can always access static and hidden
 # symbols in a position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/csky/configure b/sysdeps/csky/configure
index 19acb084fb..27464eb707 100644
--- a/sysdeps/csky/configure
+++ b/sysdeps/csky/configure
@@ -2,3 +2,10 @@
  # Local configure fragment for sysdeps/csky.
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
+
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/csky/configure.ac b/sysdeps/csky/configure.ac
index 5656b665da..8e00824909 100644
--- a/sysdeps/csky/configure.ac
+++ b/sysdeps/csky/configure.ac
@@ -2,3 +2,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 # Local configure fragment for sysdeps/csky.
 
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure b/sysdeps/hppa/configure
index 2cfe6cbea1..cf5acf966d 100644
--- a/sysdeps/hppa/configure
+++ b/sysdeps/hppa/configure
@@ -30,3 +30,10 @@ $as_echo "$libc_cv_asm_line_sep" >&6; }
 cat >>confdefs.h <<_ACEOF
 #define ASM_LINE_SEP $libc_cv_asm_line_sep
 _ACEOF
+
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/hppa/configure.ac b/sysdeps/hppa/configure.ac
index 1ec417b947..3e1c35bbd9 100644
--- a/sysdeps/hppa/configure.ac
+++ b/sysdeps/hppa/configure.ac
@@ -19,3 +19,8 @@ else
 fi
 rm -f conftest*])
 AC_DEFINE_UNQUOTED(ASM_LINE_SEP, $libc_cv_asm_line_sep)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure b/sysdeps/ia64/configure
index 1ef70921bc..748cb52601 100644
--- a/sysdeps/ia64/configure
+++ b/sysdeps/ia64/configure
@@ -3,4 +3,9 @@
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
 
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/ia64/configure.ac b/sysdeps/ia64/configure.ac
index 3bae9fc5e1..8e5fba32c3 100644
--- a/sysdeps/ia64/configure.ac
+++ b/sysdeps/ia64/configure.ac
@@ -4,4 +4,8 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
 dnl It is always possible to access static and hidden symbols in an
 dnl position independent way.
 AC_DEFINE(PI_STATIC_AND_HIDDEN)
+
+# PIE builds fail on binutils 2.37 and earlier, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28672
+AC_DEFINE(PIE_UNSUPPORTED)
 # work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure b/sysdeps/mach/hurd/configure
index 8d0702ad43..3303e5dff8 100644
--- a/sysdeps/mach/hurd/configure
+++ b/sysdeps/mach/hurd/configure
@@ -49,3 +49,9 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# Hurd build needs to be updated to support static pie, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/mach/hurd/configure.ac b/sysdeps/mach/hurd/configure.ac
index 82d085af33..022c2eff79 100644
--- a/sysdeps/mach/hurd/configure.ac
+++ b/sysdeps/mach/hurd/configure.ac
@@ -29,3 +29,8 @@ fi
 
 # Hurd has libpthread as a separate library.
 pthread_in_libc=no
+
+# Hurd build needs to be updated to support static pie, see:
+# https://sourceware.org/bugzilla/show_bug.cgi?id=28671
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure b/sysdeps/microblaze/configure
new file mode 100755
index 0000000000..e6652562d2
--- /dev/null
+++ b/sysdeps/microblaze/configure
@@ -0,0 +1,8 @@
+# This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/microblaze.
+
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
+$as_echo "#define PIE_UNSUPPORTED 1" >>confdefs.h
+
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/microblaze/configure.ac b/sysdeps/microblaze/configure.ac
new file mode 100644
index 0000000000..1c58f70a7b
--- /dev/null
+++ b/sysdeps/microblaze/configure.ac
@@ -0,0 +1,7 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/microblaze.
+
+# gcc 11.2.1 and earlier crash with an internal compiler error, see:
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103613
+AC_DEFINE(PIE_UNSUPPORTED)
+# work around problem with autoconf and empty lines at the end of files
diff --git a/sysdeps/sparc/Makefile b/sysdeps/sparc/Makefile
index 1be9a3db2c..12c2c1b085 100644
--- a/sysdeps/sparc/Makefile
+++ b/sysdeps/sparc/Makefile
@@ -2,6 +2,7 @@
 long-double-fcts = yes
 
 pie-ccflag = -fPIE
+no-pie-ccflag = -fno-PIE
 
 ifeq ($(subdir),gmon)
 sysdep_routines += sparc-mcount
-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
@ 2021-12-13 13:22   ` H.J. Lu
  2021-12-13 13:41     ` Siddhesh Poyarekar
  2021-12-13 14:28   ` Siddhesh Poyarekar
  2021-12-16 19:26   ` Florian Weimer
  2 siblings, 1 reply; 17+ messages in thread
From: H.J. Lu @ 2021-12-13 13:22 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: GNU C Library

On Sun, Dec 12, 2021 at 7:03 PM Siddhesh Poyarekar via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
>
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
>
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64, alpha and csky
> don't work because the linker is unable to handle a pcrel relocation

Please reference linker bugs here.

> generated from PIE objects.  The microblaze compiler is currently
> failing with an ICE.  GNU hurd tries to enable static-pie, which does
> not work and hence fails.  All these targets have default PIE disabled
> at the moment and I have left it to the target maintainers to enable PIE
> on their targets.
>
> build-many-glibcs runs clean for all targets.  I also tested x86_64 on
> Fedora and Ubuntu, to verify that the default build as well as
> --disable-default-pie work as expected with both system toolchains.
>
> Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>


-- 
H.J.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13 13:22   ` H.J. Lu
@ 2021-12-13 13:41     ` Siddhesh Poyarekar
  2021-12-13 13:43       ` H.J. Lu
  0 siblings, 1 reply; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-13 13:41 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GNU C Library

On 12/13/21 18:52, H.J. Lu wrote:
> On Sun, Dec 12, 2021 at 7:03 PM Siddhesh Poyarekar via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
>>
>> Build glibc programs and tests as PIE by default and enable static-pie
>> automatically if the architecture and toolchain supports it.
>>
>> Also add a new configuration option --disable-default-pie to prevent
>> building programs as PIE.
>>
>> Only the following architectures now have PIE disabled by default
>> because they do not work at the moment.  hppa, ia64, alpha and csky
>> don't work because the linker is unable to handle a pcrel relocation
> 
> Please reference linker bugs here.

I mentioned them in the configure fragments.  Sorry I already pushed it.

Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13 13:41     ` Siddhesh Poyarekar
@ 2021-12-13 13:43       ` H.J. Lu
  0 siblings, 0 replies; 17+ messages in thread
From: H.J. Lu @ 2021-12-13 13:43 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: GNU C Library

On Mon, Dec 13, 2021 at 5:41 AM Siddhesh Poyarekar
<siddhesh@sourceware.org> wrote:
>
> On 12/13/21 18:52, H.J. Lu wrote:
> > On Sun, Dec 12, 2021 at 7:03 PM Siddhesh Poyarekar via Libc-alpha
> > <libc-alpha@sourceware.org> wrote:
> >>
> >> Build glibc programs and tests as PIE by default and enable static-pie
> >> automatically if the architecture and toolchain supports it.
> >>
> >> Also add a new configuration option --disable-default-pie to prevent
> >> building programs as PIE.
> >>
> >> Only the following architectures now have PIE disabled by default
> >> because they do not work at the moment.  hppa, ia64, alpha and csky
> >> don't work because the linker is unable to handle a pcrel relocation
> >
> > Please reference linker bugs here.
>
> I mentioned them in the configure fragments.  Sorry I already pushed it.
>
> Siddhesh

That is OK.

-- 
H.J.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
  2021-12-13 13:22   ` H.J. Lu
@ 2021-12-13 14:28   ` Siddhesh Poyarekar
  2021-12-13 15:29     ` Siddhesh Poyarekar
  2021-12-16 19:26   ` Florian Weimer
  2 siblings, 1 reply; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-13 14:28 UTC (permalink / raw)
  To: libc-alpha

On 12/13/21 08:32, Siddhesh Poyarekar via Libc-alpha wrote:
> Build glibc programs and tests as PIE by default and enable static-pie
> automatically if the architecture and toolchain supports it.
> 
> Also add a new configuration option --disable-default-pie to prevent
> building programs as PIE.
> 
> Only the following architectures now have PIE disabled by default
> because they do not work at the moment.  hppa, ia64, alpha and csky
> don't work because the linker is unable to handle a pcrel relocation
> generated from PIE objects.  The microblaze compiler is currently
> failing with an ICE.  GNU hurd tries to enable static-pie, which does
> not work and hence fails.  All these targets have default PIE disabled
> at the moment and I have left it to the target maintainers to enable PIE
> on their targets.
> 
> build-many-glibcs runs clean for all targets.  I also tested x86_64 on
> Fedora and Ubuntu, to verify that the default build as well as
> --disable-default-pie work as expected with both system toolchains.

I noticed some conform tests failing on armv7hl and x86_64 in Fedora 
builds.  I'll post patches to fix them.

Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13 14:28   ` Siddhesh Poyarekar
@ 2021-12-13 15:29     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2021-12-13 15:29 UTC (permalink / raw)
  To: libc-alpha

On 12/13/21 19:58, Siddhesh Poyarekar wrote:
>> build-many-glibcs runs clean for all targets.  I also tested x86_64 on
>> Fedora and Ubuntu, to verify that the default build as well as
>> --disable-default-pie work as expected with both system toolchains.
> 
> I noticed some conform tests failing on armv7hl and x86_64 in Fedora 
> builds.  I'll post patches to fix them.

Ahh never mind, false alarm; I was missing 
885762aa31d75de8b9fea4c0e2e372b582d4c548 in my backports.  This patch is 
perfect ;)

Siddhesh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [COMMITTED] Replace --enable-static-pie with --disable-default-pie
  2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
  2021-12-13 13:22   ` H.J. Lu
  2021-12-13 14:28   ` Siddhesh Poyarekar
@ 2021-12-16 19:26   ` Florian Weimer
  2 siblings, 0 replies; 17+ messages in thread
From: Florian Weimer @ 2021-12-16 19:26 UTC (permalink / raw)
  To: Siddhesh Poyarekar via Libc-alpha; +Cc: Siddhesh Poyarekar

We recently started building libc.a with -DPIC on arm:

gcc ../sysdeps/unix/sysv/linux/arm/setcontext.S -c     -I../include -I/builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi/stdlib  -I/builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi  -I../sysdeps/unix/sysv/linux/arm/le  -I../sysdeps/unix/sysv/linux/arm  -I../sysdeps/arm/nptl  -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux  -I../sysdeps/nptl  -I../sysdeps/pthread  -I../sysdeps/gnu  -I../sysdeps/unix/inet  -I../sysdeps/unix/sysv  -I../sysdeps/unix/arm  -I../sysdeps/unix  -I../sysdeps/posix  -I../sysdeps/arm/le/armv7/multiarch  -I../sysdeps/arm/armv7/multiarch  -I../sysdeps/arm/le/armv7  -I../sysdeps/arm/armv7  -I../sysdeps/arm/armv6t2  -I../sysdeps/arm/armv6  -I../sysdeps/arm/le  -I../sysdeps/arm/include -I../sysdeps/arm  -I../sysdeps/wordsize-32  -I../sysdeps/ieee754/flt-32  -I../sysdeps/ieee754/dbl-64  -I../sysdeps/ieee754  -I../sysdeps/generic  -I.. -I../libio -I. -nostdinc -isystem /usr/lib/gcc/armv7hl-redhat-linux-gnueabi/11/include -isystem /usr/include -D_LIBC_REENTRANT -include /builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi/libc-modules.h -DMODULE_NAME=libc -include ../include/libc-symbols.h  -DPIC     -DTOP_NAMESPACE=glibc -DASSEMBLER  -g -Wa,--generate-missing-build-notes=yes -Werror=undef -Wa,--noexecstack   -o /builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o -MD -MP -MF /builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o.dt -MT /builddir/build/BUILD/glibc-2.34.9000-376-g4435c29892/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o

Before, we had this (no -DPIC between “../include/libc-symbols.h” and
“-DTOP_NAMESPACE=glibc“):

gcc ../sysdeps/unix/sysv/linux/arm/setcontext.S -c     -I../include -I/builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi/stdlib  -I/builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi  -I../sysdeps/unix/sysv/linux/arm/le  -I../sysdeps/unix/sysv/linux/arm  -I../sysdeps/arm/nptl  -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux  -I../sysdeps/nptl  -I../sysdeps/pthread  -I../sysdeps/gnu  -I../sysdeps/unix/inet  -I../sysdeps/unix/sysv  -I../sysdeps/unix/arm  -I../sysdeps/unix  -I../sysdeps/posix  -I../sysdeps/arm/le/armv7/multiarch  -I../sysdeps/arm/armv7/multiarch  -I../sysdeps/arm/le/armv7  -I../sysdeps/arm/armv7  -I../sysdeps/arm/armv6t2  -I../sysdeps/arm/armv6  -I../sysdeps/arm/le  -I../sysdeps/arm/include -I../sysdeps/arm  -I../sysdeps/wordsize-32  -I../sysdeps/ieee754/flt-32  -I../sysdeps/ieee754/dbl-64  -I../sysdeps/ieee754  -I../sysdeps/generic  -I.. -I../libio -I. -nostdinc -isystem /usr/lib/gcc/armv7hl-redhat-linux-gnueabi/11/include -isystem /usr/include -D_LIBC_REENTRANT -include /builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi/libc-modules.h -DMODULE_NAME=libc -include ../include/libc-symbols.h       -DTOP_NAMESPACE=glibc -DASSEMBLER  -g -Wa,--generate-missing-build-notes=yes -Werror=undef -Wa,--noexecstack   -o /builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o -MD -MP -MF /builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o.dt -MT /builddir/build/BUILD/glibc-2.34.9000-326-g4df1fa6ddc/build-armv7hl-redhat-linuxeabi/stdlib/setcontext.o

I'm going to send a patch, but I can't really test it.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-12-16 19:26 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07  8:26 [PATCH] Replace --enable-static-pie with --disable-default-pie Siddhesh Poyarekar
2021-12-07 16:06 ` Florian Weimer
2021-12-07 16:21   ` Siddhesh Poyarekar
2021-12-07 16:30     ` Florian Weimer
2021-12-07 18:52 ` Joseph Myers
2021-12-07 20:13 ` Adhemerval Zanella
2021-12-08  4:34   ` Siddhesh Poyarekar
2021-12-08  6:39 ` [PATCH v2] " Siddhesh Poyarekar
2021-12-10 17:35   ` Siddhesh Poyarekar
2021-12-10 19:28   ` Adhemerval Zanella
2021-12-13  3:02 ` [COMMITTED] " Siddhesh Poyarekar
2021-12-13 13:22   ` H.J. Lu
2021-12-13 13:41     ` Siddhesh Poyarekar
2021-12-13 13:43       ` H.J. Lu
2021-12-13 14:28   ` Siddhesh Poyarekar
2021-12-13 15:29     ` Siddhesh Poyarekar
2021-12-16 19:26   ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).