|
|
9af138 |
diff -Nrup a/bfd/elf.c b/bfd/elf.c
|
|
|
9af138 |
--- a/bfd/elf.c 2015-03-11 13:58:14.127506851 -0600
|
|
|
9af138 |
+++ b/bfd/elf.c 2015-03-11 14:01:51.155695916 -0600
|
|
|
9af138 |
@@ -4482,7 +4482,6 @@ assign_file_positions_for_load_sections
|
|
|
9af138 |
unsigned int alloc;
|
|
|
9af138 |
unsigned int i, j;
|
|
|
9af138 |
bfd_vma header_pad = 0;
|
|
|
9af138 |
- bfd_vma relro_start = 0, relro_end = 0;
|
|
|
9af138 |
|
|
|
9af138 |
if (link_info == NULL
|
|
|
9af138 |
&& !_bfd_elf_map_sections_to_segments (abfd, link_info))
|
|
|
9af138 |
@@ -4553,23 +4552,6 @@ assign_file_positions_for_load_sections
|
|
|
9af138 |
header_pad -= off;
|
|
|
9af138 |
off += header_pad;
|
|
|
9af138 |
|
|
|
9af138 |
- /* Get start and end of PT_GNU_RELRO segment. */
|
|
|
9af138 |
- if (link_info != NULL)
|
|
|
9af138 |
- {
|
|
|
9af138 |
- relro_start = link_info->relro_start;
|
|
|
9af138 |
- relro_end = link_info->relro_end;
|
|
|
9af138 |
- }
|
|
|
9af138 |
- else
|
|
|
9af138 |
- {
|
|
|
9af138 |
- for (m = elf_seg_map (abfd); m != NULL; m = m->next)
|
|
|
9af138 |
- if (m->p_type == PT_GNU_RELRO)
|
|
|
9af138 |
- {
|
|
|
9af138 |
- relro_start = m->p_paddr;
|
|
|
9af138 |
- relro_end = relro_start + m->p_size;
|
|
|
9af138 |
- break;
|
|
|
9af138 |
- }
|
|
|
9af138 |
- }
|
|
|
9af138 |
-
|
|
|
9af138 |
for (m = elf_seg_map (abfd), p = phdrs, j = 0;
|
|
|
9af138 |
m != NULL;
|
|
|
9af138 |
m = m->next, p++, j++)
|
|
|
9af138 |
@@ -4914,22 +4896,6 @@ assign_file_positions_for_load_sections
|
|
|
9af138 |
}
|
|
|
9af138 |
}
|
|
|
9af138 |
|
|
|
9af138 |
- if (relro_start != 0
|
|
|
9af138 |
- && p->p_type == PT_LOAD
|
|
|
9af138 |
- && p->p_vaddr >= relro_start)
|
|
|
9af138 |
- {
|
|
|
9af138 |
- /* If PT_LOAD segment doesn't fit PT_GNU_RELRO segment,
|
|
|
9af138 |
- adjust its p_filesz and p_memsz. */
|
|
|
9af138 |
- if (p->p_vaddr + p->p_filesz < relro_end)
|
|
|
9af138 |
- {
|
|
|
9af138 |
- bfd_vma adjust = relro_end - (p->p_vaddr + p->p_filesz);
|
|
|
9af138 |
- p->p_filesz += adjust;
|
|
|
9af138 |
- off += adjust;
|
|
|
9af138 |
- }
|
|
|
9af138 |
- if (p->p_vaddr + p->p_memsz < relro_end)
|
|
|
9af138 |
- p->p_memsz += relro_end - (p->p_vaddr + p->p_memsz);
|
|
|
9af138 |
- }
|
|
|
9af138 |
-
|
|
|
9af138 |
off -= off_adjust;
|
|
|
9af138 |
|
|
|
9af138 |
/* Check that all sections are in a PT_LOAD segment.
|
|
|
9af138 |
@@ -5131,14 +5097,11 @@ assign_file_positions_for_non_load_secti
|
|
|
9af138 |
{
|
|
|
9af138 |
if (lp->p_type == PT_LOAD
|
|
|
9af138 |
&& lp->p_vaddr < link_info->relro_end
|
|
|
9af138 |
- && lp->p_vaddr + lp->p_filesz >= link_info->relro_end
|
|
|
9af138 |
&& lm->count != 0
|
|
|
9af138 |
&& lm->sections[0]->vma >= link_info->relro_start)
|
|
|
9af138 |
break;
|
|
|
9af138 |
}
|
|
|
9af138 |
|
|
|
9af138 |
- /* PR ld/14207. If the RELRO segment doesn't fit in the
|
|
|
9af138 |
- LOAD segment, it should be removed. */
|
|
|
9af138 |
BFD_ASSERT (lm != NULL);
|
|
|
9af138 |
}
|
|
|
9af138 |
else
|
|
|
9af138 |
diff -Nrup a/ld/ld.texinfo b/ld/ld.texinfo
|
|
|
9af138 |
--- a/ld/ld.texinfo 2013-02-27 13:28:03.000000000 -0700
|
|
|
9af138 |
+++ b/ld/ld.texinfo 2015-03-11 14:01:51.156695894 -0600
|
|
|
9af138 |
@@ -5865,13 +5865,15 @@ evaluation purposes.
|
|
|
9af138 |
@item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
|
|
|
9af138 |
@kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
|
|
|
9af138 |
This defines the end of the @code{PT_GNU_RELRO} segment when
|
|
|
9af138 |
-@samp{-z relro} option is used. Second argument is returned.
|
|
|
9af138 |
+@samp{-z relro} option is used.
|
|
|
9af138 |
When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
|
|
|
9af138 |
does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
|
|
|
9af138 |
@var{exp} + @var{offset} is aligned to the most commonly used page
|
|
|
9af138 |
boundary for particular target. If present in the linker script,
|
|
|
9af138 |
it must always come in between @code{DATA_SEGMENT_ALIGN} and
|
|
|
9af138 |
-@code{DATA_SEGMENT_END}.
|
|
|
9af138 |
+@code{DATA_SEGMENT_END}. Evaluates to the second argument plus any
|
|
|
9af138 |
+padding needed at the end of the @code{PT_GNU_RELRO} segment due to
|
|
|
9af138 |
+section alignment.
|
|
|
9af138 |
|
|
|
9af138 |
@smallexample
|
|
|
9af138 |
. = DATA_SEGMENT_RELRO_END(24, .);
|
|
|
9af138 |
diff -Nrup a/ld/ldlang.c b/ld/ldlang.c
|
|
|
9af138 |
--- a/ld/ldlang.c 2015-03-11 13:58:14.128506829 -0600
|
|
|
9af138 |
+++ b/ld/ldlang.c 2015-03-11 14:01:51.157695872 -0600
|
|
|
9af138 |
@@ -5379,18 +5379,14 @@ lang_size_sections (bfd_boolean *relax,
|
|
|
9af138 |
&& link_info.relro && expld.dataseg.relro_end)
|
|
|
9af138 |
{
|
|
|
9af138 |
/* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try
|
|
|
9af138 |
- to put expld.dataseg.relro on a (common) page boundary. */
|
|
|
9af138 |
- bfd_vma min_base, old_base, relro_end, maxpage;
|
|
|
9af138 |
+ to put expld.dataseg.relro_end on a (common) page boundary. */
|
|
|
9af138 |
+ bfd_vma min_base, relro_end, maxpage;
|
|
|
9af138 |
|
|
|
9af138 |
expld.dataseg.phase = exp_dataseg_relro_adjust;
|
|
|
9af138 |
maxpage = expld.dataseg.maxpagesize;
|
|
|
9af138 |
/* MIN_BASE is the absolute minimum address we are allowed to start the
|
|
|
9af138 |
read-write segment (byte before will be mapped read-only). */
|
|
|
9af138 |
min_base = (expld.dataseg.min_base + maxpage - 1) & ~(maxpage - 1);
|
|
|
9af138 |
- /* OLD_BASE is the address for a feasible minimum address which will
|
|
|
9af138 |
- still not cause a data overlap inside MAXPAGE causing file offset skip
|
|
|
9af138 |
- by MAXPAGE. */
|
|
|
9af138 |
- old_base = expld.dataseg.base;
|
|
|
9af138 |
expld.dataseg.base += (-expld.dataseg.relro_end
|
|
|
9af138 |
& (expld.dataseg.pagesize - 1));
|
|
|
9af138 |
/* Compute the expected PT_GNU_RELRO segment end. */
|
|
|
9af138 |
@@ -5406,9 +5402,9 @@ lang_size_sections (bfd_boolean *relax,
|
|
|
9af138 |
if (expld.dataseg.relro_end > relro_end)
|
|
|
9af138 |
{
|
|
|
9af138 |
/* The alignment of sections between DATA_SEGMENT_ALIGN
|
|
|
9af138 |
- and DATA_SEGMENT_RELRO_END caused huge padding to be
|
|
|
9af138 |
- inserted at DATA_SEGMENT_RELRO_END. Try to start a bit lower so
|
|
|
9af138 |
- that the section alignments will fit in. */
|
|
|
9af138 |
+ and DATA_SEGMENT_RELRO_END can cause excessive padding to
|
|
|
9af138 |
+ be inserted at DATA_SEGMENT_RELRO_END. Try to start a
|
|
|
9af138 |
+ bit lower so that the section alignments will fit in. */
|
|
|
9af138 |
asection *sec;
|
|
|
9af138 |
unsigned int max_alignment_power = 0;
|
|
|
9af138 |
|
|
|
9af138 |
@@ -5422,9 +5418,10 @@ lang_size_sections (bfd_boolean *relax,
|
|
|
9af138 |
|
|
|
9af138 |
if (((bfd_vma) 1 << max_alignment_power) < expld.dataseg.pagesize)
|
|
|
9af138 |
{
|
|
|
9af138 |
- if (expld.dataseg.base - (1 << max_alignment_power) < old_base)
|
|
|
9af138 |
- expld.dataseg.base += expld.dataseg.pagesize;
|
|
|
9af138 |
- /* Properly align base to max_alignment_power. */
|
|
|
9af138 |
+ /* Aligning the adjusted base guarantees the padding
|
|
|
9af138 |
+ between sections won't change. This is better than
|
|
|
9af138 |
+ simply subtracting 1 << max_alignment_power which is
|
|
|
9af138 |
+ what we used to do here. */
|
|
|
9af138 |
expld.dataseg.base &= ~((1 << max_alignment_power) - 1);
|
|
|
9af138 |
lang_reset_memory_regions ();
|
|
|
9af138 |
one_lang_size_sections_pass (relax, check_regions);
|
|
|
9af138 |
diff -Nrup a/ld/testsuite/ld-x86-64/pr14207.d b/ld/testsuite/ld-x86-64/pr14207.d
|
|
|
9af138 |
--- a/ld/testsuite/ld-x86-64/pr14207.d 2015-03-11 13:58:14.128506829 -0600
|
|
|
9af138 |
+++ b/ld/testsuite/ld-x86-64/pr14207.d 2015-03-11 14:01:51.157695872 -0600
|
|
|
9af138 |
@@ -11,7 +11,7 @@ There are 4 program headers, starting at
|
|
|
9af138 |
Program Headers:
|
|
|
9af138 |
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
|
|
|
9af138 |
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001e0 0x0001e0 R 0x200000
|
|
|
9af138 |
- LOAD 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x000cf8 RW 0x200000
|
|
|
9af138 |
+ LOAD 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b0 0x000cf8 RW 0x200000
|
|
|
9af138 |
DYNAMIC 0x000b90 0x0000000000200b90 0x0000000000200b90 0x0001c0 0x0001c0 RW 0x8
|
|
|
9af138 |
GNU_RELRO 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x0004b8 R 0x1
|
|
|
9af138 |
|