Don't make dynamic .data.rel.ro SEC_READONLY
authorAlan Modra <amodra@gmail.com>
Mon, 27 Feb 2017 21:36:02 +0000 (08:06 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 28 Feb 2017 01:29:47 +0000 (11:59 +1030)
I'd made this dynamic section read-only so a flag test distinguished
it from .dynbss, but like any other .data.rel.ro section it really
should be marked read-write.  (It is read-only after relocation, not
before.)  When using the standard linker scripts this usually doesn't
matter since the output section is among other read-write sections and
not page aligned.  However, it might matter in the extraordinary case
of the dynamic section being the only .data.rel.ro section with the
output section just happening to be page aligned and a multiple of a
page in size.  In that case the output section would be read-only, and
live it its own read-only PT_LOAD segment, which is incorrect.

* elflink.c (_bfd_elf_create_dynamic_sections): Don't make
dynamic .data.rel.ro read-only.
* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Compare section
rather than section flags when deciding where copy reloc goes.
* elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Likewise.
* elf32-metag.c (elf_metag_finish_dynamic_symbol): Likewise.
* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Likewise.
* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol): Likewise.
* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Likewise.
* elf32-ppc.c (ppc_elf_finish_dynamic_symbol): Likewise.
* elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
* elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
* elf64-ppc.c (ppc64_elf_finish_dynamic_symbol): Likewise.
* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Likewise.
* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Likewise.
* elfxx-mips.c (_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
* elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.

22 files changed:
bfd/ChangeLog
bfd/elf32-arm.c
bfd/elf32-cris.c
bfd/elf32-hppa.c
bfd/elf32-i386.c
bfd/elf32-metag.c
bfd/elf32-microblaze.c
bfd/elf32-nios2.c
bfd/elf32-or1k.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-tic6x.c
bfd/elf32-tilepro.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elfnn-aarch64.c
bfd/elfnn-riscv.c
bfd/elfxx-mips.c
bfd/elfxx-sparc.c
bfd/elfxx-tilegx.c

index 652c074f7316c427dc23288cef717f40c413d23e..29166e749b279fc07ad600909e51d54bed758697 100644 (file)
@@ -1,3 +1,29 @@
+2017-02-28  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (_bfd_elf_create_dynamic_sections): Don't make
+       dynamic .data.rel.ro read-only.
+       * elf32-arm.c (elf32_arm_finish_dynamic_symbol): Compare section
+       rather than section flags when deciding where copy reloc goes.
+       * elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
+       * elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
+       * elf32-i386.c (elf_i386_finish_dynamic_symbol): Likewise.
+       * elf32-metag.c (elf_metag_finish_dynamic_symbol): Likewise.
+       * elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Likewise.
+       * elf32-nios2.c (nios2_elf32_finish_dynamic_symbol): Likewise.
+       * elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Likewise.
+       * elf32-ppc.c (ppc_elf_finish_dynamic_symbol): Likewise.
+       * elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
+       * elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
+       * elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
+       * elf64-ppc.c (ppc64_elf_finish_dynamic_symbol): Likewise.
+       * elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
+       * elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
+       * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Likewise.
+       * elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Likewise.
+       * elfxx-mips.c (_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
+       * elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
+       * elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.
+
 2017-02-28  Maciej W. Rozycki  <macro@imgtec.com>
 
        * elfxx-mips.c (mips_elf_perform_relocation): Also handle the
index 8171b0bd9a5ea6f27369f80d1ccf0c61957497c0..0a785951dcaeb42ad82e07dfa2ceac324a9dda1c 100644 (file)
@@ -16311,7 +16311,7 @@ elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
                      + h->root.u.def.section->output_section->vma
                      + h->root.u.def.section->output_offset);
       rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        s = htab->root.sreldynrelro;
       else
        s = htab->root.srelbss;
index a69c7e48767b87c69ea7a148b29f851447a99f7a..97b8cc3eb85c4c983d16fbaef68478c6deba2a97 100644 (file)
@@ -2275,7 +2275,7 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
                  && (h->root.type == bfd_link_hash_defined
                      || h->root.type == bfd_link_hash_defweak));
 
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        s = htab->root.sreldynrelro;
       else
        s = htab->root.srelbss;
index d5b911cf6a18bc85a7c79df8c87b3e07dddef7e2..1deebf4f038ee595757be714e2429331620300a2 100644 (file)
@@ -4432,7 +4432,7 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
                      + eh->root.u.def.section->output_section->vma);
       rela.r_addend = 0;
       rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_COPY);
-      if ((eh->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (eh->root.u.def.section == htab->etab.sdynrelro)
        sec = htab->etab.sreldynrelro;
       else
        sec = htab->etab.srelbss;
index e6e70d8fba9c190a82e70f75fce8f3edf6354460..2784ef71cbe323a9de9625553c7d9996312e6303 100644 (file)
@@ -5666,7 +5666,7 @@ do_glob_dat:
                      + h->root.u.def.section->output_section->vma
                      + h->root.u.def.section->output_offset);
       rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 40a2bafa2cf93bde96fd68cb064b7dd43943817d..c45d719269e12954875a480bb10007a6780264e6 100644 (file)
@@ -3229,7 +3229,7 @@ elf_metag_finish_dynamic_symbol (bfd *output_bfd,
                      + eh->root.u.def.section->output_section->vma);
       rel.r_addend = 0;
       rel.r_info = ELF32_R_INFO (eh->dynindx, R_METAG_COPY);
-      if ((eh->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (eh->root.u.def.section == htab->etab.sdynrelro)
        s = htab->etab.sreldynrelro;
       else
        s = htab->etab.srelbss;
index 27118c1ef070a76114b7c37dfc98836baf625cca..325a0d64c36ec9197596879f47374df298eacba4 100644 (file)
@@ -3277,7 +3277,7 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
                        + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_MICROBLAZE_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 3e4706f35f09aac50bfac1d7ee6be4d01809de4e..d07ef67a85e17d55e398f4af5dd3c2526b975217 100644 (file)
@@ -5280,7 +5280,7 @@ nios2_elf32_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_NIOS2_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        s = htab->root.sreldynrelro;
       else
        s = htab->root.srelbss;
index 8e0ef727b0f1e72949a79fabdb3bc04a66138753..224cbb892c1170a5be1bac3b8170e3a5fb48e8da 100644 (file)
@@ -1949,7 +1949,7 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
                        + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        s = htab->root.sreldynrelro;
       else
        s = htab->root.srelbss;
index e71757eab0ff2f533cecf5528c501e9b3b04fcd6..834ef67d00ea2014ec56ec023aa279e7f0bcda27 100644 (file)
@@ -10355,7 +10355,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
 
       if (ppc_elf_hash_entry (h)->has_sda_refs)
        s = htab->relsbss;
-      else if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      else if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index e5cb3b4d595d150ecbddf513f1ca0d88bf1e9f6f..fd1bc13d5c09383984731da0bcb28282e1ac8024 100644 (file)
@@ -3827,7 +3827,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 08361d96fc1d4468d1eeec3728e7c0fcd7f33f43..f65e24f44b38c47c0ad2874d707017879af48c41 100644 (file)
@@ -1876,7 +1876,7 @@ elf32_tic6x_finish_dynamic_symbol (bfd * output_bfd,
                      + h->root.u.def.section->output_offset);
       rel.r_info = ELF32_R_INFO (h->dynindx, R_C6000_COPY);
       rel.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 660b112abe13b53684cbbb567c78c570b330572d..fb06a477396f8a065743bf4f4326d6170f455d99 100644 (file)
@@ -3813,7 +3813,7 @@ tilepro_elf_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 4d90e0a1a6a130ec0397a5292a0f64704415bceb..7b8bacf391c61ab0c1fb363ee129a74793a248a9 100644 (file)
@@ -15477,7 +15477,7 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        srel = htab->elf.sreldynrelro;
       else
        srel = htab->elf.srelbss;
index edc9b861ea54a505f82146adcd8ec853457beb72..b5fd05f2630e53b67e3a32bfdb25f67a9b13539d 100644 (file)
@@ -3623,7 +3623,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index a058eca3abf03cc2f79601d170b2d6b9f9c459e5..e0e6c16fcd32b077228851597d087b98d053d9f0 100644 (file)
@@ -6189,7 +6189,7 @@ do_glob_dat:
                       + h->root.u.def.section->output_offset);
       rela.r_info = htab->r_info (h->dynindx, R_X86_64_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 027ce83ce1f4b40b6c225def377cd19058298719..776357fe68521ba11a7f443f48e3b93409ae2dc4 100644 (file)
@@ -424,7 +424,7 @@ _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
         initialize them at run time.  The linker script puts the .dynbss
         section into the .bss section of the final image.  */
       s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
-                                             (SEC_ALLOC | SEC_LINKER_CREATED));
+                                             SEC_ALLOC | SEC_LINKER_CREATED);
       if (s == NULL)
        return FALSE;
       htab->sdynbss = s;
@@ -432,11 +432,10 @@ _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
       if (bed->want_dynrelro)
        {
          /* Similarly, but for symbols that were originally in read-only
-            sections.  */
+            sections.  This section doesn't really need to have contents,
+            but make it like other .data.rel.ro sections.  */
          s = bfd_make_section_anyway_with_flags (abfd, ".data.rel.ro",
-                                                 (SEC_ALLOC | SEC_READONLY
-                                                  | SEC_HAS_CONTENTS
-                                                  | SEC_LINKER_CREATED));
+                                                 flags);
          if (s == NULL)
            return FALSE;
          htab->sdynrelro = s;
index c86a3e16ee07c3febae91e24801451ba2f8b82fb..dfba7f753f6db0065cbbb691666bb0a936a85f59 100644 (file)
@@ -8988,7 +8988,7 @@ do_glob_dat:
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        s = htab->root.sreldynrelro;
       else
        s = htab->root.srelbss;
index 2ccfc5f08fba79e62b10e6fbe934ee311f66e6c6..e476bb150bc81fb064d9630504acf93ab6216fa1 100644 (file)
@@ -2412,7 +2412,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
       rela.r_offset = sec_addr (h->root.u.def.section) + h->root.u.def.value;
       rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index 7a1d5f848bbbd15748b3a6de17d31b97a04188cd..901ddc15f497a975409cc4261dfd17c383c72c60 100644 (file)
@@ -11173,7 +11173,7 @@ _bfd_mips_vxworks_finish_dynamic_symbol (bfd *output_bfd,
                      + h->root.u.def.value);
       rel.r_info = ELF32_R_INFO (h->dynindx, R_MIPS_COPY);
       rel.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->root.sdynrelro)
        srel = htab->root.sreldynrelro;
       else
        srel = htab->root.srelbss;
index f66525e11ffd5e5270283d2f3ab5f3a5e6a4c7fc..80fda1b0e04ff80c3c0206e624d58120e25ab817 100644 (file)
@@ -4568,7 +4568,7 @@ _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
                       + h->root.u.def.section->output_offset);
       rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
index eb12695d027f7c2e29a037704fd247ff61988f44..76dfcd81499318c3fe23b170c76c2c4b25eb3d2c 100644 (file)
@@ -4198,7 +4198,7 @@ tilegx_elf_finish_dynamic_symbol (bfd *output_bfd,
       /* This symbols needs a copy reloc.  Set it up.  */
       BFD_ASSERT (h->dynindx != -1);
 
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;