aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2016-12-28 17:04:15 +1030
committerAlan Modra <amodra@gmail.com>2016-12-28 22:10:38 +1030
commit9acc85a62eb76c270724bba15c889d2d05567b6a (patch)
tree2f98cec208e57b60f245c4eac6bb4b71274d73e8 /bfd/elflink.c
parentb733bcb7f58c42e0e0d94a3f266a4193030e5f3a (diff)
downloadgdb-9acc85a62eb76c270724bba15c889d2d05567b6a.zip
gdb-9acc85a62eb76c270724bba15c889d2d05567b6a.tar.gz
gdb-9acc85a62eb76c270724bba15c889d2d05567b6a.tar.bz2
Use dynrelro for symbols in relro sections too
PR ld/20995 bfd/ * elflink.c (elf_link_add_object_symbols): Mark relro sections in dynamic objects SEC_READONLY. ld/ * testsuite/ld-elf/pr20995c.s: New test file. * testsuite/ld-elf/pr20995-2so.r: Likewise. * testsuite/ld-elf/elf.exp: Run it.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index d8d40f1..2fd8883 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3819,6 +3819,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
const char *soname = NULL;
char *audit = NULL;
struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
+ const Elf_Internal_Phdr *phdr;
int ret;
/* ld --just-symbols and dynamic objects don't mix very well.
@@ -3968,6 +3969,21 @@ error_free_dyn:
*pn = rpath;
}
+ /* If we have a PT_GNU_RELRO program header, mark as read-only
+ all sections contained fully therein. This makes relro
+ shared library sections appear as they will at run-time. */
+ phdr = elf_tdata (abfd)->phdr + elf_elfheader (abfd)->e_phnum;
+ while (--phdr >= elf_tdata (abfd)->phdr)
+ if (phdr->p_type == PT_GNU_RELRO)
+ {
+ for (s = abfd->sections; s != NULL; s = s->next)
+ if ((s->flags & SEC_ALLOC) != 0
+ && s->vma >= phdr->p_vaddr
+ && s->vma + s->size <= phdr->p_vaddr + phdr->p_memsz)
+ s->flags |= SEC_READONLY;
+ break;
+ }
+
/* We do not want to include any of the sections in a dynamic
object in the output file. We hack by simply clobbering the
list of sections in the BFD. This could be handled more