This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is anybody looking at the strip bug


Hi David,

> http://sources.redhat.com/ml/bug-binutils/2003-q3/msg01482.html
>
> Basicly, if strip is run on a binary where target arch != binary arch,
> then the binary is destroyed.

When you do this, do you get a message like this ?

  Warning: Output file cannot represent architecture UNKNOWN!

  
> I think strip should check elf header to make sure that the arch is
> correct before writing anything.

Would you like to try the patch below and let me know if it works for
you ?

Cheers
        Nick

2003-12-04  Nick Clifton  <nickc@redhat.com>

	* objcopy.c (copy_object): Do not copy the object if the
	output file's format cannot be set to that of the input file.
	If the input file's format is unknown, fail.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.57
diff -c -3 -p -r1.57 objcopy.c
*** binutils/objcopy.c	11 Nov 2003 17:50:26 -0000	1.57
--- binutils/objcopy.c	4 Dec 2003 17:28:36 -0000
*************** copy_object (bfd *ibfd, bfd *obfd)
*** 1138,1146 ****
    if (!bfd_set_arch_mach (obfd, iarch, imach)
        && (ibfd->target_defaulted
  	  || bfd_get_arch (ibfd) != bfd_get_arch (obfd)))
!     non_fatal (_("Warning: Output file cannot represent architecture %s"),
! 	       bfd_printable_arch_mach (bfd_get_arch (ibfd),
! 					bfd_get_mach (ibfd)));
  
    if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
      RETURN_NONFATAL (bfd_get_filename (ibfd));
--- 1138,1156 ----
    if (!bfd_set_arch_mach (obfd, iarch, imach)
        && (ibfd->target_defaulted
  	  || bfd_get_arch (ibfd) != bfd_get_arch (obfd)))
!     {
!       if (bfd_get_arch (ibfd) == bfd_arch_unknown)
! 	fatal (_("Unable to recognise the format of the input file %s"),
! 	       bfd_get_filename (ibfd));
!       else
! 	{
! 	  non_fatal (_("Warning: Output file cannot represent architecture %s"),
! 		     bfd_printable_arch_mach (bfd_get_arch (ibfd),
! 					      bfd_get_mach (ibfd)));
! 	  status = 1;
! 	  return;
! 	}
!     }
  
    if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
      RETURN_NONFATAL (bfd_get_filename (ibfd));
        


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]