diff --git a/ChangeLog b/ChangeLog index abd03bf0a..a6dd60a80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-02-03 Thomas Schwinge + + * aclocal.m4 (grub_CHECK_STACK_PROTECTOR): New definition. + * configure.ac: Use it for testing the HOST and TARGET compilers. + 2006-12-13 Thomas Schwinge * Makefile.in (enable_grub_emu): New variable. diff --git a/aclocal.m4 b/aclocal.m4 index a032c2aad..706c3ef21 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -343,3 +343,22 @@ dnl So use regparm 2 until a better test is found. [Catch gcc bug]) fi ]) + +dnl Check if the C compiler supports `-fstack-protector'. +AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[ +[# Smashing stack protector. +ssp_possible=yes] +AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector']) +# Is this a reliable test case? +AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]]) +[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling +# `ac_compile' like this correct, after all? +if eval "$ac_compile -S -fstack-protector -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 + ssp_possible=no] + AC_MSG_RESULT([no]) +[fi] +]) diff --git a/configure.ac b/configure.ac index ba205b501..1c0bbfee5 100644 --- a/configure.ac +++ b/configure.ac @@ -148,6 +148,19 @@ fi # Check for functions. AC_CHECK_FUNCS(posix_memalign memalign) +# +# Compiler features. +# + +# Smashing stack protector. +grub_CHECK_STACK_PROTECTOR +[# Need that, because some distributions ship compilers that include +# `-fstack-protector' in the default specs. +if [ x"$ssp_possible" = xyes ]; then + CFLAGS=$CFLAGS\ -fno-stack-protector +fi] + + # # Check for target programs. # @@ -225,6 +238,18 @@ if test "x$target_m32" = x1; then TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" fi +# +# Compiler features. +# + +# Smashing stack protector. +grub_CHECK_STACK_PROTECTOR +[# Need that, because some distributions ship compilers that include +# `-fstack-protector' in the default specs. +if [ x"$ssp_possible" = xyes ]; then + TARGET_CFLAGS=$TARGET_CFLAGS\ -fno-stack-protector +fi] + AC_SUBST(TARGET_CFLAGS) AC_SUBST(TARGET_CPPFLAGS) AC_SUBST(TARGET_LDFLAGS)