diff mbox series

Properly handle --disable-default-pie [BZ #28780]

Message ID 20220115222916.2148942-1-hjl.tools@gmail.com
State Superseded
Delegated to: Siddhesh Poyarekar
Headers show
Series Properly handle --disable-default-pie [BZ #28780] | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

H.J. Lu Jan. 15, 2022, 10:29 p.m. UTC
When --disable-default-pie is used, glibc programs and the testsuite
should be built as position dependent executables (non-PIE), regardless
if the build compiler supports PIE or static PIE.

When --disable-default-pie is used, don't build PIE nor static PIE.
by default.

This fixes BZ #28780.
---
 configure    | 47 +++++++++++++++++++++++++++++------------------
 configure.ac | 40 ++++++++++++++++++++++++++--------------
 2 files changed, 55 insertions(+), 32 deletions(-)

Comments

Siddhesh Poyarekar Jan. 17, 2022, 4:02 a.m. UTC | #1
On 16/01/2022 03:59, H.J. Lu wrote:
> When --disable-default-pie is used, glibc programs and the testsuite
> should be built as position dependent executables (non-PIE), regardless

should *not* be built?

> if the build compiler supports PIE or static PIE.
> 
> When --disable-default-pie is used, don't build PIE nor static PIE.
> by default.
> 
> This fixes BZ #28780.

I can't reproduce the bug here.  Could you share what you're doing?

Thanks,
Siddhesh
Siddhesh Poyarekar Jan. 17, 2022, 2:35 p.m. UTC | #2
OK review time since we're now on the same page as to what's going on. 
Mostly minor nits below.

On 16/01/2022 03:59, H.J. Lu via Libc-alpha wrote:
> When --disable-default-pie is used, glibc programs and the testsuite
> should be built as position dependent executables (non-PIE), regardless
> if the build compiler supports PIE or static PIE.
> 
> When --disable-default-pie is used, don't build PIE nor static PIE.
> by default.

Please update the commit message to reflect the latest status on the 
bug, i.e. it's static pie that doesn't honour default-pie, not all PIE.

> 
> This fixes BZ #28780.
> ---
>   configure    | 47 +++++++++++++++++++++++++++++------------------
>   configure.ac | 40 ++++++++++++++++++++++++++--------------
>   2 files changed, 55 insertions(+), 32 deletions(-)
> 
> diff --git a/configure b/configure
> index 6a7e5c6164..a12f66fa58 100755
> --- a/configure
> +++ b/configure
> @@ -7035,32 +7035,35 @@ cc-pie-default = $libc_cv_cc_pie_default"
>   
>   { $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
> +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
> +  libc_cv_pie_supported=yes
>   else
> -  libc_cv_pie_default=no
> +  libc_cv_pie_supported=no
>   fi
>   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_supported" >&5
> +$as_echo "$libc_cv_pie_supported" >&6; }
> +# Disable build-pie-default if target does not support it or glibc is
> +# configured with --disable-default-pie.
> +if test "x$default_pie" = xno; then
> +  build_pie_default=no
> +else
> +  build_pie_default=$libc_cv_pie_supported
>   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"
> +build-pie-default = $build_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 \
> +libc_cv_static_pie_supported=$libc_cv_pie_supported
> +if test "x$libc_cv_pie_supported" != 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
> @@ -7068,18 +7071,26 @@ if test "x$libc_cv_pie_default" != xno \
>   #endif
>   _ACEOF
>   if ac_fn_c_try_compile "$LINENO"; then :
> -  libc_cv_static_pie=yes
> +  libc_cv_static_pie_supported=yes
>   else
> -  libc_cv_static_pie=no
> +  libc_cv_static_pie_supported=no
>   fi
>   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> -  if test "$libc_cv_static_pie" = "yes"; then
> -    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_supported" >&5
> +$as_echo "$libc_cv_static_pie_supported" >&6; }
> +
> +# Enable static-pie only if it is available and glibc isn't configured
> +# with --disable-default-pie.
> +if test "x$default_pie" == xno; then
> +  libc_cv_static_pie=no
> +else
> +  libc_cv_static_pie=$libc_cv_static_pie_supported
> +fi
> +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 = $libc_cv_static_pie"
>   
> diff --git a/configure.ac b/configure.ac
> index 40f2de1661..cacf00140d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1868,28 +1868,40 @@ rm -f conftest.*])
>   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
> +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])
> +#endif]])], [libc_cv_pie_supported=yes], [libc_cv_pie_supported=no])
> +AC_MSG_RESULT($libc_cv_pie_supported)
> +# Disable build-pie-default if target does not support it or glibc is
> +# configured with --disable-default-pie.
> +if test "x$default_pie" = xno; then
> +  build_pie_default=no
> +else
> +  build_pie_default=$libc_cv_pie_supported
>   fi
> -AC_MSG_RESULT($libc_cv_pie_default)
> -LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
> +LIBC_CONFIG_VAR([build-pie-default], [$build_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 \
> +libc_cv_static_pie_supported=$libc_cv_pie_supported
> +if test "x$libc_cv_pie_supported" != 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
> +#endif]])], [libc_cv_static_pie_supported=yes],
> +	    [libc_cv_static_pie_supported=no])
> +fi
> +AC_MSG_RESULT($libc_cv_static_pie_supported)
> +
> +# Enable static-pie only if it is available and glibc isn't configured
> +# with --disable-default-pie.
> +if test "x$default_pie" == xno; then

Single '=' here?

> +  libc_cv_static_pie=no
> +else
> +  libc_cv_static_pie=$libc_cv_static_pie_supported
> +fi
> +if test "$libc_cv_static_pie" = "yes"; then
> +  AC_DEFINE(ENABLE_STATIC_PIE)
>   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.
H.J. Lu Jan. 17, 2022, 3:20 p.m. UTC | #3
On Mon, Jan 17, 2022 at 6:35 AM Siddhesh Poyarekar
<siddhesh@sourceware.org> wrote:
>
> OK review time since we're now on the same page as to what's going on.
> Mostly minor nits below.
>
> On 16/01/2022 03:59, H.J. Lu via Libc-alpha wrote:
> > When --disable-default-pie is used, glibc programs and the testsuite
> > should be built as position dependent executables (non-PIE), regardless
> > if the build compiler supports PIE or static PIE.
> >
> > When --disable-default-pie is used, don't build PIE nor static PIE.
> > by default.
>
> Please update the commit message to reflect the latest status on the
> bug, i.e. it's static pie that doesn't honour default-pie, not all PIE.

Fixed.

> >
> > This fixes BZ #28780.
> > ---
> >   configure    | 47 +++++++++++++++++++++++++++++------------------
> >   configure.ac | 40 ++++++++++++++++++++++++++--------------
> >   2 files changed, 55 insertions(+), 32 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 6a7e5c6164..a12f66fa58 100755
> > --- a/configure
> > +++ b/configure
> > @@ -7035,32 +7035,35 @@ cc-pie-default = $libc_cv_cc_pie_default"
> >
> >   { $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
> > +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
> > +  libc_cv_pie_supported=yes
> >   else
> > -  libc_cv_pie_default=no
> > +  libc_cv_pie_supported=no
> >   fi
> >   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_supported" >&5
> > +$as_echo "$libc_cv_pie_supported" >&6; }
> > +# Disable build-pie-default if target does not support it or glibc is
> > +# configured with --disable-default-pie.
> > +if test "x$default_pie" = xno; then
> > +  build_pie_default=no
> > +else
> > +  build_pie_default=$libc_cv_pie_supported
> >   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"
> > +build-pie-default = $build_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 \
> > +libc_cv_static_pie_supported=$libc_cv_pie_supported
> > +if test "x$libc_cv_pie_supported" != 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
> > @@ -7068,18 +7071,26 @@ if test "x$libc_cv_pie_default" != xno \
> >   #endif
> >   _ACEOF
> >   if ac_fn_c_try_compile "$LINENO"; then :
> > -  libc_cv_static_pie=yes
> > +  libc_cv_static_pie_supported=yes
> >   else
> > -  libc_cv_static_pie=no
> > +  libc_cv_static_pie_supported=no
> >   fi
> >   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> > -  if test "$libc_cv_static_pie" = "yes"; then
> > -    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
> > +fi
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_supported" >&5
> > +$as_echo "$libc_cv_static_pie_supported" >&6; }
> > +
> > +# Enable static-pie only if it is available and glibc isn't configured
> > +# with --disable-default-pie.
> > +if test "x$default_pie" == xno; then
> > +  libc_cv_static_pie=no
> > +else
> > +  libc_cv_static_pie=$libc_cv_static_pie_supported
> > +fi
> > +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 = $libc_cv_static_pie"
> >
> > diff --git a/configure.ac b/configure.ac
> > index 40f2de1661..cacf00140d 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -1868,28 +1868,40 @@ rm -f conftest.*])
> >   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
> > +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])
> > +#endif]])], [libc_cv_pie_supported=yes], [libc_cv_pie_supported=no])
> > +AC_MSG_RESULT($libc_cv_pie_supported)
> > +# Disable build-pie-default if target does not support it or glibc is
> > +# configured with --disable-default-pie.
> > +if test "x$default_pie" = xno; then
> > +  build_pie_default=no
> > +else
> > +  build_pie_default=$libc_cv_pie_supported
> >   fi
> > -AC_MSG_RESULT($libc_cv_pie_default)
> > -LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
> > +LIBC_CONFIG_VAR([build-pie-default], [$build_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 \
> > +libc_cv_static_pie_supported=$libc_cv_pie_supported
> > +if test "x$libc_cv_pie_supported" != 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
> > +#endif]])], [libc_cv_static_pie_supported=yes],
> > +         [libc_cv_static_pie_supported=no])
> > +fi
> > +AC_MSG_RESULT($libc_cv_static_pie_supported)
> > +
> > +# Enable static-pie only if it is available and glibc isn't configured
> > +# with --disable-default-pie.
> > +if test "x$default_pie" == xno; then
>
> Single '=' here?

Fixed.

> > +  libc_cv_static_pie=no
> > +else
> > +  libc_cv_static_pie=$libc_cv_static_pie_supported
> > +fi
> > +if test "$libc_cv_static_pie" = "yes"; then
> > +  AC_DEFINE(ENABLE_STATIC_PIE)
> >   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.
>

I just sent out the v2 patch.
diff mbox series

Patch

diff --git a/configure b/configure
index 6a7e5c6164..a12f66fa58 100755
--- a/configure
+++ b/configure
@@ -7035,32 +7035,35 @@  cc-pie-default = $libc_cv_cc_pie_default"
 
 { $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
+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
+  libc_cv_pie_supported=yes
 else
-  libc_cv_pie_default=no
+  libc_cv_pie_supported=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_pie_supported" >&5
+$as_echo "$libc_cv_pie_supported" >&6; }
+# Disable build-pie-default if target does not support it or glibc is
+# configured with --disable-default-pie.
+if test "x$default_pie" = xno; then
+  build_pie_default=no
+else
+  build_pie_default=$libc_cv_pie_supported
 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"
+build-pie-default = $build_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 \
+libc_cv_static_pie_supported=$libc_cv_pie_supported
+if test "x$libc_cv_pie_supported" != 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
@@ -7068,18 +7071,26 @@  if test "x$libc_cv_pie_default" != xno \
 #endif
 _ACEOF
 if ac_fn_c_try_compile "$LINENO"; then :
-  libc_cv_static_pie=yes
+  libc_cv_static_pie_supported=yes
 else
-  libc_cv_static_pie=no
+  libc_cv_static_pie_supported=no
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-  if test "$libc_cv_static_pie" = "yes"; then
-    $as_echo "#define ENABLE_STATIC_PIE 1" >>confdefs.h
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_static_pie_supported" >&5
+$as_echo "$libc_cv_static_pie_supported" >&6; }
+
+# Enable static-pie only if it is available and glibc isn't configured
+# with --disable-default-pie.
+if test "x$default_pie" == xno; then
+  libc_cv_static_pie=no
+else
+  libc_cv_static_pie=$libc_cv_static_pie_supported
+fi
+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 = $libc_cv_static_pie"
 
diff --git a/configure.ac b/configure.ac
index 40f2de1661..cacf00140d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1868,28 +1868,40 @@  rm -f conftest.*])
 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
+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])
+#endif]])], [libc_cv_pie_supported=yes], [libc_cv_pie_supported=no])
+AC_MSG_RESULT($libc_cv_pie_supported)
+# Disable build-pie-default if target does not support it or glibc is
+# configured with --disable-default-pie.
+if test "x$default_pie" = xno; then
+  build_pie_default=no
+else
+  build_pie_default=$libc_cv_pie_supported
 fi
-AC_MSG_RESULT($libc_cv_pie_default)
-LIBC_CONFIG_VAR([build-pie-default], [$libc_cv_pie_default])
+LIBC_CONFIG_VAR([build-pie-default], [$build_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 \
+libc_cv_static_pie_supported=$libc_cv_pie_supported
+if test "x$libc_cv_pie_supported" != 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
+#endif]])], [libc_cv_static_pie_supported=yes],
+	    [libc_cv_static_pie_supported=no])
+fi
+AC_MSG_RESULT($libc_cv_static_pie_supported)
+
+# Enable static-pie only if it is available and glibc isn't configured
+# with --disable-default-pie.
+if test "x$default_pie" == xno; then
+  libc_cv_static_pie=no
+else
+  libc_cv_static_pie=$libc_cv_static_pie_supported
+fi
+if test "$libc_cv_static_pie" = "yes"; then
+  AC_DEFINE(ENABLE_STATIC_PIE)
 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.