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