convert elf_link_hash macros to inline functions
authorAlan Modra <amodra@gmail.com>
Mon, 12 Apr 2021 07:46:03 +0000 (17:16 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 12 Apr 2021 11:49:02 +0000 (21:19 +0930)
Involves a bit of editing as we now need to be more precise in pointer
types.

bfd/
* elf-bfd.h (is_elf_hash_table): Convert macro to inline function.
(elf_link_hash_lookup, elf_link_hash_traverse): Likewise.
(elf_hash_table, elf_hash_table_id): Likewise.
* elf32-arm.c (elf32_arm_setup_section_lists): Delete redundant
is_elf_hash_table check.
* elf32-csky.c (elf32_csky_setup_section_lists): Likewise.
* elf32-hppa.c (clobber_millicode_symbols): Correct param types.
* elf64-alpha.c (elf64_alpha_output_extsym): Likewise.
* elfnn-ia64.c (elfNN_ia64_global_dyn_info_free: Likewise.
(elfNN_ia64_global_dyn_sym_thunk: Likewise.
* elf64-ia64-vms.c (elf64_ia64_global_dyn_info_free): Likewise.
(elf64_ia64_global_dyn_sym_thunk): Likewise.
(elf64_vms_link_add_object_symbols): Pass base type of hash table
to is_elf_hash_table.
* elflink.c (_bfd_elf_dynamic_symbol_p): Likewise.
(_bfd_elf_symbol_refs_local_p, _bfd_elf_add_dynamic_entry): Likewise.
(_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
(_bfd_elf_link_check_relocs, elf_link_add_object_symbols): Likewise.
(bfd_elf_final_link): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_setup_section_lists): Likewise.
* elf64-ppc.c (ppc64_elf_set_toc): Likewise.  Use bfd_link_hash_lookup.
ld/
* emultempl/mipself.em (mips_create_output_section_statements):
Pass base type of hash table to is_elf_hash_table.
* ldelf.c (ldelf_after_open): Likewise.

14 files changed:
bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf32-arm.c
bfd/elf32-csky.c
bfd/elf32-hppa.c
bfd/elf64-alpha.c
bfd/elf64-ia64-vms.c
bfd/elf64-ppc.c
bfd/elflink.c
bfd/elfnn-aarch64.c
bfd/elfnn-ia64.c
ld/ChangeLog
ld/emultempl/mipself.em
ld/ldelf.c

index 68224f86fe90f794853a8b60c69d21f6f5a1f21d..84f16fc21768d8f52a90016bf7cea3a957dceec9 100644 (file)
@@ -1,3 +1,27 @@
+2021-04-12  Alan Modra  <amodra@gmail.com>
+
+       * elf-bfd.h (is_elf_hash_table): Convert macro to inline function.
+       (elf_link_hash_lookup, elf_link_hash_traverse): Likewise.
+       (elf_hash_table, elf_hash_table_id): Likewise.
+       * elf32-arm.c (elf32_arm_setup_section_lists): Delete redundant
+       is_elf_hash_table check.
+       * elf32-csky.c (elf32_csky_setup_section_lists): Likewise.
+       * elf32-hppa.c (clobber_millicode_symbols): Correct param types.
+       * elf64-alpha.c (elf64_alpha_output_extsym): Likewise.
+       * elfnn-ia64.c (elfNN_ia64_global_dyn_info_free: Likewise.
+       (elfNN_ia64_global_dyn_sym_thunk: Likewise.
+       * elf64-ia64-vms.c (elf64_ia64_global_dyn_info_free): Likewise.
+       (elf64_ia64_global_dyn_sym_thunk): Likewise.
+       (elf64_vms_link_add_object_symbols): Pass base type of hash table
+       to is_elf_hash_table.
+       * elflink.c (_bfd_elf_dynamic_symbol_p): Likewise.
+       (_bfd_elf_symbol_refs_local_p, _bfd_elf_add_dynamic_entry): Likewise.
+       (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise.
+       (_bfd_elf_link_check_relocs, elf_link_add_object_symbols): Likewise.
+       (bfd_elf_final_link): Likewise.
+       * elfnn-aarch64.c (elfNN_aarch64_setup_section_lists): Likewise.
+       * elf64-ppc.c (ppc64_elf_set_toc): Likewise.  Use bfd_link_hash_lookup.
+
 2021-04-12  Alan Modra  <amodra@gmail.com>
 
        * elf-bfd.h (struct elf_backend_data): Return bfd_link_hash_entry*
index 6f9d7375eaf4db2067081b45f643d57a4b15dec4..e0b7e5759ad5553385bfe2fc89aa82dc5475f156 100644 (file)
@@ -707,30 +707,49 @@ struct elf_link_hash_table
   asection *dynsym;
 };
 
+/* Returns TRUE if the hash table is a struct elf_link_hash_table.  */
+
+static inline bool
+is_elf_hash_table (const struct bfd_link_hash_table *htab)
+{
+  return htab->type == bfd_link_elf_hash_table;
+}
+
 /* Look up an entry in an ELF linker hash table.  */
 
-#define elf_link_hash_lookup(table, string, create, copy, follow)      \
-  ((struct elf_link_hash_entry *)                                      \
-   bfd_link_hash_lookup (&(table)->root, (string), (create),           \
-                        (copy), (follow)))
+static inline struct elf_link_hash_entry *
+elf_link_hash_lookup (struct elf_link_hash_table *table, const char *string,
+                     bool create, bool copy, bool follow)
+{
+  return (struct elf_link_hash_entry *)
+    bfd_link_hash_lookup (&table->root, string, create, copy, follow);
+}
 
 /* Traverse an ELF linker hash table.  */
 
-#define elf_link_hash_traverse(table, func, info)                      \
-  (bfd_link_hash_traverse                                              \
-   (&(table)->root,                                                    \
-    (bool (*) (struct bfd_link_hash_entry *, void *)) (func),          \
-    (info)))
+static inline void
+elf_link_hash_traverse (struct elf_link_hash_table *table,
+                       bool (*f) (struct elf_link_hash_entry *, void *),
+                       void *info)
+{
+  bfd_link_hash_traverse (&table->root,
+                         (bool (*) (struct bfd_link_hash_entry *, void *)) f,
+                         info);
+}
 
 /* Get the ELF linker hash table from a link_info structure.  */
 
-#define elf_hash_table(p) ((struct elf_link_hash_table *) ((p)->hash))
-
-#define elf_hash_table_id(table)       ((table) -> hash_table_id)
+static inline struct elf_link_hash_table *
+elf_hash_table (const struct bfd_link_info *info)
+{
+  return (struct elf_link_hash_table *) info->hash;
+}
 
-/* Returns TRUE if the hash table is a struct elf_link_hash_table.  */
-#define is_elf_hash_table(htab)                                                \
-  (((struct bfd_link_hash_table *) (htab))->type == bfd_link_elf_hash_table)
+static inline enum elf_target_id
+elf_hash_table_id (const struct elf_link_hash_table *table)
+{
+  return table->hash_table_id;
+}
 \f
 /* Constant information held for an ELF backend.  */
 
index 51a65d89a846da67561ee0827aa11d4b8873260c..29656a7ab63405a0cd29fdf693563bca3b768657 100644 (file)
@@ -5262,8 +5262,6 @@ elf32_arm_setup_section_lists (bfd *output_bfd,
 
   if (htab == NULL)
     return 0;
-  if (! is_elf_hash_table (htab))
-    return 0;
 
   /* Count the number of input BFDs and find the top input section id.  */
   for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
index 1dee29a7b4a3ef4e924085485777f63e1cb91a75..f8209a4a7da46bd9b144a3e0dc7d2b7dc5c95384 100644 (file)
@@ -3865,8 +3865,6 @@ elf32_csky_setup_section_lists (bfd *output_bfd,
 
   if (!htab)
     return 0;
-  if (! is_elf_hash_table (htab))
-    return 0;
 
   /* Count the number of input BFDs and find the top input section id.  */
   for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
index 22a4625b842ea3a2d804aad0649f092ff5eb2c12..77170dd4ea65639657e1998d7951b531ec509cef 100644 (file)
@@ -2031,13 +2031,11 @@ allocate_dynrelocs (struct elf_link_hash_entry *eh, void *inf)
 
 static bool
 clobber_millicode_symbols (struct elf_link_hash_entry *eh,
-                          struct bfd_link_info *info)
+                          void *info)
 {
   if (eh->type == STT_PARISC_MILLI
       && !eh->forced_local)
-    {
-      elf32_hppa_hide_symbol (info, eh, true);
-    }
+    elf32_hppa_hide_symbol ((struct bfd_link_info *) info, eh, true);
   return true;
 }
 
index 1f68f822f790846713dfd4fdf2bd132d17ee0737..6f5eeadf256b21c6ca562564a72bc367c384cb4a 100644 (file)
@@ -1558,8 +1558,9 @@ struct extsym_info
 };
 
 static bool
-elf64_alpha_output_extsym (struct alpha_elf_link_hash_entry *h, void * data)
+elf64_alpha_output_extsym (struct elf_link_hash_entry *x, void * data)
 {
+  struct alpha_elf_link_hash_entry *h = (struct alpha_elf_link_hash_entry *) x;
   struct extsym_info *einfo = (struct extsym_info *) data;
   bool strip;
   asection *sec, *output_section;
index 3353f511546a369729bdd3bb723fc32c333deb06..c72015b450c570187e08664f9f78ab727a3292d5 100644 (file)
@@ -990,7 +990,7 @@ elf64_ia64_local_htab_eq (const void *ptr1, const void *ptr2)
 /* Free the global elf64_ia64_dyn_sym_info array.  */
 
 static bool
-elf64_ia64_global_dyn_info_free (void **xentry,
+elf64_ia64_global_dyn_info_free (struct elf_link_hash_entry *xentry,
                                 void * unused ATTRIBUTE_UNUSED)
 {
   struct elf64_ia64_link_hash_entry *entry
@@ -1090,7 +1090,7 @@ struct elf64_ia64_dyn_sym_traverse_data
 };
 
 static bool
-elf64_ia64_global_dyn_sym_thunk (struct bfd_hash_entry *xentry,
+elf64_ia64_global_dyn_sym_thunk (struct elf_link_hash_entry *xentry,
                                 void * xdata)
 {
   struct elf64_ia64_link_hash_entry *entry
@@ -4767,7 +4767,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
         hope of using a dynamic object which does not exactly match
         the format of the output file.  */
       if (bfd_link_relocatable (info)
-         || !is_elf_hash_table (htab)
+         || !is_elf_hash_table (&htab->root)
          || info->output_bfd->xvec != abfd->xvec)
        {
          if (bfd_link_relocatable (info))
@@ -4786,7 +4786,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
         format.  FIXME: If there are no input BFD's of the same
         format as the output, we can't make a shared library.  */
       if (bfd_link_pic (info)
-         && is_elf_hash_table (htab)
+         && is_elf_hash_table (&htab->root)
          && info->output_bfd->xvec == abfd->xvec
          && !htab->dynamic_sections_created)
        {
@@ -4794,7 +4794,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
            goto error_return;
        }
     }
-  else if (!is_elf_hash_table (htab))
+  else if (!is_elf_hash_table (&htab->root))
     goto error_return;
   else
     {
@@ -5034,7 +5034,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 
       *sym_hash = h;
 
-      if (is_elf_hash_table (htab))
+      if (is_elf_hash_table (&htab->root))
        {
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
@@ -5103,7 +5103,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
            h->root.u.c.p->alignment_power = old_alignment;
        }
 
-      if (is_elf_hash_table (htab))
+      if (is_elf_hash_table (&htab->root))
        {
          /* Check the alignment when a common symbol is involved. This
             can change when a common symbol is overridden by a normal
@@ -5257,7 +5257,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
      I have no idea how to handle linking PIC code into a file of a
      different format.  It probably can't be done.  */
   if (! dynamic
-      && is_elf_hash_table (htab)
+      && is_elf_hash_table (&htab->root)
       && bed->check_relocs != NULL
       && (*bed->relocs_compatible) (abfd->xvec, info->output_bfd->xvec))
     {
index 7873f97ab32fd4b2c71b7857c08075e4cb5c82d1..08227f0e43ab5b2e98aaff5ac56822970bfed162 100644 (file)
@@ -13955,19 +13955,20 @@ ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
       struct elf_link_hash_entry *h;
       struct elf_link_hash_table *htab = elf_hash_table (info);
 
-      if (is_elf_hash_table (htab)
+      if (is_elf_hash_table (&htab->root)
          && htab->hgot != NULL)
        h = htab->hgot;
       else
        {
-         h = elf_link_hash_lookup (htab, ".TOC.", false, false, true);
-         if (is_elf_hash_table (htab))
+         h = (struct elf_link_hash_entry *)
+           bfd_link_hash_lookup (&htab->root, ".TOC.", false, false, true);
+         if (is_elf_hash_table (&htab->root))
            htab->hgot = h;
        }
       if (h != NULL
          && h->root.type == bfd_link_hash_defined
          && !h->root.linker_def
-         && (!is_elf_hash_table (htab)
+         && (!is_elf_hash_table (&htab->root)
              || h->def_regular))
        {
          TOCstart = defined_sym_val (h) - TOC_BASE_OFF;
index 3acf7951b5bd07efe653aefa85b7df1c69b82f0d..cb38a025349bb44fede8f1bf11e98e23a0046446 100644 (file)
@@ -3244,7 +3244,7 @@ _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *h,
 
     case STV_PROTECTED:
       hash_table = elf_hash_table (info);
-      if (!is_elf_hash_table (hash_table))
+      if (!is_elf_hash_table (&hash_table->root))
        return false;
 
       bed = get_elf_backend_data (hash_table->dynobj);
@@ -3328,7 +3328,7 @@ _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h,
     return false;
 
   hash_table = elf_hash_table (info);
-  if (!is_elf_hash_table (hash_table))
+  if (!is_elf_hash_table (&hash_table->root))
     return true;
 
   bed = get_elf_backend_data (hash_table->dynobj);
@@ -3522,7 +3522,7 @@ _bfd_elf_add_dynamic_entry (struct bfd_link_info *info,
   Elf_Internal_Dyn dyn;
 
   hash_table = elf_hash_table (info);
-  if (! is_elf_hash_table (hash_table))
+  if (! is_elf_hash_table (&hash_table->root))
     return false;
 
   if (tag == DT_RELA || tag == DT_REL)
@@ -3566,7 +3566,7 @@ _bfd_elf_strip_zero_sized_dynamic_sections (struct bfd_link_info *info)
     return true;
 
   hash_table = elf_hash_table (info);
-  if (!is_elf_hash_table (hash_table))
+  if (!is_elf_hash_table (&hash_table->root))
     return false;
 
   if (!hash_table->dynobj)
@@ -3997,7 +3997,7 @@ _bfd_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
      I have no idea how to handle linking PIC code into a file of a
      different format.  It probably can't be done.  */
   if ((abfd->flags & DYNAMIC) == 0
-      && is_elf_hash_table (htab)
+      && is_elf_hash_table (&htab->root)
       && bed->check_relocs != NULL
       && elf_object_id (abfd) == elf_hash_table_id (htab)
       && (*bed->relocs_compatible) (abfd->xvec, info->output_bfd->xvec))
@@ -4094,7 +4094,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
         hope of using a dynamic object which does not exactly match
         the format of the output file.  */
       if (bfd_link_relocatable (info)
-         || !is_elf_hash_table (htab)
+         || !is_elf_hash_table (&htab->root)
          || info->output_bfd->xvec != abfd->xvec)
        {
          if (bfd_link_relocatable (info))
@@ -4202,7 +4202,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              || (!bfd_link_relocatable (info)
                  && info->nointerp
                  && (info->export_dynamic || info->dynamic)))
-         && is_elf_hash_table (htab)
+         && is_elf_hash_table (&htab->root)
          && info->output_bfd->xvec == abfd->xvec
          && !htab->dynamic_sections_created)
        {
@@ -4210,7 +4210,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
            goto error_return;
        }
     }
-  else if (!is_elf_hash_table (htab))
+  else if (!is_elf_hash_table (&htab->root))
     goto error_return;
   else
     {
@@ -4794,7 +4794,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       old_bfd = NULL;
       new_sec = sec;
 
-      if (is_elf_hash_table (htab))
+      if (is_elf_hash_table (&htab->root))
        {
          Elf_Internal_Versym iver;
          unsigned int vernum = 0;
@@ -4970,7 +4970,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 
       /* Setting the index to -3 tells elf_link_output_extsym that
         this symbol is defined in a discarded section.  */
-      if (discarded && is_elf_hash_table (htab))
+      if (discarded && is_elf_hash_table (&htab->root))
        h->indx = -3;
 
       new_weak = (flags & BSF_WEAK) != 0;
@@ -4978,7 +4978,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          && definition
          && new_weak
          && !bed->is_function_type (ELF_ST_TYPE (isym->st_info))
-         && is_elf_hash_table (htab)
+         && is_elf_hash_table (&htab->root)
          && h->u.alias == NULL)
        {
          /* Keep a list of all weak defined non function symbols from
@@ -5017,7 +5017,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
            h->root.u.c.p->alignment_power = old_alignment;
        }
 
-      if (is_elf_hash_table (htab))
+      if (is_elf_hash_table (&htab->root))
        {
          /* Set a flag in the hash table entry indicating the type of
             reference or definition we just found.  A dynamic symbol
@@ -5679,7 +5679,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
      of the .stab/.stabstr sections.  */
   if (! dynamic
       && ! info->traditional_format
-      && is_elf_hash_table (htab)
+      && is_elf_hash_table (&htab->root)
       && (info->strip != strip_all && info->strip != strip_debugger))
     {
       asection *stabstr;
@@ -12074,7 +12074,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
   bool sections_removed;
   bool ret;
 
-  if (!is_elf_hash_table (htab))
+  if (!is_elf_hash_table (&htab->root))
     return false;
 
   if (bfd_link_pic (info))
index e2b1de78789b42e685322b95f31891b6837db0d9..0a1d7a617c83c4c8c9dcc33fe2ac7fd7722d7f0b 100644 (file)
@@ -3423,7 +3423,7 @@ elfNN_aarch64_setup_section_lists (bfd *output_bfd,
   struct elf_aarch64_link_hash_table *htab =
     elf_aarch64_hash_table (info);
 
-  if (!is_elf_hash_table (htab))
+  if (!is_elf_hash_table (&htab->root.root))
     return 0;
 
   /* Count the number of input BFDs and find the top input section id.  */
index ceebe554a56037829150fba09526d3aecf9aca2d..d469925697d97d0b8fd1dfb2daa55a55f5502f5b 100644 (file)
@@ -1391,8 +1391,8 @@ elfNN_ia64_local_htab_eq (const void *ptr1, const void *ptr2)
 /* Free the global elfNN_ia64_dyn_sym_info array.  */
 
 static bool
-elfNN_ia64_global_dyn_info_free (void **xentry,
-                                void * unused ATTRIBUTE_UNUSED)
+elfNN_ia64_global_dyn_info_free (struct elf_link_hash_entry *xentry,
+                                void *unused ATTRIBUTE_UNUSED)
 {
   struct elfNN_ia64_link_hash_entry *entry
     = (struct elfNN_ia64_link_hash_entry *) xentry;
@@ -1489,7 +1489,7 @@ struct elfNN_ia64_dyn_sym_traverse_data
 };
 
 static bool
-elfNN_ia64_global_dyn_sym_thunk (struct bfd_hash_entry *xentry,
+elfNN_ia64_global_dyn_sym_thunk (struct elf_link_hash_entry *xentry,
                                 void * xdata)
 {
   struct elfNN_ia64_link_hash_entry *entry
index aad02a2086af20bcd11ea8cb58b52663284d2d29..244f286a0a3cd604d7f7d2f422bfeb455542aabc 100644 (file)
@@ -1,3 +1,9 @@
+2021-04-12  Alan Modra  <amodra@gmail.com>
+
+       * emultempl/mipself.em (mips_create_output_section_statements):
+       Pass base type of hash table to is_elf_hash_table.
+       * ldelf.c (ldelf_after_open): Likewise.
+
 2021-04-12  Alan Modra  <amodra@gmail.com>
 
        PR 27719
index 8f28fcd22ee77825312d48f53f6d120a05b16ea0..a31ad4466df3c2f07764ef99474481db58835d82 100644 (file)
@@ -197,7 +197,7 @@ mips_create_output_section_statements (void)
   struct elf_link_hash_table *htab;
 
   htab = elf_hash_table (&link_info);
-  if (is_elf_hash_table (htab) && is_mips_elf (link_info.output_bfd))
+  if (is_elf_hash_table (&htab->root) && is_mips_elf (link_info.output_bfd))
     _bfd_mips_elf_linker_flags (&link_info, insn32, ignore_branch_isa,
                                ${gnu_target});
 
index 631d11b921748216b1d7345f35f4cf706a9a9f64..4d4d9ca051796a07b8b67f8a658b86a5c9092670 100644 (file)
@@ -1001,7 +1001,7 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
   after_open_default ();
 
   htab = elf_hash_table (&link_info);
-  if (!is_elf_hash_table (htab))
+  if (!is_elf_hash_table (&htab->root))
     return;
 
   if (command_line.out_implib_filename)
This page took 0.049122 seconds and 4 git commands to generate.