From ded3aeb2025c6686956eb10125aacb9a6e7c298e Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 15 Jan 2022 14:23:20 -0800 Subject: Properly handle --disable-default-pie [BZ #28780] When --disable-default-pie is used, all 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 static PIE by default. This fixes BZ #28780. Reviewed-by: Siddhesh Poyarekar --- configure.ac | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 40f2de1661..87f67d25ec 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. -- cgit 1.4.1