All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Build on Cygwin
@ 2007-11-23 22:31 Christian Franke
  2008-02-08 23:34 ` Robert Millan
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Franke @ 2007-11-23 22:31 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

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  <franke@computer.org>

	* 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.



[-- Attachment #2: grub2-Cygwin-build.patch --]
[-- Type: text/x-patch, Size: 7455 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-08 23:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-23 22:31 [PATCH] Build on Cygwin Christian Franke
2008-02-08 23:34 ` Robert Millan
2008-02-08 23:56   ` Christian Franke

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.