Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Gjouj-0006CV-7D for mharc-grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:45 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Gjoui-0006CK-It for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Gjouf-0006C0-Rv for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:43 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gjouf-0006Bl-Iv for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:41 -0500 Received: from [199.232.41.67] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Gjouf-0002gP-De for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:41 -0500 Received: from [207.69.195.66] (helo=pop-canoe.atl.sa.earthlink.net) by mx20.gnu.org with esmtp (Exim 4.52) id 1Gjoue-0003RP-ID for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:40 -0500 Received: from user-0vvdf2d.cable.mindspring.com ([63.246.188.77] helo=diesel.unsanctioned.org) by pop-canoe.atl.sa.earthlink.net with esmtp (Exim 3.36 #1) id 1Gjoub-0002aW-00 for grub-devel@gnu.org; Mon, 13 Nov 2006 22:24:37 -0500 From: Hollis Blanchard To: The development of GRUB 2 In-Reply-To: <1d09f8b80611051324j51002aco39be9d26194bc18f@mail.gmail.com> References: <1d09f8b80611051324j51002aco39be9d26194bc18f@mail.gmail.com> Content-Type: text/plain Date: Mon, 13 Nov 2006 21:24:37 -0600 Message-Id: <1163474677.30879.19.camel@diesel> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 (2.6.3-1.fc5.5) Content-Transfer-Encoding: 7bit Subject: Re: Cross compiling GRUB 1.95 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2006 03:24:44 -0000 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