From c9df6640d5082e4605fb1205bd2b40653a642d8b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 17 Aug 2006 02:04:53 +0000 Subject: [PATCH] bfd/ 2006-08-16 H.J. Lu PR ld/3015 * elf.c (get_program_header_size): Add a PT_GNU_RELRO segment only if there is a PT_DYNAMIC segment. (_bfd_elf_map_sections_to_segments): Likewise. (assign_file_positions_for_load_sections): Set PT_GNU_RELRO segment alignment to 1. ld/testsuite/ 2006-08-16 H.J. Lu PR ld/3015 * ld-elf/binutils.exp: Add tests for "-z relro". --- bfd/ChangeLog | 9 +++++++++ bfd/elf.c | 25 +++++++++++++++---------- ld/testsuite/ChangeLog | 5 +++++ ld/testsuite/ld-elf/binutils.exp | 5 +++++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index a5a0df1..283ae24 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2006-08-16 H.J. Lu + + PR ld/3015 + * elf.c (get_program_header_size): Add a PT_GNU_RELRO segment + only if there is a PT_DYNAMIC segment. + (_bfd_elf_map_sections_to_segments): Likewise. + (assign_file_positions_for_load_sections): Set PT_GNU_RELRO + segment alignment to 1. + 2006-08-15 Thiemo Seufer Nigel Stephens diff --git a/bfd/elf.c b/bfd/elf.c index 1db6239..8dd94e3 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -3622,6 +3622,13 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info) { /* We need a PT_DYNAMIC segment. */ ++segs; + + if (elf_tdata (abfd)->relro) + { + /* We need a PT_GNU_RELRO segment only when there is a + PT_DYNAMIC segment. */ + ++segs; + } } if (elf_tdata (abfd)->eh_frame_hdr) @@ -3636,12 +3643,6 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info) ++segs; } - if (elf_tdata (abfd)->relro) - { - /* We need a PT_GNU_RELRO segment. */ - ++segs; - } - for (s = abfd->sections; s != NULL; s = s->next) { if ((s->flags & SEC_LOAD) != 0 @@ -4110,8 +4111,10 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) pm = &m->next; } - if (elf_tdata (abfd)->relro) + if (dynsec != NULL && elf_tdata (abfd)->relro) { + /* We make a PT_GNU_RELRO segment only when there is a + PT_DYNAMIC segment. */ amt = sizeof (struct elf_segment_map); m = bfd_zalloc (abfd, amt); if (m == NULL) @@ -4591,9 +4594,11 @@ assign_file_positions_for_load_sections (bfd *abfd, p->p_memsz += o->offset + o->size; } - if (align > p->p_align - && (p->p_type != PT_LOAD - || (abfd->flags & D_PAGED) == 0)) + if (p->p_type == PT_GNU_RELRO) + p->p_align = 1; + else if (align > p->p_align + && (p->p_type != PT_LOAD + || (abfd->flags & D_PAGED) == 0)) p->p_align = align; } diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index f07e2ca..3e25f61 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-08-16 H.J. Lu + + PR ld/3015 + * ld-elf/binutils.exp: Add tests for "-z relro". + 2006-08-16 Alan Modra * ld-scripts/overlay-size-map.d: Update. diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp index aa59b69..7ced42c 100644 --- a/ld/testsuite/ld-elf/binutils.exp +++ b/ld/testsuite/ld-elf/binutils.exp @@ -101,6 +101,11 @@ binutils_test strip "-shared" maxpage1 binutils_test objcopy "" maxpage1 binutils_test objcopy "-shared" maxpage1 +binutils_test strip "-z relro" maxpage1 +binutils_test strip "-z relro -shared" maxpage1 +binutils_test objcopy "-z relro" maxpage1 +binutils_test objcopy "-z relro -shared" maxpage1 + binutils_test objcopy "" tbss1 binutils_test objcopy "-shared" tbss1 binutils_test objcopy "-z max-page-size=0x100000" tbss1 -- 2.7.4