diff --git a/ChangeLog b/ChangeLog index 8b21400fe..6faadecdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-11-22 Vladimir Serbinenko + + * configure.ac: Compile with -fPIC when compiling with clang on + mips. + 2013-11-22 Vladimir Serbinenko * configure.ac: Add -no-integrated-as on mips(el) to TARGET_CCASFLAGS diff --git a/configure.ac b/configure.ac index 1df1e7ef4..8852a9899 100644 --- a/configure.ac +++ b/configure.ac @@ -767,10 +767,17 @@ CFLAGS="$TARGET_CFLAGS" # 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" +[# On most platforms we don't want PIC as it only makes relocations harder +# and code less efficient. On mips we want to have one got table per module +# and reload $gp in every function. +# GCC implements it using symbol __gnu_local_gp in non-PIC as well. +# However with clang we need PIC for this reloading to happen. +# Since default varies across dictributions use either -fPIC or -fno-PIC +# explicitly. +if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then + TARGET_CFLAGS="$TARGET_CFLAGS -fPIC" +elif [ x"$pic_possible" = xyes ]; then + TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC" fi] CFLAGS="$TARGET_CFLAGS"