Stop objcopy trying to convert endianness.

Nick Clifton nickc@redhat.com
Wed Jan 17 16:17:00 GMT 2001


Hi Guys,

  After handling another bug report from a customer who complained
  that objcopy could not convert from little-endian to big-endian, I
  have decided to check in this patch.  It makes objcopy produce a
  fatal error if such an attempt is made (instead of seg faulting as
  it currently does), and it adds a paragraph to binutils.texi
  explaining that this kind of conversion cannot be done.

Cheers
	Nick

2001-01-17  Nick Clifton  <nickc@redhat.com>

	* objcopy.c (copy_object): Fail if attempting to convert the
	endianness of the input object file.

	* binutils.texi: Explain that objcopy cannot convert endianness.
	
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src//src/binutils/objcopy.c,v
retrieving revision 1.14
diff -p -r1.14 objcopy.c
*** objcopy.c	2000/11/03 01:47:13	1.14
--- objcopy.c	2001/01/18 00:13:07
***************
*** 1,5 ****
  /* objcopy.c -- copy object file from input to output, optionally massaging it.
!    Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000
     Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
--- 1,5 ----
  /* objcopy.c -- copy object file from input to output, optionally massaging it.
!    Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
     Free Software Foundation, Inc.
  
     This file is part of GNU Binutils.
*************** copy_object (ibfd, obfd)
*** 765,770 ****
--- 765,777 ----
    long symsize;
    PTR dhandle;
  
+   if (ibfd->xvec->byteorder != obfd->xvec->byteorder
+       && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
+       && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
+     {
+       fatal (_("Unable to change endianness of input file(s)"));
+       return;
+     }
  
    if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
      RETURN_NONFATAL (bfd_get_filename (obfd));

Index: binutils/binutils.texi
===================================================================
RCS file: /cvs/src//src/binutils/binutils.texi,v
retrieving revision 1.30
diff -p -r1.30 binutils.texi
*** binutils.texi	2001/01/07 15:04:21	1.30
--- binutils.texi	2001/01/18 00:13:07
*************** END-INFO-DIR-ENTRY
*** 26,32 ****
  @end ifinfo
  
  @ifinfo
! Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
  
        Permission is granted to copy, distribute and/or modify this document
        under the terms of the GNU Free Documentation License, Version 1.1
--- 26,32 ----
  @end ifinfo
  
  @ifinfo
! Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
  
        Permission is granted to copy, distribute and/or modify this document
        under the terms of the GNU Free Documentation License, Version 1.1
*************** notice identical to this one except for 
*** 49,55 ****
  @c This file documents the GNU binary utilities "ar", "ld", "objcopy",
  @c  "objdump", "nm", "size", "strings", "strip", "readelf" and "ranlib".
  @c
! @c Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
  @c 
  @c This text may be freely distributed under the terms of the GNU
  @c Free Documentation License.
--- 49,55 ----
  @c This file documents the GNU binary utilities "ar", "ld", "objcopy",
  @c  "objdump", "nm", "size", "strings", "strip", "readelf" and "ranlib".
  @c
! @c Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
  @c 
  @c This text may be freely distributed under the terms of the GNU
  @c Free Documentation License.
*************** notice identical to this one except for 
*** 74,80 ****
  @end tex
  
  @vskip 0pt plus 1filll
! Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 1998, 2000 Free Software Foundation, Inc.
  
        Permission is granted to copy, distribute and/or modify this document
        under the terms of the GNU Free Documentation License, Version 1.1
--- 74,80 ----
  @end tex
  
  @vskip 0pt plus 1filll
! Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 1998, 2000, 2001 Free Software Foundation, Inc.
  
        Permission is granted to copy, distribute and/or modify this document
        under the terms of the GNU Free Documentation License, Version 1.1
*************** When generating an S-record or a raw bin
*** 930,935 ****
--- 930,940 ----
  use @samp{-S} to remove sections containing debugging information.  In
  some cases @samp{-R} will be useful to remove sections which contain
  information that is not needed by the binary file.
+ 
+ Note - @code{objcopy} is not able to change the endianness of its input
+ files.  If the input format has an endianness, (some formats do not),
+ @code{objcopy} can only copy the inputs into file formats that have the
+ same endianness or which have no endianness (eg @samp{srec}).
  
  @table @code
  @item @var{infile}


More information about the Binutils mailing list