diff --git a/acinclude.m4 b/acinclude.m4 index 526f97a3a..7884c1bb5 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -390,6 +390,24 @@ else [fi] ]) +dnl Check if the Linker supports `-no-pie'. +AC_DEFUN([grub_CHECK_NO_PIE], +[AC_MSG_CHECKING([whether linker accepts -no-pie]) +AC_CACHE_VAL(grub_cv_cc_ld_no_pie, +[save_LDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -no-pie" +AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], + [grub_cv_cc_ld_no_pie=yes], + [grub_cv_cc_ld_no_pie=no]) +LDFLAGS="$save_LDFLAGS" +]) +AC_MSG_RESULT([$grub_cv_cc_ld_no_pie]) +nopie_possible=no +if test "x$grub_cv_cc_ld_no_pie" = xyes ; then + nopie_possible=yes +fi +]) + dnl Check if the C compiler supports `-fPIC'. AC_DEFUN([grub_CHECK_PIC],[ [# Position independent executable. diff --git a/configure.ac b/configure.ac index 3d2551035..dc56564d7 100644 --- a/configure.ac +++ b/configure.ac @@ -1185,13 +1185,18 @@ CFLAGS="$TARGET_CFLAGS" # Position independent executable. grub_CHECK_PIE +grub_CHECK_NO_PIE [# Need that, because some distributions ship compilers that include -# `-fPIE' or '-fpie' in the default specs. +# `-fPIE' or '-fpie' and '-pie' in the default specs. if [ x"$pie_possible" = xyes ]; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie" +fi +if [ x"$nopie_possible" = xyes ] && [ x"$pie_possible" = xyes ]; then + TARGET_LDFLAGS="$TARGET_LDFLAGS -no-pie" fi] CFLAGS="$TARGET_CFLAGS" +LDFLAGS="$TARGET_LDFLAGS" # Position independent executable. grub_CHECK_PIC