From 4f73293264a46b8bd15c49ed86044b57f2531d8e Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Feb 03 2017 00:59:47 +0000 Subject: Fix PR ld/20995 for cris-linux * elf32-cris.c (elf_cris_finish_dynamic_symbol): Remove now unused local variable dynobj. PR ld/20995 * elf32-cris.c (elf_cris_size_dynamic_sections): Handle sdynrelro. (elf_cris_adjust_dynamic_symbol): Place variables copied into the executable from read-only sections into sdynrelro. (elf_cris_finish_dynamic_symbol): Select sreldynrelro for dynamic relocs in sdynrelro. (elf_backend_want_dynrelro): Define. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8ff43e1..e99e8ac 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,16 @@ +2017-02-02 Hans-Peter Nilsson + + * elf32-cris.c (elf_cris_finish_dynamic_symbol): Remove now unused + local variable dynobj. + + PR ld/20995 + * elf32-cris.c (elf_cris_size_dynamic_sections): Handle sdynrelro. + (elf_cris_adjust_dynamic_symbol): Place variables copied into the + executable from read-only sections into sdynrelro. + (elf_cris_finish_dynamic_symbol): Select sreldynrelro for + dynamic relocs in sdynrelro. + (elf_backend_want_dynrelro): Define. + 2017-01-30 Maciej W. Rozycki * elfxx-mips.h (_bfd_mips_elf_insn32): Rename prototype to... diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index ba4e494..a69c7e4 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -2057,7 +2057,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd, Elf_Internal_Sym *sym) { struct elf_cris_link_hash_table * htab; - bfd *dynobj; /* Where in the plt entry to put values. */ int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16; @@ -2089,8 +2088,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd, plt_pic_entry = elf_cris_pic_plt_entry_v32; } - dynobj = htab->root.dynobj; - if (h->plt.offset != (bfd_vma) -1) { asection *splt; @@ -2278,8 +2275,10 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd, && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)); - s = bfd_get_linker_section (dynobj, ".rela.bss"); - BFD_ASSERT (s != NULL); + if ((h->root.u.def.section->flags & SEC_READONLY) != 0) + s = htab->root.sreldynrelro; + else + s = htab->root.srelbss; rela.r_offset = (h->root.u.def.value + h->root.u.def.section->output_section->vma @@ -2840,6 +2839,7 @@ elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info, struct elf_cris_link_hash_table * htab; bfd *dynobj; asection *s; + asection *srel; bfd_size_type plt_entry_size; htab = elf_cris_hash_table (info); @@ -3027,23 +3027,30 @@ elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info, both the dynamic object and the regular object will refer to the same memory location for the variable. */ - s = bfd_get_linker_section (dynobj, ".dynbss"); - BFD_ASSERT (s != NULL); - /* We must generate a R_CRIS_COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the runtime process image. We need to remember the offset into the .rela.bss section we are going to use. */ + + if ((h->root.u.def.section->flags & SEC_READONLY) != 0) + { + s = htab->root.sdynrelro; + srel = htab->root.sreldynrelro; + } + else + { + s = htab->root.sdynbss; + srel = htab->root.srelbss; + } if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) { - asection *srel; - - srel = bfd_get_linker_section (dynobj, ".rela.bss"); BFD_ASSERT (srel != NULL); srel->size += sizeof (Elf32_External_Rela); h->needs_copy = 1; } + BFD_ASSERT (s != NULL); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } @@ -3787,7 +3794,8 @@ elf_cris_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, } } else if (! CONST_STRNEQ (name, ".got") - && strcmp (name, ".dynbss") != 0) + && strcmp (name, ".dynbss") != 0 + && s != htab->root.sdynrelro) { /* It's not one of our sections, so don't allocate space. */ continue; @@ -4325,6 +4333,7 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED, #define elf_backend_got_header_size 12 #define elf_backend_got_elt_size elf_cris_got_elt_size #define elf_backend_dtrel_excludes_plt 1 +#define elf_backend_want_dynrelro 1 /* Later, we my want to optimize RELA entries into REL entries for dynamic linking and libraries (if it's a win of any significance). Until then,