grub-devel
[Top][All Lists]
Advanced

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

[PATCH] make grub2 compile with libc-less crosscompilers


From: Patrick Georgi
Subject: [PATCH] make grub2 compile with libc-less crosscompilers
Date: Sat, 19 May 2007 17:30:25 +0200
User-agent: Thunderbird 1.5.0.8 (X11/20061204)

Hi,

I'll work on LinuxBIOS as part of the GSoC 2007 and I'm tasked to enable
grub2 as payload for LinuxBIOSv3.
Currently, I'm preparing my workspace, and I had some issues with
getting grub2 to build on my Solaris machine as solaris-gccs tend to use
sun as and sun ld in the back end which have a different interface than
the gnu variants.

I'm now using a cross compiler with target "i386-elf", ie. no operating
system specification, which works fine so far. With grub2 I had an issue
in the configuration process as some tests try to build executables with
the target compiler that link libc (and potentially even more libs) -
which don't exist in my configuration.
As those are not necessary, I decided to modify grub2 instead of messing
around even more with the not-so-nice gcc build system.

The attached patch does the following:
1. provide a new macro, that changes CFLAGS for a limited context
2. uses that macro to build all tests for _start, __bss_start, _end and
their variants with "-nostdlib -fno-builtin" to avoid _any_ complication
(-fno-builtin could very likely be left out here)
3. makes the _start/start test not fail

3. is probably the most controversial change.
I decided that this is okay, as the startup code (at least on i386/pc)
provides both symbols itself. maybe the check for _start/start could be
left out entirely, but I kept it, so that on systems where _start or
start get defined in the compiler context somehow, the defined name is used.
This should guarantee that this change doesn't affect any system where
grub2 built before.

Comments welcome!


Regards,
Patrick Georgi

Index: aclocal.m4
===================================================================
RCS file: /sources/grub/grub2/aclocal.m4,v
retrieving revision 1.6
diff -u -r1.6 aclocal.m4
--- aclocal.m4  3 Feb 2007 11:36:13 -0000       1.6
+++ aclocal.m4  19 May 2007 15:07:33 -0000
@@ -188,10 +188,20 @@
 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
 
 
+dnl Build wrapped code with different cflags, restore cflags at the end
+dnl Written by Patrick Georgi
+dnl grub_WRAP_FOR_CFLAGS([CFLAGS],[actual code])
+AC_DEFUN(grub_WRAP_FOR_CFLAGS,
+[save_CFLAGS=$CFLAGS
+CFLAGS="$1"
+$2
+CFLAGS=$save_CFLAGS])
+
 dnl Check what symbol is defined as a start symbol.
 dnl Written by Yoshinori K. Okuji.
 AC_DEFUN(grub_CHECK_START_SYMBOL,
 [AC_REQUIRE([AC_PROG_CC])
+grub_WRAP_FOR_CFLAGS([-nostdlib -fno-builtin],[
 AC_MSG_CHECKING([if start is defined by the compiler])
 AC_CACHE_VAL(grub_cv_check_start_symbol,
 [AC_TRY_LINK([], [asm ("incl start")],
@@ -215,14 +225,18 @@
 elif test "x$grub_cv_check_uscore_start_symbol" = xyes; then
   AC_DEFINE([START_SYMBOL], [_start])
 else
-  AC_MSG_ERROR([neither start nor _start is defined])
+  dnl assume some default in case none exists (eg. libc-less xcompiler)
+  dnl the code provides both of them
+  AC_DEFINE([START_SYMBOL], [_start])
 fi
 ])
+])
 
 dnl Check what symbol is defined as a bss start symbol.
 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
 AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
 [AC_REQUIRE([AC_PROG_CC])
+grub_WRAP_FOR_CFLAGS([-nostdlib -fno-builtin],[
 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
 [AC_TRY_LINK([], [asm ("incl __bss_start")],
@@ -259,11 +273,13 @@
   AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
 fi
 ])
+])
 
 dnl Check what symbol is defined as an end symbol.
 dnl Written by Yoshinori K. Okuji.
 AC_DEFUN(grub_CHECK_END_SYMBOL,
 [AC_REQUIRE([AC_PROG_CC])
+grub_WRAP_FOR_CFLAGS([-nostdlib -fno-builtin],[
 AC_MSG_CHECKING([if end is defined by the compiler])
 AC_CACHE_VAL(grub_cv_check_end_symbol,
 [AC_TRY_LINK([], [asm ("incl end")],
@@ -290,6 +306,7 @@
   AC_MSG_ERROR([neither end nor _end is defined])
 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

reply via email to

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