* [PATCH] make grub2 compile with libc-less crosscompilers
@ 2007-05-19 15:30 Patrick Georgi
2007-05-19 17:44 ` Yoshinori K. Okuji
2007-05-31 14:59 ` Patrick Georgi
0 siblings, 2 replies; 6+ messages in thread
From: Patrick Georgi @ 2007-05-19 15:30 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 1612 bytes --]
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
[-- Attachment #2: patch-20070519-1-grub2-configure-script-on-libc-less-cross-compiler --]
[-- Type: text/plain, Size: 2353 bytes --]
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] make grub2 compile with libc-less crosscompilers
2007-05-19 15:30 [PATCH] make grub2 compile with libc-less crosscompilers Patrick Georgi
@ 2007-05-19 17:44 ` Yoshinori K. Okuji
2007-05-19 17:53 ` Patrick Georgi
` (2 more replies)
2007-05-31 14:59 ` Patrick Georgi
1 sibling, 3 replies; 6+ messages in thread
From: Yoshinori K. Okuji @ 2007-05-19 17:44 UTC (permalink / raw)
To: The development of GRUB 2
On Saturday 19 May 2007 17:30, Patrick Georgi wrote:
> 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.
They are necessary. Otherwise, you cannot make a core image, for example.
Also, without grub-emu, how do you plan to debug GRUB?
BTW I can hardly believe that it is so difficult to use gnu build tools on
solaris. Otherwise, how are opensolaris developers building GRUB?
Okuji
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] make grub2 compile with libc-less crosscompilers
2007-05-19 17:44 ` Yoshinori K. Okuji
@ 2007-05-19 17:53 ` Patrick Georgi
2007-05-20 17:45 ` Stefan Reinauer
2007-06-04 17:03 ` Patrick Georgi
2 siblings, 0 replies; 6+ messages in thread
From: Patrick Georgi @ 2007-05-19 17:53 UTC (permalink / raw)
To: The development of GRUB 2
Yoshinori K. Okuji schrieb:
> On Saturday 19 May 2007 17:30, Patrick Georgi wrote:
>
>> 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.
>>
>
> They are necessary. Otherwise, you cannot make a core image, for example.
>
uhm. where do you expect a target compiled file (ie. one that's run at
boot time) to use libc?
I'm _not_ talking about the host compiler - here everything works fine,
after all, there's no linker abuse going on there, just the average
compile+link process.
> Also, without grub-emu, how do you plan to debug GRUB?
>
qemu - the portions I work on need it anyway
> BTW I can hardly believe that it is so difficult to use gnu build tools on
> solaris. Otherwise, how are opensolaris developers building GRUB?
>
Compiling gcc 4.2 (or 4.1.2) with gnu as and gnu ld in the back end
resulted in compile errors here, when I tried to do a "normal" build.
The grub (0.95 btw!) in the OpenSolaris tree features a parallel
makefile hierarchy that uses /usr/sfw/bin/gcc (which uses Sun tools in
the back end) and, it seems, manual invocations of gnu ld.
so here you are - they basically link by hand
Regards,
Patrick Georgi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] make grub2 compile with libc-less crosscompilers
2007-05-19 17:44 ` Yoshinori K. Okuji
2007-05-19 17:53 ` Patrick Georgi
@ 2007-05-20 17:45 ` Stefan Reinauer
2007-06-04 17:03 ` Patrick Georgi
2 siblings, 0 replies; 6+ messages in thread
From: Stefan Reinauer @ 2007-05-20 17:45 UTC (permalink / raw)
To: The development of GRUB 2
* Yoshinori K. Okuji <okuji@enbug.org> [070519 19:44]:
> On Saturday 19 May 2007 17:30, Patrick Georgi wrote:
> > 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.
I second this patch. Cleaning out platform dependencies where there
should be none is a good goal on the long and stony road to portable
software.
> They are necessary. Otherwise, you cannot make a core image, for example.
> Also, without grub-emu, how do you plan to debug GRUB?
Can you please explain this? I would think grub-emu is something that
needs to be compiled with the host compiler, not the target compiler. If
you need the target, it is not an emulation, thus pretty useless.
> BTW I can hardly believe that it is so difficult to use gnu build tools on
> solaris. Otherwise, how are opensolaris developers building GRUB?
Well, niche products are always hard to maintain. Try cross-compiling a driver
from the mainstream operating system windows under the niche OS Linux
and you will find lots of trouble, too. Not hard to believe. Cross
compiling a Linux/BSD only product like Grub under Solaris is for sure
easier, but not exactly trivial. Not hard to believe that one would not
start fixing auto tools code without a reason ;-)
Stefan
--
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: info@coresystems.de • http://www.coresystems.de/
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] make grub2 compile with libc-less crosscompilers
2007-05-19 17:44 ` Yoshinori K. Okuji
2007-05-19 17:53 ` Patrick Georgi
2007-05-20 17:45 ` Stefan Reinauer
@ 2007-06-04 17:03 ` Patrick Georgi
2 siblings, 0 replies; 6+ messages in thread
From: Patrick Georgi @ 2007-06-04 17:03 UTC (permalink / raw)
To: grub-devel
Yoshinori K. Okuji schrieb:
> Also, without grub-emu, how do you plan to debug GRUB?
I'd have some questions relating to that to improve the patch, if possible.
But first, please note that grub-emu currently can't work because argp.h
and its features aren't provided on Solaris, so I can't test the proper
operation of it.
As for grub-emu, does it use the target-built objects (ie. .mod files)
and loads them in the host system?
If so, is this why you need the _start/start (and the other) detection,
so the modules contain the right symbol for the host?
In this case, the right solution would probably be to do those tests
using the host compiler, not the target's.
The target doesn't care one way or the other (there is no non-grub code
around that looks for symbols at boot time), so it can just inherit,
what the host is doing.
I can provide a patch that takes this into account, if my guesses are
correct, but I'd need some more insights in what exactly is required.
Thanks,
Patrick Georgi
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] make grub2 compile with libc-less crosscompilers
2007-05-19 15:30 [PATCH] make grub2 compile with libc-less crosscompilers Patrick Georgi
2007-05-19 17:44 ` Yoshinori K. Okuji
@ 2007-05-31 14:59 ` Patrick Georgi
1 sibling, 0 replies; 6+ messages in thread
From: Patrick Georgi @ 2007-05-31 14:59 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 111 bytes --]
Hi,
any more comments or questions on this patch, so I can improve it if
necessary?
Thanks,
Patrick Georgi
[-- Attachment #2: patch-20070519-1-grub2-configure-script-on-libc-less-cross-compiler --]
[-- Type: text/plain, Size: 2353 bytes --]
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-06-04 17:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-19 15:30 [PATCH] make grub2 compile with libc-less crosscompilers Patrick Georgi
2007-05-19 17:44 ` Yoshinori K. Okuji
2007-05-19 17:53 ` Patrick Georgi
2007-05-20 17:45 ` Stefan Reinauer
2007-06-04 17:03 ` Patrick Georgi
2007-05-31 14:59 ` Patrick Georgi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.