diff --git a/ChangeLog b/ChangeLog index 018b771ed..9bde17b60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-02-29 Vladimir Serbinenko + + * acinclude.m4 (grub_CHECK_PIC): New test. + * configure.ac: Add -fno-PIC to TARGET_CFLAGS if -fPIC is default. + 2012-02-29 Vladimir Serbinenko * include/grub/libgcc.h (__STDC_VERSION__): Define if it's not yet so diff --git a/acinclude.m4 b/acinclude.m4 index 5c623baee..0eb2e2a17 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -424,3 +424,31 @@ else AC_MSG_RESULT([no]) [fi] ]) + +dnl Check if the C compiler supports `-fPIC'. +AC_DEFUN([grub_CHECK_PIC],[ +[# Position independent executable. +pic_possible=yes] +AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default]) +# Is this a reliable test case? +AC_LANG_CONFTEST([AC_LANG_SOURCE([[ +#ifdef __PIC__ +int main() { + return 0; +} +#else +#error NO __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 + pic_possible=no] + AC_MSG_RESULT([no]) +[fi] +]) diff --git a/configure.ac b/configure.ac index 4b64653c8..4f482f647 100644 --- a/configure.ac +++ b/configure.ac @@ -596,6 +596,14 @@ if [ x"$pie_possible" = xyes ]; then TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE" fi] +# Position independent executable. +grub_CHECK_PIC +[# Need that, because some distributions ship compilers that include +# `-fPIC' in the default specs. +if [ x"$pic_possible" = xyes ]; then + TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC" +fi] + # Smashing stack protector. grub_CHECK_STACK_PROTECTOR # Need that, because some distributions ship compilers that include