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: possible BFD regression from a change made last September


On Tue, May 17, 2005 at 10:15:32AM -0700, Bob Wilson wrote:
> If the page size is not 1, I can see how this case is now handled by:
> 
> 		  /* The section VMA must equal the file position
> 		     modulo the page size.  */
> 		  bfd_size_type page = align;
> 		  if ((abfd->flags & D_PAGED) != 0)
> 		    page = bed->maxpagesize;
> 		  adjust = vma_page_aligned_bias (sec->vma,
> 						  p->p_vaddr + p->p_memsz,
> 						  page);
> 		  p->p_memsz += adjust;
> 
> but that breaks in my scenario where align == 16 but maxpagesize == 1.

We ought to be taking the maximum of align and maxpagesize.  I think the
following should do the trick.

	* elf.c (assign_file_positions_for_segments): Use maximum of
	maxpagesize and section alignment when adjusting initial
	segment offset and section offsets.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.292
diff -u -p -r1.292 elf.c
--- bfd/elf.c	11 May 2005 02:15:46 -0000	1.292
+++ bfd/elf.c	18 May 2005 00:02:48 -0000
@@ -4145,22 +4145,20 @@ assign_file_positions_for_segments (bfd 
 	{
 	  bfd_size_type align;
 	  bfd_vma adjust;
+	  unsigned int align_power = 0;
 
-	  if ((abfd->flags & D_PAGED) != 0)
-	    align = bed->maxpagesize;
-	  else
+	  for (i = 0, secpp = m->sections; i < m->count; i++, secpp++)
 	    {
-	      unsigned int align_power = 0;
-	      for (i = 0, secpp = m->sections; i < m->count; i++, secpp++)
-		{
-		  unsigned int secalign;
+	      unsigned int secalign;
 
-		  secalign = bfd_get_section_alignment (abfd, *secpp);
-		  if (secalign > align_power)
-		    align_power = secalign;
-		}
-	      align = (bfd_size_type) 1 << align_power;
+	      secalign = bfd_get_section_alignment (abfd, *secpp);
+	      if (secalign > align_power)
+		align_power = secalign;
 	    }
+	  align = (bfd_size_type) 1 << align_power;
+
+	  if ((abfd->flags & D_PAGED) != 0 && bed->maxpagesize > align)
+	    align = bed->maxpagesize;
 
 	  adjust = vma_page_aligned_bias (m->sections[0]->vma, off, align);
 	  off += adjust;
@@ -4346,7 +4344,7 @@ assign_file_positions_for_segments (bfd 
 		  /* The section VMA must equal the file position
 		     modulo the page size.  */
 		  bfd_size_type page = align;
-		  if ((abfd->flags & D_PAGED) != 0)
+		  if ((abfd->flags & D_PAGED) != 0 && bed->maxpagesize > page)
 		    page = bed->maxpagesize;
 		  adjust = vma_page_aligned_bias (sec->vma,
 						  p->p_vaddr + p->p_memsz,

-- 
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]