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: objcopy interleave address bug ?


On Tue, Dec 23, 2003 at 09:57:45PM +0200, Galit Heller wrote:
> This seems to be the "logical" thing to do, at least for formats
> which are used for loading executables onto memory devices of embedded
> systems, since interleaved output files are each loaded onto a separate
> device, and these devices are concatanated, and so the contents of address x
> in the original object would be placed in address x divided by
> interleave-block-size in e.g. the first device.
> 
> Do you agree ?

Yes.  Most people must start their ROMs at zero, otherwise I expect this
issue would have already been raised.  Or perhaps people have discovered
that --change-section-lma works around the problem.  That's not a nice
solution since it requires you know the original section lma, but if I
commit the following I'll change the behaviour for people who might
currently use "objcopy --interleave=x --byte=y --change-section-lma=z".
On the whole, I think the following is a desirable patch, but I'll leave
committing it for a while to see if there are dissenting opinions.

	   * objcopy.c (filter_bytes): Delete.  Move code to..
	   (copy_section): ..here.  Simplify size adjustment.  Divide
	   section lma by interleave.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.61
diff -u -p -r1.61 objcopy.c
--- binutils/objcopy.c	23 Dec 2003 13:01:11 -0000	1.61
+++ binutils/objcopy.c	24 Dec 2003 00:28:49 -0000
@@ -1084,23 +1084,6 @@ add_redefine_syms_file (const char *file
   free (buf);
 }
 
-/* Keep only every `copy_byte'th byte in MEMHUNK, which is *SIZE bytes long.
-   Adjust *SIZE.  */
-
-static void
-filter_bytes (char *memhunk, bfd_size_type *size)
-{
-  char *from = memhunk + copy_byte, *to = memhunk, *end = memhunk + *size;
-
-  for (; from < end; from += interleave)
-    *to++ = *from;
-
-  if (*size % interleave > (bfd_size_type) copy_byte)
-    *size = (*size / interleave) + 1;
-  else
-    *size /= interleave;
-}
-
 /* Copy object file IBFD onto OBFD.  */
 
 static void
@@ -2003,7 +1986,18 @@ copy_section (bfd *ibfd, sec_ptr isectio
 	RETURN_NONFATAL (bfd_get_filename (ibfd));
 
       if (copy_byte >= 0)
-	filter_bytes (memhunk, &size);
+	{
+	  /* Keep only every `copy_byte'th byte in MEMHUNK.  */
+	  char *from = memhunk + copy_byte;
+	  char *to = memhunk;
+	  char *end = memhunk + size;
+
+	  for (; from < end; from += interleave)
+	    *to++ = *from;
+
+	  size = (size + interleave - 1 - copy_byte) / interleave;
+	  osection->lma /= interleave;
+	}
 
       if (!bfd_set_section_contents (obfd, osection, memhunk, 0, size))
 	RETURN_NONFATAL (bfd_get_filename (obfd));

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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