ELF: Add _bfd_elf_add_dynamic_tags
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 23 Jun 2020 12:07:31 +0000 (05:07 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 23 Jun 2020 12:07:45 +0000 (05:07 -0700)
All ELF backends with shared library support need to add dynamic tags.
Add dt_pltgot_required and dt_jmprel_required to elf_link_hash_table to
indicate that DT_PLTGOT and DT_JMPREL are required dynamic tags.

1. Add _bfd_elf_add_dynamic_tags to add common dynamic tags.
2. Add _bfd_elf_maybe_vxworks_add_dynamic_tags to add common VxWorks
dynamic tags.

* elf-bfd.h (elf_link_hash_table): Add dt_pltgot_required and
dt_jmprel_required.
(_bfd_elf_add_dynamic_tags): New.
* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Call
_bfd_elf_add_dynamic_tags.
* elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
* elf32-bfin.c (elf32_bfinfdpic_size_dynamic_sections): Likewise.
* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
* elf32-frv.c (elf32_frvfdpic_size_dynamic_sections): Likewise.
* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
* elf32-microblaze.c (microblaze_elf_size_dynamic_sections):
Likewise.
* elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
* elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections):
Likewise.
* elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
* elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
* elf32-arm.c (elf32_arm_size_dynamic_sections): Call
_bfd_elf_maybe_vxworks_add_dynamic_tags.
* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections):
Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise.
(_bfd_x86_elf_size_dynamic_sections): Likewise.
* elfxx-x86.h (elf_x86_link_hash_table): Remove dt_reloc,
dt_reloc_sz and dt_reloc_ent.
* elf-vxworks.c (_bfd_elf_maybe_vxworks_add_dynamic_tags): New.
* elf-vxworks.h (_bfd_elf_maybe_vxworks_add_dynamic_tags):
Likewise.
* elf32-hppa.c (elf32_hppa_link_hash_table_create): Set
etab.dt_pltgot_required.
(elf32_hppa_size_dynamic_sections): Call
_bfd_elf_add_dynamic_tags.
* elf32-metag.c (elf_metag_link_hash_table_create): Set
etab.dt_pltgot_required.
(elf_metag_size_dynamic_sections): Call _bfd_elf_add_dynamic_tags.
* elf32-sh.c (sh_elf_link_hash_table_create): Set
root.dt_pltgot_required for FDPIC output.
(sh_elf_size_dynamic_sections): Call
_bfd_elf_maybe_vxworks_add_dynamic_tags.
* elf32-xtensa.c (elf_xtensa_link_hash_table_create): Set
elf.dt_pltgot_required.
(elf_xtensa_size_dynamic_sections): Call
_bfd_elf_add_dynamic_tags.
* elf64-hppa.c (elf64_hppa_hash_table_create): Set
root.dt_pltgot_required.
(elf64_hppa_size_dynamic_sections): Call
_bfd_elf_add_dynamic_tags.
* elfnn-ia64.c (elfNN_ia64_hash_table_create): Set
root.dt_pltgot_required.
(elfNN_ia64_size_dynamic_sections): Set root.dt_jmprel_required
for rel_pltoff_sec.  Call _bfd_elf_add_dynamic_tags.
* elflink.c (_bfd_elf_add_dynamic_tags): New.

36 files changed:
bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf-m10300.c
bfd/elf-vxworks.c
bfd/elf-vxworks.h
bfd/elf32-arc.c
bfd/elf32-arm.c
bfd/elf32-bfin.c
bfd/elf32-cr16.c
bfd/elf32-frv.c
bfd/elf32-hppa.c
bfd/elf32-lm32.c
bfd/elf32-m32r.c
bfd/elf32-m68k.c
bfd/elf32-metag.c
bfd/elf32-microblaze.c
bfd/elf32-nds32.c
bfd/elf32-nios2.c
bfd/elf32-or1k.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sh.c
bfd/elf32-tilepro.c
bfd/elf32-vax.c
bfd/elf32-xtensa.c
bfd/elf64-alpha.c
bfd/elf64-hppa.c
bfd/elf64-s390.c
bfd/elflink.c
bfd/elfnn-aarch64.c
bfd/elfnn-ia64.c
bfd/elfnn-riscv.c
bfd/elfxx-sparc.c
bfd/elfxx-tilegx.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index f14967791339ef03ae528b7d8af281a4510ee31b..5d1075e743d34cc462bebd7e889806e8492fce06 100644 (file)
@@ -1,3 +1,68 @@
+2020-06-23  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf-bfd.h (elf_link_hash_table): Add dt_pltgot_required and
+       dt_jmprel_required.
+       (_bfd_elf_add_dynamic_tags): New.
+       * elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Call
+       _bfd_elf_add_dynamic_tags.
+       * elf32-arc.c (elf_arc_size_dynamic_sections): Likewise.
+       * elf32-bfin.c (elf32_bfinfdpic_size_dynamic_sections): Likewise.
+       * elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
+       * elf32-frv.c (elf32_frvfdpic_size_dynamic_sections): Likewise.
+       * elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
+       * elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
+       * elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
+       * elf32-microblaze.c (microblaze_elf_size_dynamic_sections):
+       Likewise.
+       * elf32-nds32.c (nds32_elf_size_dynamic_sections): Likewise.
+       * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
+       * elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
+       * elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
+       * elf32-tilepro.c (tilepro_elf_size_dynamic_sections): Likewise.
+       * elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
+       * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
+       * elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
+       * elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections):
+       Likewise.
+       * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Likewise.
+       * elfxx-tilegx.c (tilegx_elf_size_dynamic_sections): Likewise.
+       * elf32-arm.c (elf32_arm_size_dynamic_sections): Call
+       _bfd_elf_maybe_vxworks_add_dynamic_tags.
+       * elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
+       * elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections):
+       Likewise.
+       * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise.
+       (_bfd_x86_elf_size_dynamic_sections): Likewise.
+       * elfxx-x86.h (elf_x86_link_hash_table): Remove dt_reloc,
+       dt_reloc_sz and dt_reloc_ent.
+       * elf-vxworks.c (_bfd_elf_maybe_vxworks_add_dynamic_tags): New.
+       * elf-vxworks.h (_bfd_elf_maybe_vxworks_add_dynamic_tags):
+       Likewise.
+       * elf32-hppa.c (elf32_hppa_link_hash_table_create): Set
+       etab.dt_pltgot_required.
+       (elf32_hppa_size_dynamic_sections): Call
+       _bfd_elf_add_dynamic_tags.
+       * elf32-metag.c (elf_metag_link_hash_table_create): Set
+       etab.dt_pltgot_required.
+       (elf_metag_size_dynamic_sections): Call _bfd_elf_add_dynamic_tags.
+       * elf32-sh.c (sh_elf_link_hash_table_create): Set
+       root.dt_pltgot_required for FDPIC output.
+       (sh_elf_size_dynamic_sections): Call
+       _bfd_elf_maybe_vxworks_add_dynamic_tags.
+       * elf32-xtensa.c (elf_xtensa_link_hash_table_create): Set
+       elf.dt_pltgot_required.
+       (elf_xtensa_size_dynamic_sections): Call
+       _bfd_elf_add_dynamic_tags.
+       * elf64-hppa.c (elf64_hppa_hash_table_create): Set
+       root.dt_pltgot_required.
+       (elf64_hppa_size_dynamic_sections): Call
+       _bfd_elf_add_dynamic_tags.
+       * elfnn-ia64.c (elfNN_ia64_hash_table_create): Set
+       root.dt_pltgot_required.
+       (elfNN_ia64_size_dynamic_sections): Set root.dt_jmprel_required
+       for rel_pltoff_sec.  Call _bfd_elf_add_dynamic_tags.
+       * elflink.c (_bfd_elf_add_dynamic_tags): New.
+
 2020-06-22  Saagar Jha  <saagar@saagarjha.com>
 
        * mach-o.c: Support the new load commands by reading a linkedit
index 242750fa581b3163f54efec9c1b81b3dad368171..1576724511d2f1cffce3c241754dfa3fe129ff96 100644 (file)
@@ -573,6 +573,12 @@ struct elf_link_hash_table
   /* TRUE if there are IFUNC resolvers.  */
   bfd_boolean ifunc_resolvers;
 
+  /* TRUE if DT_PLTGOT is a required dynamic tag.  */
+  bfd_boolean dt_pltgot_required;
+
+  /* TRUE if DT_JMPREL is a required dynamic tag.  */
+  bfd_boolean dt_jmprel_required;
+
   /* The BFD used to hold special sections created by the linker.
      This will be the first BFD found which requires these sections to
      be created.  */
@@ -2908,6 +2914,9 @@ extern asection *_bfd_elf_readonly_dynrelocs
 extern bfd_boolean _bfd_elf_maybe_set_textrel
   (struct elf_link_hash_entry *, void *);
 
+extern bfd_boolean _bfd_elf_add_dynamic_tags
+  (bfd *, struct bfd_link_info *, bfd_boolean);
+
 /* Large common section.  */
 extern asection _bfd_elf_large_com_section;
 
index 5a0bb9f005af556c2995971885762be40c7df8cc..1c436a78d5cb2aeb593251442d88854295763f6c 100644 (file)
@@ -5012,9 +5012,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
   struct elf32_mn10300_link_hash_table *htab = elf32_mn10300_hash_table (info);
   bfd * dynobj;
   asection * s;
-  bfd_boolean plt;
   bfd_boolean relocs;
-  bfd_boolean reltext;
 
   dynobj = htab->root.dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -5052,9 +5050,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
-  reltext = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char * name;
@@ -5069,34 +5065,16 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
       if (streq (name, ".plt"))
        {
          /* Remember whether there is a PLT.  */
-         plt = s->size != 0;
+         ;
        }
       else if (CONST_STRNEQ (name, ".rela"))
        {
          if (s->size != 0)
            {
-             asection * target;
-
              /* Remember whether there are any reloc sections other
                 than .rela.plt.  */
              if (! streq (name, ".rela.plt"))
-               {
-                 const char * outname;
-
-                 relocs = TRUE;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  The entries in the .rela.plt section
-                    really apply to the .got section, which we
-                    created ourselves and so know is not readonly.  */
-                 outname = bfd_section_name (s->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 5);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = TRUE;
-               }
+               relocs = TRUE;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -5136,45 +5114,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in _bfd_mn10300_elf_finish_dynamic_sections,
-        but we must add the entries now so that we get the correct
-        size for the .dynamic section.  The DT_DEBUG entry is filled
-        in by the dynamic linker and used by the debugger.  */
-      if (! bfd_link_pic (info))
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (plt)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
-                                             sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
-
-      if (reltext)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Finish up dynamic symbol handling.  We set the contents of various
index 0984cc83e6dc2f7aa9490024b30490a45429e006..f8a57e1a7dc7d18ed723816248d973a294afff42 100644 (file)
@@ -295,4 +295,17 @@ elf_vxworks_finish_dynamic_entry (bfd *output_bfd, Elf_Internal_Dyn *dyn)
   return TRUE;
 }
 
+/* Add dynamic tags.  */
 
+bfd_boolean
+_bfd_elf_maybe_vxworks_add_dynamic_tags (bfd *output_bfd,
+                                        struct bfd_link_info *info,
+                                        bfd_boolean need_dynamic_reloc)
+{
+  struct elf_link_hash_table *htab = elf_hash_table (info);
+  return (_bfd_elf_add_dynamic_tags (output_bfd, info,
+                                    need_dynamic_reloc)
+         && (!htab->dynamic_sections_created
+             || htab->target_os != is_vxworks
+             || elf_vxworks_add_dynamic_entries (output_bfd, info)));
+}
index 3c7a82b9457e79ae46c6b6a4c7a860c02f0cb14d..47a099fca729229258386caca7ecb27eb466a36d 100644 (file)
@@ -33,4 +33,5 @@ bfd_boolean elf_vxworks_create_dynamic_sections
   (bfd *, struct bfd_link_info *, asection **);
 bfd_boolean elf_vxworks_add_dynamic_entries (bfd *, struct bfd_link_info *);
 bfd_boolean elf_vxworks_finish_dynamic_entry (bfd *, Elf_Internal_Dyn *);
-
+bfd_boolean _bfd_elf_maybe_vxworks_add_dynamic_tags
+  (bfd *, struct bfd_link_info *, bfd_boolean);
index 06ee60ac409760286d98b6b9febf32260a9866f2..4d9d6b999285e0ded9601b265e098a88c07c4de6 100644 (file)
@@ -2707,7 +2707,6 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   bfd *dynobj;
   asection *s;
   bfd_boolean relocs_exist = FALSE;
-  bfd_boolean reltext_exist = FALSE;
   struct elf_link_hash_table *htab = elf_hash_table (info);
 
   dynobj = htab->dynobj;
@@ -2762,29 +2761,7 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       else if (strncmp (s->name, ".rela", 5) == 0)
        {
          if (s->size != 0 && s != htab->srelplt)
-           {
-             if (!reltext_exist)
-               {
-                 const char *name = s->name + 5;
-                 bfd *ibfd;
-                 for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
-                   if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour
-                       && ibfd->flags & DYNAMIC)
-                     {
-                       asection *target = bfd_get_section_by_name (ibfd, name);
-                       if (target != NULL
-                           && elf_section_data (target)->sreloc == s
-                           && ((target->output_section->flags
-                                & (SEC_READONLY | SEC_ALLOC))
-                               == (SEC_READONLY | SEC_ALLOC)))
-                         {
-                           reltext_exist = TRUE;
-                           break;
-                         }
-                     }
-               }
-             relocs_exist = TRUE;
-           }
+           relocs_exist = TRUE;
 
          /* We use the reloc_count field as a counter if we need to
             copy relocs into the output file.  */
@@ -2811,33 +2788,7 @@ elf_arc_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->dynamic_sections_created)
-    {
-      /* TODO: Check if this is needed.  */
-      if (!bfd_link_pic (info))
-       if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
-               return FALSE;
-
-      if (htab->splt && (htab->splt->flags & SEC_EXCLUDE) == 0)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-           || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
-         return FALSE;
-
-      if (relocs_exist)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
-                                           sizeof (Elf32_External_Rela)))
-         return FALSE;
-
-      if (reltext_exist)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
-         return FALSE;
-    }
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs_exist);
 }
 
 
index 35eee87a6d67dd406d752a8705d87a3c0745d3db..508f4236932ac9a5234af26563cea6246bcd448f 100644 (file)
@@ -16673,7 +16673,6 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
 {
   bfd * dynobj;
   asection * s;
-  bfd_boolean plt;
   bfd_boolean relocs;
   bfd *ibfd;
   struct elf32_arm_link_hash_table *htab;
@@ -16976,7 +16975,6 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -16992,7 +16990,7 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
       if (s == htab->root.splt)
        {
          /* Remember whether there is a PLT.  */
-         plt = s->size != 0;
+         ;
        }
       else if (CONST_STRNEQ (name, ".rel"))
        {
@@ -17044,73 +17042,8 @@ elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf32_arm_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-     if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (plt)
-       {
-         if (   !add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL,
-                                    htab->use_rel ? DT_REL : DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-
-         if (htab->root.tlsdesc_plt
-             && (!add_dynamic_entry (DT_TLSDESC_PLT,0)
-                 || !add_dynamic_entry (DT_TLSDESC_GOT,0)))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (htab->use_rel)
-           {
-             if (!add_dynamic_entry (DT_REL, 0)
-                 || !add_dynamic_entry (DT_RELSZ, 0)
-                 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
-               return FALSE;
-           }
-         else
-           {
-             if (!add_dynamic_entry (DT_RELA, 0)
-                 || !add_dynamic_entry (DT_RELASZ, 0)
-                 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
-               return FALSE;
-           }
-       }
-
-      /* If any dynamic relocs apply to a read-only section,
-        then we need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (&htab->root,
-                               _bfd_elf_maybe_set_textrel, info);
-
-      if ((info->flags & DF_TEXTREL) != 0)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-      if (htab->root.target_os == is_vxworks
-         && !elf_vxworks_add_dynamic_entries (output_bfd, info))
-       return FALSE;
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+                                                 relocs);
 }
 
 /* Size sections even though they're not dynamic.  We use it to setup
index 31ae4a68755b9757f61748458d86d477fc64ba04..eed437f8f43fbdf122e80fc6e2efa86d1a80b021 100644 (file)
@@ -4067,26 +4067,6 @@ elf32_bfinfdpic_size_dynamic_sections (bfd *output_bfd,
   if (!_bfinfdpic_size_got_plt (output_bfd, &gpinfo))
       return FALSE;
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      if (bfinfdpic_got_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
-         return FALSE;
-
-      if (bfinfdpic_pltrel_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
-           || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
-         return FALSE;
-
-      if (bfinfdpic_gotrel_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
-                                           sizeof (Elf32_External_Rel)))
-         return FALSE;
-    }
-
   s = bfd_get_linker_section (dynobj, ".dynbss");
   if (s && s->size == 0)
     s->flags |= SEC_EXCLUDE;
@@ -4095,7 +4075,7 @@ elf32_bfinfdpic_size_dynamic_sections (bfd *output_bfd,
   if (s && s->size == 0)
     s->flags |= SEC_EXCLUDE;
 
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 
 static bfd_boolean
index 62906c83a500821dcedbcf367d0338ede5e47146..8a3775efc07e80beb9a01c88870854aa2d55b16b 100644 (file)
@@ -2407,9 +2407,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
 {
   bfd * dynobj;
   asection * s;
-  bfd_boolean plt;
   bfd_boolean relocs;
-  bfd_boolean reltext;
 
   dynobj = elf_hash_table (info)->dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -2442,9 +2440,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
-  reltext = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char * name;
@@ -2459,34 +2455,16 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
       if (strcmp (name, ".plt") == 0)
        {
          /* Remember whether there is a PLT.  */
-         plt = s->size != 0;
+         ;
        }
       else if (CONST_STRNEQ (name, ".rela"))
        {
          if (s->size != 0)
            {
-             asection * target;
-
              /* Remember whether there are any reloc sections other
                 than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-               {
-                 const char * outname;
-
-                 relocs = TRUE;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  The entries in the .rela.plt section
-                    really apply to the .got section, which we
-                    created ourselves and so know is not readonly.  */
-                 outname = bfd_section_name (s->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 5);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = TRUE;
-               }
+               relocs = TRUE;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -2526,45 +2504,7 @@ _bfd_cr16_elf_size_dynamic_sections (bfd * output_bfd,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in _bfd_cr16_elf_finish_dynamic_sections,
-        but we must add the entries now so that we get the correct
-        size for the .dynamic section.  The DT_DEBUG entry is filled
-        in by the dynamic linker and used by the debugger.  */
-      if (! bfd_link_executable (info))
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (plt)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_RELA, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_RELASZ, 0)
-             || !_bfd_elf_add_dynamic_entry (info, DT_RELAENT,
-                                             sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
-
-      if (reltext)
-       {
-         if (!_bfd_elf_add_dynamic_entry (info, DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Finish up dynamic symbol handling.  We set the contents of various
index 83de5e67b5f30f10b2d8f85f156314074b84ae1b..96ed5f6bb065c9317c75449b5afb670a2c406812 100644 (file)
@@ -5466,27 +5466,7 @@ elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
   if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
     return FALSE;
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      if (frvfdpic_got_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_PLTGOT, 0))
-         return FALSE;
-
-      if (frvfdpic_pltrel_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_PLTREL, DT_REL)
-           || !_bfd_elf_add_dynamic_entry (info, DT_JMPREL, 0))
-         return FALSE;
-
-      if (frvfdpic_gotrel_section (info)->size)
-       if (!_bfd_elf_add_dynamic_entry (info, DT_REL, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELSZ, 0)
-           || !_bfd_elf_add_dynamic_entry (info, DT_RELENT,
-                                           sizeof (Elf32_External_Rel)))
-         return FALSE;
-    }
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 
 static bfd_boolean
index d131f1a0794a26a752d3aee72a8fb2719911e2b2..36582d078f946ae14f597cd0a461d15beac63e1b 100644 (file)
@@ -435,6 +435,7 @@ elf32_hppa_link_hash_table_create (bfd *abfd)
       return NULL;
     }
   htab->etab.root.hash_table_free = elf32_hppa_link_hash_table_free;
+  htab->etab.dt_pltgot_required = TRUE;
 
   htab->text_segment_base = (bfd_vma) -1;
   htab->data_segment_base = (bfd_vma) -1;
@@ -2278,60 +2279,7 @@ elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->etab.dynamic_sections_created)
-    {
-      /* Like IA-64 and HPPA64, always create a DT_PLTGOT.  It
-        actually has nothing to do with the PLT, it is how we
-        communicate the LTP value of a load module to the dynamic
-        linker.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (!add_dynamic_entry (DT_PLTGOT, 0))
-       return FALSE;
-
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf32_hppa_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->etab.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->etab,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* External entry points for sizing and building linker stubs.  */
index aba821ffd1a4245b1dee969b7db50974c776077e..2be3b9264421ff114c76a79646e67b0b6b8b35ce 100644 (file)
@@ -2060,53 +2060,8 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd,
        return FALSE;
     }
 
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in lm32_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-     if (bfd_link_executable (info))
-       {
-         if (! add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->root.splt->size != 0)
-       {
-         if (! add_dynamic_entry (DT_PLTGOT, 0)
-             || ! add_dynamic_entry (DT_PLTRELSZ, 0)
-             || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || ! add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (! add_dynamic_entry (DT_RELA, 0)
-             || ! add_dynamic_entry (DT_RELASZ, 0)
-             || ! add_dynamic_entry (DT_RELAENT,
-                                     sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (! add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
+  if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
+    return FALSE;
 
   /* Allocate .rofixup section.  */
   if (IS_FDPIC (output_bfd))
index 740be9338295f29aa8db8d10a15ce78499fbff9b..dfdf8f38c77bab13d3b7e1d232cae4dc77c9a4a7 100644 (file)
@@ -2137,55 +2137,7 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in m32r_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-     if (bfd_link_executable (info))
-       {
-         if (! add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->root.splt->size != 0)
-       {
-         if (! add_dynamic_entry (DT_PLTGOT, 0)
-             || ! add_dynamic_entry (DT_PLTRELSZ, 0)
-             || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || ! add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (! add_dynamic_entry (DT_RELA, 0)
-             || ! add_dynamic_entry (DT_RELASZ, 0)
-             || ! add_dynamic_entry (DT_RELAENT,
-                                     sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (! add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Relocate an M32R/D ELF section.
index 868435a444252e7826c139adb096160ec29a331b..39c5e1c2cc9a0fd9388a3491c29177b811642de9 100644 (file)
@@ -3052,7 +3052,6 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 {
   bfd *dynobj;
   asection *s;
-  bfd_boolean plt;
   bfd_boolean relocs;
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -3095,7 +3094,6 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -3111,7 +3109,7 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (strcmp (name, ".plt") == 0)
        {
          /* Remember whether there is a PLT.  */
-         plt = s->size != 0;
+         ;
        }
       else if (CONST_STRNEQ (name, ".rela"))
        {
@@ -3160,48 +3158,7 @@ elf_m68k_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_m68k_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (plt)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
-
-      if ((info->flags & DF_TEXTREL) != 0)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* This function is called via elf_link_hash_traverse if we are
index 7938b24d2a5fd3517b916913a5924693f2731aed..fc5f3a99d47706befebc4de800e12db6edec0995 100644 (file)
@@ -1039,6 +1039,7 @@ elf_metag_link_hash_table_create (bfd *abfd)
       return NULL;
     }
   htab->etab.root.hash_table_free = elf_metag_link_hash_table_free;
+  htab->etab.dt_pltgot_required = TRUE;
 
   return &htab->etab.root;
 }
@@ -2902,56 +2903,7 @@ elf_metag_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
     }
 
-  if (htab->etab.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_metag_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (!add_dynamic_entry (DT_PLTGOT, 0))
-       return FALSE;
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->etab.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->etab,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Finish up dynamic symbol handling.  We set the contents of various
index caf0f2edcaa2a95c20c038a9b49cec51af22007d..693fc71f73007677fabc49c33bcedc6ebec1e077 100644 (file)
@@ -3103,45 +3103,9 @@ microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in microblaze_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL)                    \
-      _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-       return FALSE;
-
-      if (htab->elf.splt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0)
-             || !add_dynamic_entry (DT_BIND_NOW, 1))
-           return FALSE;
-       }
-
-      if (info->flags & DF_TEXTREL)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-  return TRUE;
+  /* ??? Force DF_BIND_NOW?  */
+  info->flags |= DF_BIND_NOW;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 
 /* Finish up dynamic symbol handling.  We set the contents of various
index d8726359d568f9a78ab83a5d545c5b97a7153912..186ab36e89c53eb4f42e866a9860bfe822f55d6d 100644 (file)
@@ -4262,7 +4262,6 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   bfd *dynobj;
   asection *s;
   bfd_boolean relocs;
-  bfd_boolean plt;
   bfd *ibfd;
 
   htab = nds32_elf_hash_table (info);
@@ -4422,7 +4421,6 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -4433,7 +4431,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          /* Strip this section if we don't need it; see the
             comment below.  */
-         plt = s->size != 0;
+         ;
        }
       else if (s == elf_hash_table (info)->sgot)
        {
@@ -4483,64 +4481,7 @@ nds32_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in nds32_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (elf_hash_table (info)->splt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (htab->tls_desc_trampoline && plt)
-       {
-         if (htab->root.tlsdesc_plt
-             && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
-                 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel,
-                                   (void *) info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 static bfd_reloc_status_type
index cdc11f97159810584216c31ccc1695c965b8148b..01c2fe5ee54cfe65b1fdbb1b4bf9816f5249fd4c 100644 (file)
@@ -5877,52 +5877,7 @@ nios2_elf32_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   if (htab->res_n_size)
     elf_link_hash_traverse (& htab->root, adjust_dynrelocs, info);
 
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_nios2_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (!bfd_link_pic (info) && !add_dynamic_entry (DT_DEBUG, 0))
-       return FALSE;
-
-      if (htab->root.sgotplt->size != 0
-         && !add_dynamic_entry (DT_PLTGOT, 0))
-       return FALSE;
-
-      if (htab->root.splt->size != 0
-         && (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0)))
-       return FALSE;
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT,
-                                    sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0
-             && !add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-
-      if (!bfd_link_pic (info) && !add_dynamic_entry (DT_NIOS2_GP, 0))
-       return FALSE;
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Free the derived linker hash table.  */
index b25f96b42de4a20456f3c57eb8a431996583ca37..7c02d004cc7afcd1e8c932a108e706e4f0ce2fbe 100644 (file)
@@ -3078,55 +3078,7 @@ or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in or1k_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-     if (bfd_link_executable (info))
-       {
-        if (! add_dynamic_entry (DT_DEBUG, 0))
-          return FALSE;
-       }
-
-     if (htab->root.splt->size != 0)
-       {
-        if (! add_dynamic_entry (DT_PLTGOT, 0)
-            || ! add_dynamic_entry (DT_PLTRELSZ, 0)
-            || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
-            || ! add_dynamic_entry (DT_JMPREL, 0))
-          return FALSE;
-       }
-
-     if (relocs)
-       {
-        if (! add_dynamic_entry (DT_RELA, 0)
-            || ! add_dynamic_entry (DT_RELASZ, 0)
-            || ! add_dynamic_entry (DT_RELAENT,
-                                    sizeof (Elf32_External_Rela)))
-          return FALSE;
-
-        /* If any dynamic relocs apply to a read-only section,
-           then we need a DT_TEXTREL entry.  */
-        if ((info->flags & DF_TEXTREL) == 0)
-          elf_link_hash_traverse (&htab->root,
-                                  _bfd_elf_maybe_set_textrel, info);
-
-        if ((info->flags & DF_TEXTREL) != 0)
-          {
-            if (! add_dynamic_entry (DT_TEXTREL, 0))
-              return FALSE;
-          }
-       }
-    }
-
-#undef add_dynamic_entry
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
index 89c069b3c51f4a1c1f46978ff9af4f5f9e59e4c4..5155dc935f98c563f629f1cd13b7b2bce9a6357c 100644 (file)
@@ -5822,20 +5822,9 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
+      if (!_bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+                                                   relocs))
+       return FALSE;
 
       if (htab->plt_type == PLT_NEW
          && htab->glink != NULL
@@ -5849,30 +5838,6 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
              && !add_dynamic_entry (DT_PPC_OPT, PPC_OPT_TLS))
            return FALSE;
        }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
-
-      /* If any dynamic relocs apply to a read-only section, then we
-        need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (elf_hash_table (info),
-                               _bfd_elf_maybe_set_textrel,
-                               info);
-
-      if ((info->flags & DF_TEXTREL) != 0)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-      if (htab->elf.target_os == is_vxworks
-         && !elf_vxworks_add_dynamic_entries (output_bfd, info))
-       return FALSE;
    }
 #undef add_dynamic_entry
 
index 5bd63fe1c942a7aa48a1c8c514312662d684845d..ceb978791774b0300b250c28ac2dbc816e3e6da5 100644 (file)
@@ -1965,54 +1965,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->elf.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_s390_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.splt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Return the base VMA address which should be subtracted from real addresses
index 84afe44f4306beb411aa079bb216579dce80bf6b..8c74ef7c778eaf76cfde970611869bef00b0c060 100644 (file)
@@ -2255,7 +2255,11 @@ sh_elf_link_hash_table_create (bfd *abfd)
       return NULL;
     }
 
-  ret->fdpic_p = fdpic_object_p (abfd);
+  if (fdpic_object_p (abfd))
+    {
+      ret->root.dt_pltgot_required = TRUE;
+      ret->fdpic_p = TRUE;
+    }
 
   return &ret->root.root;
 }
@@ -3196,63 +3200,8 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->root.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in sh_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (! add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->root.splt->size != 0)
-       {
-         if (! add_dynamic_entry (DT_PLTGOT, 0)
-             || ! add_dynamic_entry (DT_PLTRELSZ, 0)
-             || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || ! add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-      else if ((elf_elfheader (output_bfd)->e_flags & EF_SH_FDPIC))
-       {
-         if (! add_dynamic_entry (DT_PLTGOT, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (! add_dynamic_entry (DT_RELA, 0)
-             || ! add_dynamic_entry (DT_RELASZ, 0)
-             || ! add_dynamic_entry (DT_RELAENT,
-                                     sizeof (Elf32_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (! add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-      if (htab->root.target_os == is_vxworks
-         && !elf_vxworks_add_dynamic_entries (output_bfd, info))
-       return FALSE;
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+                                                 relocs);
 }
 \f
 /* Add a dynamic relocation to the SRELOC section.  */
index 2d78f3c9c89c1ef0c0e372af28d40156f2608cab..5b3e80a5fc9865ef86a5502ca655884b589c535c 100644 (file)
@@ -2381,51 +2381,7 @@ tilepro_elf_size_dynamic_sections (bfd *output_bfd,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in tilepro_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT, TILEPRO_ELF_RELA_BYTES))
-       return FALSE;
-
-      /* If any dynamic relocs apply to a read-only section,
-        then we need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (&htab->elf,
-                               _bfd_elf_maybe_set_textrel, info);
-
-      if (info->flags & DF_TEXTREL)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 \f
 /* Return the base VMA address which should be subtracted from real addresses
index b5c3d8943a86e561dbd65b44fad5a2188cff0f87..58a4a8bdfbee928ea4820e4a5bc154268cf6fd39 100644 (file)
@@ -1029,9 +1029,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 {
   bfd *dynobj;
   asection *s;
-  bfd_boolean plt;
   bfd_boolean relocs;
-  bfd_boolean reltext;
 
   dynobj = elf_hash_table (info)->dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -1067,9 +1065,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
-  reltext = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -1084,33 +1080,14 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
       if (strcmp (name, ".plt") == 0)
        {
          /* Remember whether there is a PLT.  */
-         plt = s->size != 0;
+         ;
        }
       else if (CONST_STRNEQ (name, ".rela"))
        {
          if (s->size != 0)
            {
-             asection *target;
-
-             /* Remember whether there are any reloc sections other
-                than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-               {
-                 const char *outname;
-
-                 relocs = TRUE;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  .rela.plt is actually associated with
-                    .got.plt, which is never readonly.  */
-                 outname = bfd_section_name (s->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 5);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = TRUE;
-               }
+               relocs = TRUE;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -1148,48 +1125,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_vax_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (!bfd_link_pic (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (plt)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
-
-      if (reltext || (info->flags & DF_TEXTREL) != 0)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* This function is called via elf_vax_link_hash_traverse if we are
index b223424cce4e0c36b787aab144e7a28486fa3e65..45727b3f805c070eb9dc208082318fea915d574a 100644 (file)
@@ -766,6 +766,7 @@ elf_xtensa_link_hash_table_create (bfd *abfd)
   tlsbase->root.type = bfd_link_hash_new;
   tlsbase->root.u.undef.abfd = NULL;
   tlsbase->non_elf = 0;
+  ret->elf.dt_pltgot_required = TRUE;
   ret->tlsbase = elf_xtensa_hash_entry (tlsbase);
   ret->tlsbase->tls_type = GOT_UNKNOWN;
 
@@ -1767,30 +1768,11 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (relplt)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relgot)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return FALSE;
-       }
+      if (!_bfd_elf_add_dynamic_tags (output_bfd, info,
+                                     relplt || relgot))
+       return FALSE;
 
-      if (!add_dynamic_entry (DT_PLTGOT, 0)
-         || !add_dynamic_entry (DT_XTENSA_GOT_LOC_OFF, 0)
+      if (!add_dynamic_entry (DT_XTENSA_GOT_LOC_OFF, 0)
          || !add_dynamic_entry (DT_XTENSA_GOT_LOC_SZ, 0))
        return FALSE;
     }
index 0b31d450dca1eaf36d04be0e99e26600b9e12084..a6b20982609b3d2ca3ed8a052d011dfe0cae88f3 100644 (file)
@@ -2910,38 +2910,14 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (relplt)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-
-         if (elf64_alpha_use_secureplt
-             && !add_dynamic_entry (DT_ALPHA_PLTRO, 1))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
-           return FALSE;
+      if (!_bfd_elf_add_dynamic_tags (output_bfd, info,
+                                     relocs || relplt))
+       return FALSE;
 
-         if (info->flags & DF_TEXTREL)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
+      if (relplt
+         && elf64_alpha_use_secureplt
+         && !add_dynamic_entry (DT_ALPHA_PLTRO, 1))
+       return FALSE;
     }
 #undef add_dynamic_entry
 
index 1088bcc21f05c3e9c49275ff7ce06b4ee5e94535..dd52b3511825bd7c3531f5eb7b4a39b9d1dd079d 100644 (file)
@@ -302,6 +302,7 @@ elf64_hppa_hash_table_create (bfd *abfd)
       return NULL;
     }
 
+  htab->root.dt_pltgot_required = TRUE;
   htab->text_segment_base = (bfd_vma) -1;
   htab->data_segment_base = (bfd_vma) -1;
 
@@ -1526,9 +1527,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
   bfd *dynobj;
   bfd *ibfd;
   asection *sec;
-  bfd_boolean plt;
   bfd_boolean relocs;
-  bfd_boolean reltext;
 
   hppa_info = hppa_link_hash_table (info);
   if (hppa_info == NULL)
@@ -1736,9 +1735,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
                            allocate_dynrel_entries, &data);
 
   /* The sizes of all the sections are set.  Allocate memory for them.  */
-  plt = FALSE;
   relocs = FALSE;
-  reltext = FALSE;
   for (sec = dynobj->sections; sec != NULL; sec = sec->next)
     {
       const char *name;
@@ -1753,7 +1750,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
       if (strcmp (name, ".plt") == 0)
        {
          /* Remember whether there is a PLT.  */
-         plt = sec->size != 0;
+         ;
        }
       else if (strcmp (name, ".opd") == 0
               || CONST_STRNEQ (name, ".dlt")
@@ -1766,28 +1763,10 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
        {
          if (sec->size != 0)
            {
-             asection *target;
-
              /* Remember whether there are any reloc sections other
                 than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-               {
-                 const char *outname;
-
-                 relocs = TRUE;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  The entries in the .rela.plt section
-                    really apply to the .got section, which we
-                    created ourselves and so know is not readonly.  */
-                 outname = bfd_section_name (sec->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 4);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = TRUE;
-               }
+               relocs = TRUE;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -1840,8 +1819,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0)
-         || !add_dynamic_entry (DT_PLTGOT, 0))
+      if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0))
        return FALSE;
 
       /* Add some entries to the .dynamic section.  We fill in the
@@ -1851,8 +1829,7 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
         dynamic linker and used by the debugger.  */
       if (! bfd_link_pic (info))
        {
-         if (!add_dynamic_entry (DT_DEBUG, 0)
-             || !add_dynamic_entry (DT_HP_DLD_HOOK, 0)
+         if (!add_dynamic_entry (DT_HP_DLD_HOOK, 0)
              || !add_dynamic_entry (DT_HP_LOAD_MAP, 0))
            return FALSE;
        }
@@ -1861,33 +1838,10 @@ elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
         Required by HPUX 11.00 patch PHSS_26559.  */
       if (!add_dynamic_entry (DT_FLAGS, (info)->flags))
        return FALSE;
-
-      if (plt)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
-           return FALSE;
-       }
-
-      if (reltext)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-         info->flags |= DF_TEXTREL;
-       }
     }
 #undef add_dynamic_entry
 
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Called after we have output the symbol into the dynamic symbol
index 5b95b5f814ad239752452d9b60fbb1e7dcb15e4d..da72c78753ef34fc9ac1b9aea14cda7a4872512c 100644 (file)
@@ -1919,54 +1919,7 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (htab->elf.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_s390_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.splt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
 }
 
 /* Return the base VMA address which should be subtracted from real addresses
index 14d8d159da7404748efafb8be9041878effb2bcd..998b72f2281c5b9b5482795b9b55dfffe284ee23 100644 (file)
@@ -14897,3 +14897,96 @@ _bfd_elf_maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
     }
   return TRUE;
 }
+
+/* Add dynamic tags.  */
+
+bfd_boolean
+_bfd_elf_add_dynamic_tags (bfd *output_bfd, struct bfd_link_info *info,
+                          bfd_boolean need_dynamic_reloc)
+{
+  struct elf_link_hash_table *htab = elf_hash_table (info);
+
+  if (htab->dynamic_sections_created)
+    {
+      /* Add some entries to the .dynamic section.  We fill in the
+        values later, in finish_dynamic_sections, but we must add
+        the entries now so that we get the correct size for the
+        .dynamic section.  The DT_DEBUG entry is filled in by the
+        dynamic linker and used by the debugger.  */
+#define add_dynamic_entry(TAG, VAL) \
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
+
+      const struct elf_backend_data *bed
+       = get_elf_backend_data (output_bfd);
+
+      if (bfd_link_executable (info))
+       {
+         if (!add_dynamic_entry (DT_DEBUG, 0))
+           return FALSE;
+       }
+
+      if (htab->dt_pltgot_required || htab->splt->size != 0)
+       {
+         /* DT_PLTGOT is used by prelink even if there is no PLT
+            relocation.  */
+         if (!add_dynamic_entry (DT_PLTGOT, 0))
+           return FALSE;
+       }
+
+      if (htab->dt_jmprel_required || htab->srelplt->size != 0)
+       {
+         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
+             || !add_dynamic_entry (DT_PLTREL,
+                                    (bed->rela_plts_and_copies_p
+                                     ? DT_RELA : DT_REL))
+             || !add_dynamic_entry (DT_JMPREL, 0))
+           return FALSE;
+       }
+
+      if (htab->tlsdesc_plt
+         && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
+             || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
+       return FALSE;
+
+      if (need_dynamic_reloc)
+       {
+         if (bed->rela_plts_and_copies_p)
+           {
+             if (!add_dynamic_entry (DT_RELA, 0)
+                 || !add_dynamic_entry (DT_RELASZ, 0)
+                 || !add_dynamic_entry (DT_RELAENT,
+                                        bed->s->sizeof_rela))
+               return FALSE;
+           }
+         else
+           {
+             if (!add_dynamic_entry (DT_REL, 0)
+                 || !add_dynamic_entry (DT_RELSZ, 0)
+                 || !add_dynamic_entry (DT_RELENT,
+                                        bed->s->sizeof_rel))
+               return FALSE;
+           }
+
+         /* If any dynamic relocs apply to a read-only section,
+            then we need a DT_TEXTREL entry.  */
+         if ((info->flags & DF_TEXTREL) == 0)
+           elf_link_hash_traverse (htab, _bfd_elf_maybe_set_textrel,
+                                   info);
+
+         if ((info->flags & DF_TEXTREL) != 0)
+           {
+             if (htab->ifunc_resolvers)
+               info->callbacks->einfo
+                 (_("%P: warning: GNU indirect functions with DT_TEXTREL "
+                    "may result in a segfault at runtime; recompile with %s\n"),
+                  bfd_link_dll (info) ? "-fPIC" : "-fPIE");
+
+             if (!add_dynamic_entry (DT_TEXTREL, 0))
+               return FALSE;
+           }
+       }
+    }
+#undef add_dynamic_entry
+
+  return TRUE;
+}
index eff27f6ae35ead15d32e86966d788ce3ebc3515a..8f1e5e1e456abbfa8b8eb9ae219d76f1f49c0cab 100644 (file)
@@ -9101,29 +9101,15 @@ elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 #define add_dynamic_entry(TAG, VAL)                    \
       _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
+      if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
+       return FALSE;
 
       if (htab->root.splt->size != 0)
        {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-
          if (htab->variant_pcs
              && !add_dynamic_entry (DT_AARCH64_VARIANT_PCS, 0))
            return FALSE;
 
-         if (htab->root.tlsdesc_plt
-             && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
-                 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
-           return FALSE;
-
          if ((elf_aarch64_tdata (output_bfd)->plt_type == PLT_BTI_PAC)
              && (!add_dynamic_entry (DT_AARCH64_BTI_PLT, 0)
                  || !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0)))
@@ -9137,26 +9123,6 @@ elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
                   && !add_dynamic_entry (DT_AARCH64_PAC_PLT, 0))
            return FALSE;
        }
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (DT_RELA, 0)
-             || !add_dynamic_entry (DT_RELASZ, 0)
-             || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
     }
 #undef add_dynamic_entry
 
index ba46270f8669e1bfcbaff0cedd1e3ac60a4b9843..4d6a0279e319cbca553257508509dad7c47d5e78 100644 (file)
@@ -1473,6 +1473,7 @@ elfNN_ia64_hash_table_create (bfd *abfd)
       return NULL;
     }
   ret->root.root.hash_table_free = elfNN_ia64_link_hash_table_free;
+  ret->root.dt_pltgot_required = TRUE;
 
   return &ret->root.root;
 }
@@ -2994,7 +2995,6 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   struct elfNN_ia64_link_hash_table *ia64_info;
   asection *sec;
   bfd *dynobj;
-  bfd_boolean relplt = FALSE;
 
   ia64_info = elfNN_ia64_hash_table (info);
   if (ia64_info == NULL)
@@ -3148,7 +3148,7 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
            ia64_info->rel_pltoff_sec = NULL;
          else
            {
-             relplt = TRUE;
+             ia64_info->root.dt_jmprel_required = TRUE;
              /* We use the reloc_count field as a counter if we need to
                 copy relocs into the output file.  */
              sec->reloc_count = 0;
@@ -3194,40 +3194,14 @@ elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
         later (in finish_dynamic_sections) but we must add the entries now
         so that we get the correct size for the .dynamic section.  */
 
-      if (bfd_link_executable (info))
-       {
-         /* The DT_DEBUG entry is filled in by the dynamic linker and used
-            by the debugger.  */
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0))
-       return FALSE;
-      if (!add_dynamic_entry (DT_PLTGOT, 0))
+      if (!_bfd_elf_add_dynamic_tags (output_bfd, info, TRUE))
        return FALSE;
 
-      if (relplt)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
+      if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0))
        return FALSE;
-
-      if ((info->flags & DF_TEXTREL) != 0)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
     }
 
   /* ??? Perhaps force __gp local.  */
index 00553f774644d98ac30a2c358014c9a1c0b98137..a5fa415309ae890ef96d97ea82562cb7a1735067 100644 (file)
@@ -1261,51 +1261,7 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in riscv_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela)))
-       return FALSE;
-
-      /* If any dynamic relocs apply to a read-only section,
-        then we need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (&htab->elf,
-                               _bfd_elf_maybe_set_textrel, info);
-
-      if (info->flags & DF_TEXTREL)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 
 #define TP_OFFSET 0
index 4dcdd1793ebc228a461a188abf6bb5224cdc38ed..bd046aca6c8e2ad93044b37994c1f0cc9c1ab9a6 100644 (file)
@@ -2590,39 +2590,10 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
 #define add_dynamic_entry(TAG, VAL) \
   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT,
-                                SPARC_ELF_RELA_BYTES (htab)))
+      if (!_bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+                                                   TRUE))
        return FALSE;
 
-      /* If any dynamic relocs apply to a read-only section,
-        then we need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (&htab->elf,
-                               _bfd_elf_maybe_set_textrel, info);
-
-      if (info->flags & DF_TEXTREL)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-
       if (ABI_64_P (output_bfd))
        {
          int reg;
@@ -2678,9 +2649,6 @@ _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
                eht->dynsymcount++;
              }
        }
-      if (htab->elf.target_os == is_vxworks
-         && !elf_vxworks_add_dynamic_entries (output_bfd, info))
-       return FALSE;
     }
 #undef add_dynamic_entry
 
index 9d8b42e1de0804fd93c7b33694a90f20438e6a70..c0494a4ced526826b157d55467b38ba88ae33ef3 100644 (file)
@@ -2621,51 +2621,7 @@ tilegx_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        return FALSE;
     }
 
-  if (elf_hash_table (info)->dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in tilegx_elf_finish_dynamic_sections, but we
-        must add the entries now so that we get the correct size for
-        the .dynamic section.  The DT_DEBUG entry is filled in by the
-        dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTGOT, 0)
-             || !add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (!add_dynamic_entry (DT_RELA, 0)
-         || !add_dynamic_entry (DT_RELASZ, 0)
-         || !add_dynamic_entry (DT_RELAENT, TILEGX_ELF_RELA_BYTES (htab)))
-       return FALSE;
-
-      /* If any dynamic relocs apply to a read-only section,
-        then we need a DT_TEXTREL entry.  */
-      if ((info->flags & DF_TEXTREL) == 0)
-       elf_link_hash_traverse (&htab->elf,
-                               _bfd_elf_maybe_set_textrel, info);
-
-      if (info->flags & DF_TEXTREL)
-       {
-         if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return FALSE;
-       }
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
 }
 \f
 /* Return the base VMA address which should be subtracted from real addresses
index 29b020442f808aef23e0570e4e7f8ea30489d8ec..5b1793ae8071a17c9b47ef60744946b9f92d7698 100644 (file)
@@ -721,9 +721,6 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
   if (bed->target_id == X86_64_ELF_DATA)
     {
       ret->is_reloc_section = elf_x86_64_is_reloc_section;
-      ret->dt_reloc = DT_RELA;
-      ret->dt_reloc_sz = DT_RELASZ;
-      ret->dt_reloc_ent = DT_RELAENT;
       ret->got_entry_size = 8;
       ret->pcrel_plt = TRUE;
       ret->tls_get_addr = "__tls_get_addr";
@@ -748,9 +745,6 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
       else
        {
          ret->is_reloc_section = elf_i386_is_reloc_section;
-         ret->dt_reloc = DT_REL;
-         ret->dt_reloc_sz = DT_RELSZ;
-         ret->dt_reloc_ent = DT_RELENT;
          ret->sizeof_reloc = sizeof (Elf32_External_Rel);
          ret->got_entry_size = 4;
          ret->pcrel_plt = FALSE;
@@ -1362,76 +1356,8 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
                   + PLT_FDE_LEN_OFFSET));
     }
 
-  if (htab->elf.dynamic_sections_created)
-    {
-      /* Add some entries to the .dynamic section.  We fill in the
-        values later, in elf_{i386,x86_64}_finish_dynamic_sections,
-        but we must add the entries now so that we get the correct
-        size for the .dynamic section.  The DT_DEBUG entry is filled
-        in by the dynamic linker and used by the debugger.  */
-#define add_dynamic_entry(TAG, VAL) \
-  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
-      if (bfd_link_executable (info))
-       {
-         if (!add_dynamic_entry (DT_DEBUG, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.splt->size != 0)
-       {
-         /* DT_PLTGOT is used by prelink even if there is no PLT
-            relocation.  */
-         if (!add_dynamic_entry (DT_PLTGOT, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.srelplt->size != 0)
-       {
-         if (!add_dynamic_entry (DT_PLTRELSZ, 0)
-             || !add_dynamic_entry (DT_PLTREL, htab->dt_reloc)
-             || !add_dynamic_entry (DT_JMPREL, 0))
-           return FALSE;
-       }
-
-      if (htab->elf.tlsdesc_plt
-         && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
-             || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
-       return FALSE;
-
-      if (relocs)
-       {
-         if (!add_dynamic_entry (htab->dt_reloc, 0)
-             || !add_dynamic_entry (htab->dt_reloc_sz, 0)
-             || !add_dynamic_entry (htab->dt_reloc_ent,
-                                    htab->sizeof_reloc))
-           return FALSE;
-
-         /* If any dynamic relocs apply to a read-only section,
-            then we need a DT_TEXTREL entry.  */
-         if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf,
-                                   _bfd_elf_maybe_set_textrel, info);
-
-         if ((info->flags & DF_TEXTREL) != 0)
-           {
-             if (htab->elf.ifunc_resolvers)
-               info->callbacks->einfo
-                 (_("%P: warning: GNU indirect functions with DT_TEXTREL "
-                    "may result in a segfault at runtime; recompile with %s\n"),
-                  bfd_link_dll (info) ? "-fPIC" : "-fPIE");
-
-             if (!add_dynamic_entry (DT_TEXTREL, 0))
-               return FALSE;
-           }
-       }
-      if (htab->elf.target_os == is_vxworks
-         && !elf_vxworks_add_dynamic_entries (output_bfd, info))
-       return FALSE;
-    }
-#undef add_dynamic_entry
-
-  return TRUE;
+  return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd, info,
+                                                 relocs);
 }
 
 /* Finish up the x86 dynamic sections.  */
index 915cd4d5d04dfad0b92eb7b1482508cfcfa5c0ce..7541554bafb357a18d0fbe4ed282ffbb7c4f0923 100644 (file)
@@ -510,9 +510,6 @@ struct elf_x86_link_hash_table
   bfd_vma (*r_sym) (bfd_vma);
   bfd_boolean (*is_reloc_section) (const char *);
   unsigned int sizeof_reloc;
-  unsigned int dt_reloc;
-  unsigned int dt_reloc_sz;
-  unsigned int dt_reloc_ent;
   unsigned int got_entry_size;
   unsigned int pointer_r_type;
   int dynamic_interpreter_size;
This page took 0.070914 seconds and 4 git commands to generate.