aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2014-01-10 21:11:46 +1030
committerAlan Modra <amodra@gmail.com>2014-01-10 21:49:56 +1030
commiteec2f3ed9f053653ed5d629eb50e08e3ee61e9bd (patch)
tree2a12dda58d04db24d58892f45db6eab16240bb00 /ld
parenta2cd8cfed14491303eb8338f90e206034c5a3fe2 (diff)
downloadgdb-eec2f3ed9f053653ed5d629eb50e08e3ee61e9bd.zip
gdb-eec2f3ed9f053653ed5d629eb50e08e3ee61e9bd.tar.gz
gdb-eec2f3ed9f053653ed5d629eb50e08e3ee61e9bd.tar.bz2
Don't adjust LOAD segment to match GNU_RELRO segment
Instead, fix Jakub's original code setting up the PR_GNU_RELRO header from the PT_LOAD header. PR ld/14207 PR ld/16322 PR binutils/16323 bfd/ * elf.c (assign_file_positions_for_load_sections): Revert last change. (assign_file_positions_for_non_load_sections): When setting up PT_GNU_RELRO header, don't require a corresponding PT_LOAD header that completely covers the relro region. ld/ * ldlang.c (lang_size_sections): Remove unneeded RELRO base adjust. Tidy comments. * ld.texinfo (DATA_SEGMENT_RELRO_END): Correct description. ld/testsuite/ * ld-x86-64/pr14207.d: Adjust
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog9
-rw-r--r--ld/ld.texinfo6
-rw-r--r--ld/ldlang.c21
-rw-r--r--ld/testsuite/ChangeLog4
-rw-r--r--ld/testsuite/ld-x86-64/pr14207.d2
5 files changed, 27 insertions, 15 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 41996a5..2b7a573 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2014-01-10 Alan Modra <amodra@gmail.com>
+
+ PR ld/14207
+ PR ld/16322
+ PR binutils/16323
+ * ldlang.c (lang_size_sections): Remove unneeded RELRO base
+ adjust. Tidy comments.
+ * ld.texinfo (DATA_SEGMENT_RELRO_END): Correct description.
+
2014-01-10 Hans-Peter Nilsson <hp@axis.com>
* emulparams/crislinux.sh (COMMONPAGESIZE): Define.
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 398dd594..ae3d568 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -5916,13 +5916,15 @@ evaluation purposes.
@item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
@kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
This defines the end of the @code{PT_GNU_RELRO} segment when
-@samp{-z relro} option is used. Second argument is returned.
+@samp{-z relro} option is used.
When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
@var{exp} + @var{offset} is aligned to the most commonly used page
boundary for particular target. If present in the linker script,
it must always come in between @code{DATA_SEGMENT_ALIGN} and
-@code{DATA_SEGMENT_END}.
+@code{DATA_SEGMENT_END}. Evaluates to the second argument plus any
+padding needed at the end of the @code{PT_GNU_RELRO} segment due to
+section alignment.
@smallexample
. = DATA_SEGMENT_RELRO_END(24, .);
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 7851615..c5e7a3d 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5362,18 +5362,14 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
&& link_info.relro && expld.dataseg.relro_end)
{
/* If DATA_SEGMENT_ALIGN DATA_SEGMENT_RELRO_END pair was seen, try
- to put expld.dataseg.relro on a (common) page boundary. */
- bfd_vma min_base, old_base, relro_end, maxpage;
+ to put expld.dataseg.relro_end on a (common) page boundary. */
+ bfd_vma min_base, relro_end, maxpage;
expld.dataseg.phase = exp_dataseg_relro_adjust;
maxpage = expld.dataseg.maxpagesize;
/* MIN_BASE is the absolute minimum address we are allowed to start the
read-write segment (byte before will be mapped read-only). */
min_base = (expld.dataseg.min_base + maxpage - 1) & ~(maxpage - 1);
- /* OLD_BASE is the address for a feasible minimum address which will
- still not cause a data overlap inside MAXPAGE causing file offset skip
- by MAXPAGE. */
- old_base = expld.dataseg.base;
expld.dataseg.base += (-expld.dataseg.relro_end
& (expld.dataseg.pagesize - 1));
/* Compute the expected PT_GNU_RELRO segment end. */
@@ -5389,9 +5385,9 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
if (expld.dataseg.relro_end > relro_end)
{
/* The alignment of sections between DATA_SEGMENT_ALIGN
- and DATA_SEGMENT_RELRO_END caused huge padding to be
- inserted at DATA_SEGMENT_RELRO_END. Try to start a bit lower so
- that the section alignments will fit in. */
+ and DATA_SEGMENT_RELRO_END can cause excessive padding to
+ be inserted at DATA_SEGMENT_RELRO_END. Try to start a
+ bit lower so that the section alignments will fit in. */
asection *sec;
unsigned int max_alignment_power = 0;
@@ -5405,9 +5401,10 @@ lang_size_sections (bfd_boolean *relax, bfd_boolean check_regions)
if (((bfd_vma) 1 << max_alignment_power) < expld.dataseg.pagesize)
{
- if (expld.dataseg.base - (1 << max_alignment_power) < old_base)
- expld.dataseg.base += expld.dataseg.pagesize;
- /* Properly align base to max_alignment_power. */
+ /* Aligning the adjusted base guarantees the padding
+ between sections won't change. This is better than
+ simply subtracting 1 << max_alignment_power which is
+ what we used to do here. */
expld.dataseg.base &= ~((1 << max_alignment_power) - 1);
lang_reset_memory_regions ();
one_lang_size_sections_pass (relax, check_regions);
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index da8ce89..756e7ae 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2014-01-10 Alan Modra <amodra@gmail.com>
+
+ * ld-x86-64/pr14207.d: Adjust.
+
2014-01-09 H.J. Lu <hongjiu.lu@intel.com>
* ld-elf/binutils.exp (binutils_test): Check if GNU_RELRO segment
diff --git a/ld/testsuite/ld-x86-64/pr14207.d b/ld/testsuite/ld-x86-64/pr14207.d
index b1e2d5a..d4e22a1 100644
--- a/ld/testsuite/ld-x86-64/pr14207.d
+++ b/ld/testsuite/ld-x86-64/pr14207.d
@@ -11,7 +11,7 @@ There are 4 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001e0 0x0001e0 R 0x200000
- LOAD 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x000cf8 RW 0x200000
+ LOAD 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b0 0x000cf8 RW 0x200000
DYNAMIC 0x000b90 0x0000000000200b90 0x0000000000200b90 0x0001c0 0x0001c0 RW 0x8
GNU_RELRO 0x000b48 0x0000000000200b48 0x0000000000200b48 0x0004b8 0x0004b8 R 0x1