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