Bug#921249: grub2: Please include patch to fix build on sparc64

John Paul Adrian Glaubitz glaubitz at physik.fu-berlin.de
Sun Feb 3 15:03:13 GMT 2019


Source: grub2
Version: 2.02+dfsg1-10
Severity: normal
Tags: patch
Usertags: sparc64

Hi!

Recent versions of binutils no longer support a.out or COFF as
output formats on SPARC. Since GRUB used a.out on SPARC as the
executable format for the stage2 loader, the build currently
fails with:

objcopy:boot.img: invalid bfd target
make[5]: *** [Makefile:45616: boot.img] Error 1
make[5]: *** Waiting for unfinished jobs....
objcopy:cdboot.img: invalid bfd target

We have decided that the easiest solution to fix this problem is
by just writing the a.out header for the stage2 binary ourselves.

The header consists of merely a magic word and some segment sizes
and offsets. From the elftoaout.c, the format for the header is:

/* We carry a.out header here in order to compile the thing on Solaris */

#define AMAGIC      0x01030107
#define CMAGIC      0x01030108

typedef struct {
        unsigned long   a_magic;        /* magic number */
        unsigned long   a_text;         /* size of text segment */
        unsigned long   a_data;         /* size of initialized data */
        unsigned long   a_bss;          /* size of uninitialized data */
        unsigned long   a_syms;         /* size of symbol table || checksum */
        unsigned long   a_entry;        /* entry point */
        unsigned long   a_trsize;       /* size of text relocation */
        unsigned long   a_drsize;       /* size of data relocation */
} Exec;

The attached patch uses this information to calculate and write the
header manually. It disables the a.out-sunos-big output format for
objcopy in one of the common makefiles and adjusts some of the offset
and size calculations due to the changed size of the code from boot.S.

The patch applies cleanly to the -10 version of the grub2 package, fixes
the build of grub2 on sparc64 and produces a working stage2 loader which
is identical to the one generated in the grub2 builds with the old
binutils versions which still supported a.out on SPARC.

Please consider including the patch for the next upload.

Thanks,
Adrian

--
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz at debian.org
`. `'   Freie Universitaet Berlin - glaubitz at physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
-------------- next part --------------
Description: Generate a.out header manually for sparc64
 Recent versions of binutils no longer support the a.out
 or COFF format on SPARC targets. Since the stage2 loader
 on SPARC is supposed to be an a.out binary and the a.out
 header entries are rather simple to calculate in this case,
 we just write the header ourselves instead of using external
 tools for that.
 .
Author: John Paul Adrian Glaubitz <glaubitz at physik.fu-berlin.de>
Last-Update: 2019-02-03

Index: grub2-2.02+dfsg1/grub-core/Makefile.core.def
===================================================================
--- grub2-2.02+dfsg1.orig/grub-core/Makefile.core.def
+++ grub2-2.02+dfsg1/grub-core/Makefile.core.def
@@ -381,8 +381,7 @@ image = {
   i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)';
   i386_qemu_ccasflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
 
-  sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big';
-  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000';
+  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0';
 
   objcopyflags = '-O binary';
   enable = i386_pc;
@@ -411,8 +410,7 @@ image = {
   i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00';
 
   sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S;
-  sparc64_ieee1275_objcopyflags = '-O a.out-sunos-big';
-  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x4000';
+  sparc64_ieee1275_ldflags = ' -Wl,-Ttext=0x3fe0';
   sparc64_ieee1275_cppflags = '-DCDBOOT=1';
 
   objcopyflags = '-O binary';
Index: grub2-2.02+dfsg1/grub-core/boot/sparc64/ieee1275/boot.S
===================================================================
--- grub2-2.02+dfsg1.orig/grub-core/boot/sparc64/ieee1275/boot.S
+++ grub2-2.02+dfsg1/grub-core/boot/sparc64/ieee1275/boot.S
@@ -21,6 +21,16 @@
 
 	.text
 	.align	4
+	/* The a.out header, as binutils decided to drop a.out
+         */
+	.word 0x1030107                        /* A_MAGIC */
+	.word 512 - GRUB_BOOT_AOUT_HEADER_SIZE /* text size */
+	.word 0                                /* data size */
+	.word 0                                /* bss size */
+	.word 0                                /* symbol table size */
+	.word _start                           /* entry point */
+	.word 0                                /* text relocations */
+	.word 0                                /* data relocations */
 	.globl	_start
 _start:
 	/* OF CIF entry point arrives in %o4 */
@@ -41,9 +51,9 @@ pic_base:
 	 * After loading in that block we will execute it by jumping to the
 	 * load address plus the size of the prepended A.OUT header (32 bytes).
 	 */
-	.org GRUB_BOOT_MACHINE_BOOT_DEVPATH
+	.org GRUB_BOOT_MACHINE_BOOT_DEVPATH + GRUB_BOOT_AOUT_HEADER_SIZE
 boot_path:
-	.org GRUB_BOOT_MACHINE_KERNEL_BYTE
+	.org GRUB_BOOT_MACHINE_KERNEL_BYTE + GRUB_BOOT_AOUT_HEADER_SIZE
 boot_path_end:
 kernel_byte:		.xword (2 << 9)
 kernel_address:		.word  GRUB_BOOT_MACHINE_KERNEL_ADDR
@@ -52,7 +62,7 @@ kernel_address:		.word  GRUB_BOOT_MACHIN
 #define boot_path_end (_start + 1024)
 #include <grub/offsets.h>
 
-	.org 8
+	.org 8 + GRUB_BOOT_AOUT_HEADER_SIZE
 kernel_byte:		.xword (2 << 9)
 kernel_size:	        .word  512
 kernel_address:		.word  GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS
Index: grub2-2.02+dfsg1/include/grub/sparc64/ieee1275/boot.h
===================================================================
--- grub2-2.02+dfsg1.orig/include/grub/sparc64/ieee1275/boot.h
+++ grub2-2.02+dfsg1/include/grub/sparc64/ieee1275/boot.h
@@ -46,8 +46,7 @@
 
 #define GRUB_BOOT_MACHINE_KERNEL_BYTE 0x80
 
-#define GRUB_BOOT_MACHINE_CODE_END \
-	(0x1fc - GRUB_BOOT_AOUT_HEADER_SIZE)
+#define GRUB_BOOT_MACHINE_CODE_END 0x1fc
 
 #define GRUB_BOOT_MACHINE_KERNEL_ADDR 0x4200
 


More information about the Pkg-grub-devel mailing list