diff --git a/ChangeLog b/ChangeLog index 84c051eee..fda47fe51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-09-03 Magnus Granberg + + * aclocal.m4: Add grub_CHECK_PIE. It check if the compiler + include -fPIE in the default specs. + * configure.ac: Check if pie_possible is yes and add -fno-PIE + to TARGET_CFLAGS. + 2009-09-03 Felix Zielcke * INSTALL: Note that GNU Bison 2.3 or later is required. diff --git a/aclocal.m4 b/aclocal.m4 index bde935dc9..313b241fa 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -413,3 +413,31 @@ else [fi rm -rf testdir] ]) + +dnl Check if the C compiler supports `-fPIE'. +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([[ +#ifdef __PIE__ +int main() { + return 0; +} +#else +#error NO __PIE__ 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] +]) diff --git a/configure.ac b/configure.ac index cddd9fe2d..3c4c6dce6 100644 --- a/configure.ac +++ b/configure.ac @@ -346,6 +346,14 @@ fi # Need __enable_execute_stack() for nested function trampolines? grub_CHECK_ENABLE_EXECUTE_STACK +# 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 + TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE" +fi] + # Smashing stack protector. grub_CHECK_STACK_PROTECTOR # Need that, because some distributions ship compilers that include