public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: Bob Wilson <bwilson@tensilica.com>
Cc: binutils@sources.redhat.com
Subject: Re: possible BFD regression from a change made last September
Date: Wed, 18 May 2005 01:31:00 -0000	[thread overview]
Message-ID: <20050518001540.GP27573@bubble.grove.modra.org> (raw)
In-Reply-To: <428A26B4.2040007@tensilica.com>

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

  reply	other threads:[~2005-05-18  0:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-17 17:19 Bob Wilson
2005-05-18  1:31 ` Alan Modra [this message]
2005-05-18 17:12   ` Bob Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050518001540.GP27573@bubble.grove.modra.org \
    --to=amodra@bigpond.net.au \
    --cc=binutils@sources.redhat.com \
    --cc=bwilson@tensilica.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).