Use common linker script for all i386-pc systems
PATCH 1/1 Use common linker script for all i386-pc systems
This allows us to remove checks for the linker symbols for the beginning and the end of the .bss section. Instead, we use the names from the linker script. Another benefit is a better unification of the build system.
ChangeLog:
* aclocal.m4: Remove grub_CHECK_BSS_START_SYMBOL and grub_CHECK_END_SYMBOL.
* configure.ac: Don't call grub_CHECK_BSS_START_SYMBOL and grub_CHECK_END_SYMBOL. Check for ${target_cpu}-${platform}.lds as the linker script.
* conf/i386-pc-cygwin-img-ld.sc: Rename to ...
* conf/i386-pc.lds: ... this.
* kern/i386/pc/startup.S: Use __bss_start__ and __bss_end__ instead of BSS_START_SYMBOL and END_SYMBOL.
--- aclocal.m4 | 77 ----------------------------------------- conf/i386-pc-cygwin-img-ld.sc | 53 ---------------------------- conf/i386-pc.lds | 53 ++++++++++++++++++++++++++++ configure.ac | 10 ++--- kern/i386/pc/startup.S | 8 ++-- 5 files changed, 60 insertions(+), 141 deletions(-) delete mode 100644 conf/i386-pc-cygwin-img-ld.sc create mode 100644 conf/i386-pc.lds
aclocal.m4 +0 -77
@@ -224,83 +224,6 @@ fi AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])]) -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]) -AC_MSG_CHECKING([if __bss_start is defined by the compiler]) -AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], - [[asm ("incl __bss_start")]])], - [grub_cv_check_uscore_uscore_bss_start_symbol=yes], - [grub_cv_check_uscore_uscore_bss_start_symbol=no])]) - -AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol]) - -AC_MSG_CHECKING([if edata is defined by the compiler]) -AC_CACHE_VAL(grub_cv_check_edata_symbol, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], - [[asm ("incl edata")]])], - [grub_cv_check_edata_symbol=yes], - [grub_cv_check_edata_symbol=no])]) - -AC_MSG_RESULT([$grub_cv_check_edata_symbol]) - -AC_MSG_CHECKING([if _edata is defined by the compiler]) -AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], - [[asm ("incl _edata")]])], - [grub_cv_check_uscore_edata_symbol=yes], - [grub_cv_check_uscore_edata_symbol=no])]) - -AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol]) - -AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata]) - -if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then - AC_DEFINE([BSS_START_SYMBOL], [__bss_start]) -elif test "x$grub_cv_check_edata_symbol" = xyes; then - AC_DEFINE([BSS_START_SYMBOL], [edata]) -elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then - AC_DEFINE([BSS_START_SYMBOL], [_edata]) -else - 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]) -AC_MSG_CHECKING([if end is defined by the compiler]) -AC_CACHE_VAL(grub_cv_check_end_symbol, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], - [[asm ("incl end")]])], - [grub_cv_check_end_symbol=yes], - [grub_cv_check_end_symbol=no])]) - -AC_MSG_RESULT([$grub_cv_check_end_symbol]) - -AC_MSG_CHECKING([if _end is defined by the compiler]) -AC_CACHE_VAL(grub_cv_check_uscore_end_symbol, -[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], - [[asm ("incl _end")]])], - [grub_cv_check_uscore_end_symbol=yes], - [grub_cv_check_uscore_end_symbol=no])]) - -AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol]) - -AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end]) - -if test "x$grub_cv_check_end_symbol" = xyes; then - AC_DEFINE([END_SYMBOL], [end]) -elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then - AC_DEFINE([END_SYMBOL], [_end]) -else - 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 dnl parameter correctly to the nested function.
conf/i386-pc-cygwin-img-ld.sc deleted +0 -53
53 lines not on this page · raw message
conf/i386-pc.lds new file +53 -0
53 lines not on this page · raw message
configure.ac +3 -7
@@ -209,10 +209,10 @@ AC_CHECK_FUNCS(posix_memalign memalign asprintf) # Use linker script if present, otherwise use builtin -N script. AC_MSG_CHECKING([for option to link raw image]) -if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then - TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc" +if test -f "${srcdir}/conf/${target_cpu}-${platform}.lds"; then + TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}.lds" TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}" - TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc" + TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}.lds" else TARGET_IMG_LDSCRIPT= TARGET_IMG_LDFLAGS='-Wl,-N'
@@ -383,10 +383,6 @@ if test "x$target_cpu" = xi386; then # Check symbols provided by linker script. CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100" fi - if test "x$platform" = xpc; then - grub_CHECK_BSS_START_SYMBOL - grub_CHECK_END_SYMBOL - fi CFLAGS="$TARGET_CFLAGS" grub_I386_ASM_PREFIX_REQUIREMENT grub_I386_ASM_ADDR32
kern/i386/pc/startup.S +4 -4
@@ -241,7 +241,7 @@ codestart: addl %ecx, %esi addl $_start, %esi decl %esi - movl $END_SYMBOL, %edi + movl $__bss_end__, %edi addl %ecx, %edi decl %edi std
@@ -250,10 +250,10 @@ codestart: #endif /* clean out the bss */ - movl $BSS_START_SYMBOL, %edi + movl $__bss_start__, %edi /* compute the bss length */ - movl $END_SYMBOL, %ecx + movl $__bss_end__, %ecx subl %edi, %ecx /* clean out */
@@ -285,7 +285,7 @@ VARIABLE(grub_start_addr) .long _start VARIABLE(grub_end_addr) - .long END_SYMBOL + .long __bss_end__ VARIABLE(grub_apm_bios_info) .word 0 /* version */
Hello.
Quoted 5 lines · Pavel Roskin
This allows us to remove checks for the linker symbols for the beginning and the end of the .bss section. Instead, we use the names from the linker script. Another benefit is a better unification of the build system.
I have nothing against this patch. However it modifies similar parts of build system as my Apple's CC patch. Could we perhaps get my patch in first? Also Apple's LD has no support for linker scripts so unification will not be complete.
conf/i386-pc.lds line 1
Quoted 7 lines
conf/i386-pc.lds new file +1
-0@@ -0,0 +1,53 @@ +/* Linker script to create grub .img files on Cygwin. */
This comment is out of sync
Quoted 3 lines
VARIABLE(grub_end_addr)
- .longEND_SYMBOL
+ .long__bss_end__
This variable isn't used at all. In my Apple's CC patch I just remove it
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoted 12 lines · Vladimir 'phcoder' Serbinenko
Hello.
Quoted 6 lines · Pavel Roskin
This allows us to remove checks for the linker symbols for the beginning and the end of the .bss section. Instead, we use the names from the linker script. Another benefit is a better unification of the build system.
Good idea. Patch works on Cygwin. Does it work on Linux, FreeBSD, ... ?
The variable TARGET_IMG_LDFLAGS_AC can also be removed, see attached patch.
The linker script is actually identical to the script from my first Cygwin patch. It can be further simplified if desired.
Quoted 5 lines
Review line 1
Quoted 3 lines
(quoted diff) +1
-0@@ -0,0 +1,53 @@ +/* Linker script to create grub .img files on Cygwin. */This comment is out of sync
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +1
-1VARIABLE(grub_end_addr) - .long END_SYMBOL + .long __bss_end__This variable isn't used at all. In my Apple's CC patch I just remove it
'grub_start_addr' and '.globl start, _start' are also not used.
Signature · 1 line
Christian Franke
configure.ac +1 -8
@@ -212,15 +212,13 @@ AC_MSG_CHECKING([for option to link raw image]) if test -f "${srcdir}/conf/${target_cpu}-${platform}.lds"; then TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}.lds" TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}" - TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}.lds" else TARGET_IMG_LDSCRIPT= TARGET_IMG_LDFLAGS='-Wl,-N' - TARGET_IMG_LDFLAGS_AC='-Wl,-N' fi AC_SUBST(TARGET_IMG_LDSCRIPT) AC_SUBST(TARGET_IMG_LDFLAGS) -AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC]) +AC_MSG_RESULT([$TARGET_IMG_LDFLAGS]) # For platforms where ELF is not the default link format. AC_MSG_CHECKING([for command to convert module to ELF format])
@@ -379,11 +377,6 @@ grub_PROG_OBJCOPY_ABSOLUTE grub_PROG_LD_BUILD_ID_NONE grub_ASM_USCORE if test "x$target_cpu" = xi386; then - if test ! -z "$TARGET_IMG_LDSCRIPT"; then - # Check symbols provided by linker script. - CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100" - fi - CFLAGS="$TARGET_CFLAGS" grub_I386_ASM_PREFIX_REQUIREMENT grub_I386_ASM_ADDR32 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
Quoted 16 lines · Christian Franke
Quoted 14 lines · Vladimir 'phcoder' Serbinenko
Hello.
Quoted 7 lines · Pavel Roskin
This allows us to remove checks for the linker symbols for the beginning and the end of the .bss section. Instead, we use the names from the linker script. Another benefit is a better unification of the build system.
Quoted 1 line
Good idea. Patch works on Cygwin. Does it work on Linux, FreeBSD, ... ?
I will test it on Linux
Quoted 6 lines
The variable
TARGET_IMG_LDFLAGS_ACcan also be removed, see attached patch.The linker script is actually identical to the script from my first Cygwin patch. It can be further simplified if desired.
Could you instead first have a look at my apple cc patch so we can integrate it first instead of having conflicting patches
Quoted 2 lines
'
grub_start_addr'
AFAIK this one can be removed
Quoted 1 line
and '.globl start,
_start' are also not used.
Please keep them. They are required for at least some compilers to work. If you look at my apple cc patch you'll see I had to add start/_start in some files
Quoted 48 lines
--
Christian Frankeconfigure.ac +0
-0@@ -212,15 +212,13 @@ AC_MSG_CHECKING([for option to link raw image])if test -f "
${srcdir}/conf/${target_cpu}-${platform}.lds"; then TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}.lds" TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
- TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}.lds" else
TARGET_IMG_LDSCRIPT=
TARGET_IMG_LDFLAGS='-Wl,-N'
- TARGET_IMG_LDFLAGS_AC='-Wl,-N'
fi
AC_SUBST(TARGET_IMG_LDSCRIPT)
AC_SUBST(TARGET_IMG_LDFLAGS)configure.ac +1
-1-AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC]) +AC_MSG_RESULT([$TARGET_IMG_LDFLAGS])# For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format])configure.ac +0
-0@@ -379,11 +377,6 @@ grub_PROG_OBJCOPY_ABSOLUTEgrub_PROG_LD_BUILD_ID_NONE
grub_ASM_USCORE
if test "x$target_cpu" = xi386; then
- if test ! -z "$TARGET_IMG_LDSCRIPT"; then
- # Check symbols provided by linker script.
- CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
- fi
- CFLAGS="$TARGET_CFLAGS"grub_I386_ASM_PREFIX_REQUIREMENTgrub_I386_ASM_ADDR32grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Quoting Christian Franke <[email protected]>:
Quoted 1 line
Good idea. Patch works on Cygwin. Does it work on Linux, FreeBSD, ... ?
It works on Linux. I assume it should work on every OS that has GNU ld.
Quoted 1 line
The variable
TARGET_IMG_LDFLAGS_ACcan also be removed, see attached patch.
I think we can do a big cleanup. The start address could be specified in the linker script. Some tests will become unnecessary. We should be able to move a lot of code from the configure script into the makefiles.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
+/* Linker script to create grub .img files on Cygwin. */
This comment is out of sync
I know.
Quoted 5 lines
Quoted 5 lines
Review
Quoted 4 lines
VARIABLE(grub_end_addr)(quoted diff) +1
-1- .long END_SYMBOL + .long __bss_end__This variable isn't used at all. In my Apple's CC patch I just remove it
OK, let's remove it.
Quoted 1 line
'
grub_start_addr' and '.globl start,_start' are also not used.
Patches are welcome.
Signature · 2 lines
Regards, Pavel Roskin
Quoting Vladimir 'phcoder' Serbinenko <[email protected]>:
Quoted 8 lines
Hello.
Quoted 5 lines · Pavel Roskin
This allows us to remove checks for the linker symbols for the beginning and the end of the .bss section. Instead, we use the names from the linker script. Another benefit is a better unification of the build system.
Quoted 4 lines
I have nothing against this patch. However it modifies similar parts of build system as my Apple's CC patch. Could we perhaps get my patch in first? Also Apple's LD has no support for linker scripts so unification will not be complete.
I appreciate a lot of work you put into the Apple CC support, but your patch complicates the code a lot. All features have a maintenance cost. Somebody will need to fix your code when it breaks. Considering that it can only be tested on Darwin, I'm afraid it will be vulnerable to bitrot.
My patch simplifies things and allows further simplifications, some of which could be beneficial to your effort.
Perhaps it would be better if you split uncontroversial or simple parts of your patch and submit them. Also, maybe it would be better to limit Apple support to the EFI platforms? That would make your patch less intrusive.
Quoted 4 lines
Quoted 3 lines
VARIABLE(grub_end_addr)
- .longEND_SYMBOL
+ .long__bss_end__This variable isn't used at all. In my Apple's CC patch I just remove it
That change doesn't need to be in the Apple patch. Let's do the simplifications first.
I, for one, didn't push support for compiling GRUB for i386-pc on pure x86_64 Linux because it wasn't ready. But I committed the simple parts that remove unnecessary tests and simplify the code.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 6 lines · Pavel Roskin
I appreciate a lot of work you put into the Apple CC support, but your patch complicates the code a lot. All features have a maintenance cost. Somebody will need to fix your code when it breaks. Considering that it can only be tested on Darwin, I'm afraid it will be vulnerable to bitrot.
Quoted 7 lines
My patch simplifies things and allows further simplifications, some of which could be beneficial to your effort.
Perhaps it would be better if you split uncontroversial or simple parts of your patch and submit them. Also, maybe it would be better to limit Apple support to the EFI platforms? That would make your patch less intrusive.
The original of this message can be found here:
http://lists.gnu.org/archive/html/grub-devel/2009-05/msg00238.html
There was no reply to that message. It means that the Apple support was committed despite my objections. I wasn't the maintainer at the time, but neither was Vladimir. We should not do it again.
Signature · 2 lines
Regards, Pavel Roskin