Skip to contentSkip to conversation

Eliminate grub_CHECK_START_SYMBOL

PATCH New Pavel Roskin 1 participant 1 message Mar 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Eliminate grub_CHECK_START_SYMBOL

Hello!

It should be possible to compile grub for i386-pc on a pure x64_64 system with i386 support in the compiler and binutils, but without 32-bit libc or its headers.

It requires several unrelated changes. This is the first step. It's a pure simplification.

The grub_CHECK_START_SYMBOL defines START_SYMBOL either as "start" or as "_start". But it really doesn't matter. START_SYMBOL is only used in kern/i386/pc/startup.S, where both "start" and "_start" are explicitly defined labels pointing to the same code. EXT_C(start) also expands to "start" or "_start", so it can be replaced with "_start" as well.

ChangeLog:

* kern/i386/pc/startup.S: Replace EXT_C(start) and START_SYMBOL with _start, as it's always equal to start.
* configure.ac: Don't call grub_CHECK_START_SYMBOL. It's not needed, as we no longer use START_SYMBOL.
* aclocal.m4 (grub_CHECK_START_SYMBOL): Remove.

i386/pc/startup.S +9 -9
Index: kern/i386/pc/startup.S
===================================================================
@@ -53,7 +53,7 @@
 #include <multiboot.h>
 #include <multiboot2.h>
 		
-#define ABS(x)	((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
+#define ABS(x)	((x) - _start + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
 	
 	.file	"startup.S"
 
@@ -77,14 +77,14 @@
 	 *  These MUST be at byte offset 6 and 7 of the executable
 	 *  DO NOT MOVE !!!
 	 */
-	. = EXT_C(start) + 0x6
+	. = _start + 0x6
 	.byte	GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
 
 	/*
 	 *  This is a special data area 8 bytes from the beginning.
 	 */
 
-	. = EXT_C(start) + 0x8
+	. = _start + 0x8
 
 VARIABLE(grub_total_module_size)
 	.long	0
@@ -103,7 +103,7 @@
 	 *  Leave some breathing room for the prefix.
 	 */
 
-	. = EXT_C(start) + GRUB_KERNEL_MACHINE_DATA_END
+	. = _start + GRUB_KERNEL_MACHINE_DATA_END
 
 /*
  * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
@@ -202,7 +202,7 @@
 #if defined(ENABLE_LZO)
 	/* decompress the compressed part and put the result at 1MB */
 	movl	$GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
-	movl	$(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
+	movl	$(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
 
 	pushl	%esi
 	pushl	EXT_C(grub_compressed_size)
@@ -214,7 +214,7 @@
 	cld
 #elif defined(ENABLE_LZMA)
 	movl	$GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
-	movl	$(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
+	movl	$(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
 	pushl	%edi
 	pushl	%esi
 	movl	EXT_C(grub_kernel_image_size), %ecx
@@ -239,7 +239,7 @@
 	movl	EXT_C(grub_total_module_size), %ecx
 	movl	EXT_C(grub_kernel_image_size), %esi
 	addl	%ecx, %esi
-	addl	$START_SYMBOL, %esi
+	addl	$_start, %esi
 	decl	%esi
 	movl	$END_SYMBOL, %edi
 	addl	%ecx, %edi
@@ -282,7 +282,7 @@
 	.long	0
 
 VARIABLE(grub_start_addr)
-	.long	START_SYMBOL
+	.long	_start
 
 VARIABLE(grub_end_addr)
 	.long	END_SYMBOL
@@ -510,7 +510,7 @@
  * The code beyond this point is compressed.  Assert that the uncompressed
  * code fits GRUB_KERNEL_MACHINE_RAW_SIZE.
  */
-	. = EXT_C(start) + GRUB_KERNEL_MACHINE_RAW_SIZE
+	. = _start + GRUB_KERNEL_MACHINE_RAW_SIZE
 
 /*
  *  This call is special...  it never returns...  in fact it should simply
configure.ac +0 -1
Index: configure.ac
===================================================================
@@ -383,7 +383,6 @@
     CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
   fi
   if test "x$platform" = xpc; then
-    grub_CHECK_START_SYMBOL
     grub_CHECK_BSS_START_SYMBOL
     grub_CHECK_END_SYMBOL
   fi
aclocal.m4 +0 -33
Index: aclocal.m4
===================================================================
@@ -224,39 +224,6 @@
 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
 
 
-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])
-AC_MSG_CHECKING([if start is defined by the compiler])
-AC_CACHE_VAL(grub_cv_check_start_symbol,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
-		[[asm ("incl start")]])],
-		[grub_cv_check_start_symbol=yes],
-		[grub_cv_check_start_symbol=no])])
-
-AC_MSG_RESULT([$grub_cv_check_start_symbol])
-
-AC_MSG_CHECKING([if _start is defined by the compiler])
-AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
-		[[asm ("incl _start")]])],
-		[grub_cv_check_uscore_start_symbol=yes],
-		[grub_cv_check_uscore_start_symbol=no])])
-
-AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
-
-AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start])
-
-if test "x$grub_cv_check_start_symbol" = xyes; then
-  AC_DEFINE([START_SYMBOL], [start])
-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])
-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,
Signature · 2 lines
Regards,
Pavel Roskin