Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Ivh3t-0003C0-2t for mharc-grub-devel@gnu.org; Fri, 23 Nov 2007 17:31:49 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ivh3r-00039z-Gc for grub-devel@gnu.org; Fri, 23 Nov 2007 17:31:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ivh3r-00039T-1T for grub-devel@gnu.org; Fri, 23 Nov 2007 17:31:47 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ivh3q-00039Q-Pt for grub-devel@gnu.org; Fri, 23 Nov 2007 17:31:46 -0500 Received: from mailout03.sul.t-online.de ([194.25.134.81] helo=mailout03.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ivh3q-0001GL-9l for grub-devel@gnu.org; Fri, 23 Nov 2007 17:31:46 -0500 Received: from fwd26.aul.t-online.de by mailout03.sul.t-online.com with smtp id 1Ivh3o-0004Ep-05; Fri, 23 Nov 2007 23:31:44 +0100 Received: from [10.3.2.2] (EfrvPrZJohL0naIOHhkMhZhTVLTSiMpCOlxsjowwzGgdPxog6AE6Df2ccdRAdNLwoQ@[217.235.189.78]) by fwd26.aul.t-online.de with esmtp id 1Ivh3l-2HrrOq0; Fri, 23 Nov 2007 23:31:41 +0100 Message-ID: <474754C9.5050400@t-online.de> Date: Fri, 23 Nov 2007 23:31:37 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------030402060806090206050807" X-ID: EfrvPrZJohL0naIOHhkMhZhTVLTSiMpCOlxsjowwzGgdPxog6AE6Df2ccdRAdNLwoQ X-TOI-MSGID: 8a0feb28-e31e-4eb7-aacb-38447937c3a2 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Build on Cygwin 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: Fri, 23 Nov 2007 22:31:47 -0000 This is a multi-part message in MIME format. --------------030402060806090206050807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch enables build on Cygwin. It handles the issues introduced by the non-ELF object format. A linker script replaces the unsupported -N option. PE modules are converted to ELF. ELF-only assembly language features are removed. Please note that this patch produces a conflict in genmk.rb unless the "Handle C symbols with leading underscore" is applied first. This is the last patch derived from "[PATCH] grub2 for Cygwin". Christian 2007-11-23 Christian Franke * Makefile.in: Add autoconf replacements TARGET_IMG_LDSCRIPT, TARGET_IMG_LDFLAGS, TARGET_MOD_COPY and EXEEXT. * aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Replace -Wl,-N by TARGET_IMG_LDFLAGS_AC. (grub_CHECK_STACK_ARG_PROBE): New function. * configure.ac: Add check for linker script "conf/${target}-img-ld.c" to set TARGET_IMG_LD* accordingly. Add check for Cygwin to set TARGET_MOD_OBJCOPY accordingly. Use TARGET_IMG_LDFLAGS to check start, bss_start, end symbols. * genmk.rb: Add TARGET_MOD_OBJCOPY step to convert native linker output format to ELF. * conf/i386-pc.rmk: Replace -Wl,-N by TARGET_IMG_LDFLAGS. * conf/i386-pc-cygwin-ld-img.sc: New linker script. * include/grub/dl.h: Remove .previous, gas supports this only for ELF format. * include/grub/symbol.h [__CYGWIN__] (#define FUNCTION/VARIABLE): Remove .type, gas supports this only for ELF format. --------------030402060806090206050807 Content-Type: text/x-patch; name="grub2-Cygwin-build.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-Cygwin-build.patch" diff -rupN grub2.orig/Makefile.in grub2/Makefile.in --- grub2.orig/Makefile.in 2007-06-11 08:26:17.000000000 +0200 +++ grub2/Makefile.in 2007-10-12 22:43:29.000000000 +0200 @@ -67,6 +67,10 @@ TARGET_CFLAGS = @TARGET_CFLAGS@ TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I. -Iinclude -I$(srcdir)/include \ -Wall -W TARGET_LDFLAGS = @TARGET_LDFLAGS@ +TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@ +TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@ +TARGET_MOD_COPY = @TARGET_MOD_COPY@ +EXEEXT = @EXEEXT@ OBJCOPY = @OBJCOPY@ STRIP = @STRIP@ NM = @NM@ diff -rupN grub2.orig/conf/i386-pc-cygwin-img-ld.sc grub2/conf/i386-pc-cygwin-img-ld.sc --- grub2.orig/conf/i386-pc-cygwin-img-ld.sc 1970-01-01 01:00:00.000000000 +0100 +++ grub2/conf/i386-pc-cygwin-img-ld.sc 2007-11-23 22:31:42.562500000 +0100 @@ -0,0 +1,53 @@ +/* Linker script to create grub .img files on Cygwin. */ + +SECTIONS +{ + .text : + { + start = . ; + *(.text) + etext = . ; + } + .data : + { + __data_start__ = . ; + *(.data) + __data_end__ = . ; + } + .rdata : + { + __rdata_start__ = . ; + *(.rdata) + __rdata_end__ = . ; + } + .pdata : + { + *(.pdata) + edata = . ; + } + .bss : + { + __bss_start__ = . ; + *(.bss) + __common_start__ = . ; + *(COMMON) + __bss_end__ = . ; + } + .edata : + { + *(.edata) + end = . ; + } + .stab : + { + *(.stab) + } + .stabstr : + { + *(.stabstr) + } +} + +ASSERT("__rdata_end__"=="__bss_start__", ".pdata not empty") +ASSERT("__bss_end__" =="end" , ".edata not empty") + diff -rupN grub2.orig/conf/i386-pc.rmk grub2/conf/i386-pc.rmk --- grub2.orig/conf/i386-pc.rmk 2007-11-18 17:57:00.640625000 +0100 +++ grub2/conf/i386-pc.rmk 2007-11-18 18:14:24.125000000 +0100 @@ -10,17 +10,17 @@ pkgdata_IMAGES = boot.img diskboot.img k # For boot.img. boot_img_SOURCES = boot/i386/pc/boot.S boot_img_ASFLAGS = $(COMMON_ASFLAGS) -boot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,7C00 +boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00 # For pxeboot.img pxeboot_img_SOURCES = boot/i386/pc/pxeboot.S pxeboot_img_ASFLAGS = $(COMMON_ASFLAGS) -pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,7C00 +pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00 # For diskboot.img. diskboot_img_SOURCES = boot/i386/pc/diskboot.S diskboot_img_ASFLAGS = $(COMMON_ASFLAGS) -diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8000 +diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,8000 # For kernel.img. kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \ @@ -37,7 +37,7 @@ kernel_img_HEADERS = arg.h boot.h cache. machine/memory.h machine/loader.h machine/vga.h machine/vbe.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,8200 $(COMMON_CFLAGS) MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst diff -rupN grub2.orig/configure.ac grub2/configure.ac --- grub2.orig/configure.ac 2007-10-31 23:55:56.031250000 +0100 +++ grub2/configure.ac 2007-11-23 22:30:32.671875000 +0100 @@ -156,6 +156,32 @@ AC_CHECK_FUNCS(posix_memalign memalign) # Check for target programs. # + +# 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}-${target_os}-img-ld.sc"; then + TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc" + TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}" + TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc" +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]) + +# For platforms where ELF is not the default link format. +AC_MSG_CHECKING([for command to convert module to ELF format]) +if test "$host_os" = cygwin; then + TARGET_MOD_COPY='$(OBJCOPY) -O elf32-i386' +else + TARGET_MOD_COPY='cp -f' +fi +AC_SUBST(TARGET_MOD_COPY) +AC_MSG_RESULT([$TARGET_MOD_COPY]) + # For cross-compiling. if test "x$target" != "x$host"; then # XXX this depends on the implementation of autoconf! @@ -240,6 +266,12 @@ grub_CHECK_STACK_PROTECTOR if [ x"$ssp_possible" = xyes ]; then TARGET_CFLAGS=$TARGET_CFLAGS\ -fno-stack-protector fi] +grub_CHECK_STACK_ARG_PROBE +[# Cygwin's GCC uses alloca() to probe the stackframe on static +# stack allocations above some threshold. +if [ x"$sap_possible" = xyes ]; then + TARGET_CFLAGS=$TARGET_CFLAGS\ -mno-stack-arg-probe +fi] AC_SUBST(TARGET_CFLAGS) AC_SUBST(TARGET_CPPFLAGS) @@ -255,9 +287,14 @@ LDFLAGS="$TARGET_LDFLAGS" grub_PROG_OBJCOPY_ABSOLUTE 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 grub_CHECK_START_SYMBOL grub_CHECK_BSS_START_SYMBOL grub_CHECK_END_SYMBOL + CFLAGS="$TARGET_CFLAGS" grub_I386_ASM_PREFIX_REQUIREMENT grub_I386_ASM_ADDR32 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK diff -rupN grub2.orig/genmk.rb grub2/genmk.rb --- grub2.orig/genmk.rb 2007-11-10 19:37:17.562500000 +0100 +++ grub2/genmk.rb 2007-10-20 22:51:41.796875000 +0200 @@ -114,7 +114,9 @@ UNDSYMFILES += #{undsym} #{@name}: #{pre_obj} #{mod_obj} -rm -f $@ - $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ + $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@.tmp $^ + $(TARGET_MOD_COPY) $@.tmp $@ || (rm -f $@.tmp; exit 1) + rm -f $@.tmp $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -K _grub_mod_init -K _grub_mod_fini -R .note -R .comment $@ #{pre_obj}: $(#{prefix}_DEPENDENCIES) #{objs_str} diff -rupN grub2.orig/include/grub/dl.h grub2/include/grub/dl.h --- grub2.orig/include/grub/dl.h 2007-07-22 01:32:21.000000000 +0200 +++ grub2/include/grub/dl.h 2007-11-23 22:31:08.906250000 +0100 @@ -40,11 +40,12 @@ grub_##name##_fini (void) { grub_mod_fin static void \ grub_mod_fini (void) +/* Note: .previous not supported for non-ELF targets. */ #define GRUB_MOD_NAME(name) \ -__asm__ (".section .modname,\"S\"\n.string \"" #name "\"\n.previous") +__asm__ (".section .modname\n.string \"" #name "\"\n") #define GRUB_MOD_DEP(name) \ -__asm__ (".section .moddeps,\"S\"\n.string \"" #name "\"\n.previous") +__asm__ (".section .moddeps\n.string \"" #name "\"\n") struct grub_dl_segment { diff -rupN grub2.orig/include/grub/symbol.h grub2/include/grub/symbol.h --- grub2.orig/include/grub/symbol.h 2007-07-22 01:32:22.000000000 +0200 +++ grub2/include/grub/symbol.h 2007-11-23 22:30:48.468750000 +0100 @@ -28,8 +28,14 @@ # define EXT_C(sym) sym #endif +#ifndef __CYGWIN__ #define FUNCTION(x) .globl EXT_C(x) ; .type EXT_C(x), "function" ; EXT_C(x): #define VARIABLE(x) .globl EXT_C(x) ; .type EXT_C(x), "object" ; EXT_C(x): +#else +/* .type not supported for non-ELF targets. XXX: Check this in configure? */ +#define FUNCTION(x) .globl EXT_C(x) ; EXT_C(x): +#define VARIABLE(x) .globl EXT_C(x) ; EXT_C(x): +#endif /* Mark an exported symbol. */ #ifndef GRUB_SYMBOL_GENERATOR --------------030402060806090206050807--