[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Build fixes for Cygwin
From: |
Christian Franke |
Subject: |
[PATCH] Build fixes for Cygwin |
Date: |
Sun, 20 Jul 2008 22:52:21 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 |
This adds Cygwin support to the build system. It adds PE->ELF
conversion, a linker script and support for HAVE_ASM_USCORE.
Christian
2007-07-20 Christian Franke <address@hidden>
* 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.
* conf/i386-pc.rmk: Replace -Wl,-N by TARGET_IMG_LDFLAGS.
* conf/i386-pc-cygwin-ld-img.sc: New linker script.
* 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.
Add call to grub_CHECK_STACK_ARG_PROBE.
Use TARGET_IMG_LDFLAGS to check start, bss_start, end symbols.
* genkernsyms.sh.in: Handle HAVE_ASM_USCORE case.
* genmk.rb: Add TARGET_MOD_OBJCOPY step to convert native linker
output format to ELF. Handle HAVE_ASM_USCORE case in strip command.
Add EXEEXT to CLEANFILES.
* gensymlist.sh.in: Handle HAVE_ASM_USCORE case.
diff --git a/Makefile.in b/Makefile.in
index 6f9474c..add81d5 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -68,7 +68,11 @@ 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@
MODULE_LDFLAGS = @MODULE_LDFLAGS@
+EXEEXT = @EXEEXT@
OBJCOPY = @OBJCOPY@
STRIP = @STRIP@
NM = @NM@
diff --git a/aclocal.m4 b/aclocal.m4
index b7cc0a2..ee6c4db 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -73,7 +73,7 @@ else
fi
grub_cv_prog_objcopy_absolute=yes
for link_addr in 2000 8000 7C00; do
- if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext
-Wl,$link_addr conftest.o -o conftest.exec]); then :
+ if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC}
-Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
else
AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
fi
@@ -398,3 +398,19 @@ else
AC_MSG_RESULT([no])
[fi]
])
+
+dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
+AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[
+[# Smashing stack arg probe.
+sap_possible=yes]
+AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
+AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
+[if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
+ AC_MSG_RESULT([yes])
+ [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
+ rm -f conftest.s
+else
+ sap_possible=no]
+ AC_MSG_RESULT([no])
+[fi]
+])
diff --git a/conf/i386-pc-cygwin-img-ld.sc b/conf/i386-pc-cygwin-img-ld.sc
new file mode 100644
index 0000000..a41cac7
--- /dev/null
+++ b/conf/i386-pc-cygwin-img-ld.sc
@@ -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__"=="edata", ".pdata not empty")
+ASSERT("__bss_end__" =="end" , ".edata not empty")
+
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index b677a96..84c0b7d 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -16,27 +16,27 @@ pkglib_IMAGES = boot.img diskboot.img kernel.img
pxeboot.img lnxboot.img \
# 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 lnxboot.img.
lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S
lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,6000
+lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,6000
# For cdboot.img.
cdboot_img_SOURCES = boot/i386/pc/cdboot.S
cdboot_img_ASFLAGS = $(COMMON_ASFLAGS)
-cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-Ttext,7C00
+cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
# For kernel.img.
kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
@@ -53,7 +53,7 @@ kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h
dl.h elf.h elfload.h \
machine/memory.h machine/loader.h machine/vga.h machine/vbe.h
machine/kernel.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
-kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
-Wl,-N,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
+kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)
-Wl,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst
diff --git a/configure.ac b/configure.ac
index 1d8bd08..0062901 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,6 +188,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!
@@ -278,6 +304,12 @@ grub_CHECK_STACK_PROTECTOR
if test "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 test x"$sap_possible" = xyes; then
+ TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
+fi
AC_SUBST(TARGET_CFLAGS)
AC_SUBST(TARGET_CPPFLAGS)
@@ -296,9 +328,14 @@ 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
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 --git a/genkernsyms.sh.in b/genkernsyms.sh.in
index a5e1271..0df0bbf 100644
--- a/genkernsyms.sh.in
+++ b/genkernsyms.sh.in
@@ -16,9 +16,12 @@
: address@hidden@}
: address@hidden@}
+u=
+grep "^#define HAVE_ASM_USCORE" config.h >/dev/null 2>&1 && u="_"
+
$CC -DGRUB_SYMBOL_GENERATOR=1 -E -I. -Iinclude -I"$srcdir/include" $* \
| grep -v '^#' \
| sed -n \
- -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
*(\([a-zA-Z0-9_]*\)).*/\1 kernel/;p;}' \
- -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR
*(\([a-zA-Z0-9_]*\)).*/\1 kernel/;p;}' \
+ -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
*(\([a-zA-Z0-9_]*\)).*/'"$u"'\1 kernel/;p;}' \
+ -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR
*(\([a-zA-Z0-9_]*\)).*/'"$u"'\1 kernel/;p;}' \
| sort -u
diff --git a/genmk.rb b/genmk.rb
index 56dee5c..ba9b127 100644
--- a/genmk.rb
+++ b/genmk.rb
@@ -114,8 +114,10 @@ UNDSYMFILES += #{undsym}
address@hidden: #{pre_obj} #{mod_obj}
-rm -f $@
- $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) $(MODULE_LDFLAGS)
-Wl,-r,-d -o $@ $^
- $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R
.comment $@
+ $(TARGET_CC) $(#{prefix}_LDFLAGS) $(TARGET_LDFLAGS) $(MODULE_LDFLAGS)
-Wl,-r,-d -o address@hidden $^
+ $(TARGET_MOD_COPY) address@hidden $@ || (rm -f address@hidden; exit 1)
+ rm -f address@hidden
+ $(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}
-rm -f $@
@@ -194,7 +196,7 @@ class Utility
deps = objs.collect {|obj| obj.suffix('d')}
deps_str = deps.join(' ');
- "CLEANFILES += address@hidden #{objs_str}
+ "CLEANFILES += address@hidden(EXEEXT) #{objs_str}
MOSTLYCLEANFILES += #{deps_str}
address@hidden: $(#{prefix}_DEPENDENCIES) #{objs_str}
diff --git a/gensymlist.sh.in b/gensymlist.sh.in
index d8b9871..d9aa65c 100644
--- a/gensymlist.sh.in
+++ b/gensymlist.sh.in
@@ -16,6 +16,8 @@
: address@hidden@}
: address@hidden@}
+u=
+grep "^#define HAVE_ASM_USCORE" config.h >/dev/null 2>&1 && u="_"
cat <<EOF
/* This file is automatically generated by gensymlist.sh. DO NOT EDIT! */
@@ -62,8 +64,8 @@ EOF
$CC -DGRUB_SYMBOL_GENERATOR=1 -E -I. -Iinclude -I"$srcdir/include" $* \
| grep -v '^#' \
| sed -n \
- -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
*(\([a-zA-Z0-9_]*\)).*/ {"\1", \1},/;p;}' \
- -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR
*(\([a-zA-Z0-9_]*\)).*/ {"\1", \&\1},/;p;}' \
+ -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
*(\([a-zA-Z0-9_]*\)).*/ {"'"$u"'\1", \1},/;p;}' \
+ -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR
*(\([a-zA-Z0-9_]*\)).*/ {"'"$u"'\1", \&\1},/;p;}' \
| sort -u
cat <<EOF
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Build fixes for Cygwin,
Christian Franke <=