--- configure.ac.zorry 2009-09-05 15:54:43.000000000 +0200 +++ configure.ac 2009-09-05 16:35:48.000000000 +0200 @@ -110,6 +110,42 @@ fi fi +AC_DEFUN(grub_CHECK_PIE,[ +[# Position independent executable. +pie_possible=yes] +AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default]) +# Is this a reliable test case? +AC_LANG_CONFTEST([[ +#if defined (__PIE__) || defined (__PIC__) +int main() { + return 0; +} +#else +#error NO __PIE__ OR __PIC__ DEFINED. +#endif +]]) + +[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling +# `ac_compile' like this correct, after all? +if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then] + AC_MSG_RESULT([yes]) + [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'? + rm -f conftest.s +else + pie_possible=no] + AC_MSG_RESULT([no]) +[fi] +]) + +# Position independent executable. +grub_CHECK_PIE +[# Need that, because some distributions ship compilers that include +# `-fPIE' in the default specs. +if [ x"$pie_possible" = xyes ]; then + STAGE1_CFLAGS="$STAGE1_CFLAGS -nopie" + STAGE2_CFLAGS="$STAGE2_CFLAGS -nopie" +fi] + AC_SUBST(STAGE1_CFLAGS) AC_SUBST(STAGE2_CFLAGS) AC_SUBST(GRUB_CFLAGS)