[PATCH] ELF: Move readonly_dynrelocs_against_ifunc to elf_link_hash_table

H.J. Lu hjl.tools@gmail.com
Sat Jun 6 14:33:48 GMT 2020


All IFUNC targets can use readonly_dynrelocs_against_ifunc to warn
dynamic IFUNC relocations in read-only segment.

I'd like to check it into master if there are no objections.

H.J.
---
	* elf-bfd.h (elf_link_hash_table): Add
	readonly_dynrelocs_against_ifunc.
	(_bfd_elf_allocate_ifunc_dyn_relocs): Remove the bfd_boolean *
	argument.
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Updated.
	Set readonly_dynrelocs_against_ifunc.
	* elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
	Updated.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Likewise.
	* elfxx-x86.h (elf_x86_link_hash_table): Remove
	readonly_dynrelocs_against_ifunc.
---
 bfd/elf-bfd.h       |  8 ++++++--
 bfd/elf-ifunc.c     | 11 ++---------
 bfd/elfnn-aarch64.c |  1 -
 bfd/elfxx-x86.c     |  3 +--
 bfd/elfxx-x86.h     |  4 ----
 5 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 3736ba6c7d..43f058173f 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -570,6 +570,10 @@ struct elf_link_hash_table
      section symbols.  */
   bfd_boolean is_relocatable_executable;
 
+  /* TRUE if there are dynamic relocs against IFUNC symbols that apply
+     to read-only sections.  */
+  bfd_boolean readonly_dynrelocs_against_ifunc;
+
   /* 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.  */
@@ -2864,8 +2868,8 @@ extern bfd_boolean _bfd_elf_create_ifunc_sections
   (bfd *, struct bfd_link_info *);
 extern bfd_boolean _bfd_elf_allocate_ifunc_dyn_relocs
   (struct bfd_link_info *, struct elf_link_hash_entry *,
-   struct elf_dyn_relocs **, bfd_boolean *, unsigned int,
-   unsigned int, unsigned int, bfd_boolean);
+   struct elf_dyn_relocs **, unsigned int, unsigned int,
+   unsigned int, bfd_boolean);
 
 extern void elf_append_rela (bfd *, asection *, Elf_Internal_Rela *);
 extern void elf_append_rel (bfd *, asection *, Elf_Internal_Rela *);
diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c
index b044164216..d395973f90 100644
--- a/bfd/elf-ifunc.c
+++ b/bfd/elf-ifunc.c
@@ -107,7 +107,6 @@ bfd_boolean
 _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
 				    struct elf_link_hash_entry *h,
 				    struct elf_dyn_relocs **head,
-				    bfd_boolean *readonly_dynrelocs_against_ifunc_p,
 				    unsigned int plt_entry_size,
 				    unsigned int plt_header_size,
 				    unsigned int got_entry_size,
@@ -118,7 +117,6 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
   unsigned int sizeof_reloc;
   const struct elf_backend_data *bed;
   struct elf_link_hash_table *htab;
-  bfd_boolean readonly_dynrelocs_against_ifunc;
   /* If AVOID_PLT is TRUE, don't use PLT if possible.  */
   bfd_boolean use_plt = !avoid_plt || h->plt.refcount > 0;
   bfd_boolean need_dynreloc = !use_plt || bfd_link_pic (info);
@@ -255,8 +253,6 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
   if (!need_dynreloc || !h->non_got_ref)
     *head = NULL;
 
-  readonly_dynrelocs_against_ifunc = FALSE;
-
   /* Finally, allocate space.  */
   p = *head;
   if (p != NULL)
@@ -264,11 +260,11 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
       bfd_size_type count = 0;
       do
 	{
-	  if (!readonly_dynrelocs_against_ifunc)
+	  if (!htab->readonly_dynrelocs_against_ifunc)
 	    {
 	      asection *s = p->sec->output_section;
 	      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-		readonly_dynrelocs_against_ifunc = TRUE;
+		htab->readonly_dynrelocs_against_ifunc = TRUE;
 	    }
 	  count += p->count;
 	  p = p->next;
@@ -290,9 +286,6 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
 	}
     }
 
-  if (readonly_dynrelocs_against_ifunc_p)
-    *readonly_dynrelocs_against_ifunc_p = readonly_dynrelocs_against_ifunc;
-
   /* For STT_GNU_IFUNC symbol, .got.plt has the real function address
      and .got has the PLT entry adddress.  We will load the GOT entry
      with the PLT entry in finish_dynamic_symbol if it is used.  For
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 64215f7185..3bbfa05104 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -8829,7 +8829,6 @@ elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
       && h->def_regular)
     return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
 					       &h->dyn_relocs,
-					       NULL,
 					       htab->plt_entry_size,
 					       htab->plt_header_size,
 					       GOT_ENTRY_SIZE,
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 6b8e56d7a0..a189eb20e8 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -132,7 +132,6 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
       && h->def_regular)
     {
       if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h, &h->dyn_relocs,
-					      &htab->readonly_dynrelocs_against_ifunc,
 					      plt_entry_size,
 					      (htab->plt.has_plt0
 					       * plt_entry_size),
@@ -1416,7 +1415,7 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
 
 	  if ((info->flags & DF_TEXTREL) != 0)
 	    {
-	      if (htab->readonly_dynrelocs_against_ifunc)
+	      if (htab->elf.readonly_dynrelocs_against_ifunc)
 		{
 		  info->callbacks->einfo
 		    (_("%P%X: read-only segment has dynamic IFUNC relocations;"
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 7cdc4323ab..1d5a75744c 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -487,10 +487,6 @@ struct elf_x86_link_hash_table
   /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt.  */
   bfd_vma next_irelative_index;
 
-  /* TRUE if there are dynamic relocs against IFUNC symbols that apply
-     to read-only sections.  */
-  bfd_boolean readonly_dynrelocs_against_ifunc;
-
   /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.
      This is used for i386 only.  */
   asection *srelplt2;
-- 
2.26.2



More information about the Binutils mailing list