grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cross compiling GRUB 1.95


From: Hollis Blanchard
Subject: Re: Cross compiling GRUB 1.95
Date: Mon, 13 Nov 2006 21:24:37 -0600

On Sun, 2006-11-05 at 16:24 -0500, Will Buik wrote:
> I am trying to cross compile GRUB 1.95 from an i686 linux system to an
> i686 linux uclibc system.  However, when I run the configure script I
> get the error:
> 
> checking if GCC has the regparm=3 bug... configure: error: cannot run
> test program while cross compiling
> 
> How can I bypass this test or otherwise get it to compile?

Hmm. From the documentation
(http://www.gnu.org/software/autoconf/manual/html_node/Runtime.html), I
would expect something like the following to work:

Index: aclocal.m4
===================================================================
RCS file: /cvsroot/grub/grub2/aclocal.m4,v
retrieving revision 1.5
diff -u -p -r1.5 aclocal.m4
--- aclocal.m4  13 Aug 2005 18:44:14 -0000      1.5
+++ aclocal.m4  14 Nov 2006 03:14:21 -0000
@@ -327,6 +327,7 @@ main (void)
 }
 ]])],
        [grub_cv_i386_check_nested_functions=no],
+       [grub_cv_i386_check_nested_functions=yes],
        [grub_cv_i386_check_nested_functions=yes])])

 AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])

Even worse though, it seems this test is totally ignored -- regparm(2)
is always used, no matter the outcome. So perhaps we should do this
instead:

Index: aclocal.m4
===================================================================
RCS file: /cvsroot/grub/grub2/aclocal.m4,v
retrieving revision 1.5
diff -u -p -r1.5 aclocal.m4
--- aclocal.m4  13 Aug 2005 18:44:14 -0000      1.5
+++ aclocal.m4  14 Nov 2006 03:17:44 -0000
@@ -291,55 +291,3 @@ else
 fi
 ])

-dnl Check if the C compiler has a bug while using nested functions when
-dnl mregparm is used on the i386.  Some gcc versions do not pass the third
-dnl parameter correctly to the nested function.
-dnl Written by Marco Gerards.
-AC_DEFUN(grub_I386_CHECK_REGPARM_BUG,
-[AC_REQUIRE([AC_PROG_CC])
-AC_MSG_CHECKING([if GCC has the regparm=3 bug])
-AC_CACHE_VAL(grub_cv_i386_check_nested_functions,
-[AC_RUN_IFELSE([AC_LANG_SOURCE(
-[[
-static int
-test (int *n)
-{
-  return *n == -1;
-}
-
-static int
-testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int 
*c))-{
-  int a = 0;
-  int b = 0;
-  int c = -1;
-  return hook (a, b, &c);
-}
-
-int
-main (void)
-{
-  int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c)
-    {
-      return a == b && test (c);
-    }
-  return testfunc (nestedfunc) ? 0 : 1;
-}
-]])],
-       [grub_cv_i386_check_nested_functions=no],
-       [grub_cv_i386_check_nested_functions=yes])])
-
-AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])
-
-if test "x$grub_cv_i386_check_nested_functions" = xyes; then
-  AC_DEFINE([NESTED_FUNC_ATTR],
-       [__attribute__ ((__regparm__ (2)))],
-       [Catch gcc bug])
-else
-dnl Unfortunately, the above test does not detect a bug in gcc-4.0.
-dnl So use regparm 2 until a better test is found.
-  AC_DEFINE([NESTED_FUNC_ATTR],
-       [__attribute__ ((__regparm__ (2)))],
-       [Catch gcc bug])
-fi
-])
Index: configure.ac
===================================================================
RCS file: /cvsroot/grub/grub2/configure.ac,v
retrieving revision 1.33
diff -u -p -r1.33 configure.ac
--- configure.ac        12 Jul 2006 20:42:52 -0000      1.33
+++ configure.ac        14 Nov 2006 03:17:44 -0000
@@ -253,7 +253,13 @@ if test "x$target_cpu" = xi386; then
   grub_I386_ASM_PREFIX_REQUIREMENT
   grub_I386_ASM_ADDR32
   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
-  grub_I386_CHECK_REGPARM_BUG
+
+  # Check if the C compiler has a bug while using nested functions when
+  # mregparm is used on the i386.  Some gcc versions do not pass the third
+  # parameter correctly to the nested function.
+  AC_DEFINE([NESTED_FUNC_ATTR],
+       [__attribute__ ((__regparm__ (2)))],
+       [Catch gcc bug])
 else
   AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
 fi

But wait, it gets even better! It turns out there are almost no users of
NESTED_FUNC_ATTR in grub2; only a few filesystems use it. If it only
affects nested functions with three or more arguments, then at least
functions like read_blocklist() would be broken. (If it affects all
nested functions, then almost everything is broken.)

Some attention is needed here from people who know what NESTED_FUNC_ATTR
is supposed to be doing.

-Hollis





reply via email to

[Prev in Thread] Current Thread [Next in Thread]