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

PATCH: Allow sections in adjacent pages to be included in the same segment


Hi Guys,

  I am applying the patch below to fix the assignment of adjacent ELF
  sections to a segment.  At the moment the code looks like this:

    else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
             < BFD_ALIGN (hdr->lma, maxpagesize))
      {
         /* If putting this section in this segment would force us to
            skip a page in the segment, then we need a new segment.  */
         new_segment = TRUE;
      }

  which does not work as intended because BFD_ALIGN always rounds its
  argument up to the next alignment boundary.  So for example if one
  section ended at 0x1fff and the next (potential) section to be
  allocated started at 0x2001 and the pagesize was 0x1000 then the
  comparison above would check "0x2000 < 0x3000" and so decide that a
  new segment was needed.

  The revised test looks like this:
  
    else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize) + maxpagesize
            < hdr->lma)

  so that it rounds up the end address of the previous section but
  compares it directly with the start address of the current section.
  The "+ maxpagesize" is there so that we actually allow for sections
  that are in separate pages but not more than one page apart.  The
  code has to be careful however to handle the case where rounding up
  the end address of the previous section wraps around the end of the
  address space so the actual patch looks like this:

Cheers
  Nick

bfd/ChangeLog
2008-07-22  Nick Clifton  <nickc@redhat.com>

	* elf.c (_bfd_elf_map_sections_to_segments): Allow sections in
	adjoining pages to be included in the same segment.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.455
diff -c -3 -p -r1.455 elf.c
*** bfd/elf.c	21 Jul 2008 16:01:01 -0000	1.455
--- bfd/elf.c	22 Jul 2008 10:52:52 -0000
*************** _bfd_elf_map_sections_to_segments (bfd *
*** 3720,3727 ****
  		 segment.  */
  	      new_segment = TRUE;
  	    }
! 	  else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
! 		   < BFD_ALIGN (hdr->lma, maxpagesize))
  	    {
  	      /* If putting this section in this segment would force us to
  		 skip a page in the segment, then we need a new segment.  */
--- 3720,3734 ----
  		 segment.  */
  	      new_segment = TRUE;
  	    }
! 	  /* In the next test we have to be careful when last_hdr->lma is close
! 	     to the end of the address space.  If the aligned address wraps
! 	     around to the start of the address space, then there are no more
! 	     pages left in memory and it is OK to assume that the current
! 	     section can be included in the current segment.  */
! 	  else if ((BFD_ALIGN (last_hdr->lma + last_size, maxpagesize) + maxpagesize
! 		    > last_hdr->lma)
! 		   && (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize) + maxpagesize
! 		       < hdr->lma))
  	    {
  	      /* If putting this section in this segment would force us to
  		 skip a page in the segment, then we need a new segment.  */


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