aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-02-05 20:06:52 +1030
committerAlan Modra <amodra@gmail.com>2022-02-07 13:42:41 +1030
commit6a9d08661b361e497baa76dd6d8685f2cb593adb (patch)
tree94483fd58d6262edc6d61f7da0c165843af80f4c /ld/ldlang.c
parent5197c88e2a8a17f7a67ce683df068b5bdf619427 (diff)
downloadgdb-6a9d08661b361e497baa76dd6d8685f2cb593adb.zip
gdb-6a9d08661b361e497baa76dd6d8685f2cb593adb.tar.gz
gdb-6a9d08661b361e497baa76dd6d8685f2cb593adb.tar.bz2
Revert "elf: Remove the 1-page gap before the RELRO segment"
This reverts commit 2f83249c13d86065b4c7cdb198ea871017b4bba1. PR ld/28743 * ldlang.c (lang_size_relro_segment_1): Revert 2022-01-10 changes. * testsuite/ld-i386/pr20830.d: Likewise. * testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise. * testsuite/ld-x86-64/pr14207.d: Likewise. * testsuite/ld-x86-64/pr18176.d: Likewise. * testsuite/ld-x86-64/pr20830a-now.d: Likewise. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b-now.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a-now.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c89
1 files changed, 18 insertions, 71 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index cf13932..84511c4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -6371,9 +6371,7 @@ static bfd_vma
lang_size_relro_segment_1 (seg_align_type *seg)
{
bfd_vma relro_end, desired_end;
- asection *sec, *prev_sec = NULL;
- bool remove_page_gap = false;
- unsigned int max_alignment_power = 0;
+ asection *sec;
/* Compute the expected PT_GNU_RELRO/PT_LOAD segment end. */
relro_end = ((seg->relro_end + seg->pagesize - 1)
@@ -6384,79 +6382,28 @@ lang_size_relro_segment_1 (seg_align_type *seg)
/* For sections in the relro segment.. */
for (sec = link_info.output_bfd->section_last; sec; sec = sec->prev)
- if ((sec->flags & SEC_ALLOC) != 0)
+ if ((sec->flags & SEC_ALLOC) != 0
+ && sec->vma >= seg->base
+ && sec->vma < seg->relro_end - seg->relro_offset)
{
- if (sec->alignment_power > max_alignment_power)
- max_alignment_power = sec->alignment_power;
-
- if (sec->vma >= seg->base
- && sec->vma < seg->relro_end - seg->relro_offset)
- {
- /* Where do we want to put this section so that it ends as
- desired? */
- bfd_vma start, end, bump;
-
- end = start = sec->vma;
- if (!IS_TBSS (sec))
- end += TO_ADDR (sec->size);
- bump = desired_end - end;
- /* We'd like to increase START by BUMP, but we must heed
- alignment so the increase might be less than optimum. */
- start += bump;
- start &= ~(((bfd_vma) 1 << sec->alignment_power) - 1);
- /* This is now the desired end for the previous section. */
- desired_end = start;
- prev_sec = sec->prev;
- }
+ /* Where do we want to put this section so that it ends as
+ desired? */
+ bfd_vma start, end, bump;
+
+ end = start = sec->vma;
+ if (!IS_TBSS (sec))
+ end += TO_ADDR (sec->size);
+ bump = desired_end - end;
+ /* We'd like to increase START by BUMP, but we must heed
+ alignment so the increase might be less than optimum. */
+ start += bump;
+ start &= ~(((bfd_vma) 1 << sec->alignment_power) - 1);
+ /* This is now the desired end for the previous section. */
+ desired_end = start;
}
seg->phase = exp_seg_relro_adjust;
ASSERT (desired_end >= seg->base);
-
- for (; prev_sec; prev_sec = prev_sec->prev)
- if ((prev_sec->flags & SEC_ALLOC) != 0)
- {
- if (prev_sec->alignment_power > max_alignment_power)
- max_alignment_power = prev_sec->alignment_power;
-
- if (prev_sec->size != 0)
- {
- /* The 1-page gap before the RELRO segment may be removed. */
- remove_page_gap = ((prev_sec->vma + prev_sec->size
- + seg->maxpagesize) < desired_end);
-
- break;
- }
- }
-
- if (remove_page_gap)
- {
- /* Find the maximum section alignment. */
- for (sec = prev_sec; sec; sec = sec->prev)
- if ((sec->flags & SEC_ALLOC) != 0
- && sec->alignment_power > max_alignment_power)
- max_alignment_power = sec->alignment_power;
-
- /* Remove the 1-page gap before the RELRO segment only if the
- maximum page size >= the maximum section alignment. */
- if (seg->maxpagesize >= (1U << max_alignment_power))
- {
- /* If the preceding section size is greater than the maximum
- page size, subtract the maximum page size. Otherwise,
- align the RELRO segment to the maximum page size. */
- if (prev_sec->size > seg->maxpagesize)
- {
- desired_end -= seg->maxpagesize;
- relro_end -= seg->maxpagesize;
- }
- else
- {
- desired_end &= ~(seg->maxpagesize - 1);
- relro_end &= ~(seg->maxpagesize - 1);
- }
- }
- }
-
seg->base = desired_end;
return relro_end;
}