[SuperH] Problem building *.o from binary

NIIBE Yutaka gniibe@chroot.org
Thu Jun 15 22:59:00 GMT 2000

When I tried to build zImage for SuperH, I got following error
with current CVS binutils (with patch which enables linux-sh).
ld: _tmp_27675piggy.gz: compiled for a little endian system and target is little endian
File in wrong format: failed to merge target specific data of file _tmp_27675piggy.gz
Old 2.9.1 worked well.

At least, the error message is weird.

The process of building zImage is as follows.

(1) Remove useless sections for run-time kernel

    objcopy -O binary -R .note -R .comment -R .stab -R .stabstr \
	-R .empty_zero_page -S linux/vmlinux $tmppiggy

(2) Gzip it
    gzip -f -9 < $tmppiggy > $tmppiggy.gz

(3) Prepare the linker script
    echo "SECTIONS {
	.data : { input_len = .;
		LONG(input_data_end - input_data) input_data = .;
		*(.data) input_data_end = .;
	}}" > $tmppiggy.lnk;

(4) Build .o
    ld -EL -r -o piggy.o -b binary $tmppiggy.gz -b elf32-shl -T $tmppiggy.lnk

(5) Remove temporary files
    rm -f $tmppiggy $tmppiggy.gz $tmppiggy.lnk

(6) Build the image
    ld -EL -Ttext 0x8c200000 -e startup -T linux/arch/sh/vmlinux.lds -o vmlinux head.o misc.o piggy.o

The error occurs at (4) when building .o from the binary (gzipped
kernel image).

The reason is the function _bfd_generic_verify_endian_match returns 0
when the byteorder is unknown.

With following patch, it works fine, but I don't know if this is
good solution or not.  Please let me know your opinion.

We'll send the patch for sh-unknown-linux-gnu support later.

Index: elf32-sh.c
RCS file: /cvs/src/src/bfd/elf32-sh.c,v
retrieving revision 1.11
diff -c -3 -p -r1.11 elf32-sh.c
*** elf32-sh.c	2000/05/15 23:10:59	1.11
--- elf32-sh.c	2000/06/16 05:32:16
*************** sh_elf_merge_private_data (ibfd, obfd)
*** 2334,2340 ****
    flagword old_flags, new_flags;
!   if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
      return false;
    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
--- 4342,4349 ----
    flagword old_flags, new_flags;
!   if (ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
!       && _bfd_generic_verify_endian_match (ibfd, obfd) == false)
      return false;
    if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour

More information about the Binutils mailing list