Blame SOURCES/binutils-page-to-segment-assignment.patch

869a11
diff --git a/bfd/elf.c b/bfd/elf.c
869a11
index c132098558..325bdd545a 100644
869a11
--- a/bfd/elf.c
869a11
+++ b/bfd/elf.c
869a11
@@ -4727,33 +4727,35 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
869a11
 		 the previous section, then we need a new segment.  */
869a11
 	      new_segment = TRUE;
869a11
 	    }
869a11
+	  else if ((abfd->flags & D_PAGED) != 0
869a11
+		   && (((last_hdr->lma + last_size - 1) & -maxpagesize)
869a11
+		       == (hdr->lma & -maxpagesize)))
869a11
+	    {
869a11
+	      /* If we are demand paged then we can't map two disk
869a11
+		 pages onto the same memory page.  */
869a11
+	      new_segment = FALSE;
869a11
+	    }
869a11
 	  /* In the next test we have to be careful when last_hdr->lma is close
869a11
 	     to the end of the address space.  If the aligned address wraps
869a11
 	     around to the start of the address space, then there are no more
869a11
 	     pages left in memory and it is OK to assume that the current
869a11
 	     section can be included in the current segment.  */
869a11
-	  else if ((BFD_ALIGN (last_hdr->lma + last_size, maxpagesize) + maxpagesize
869a11
-		    > last_hdr->lma)
869a11
-		   && (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize) + maxpagesize
869a11
-		       <= hdr->lma))
869a11
+	  else if ((BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
869a11
+		    + maxpagesize > last_hdr->lma)
869a11
+		   && (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
869a11
+		       + maxpagesize <= hdr->lma))
869a11
 	    {
869a11
 	      /* If putting this section in this segment would force us to
869a11
 		 skip a page in the segment, then we need a new segment.  */
869a11
 	      new_segment = TRUE;
869a11
 	    }
869a11
 	  else if ((last_hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0
869a11
-		   && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0
869a11
-		   && ((abfd->flags & D_PAGED) == 0
869a11
-		       || (((last_hdr->lma + last_size - 1) & -maxpagesize)
869a11
-			   != (hdr->lma & -maxpagesize))))
869a11
+		   && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0)
869a11
 	    {
869a11
 	      /* We don't want to put a loaded section after a
869a11
 		 nonloaded (ie. bss style) section in the same segment
869a11
 		 as that will force the non-loaded section to be loaded.
869a11
-		 Consider .tbss sections as loaded for this purpose.
869a11
-		 However, like the writable/non-writable case below,
869a11
-		 if they are on the same page then they must be put
869a11
-		 in the same segment.  */
869a11
+		 Consider .tbss sections as loaded for this purpose.  */
869a11
 	      new_segment = TRUE;
869a11
 	    }
869a11
 	  else if ((abfd->flags & D_PAGED) == 0)
869a11
@@ -4769,21 +4771,11 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
869a11
 	    {
869a11
 	      new_segment = TRUE;
869a11
 	    }
869a11
-	  else if (! writable
869a11
-		   && (hdr->flags & SEC_READONLY) == 0
869a11
-		   && ((info != NULL
869a11
-			&& info->relro_end > info->relro_start)
869a11
-		       || (((last_hdr->lma + last_size - 1) & -maxpagesize)
869a11
-			   != (hdr->lma & -maxpagesize))))
869a11
+          else if (! writable
869a11
+		   && (hdr->flags & SEC_READONLY) == 0)
869a11
 	    {
869a11
 	      /* We don't want to put a writable section in a read only
869a11
-		 segment, unless they are on the same page in memory
869a11
-		 anyhow and there is no RELRO segment.  We already
869a11
-		 know that the last section does not bring us past the
869a11
-		 current section on the page, so the only case in which
869a11
-		 the new section is not on the same page as the previous
869a11
-		 section is when the previous section ends precisely on
869a11
-		 a page boundary.  */
869a11
+		 segment.  */
869a11
 	      new_segment = TRUE;
869a11
 	    }
869a11
 	  else