Build on Cygwin
PATCH 1/1 Build on Cygwin
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 <[email protected]>
* 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.
Makefile.in +4 -0
@@ -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@
conf/i386-pc-cygwin-img-ld.sc +53 -0
53 lines not on this page · raw message
conf/i386-pc.rmk +4 -4
@@ -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
configure.ac +37 -0
@@ -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
genmk.rb +3 -1
@@ -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 [email protected] $^ + $(TARGET_MOD_COPY) [email protected] $@ || (rm -f [email protected]; exit 1) + rm -f [email protected] $(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}
include/grub/dl.h +3 -2
@@ -40,11 +40,12 @@ grub_##name##_fini (void) { grub_mod_finstatic 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 {
include/grub/symbol.h +6 -0
@@ -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
Quoted 10 lines · Christian Franke
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".
I don't recall which thread this is, but I think the last time we discussed this the conclussion was that the simplest solution was to enable a build option in binutils to obtain ELF support?
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 6 lines · Robert Millan
Quoted 4 lines · Christian Franke
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.
Quoted 10 lines
Quoted 4 lines
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".
I don't recall which thread this is, but I think the last time we discussed this the conclussion was that the simplest solution was to enable a build option in binutils to obtain ELF support?
Due to limitations and requirements of bfd (no relocation conversion support), gas (no multiple object format support) and gcc (creates object format dependent assembly output), a complete (cross-)compiler toolchain would be necessary.
See "Building GRUB on platforms without ELF support".
Christian