This is the mail archive of the binutils@sourceware.cygnus.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]

: binutils-2.9.5.0.41: possible bug in objcopy --change-addresses



On Fri, May 05, 2000 at 06:26:19PM -0700, Michael Deutschmann wrote:
> Program Headers:
>   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
>   LOAD           0x000000 0x00000000 0x00000000 0x12700 0x12700 R E 0x1000
>   LOAD           0x012700 0x00013700 0x00013700 0x00218 0x00690 RW  0x1000
>   DYNAMIC        0x012890 0x00013890 0x00013890 0x00088 0x00088 RW  0x4
> 
> I tried offsetting it by 0x80000000, and got the following:
> 
> Program Headers:
>   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
>   LOAD           0x000000 0x80000000 0x80000094 0x12700 0x12700 R E 0x1000
>   LOAD           0x012700 0x80013700 0x80013700 0x00218 0x00690 RW  0x1000
>   DYNAMIC        0x012890 0x80013890 0x80013890 0x00088 0x00088 RW  0x4

This patch should fix it.  I'll commit it in a day or so, unless someone
objects.

Alan Modra
-- 
Linuxcare.  Support for the Revolution.

bfd/ChangeLog

	* elf.c (copy_private_bfd_data): Allow for space possibly taken up
	by elf headers when calculating segment physical address from lma.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.30
diff -u -p -r1.30 elf.c
--- elf.c	2000/05/05 18:12:53	1.30
+++ elf.c	2000/05/07 12:48:39
@@ -3744,7 +3744,7 @@ copy_private_bfd_data (ibfd, obfd)
 	 more to do.  */
 
       isec = 0;
-      matching_lma = false;
+      matching_lma = 0;
       suggested_lma = 0;
 
       for (j = 0, s = ibfd->sections; s != NULL; s = s->next)
@@ -3810,21 +3810,32 @@ copy_private_bfd_data (ibfd, obfd)
 	  free (sections);
 	  continue;
 	}
-      else if (matching_lma != 0)
-	{
-	  /* At least one section fits inside the current segment.
-	     Keep it, but modify its physical address to match the
-	     LMA of the first section that fitted.  */
-
-	  m->p_paddr = matching_lma;
-	}
       else
 	{
-	  /* None of the sections fitted inside the current segment.
-	     Change the current segment's physical address to match
-	     the LMA of the first section.  */
+	  if (matching_lma != 0)
+	    {
+	      /* At least one section fits inside the current segment.
+		 Keep it, but modify its physical address to match the
+		 LMA of the first section that fitted.  */
+
+	      m->p_paddr = matching_lma;
+	    }
+	  else
+	    {
+	      /* None of the sections fitted inside the current segment.
+		 Change the current segment's physical address to match
+		 the LMA of the first section.  */
+
+	      m->p_paddr = suggested_lma;
+	    }
+
+	  /* Offset the segment physical address from the lma to allow
+	     for space taken up by elf headers.  */
+	  if (m->includes_filehdr)
+	    m->p_paddr -= iehdr->e_ehsize;
 
-	  m->p_paddr = suggested_lma;
+	  if (m->includes_phdrs)
+	    m->p_paddr -= iehdr->e_phnum * iehdr->e_phentsize;
 	}
 
       /* Step Three: Loop over the sections again, this time assigning
@@ -3857,7 +3868,12 @@ copy_private_bfd_data (ibfd, obfd)
 		    {
 		      /* If the first section in a segment does not start at
 			 the beginning of the segment, then something is wrong.  */
-		      if (os->lma != m->p_paddr)
+		      if (os->lma != (m->p_paddr
+				      + (m->includes_filehdr
+					 ? iehdr->e_ehsize : 0)
+				      + (m->includes_phdrs
+					 ? iehdr->e_phnum * iehdr->e_phentsize
+					 : 0)))
 			abort ();
 		    }
 		  else


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