[PATCH 4/4] bfd/COFF: drop link_add_one_symbol() hook

Jan Beulich jbeulich@suse.com
Fri Mar 28 14:51:58 GMT 2025


The need for this has disappeared with dc12032bca08 ("Remove m68k-aout
and m68k-coff support"); avoid the unnecessary indirection.

Sadly, with ld/pe-dll.c using the wrapper, the removal requires moving
the declaration out of libcoff.h, to properly export the underlying BFD
function.
---
This isn't the first _bfd_generic_*() which is exported from libbfd.
While presumably not nice, it looks as if this is deemed tolerable
despite bfdint.texi saying otherwise.

--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2913,6 +2913,18 @@ const char *bfd_format_string (bfd_forma
    && bfd_is_abs_section ((H)->u.def.section) \
    && !(H)->rel_from_abs)
 
+bool _bfd_generic_link_add_one_symbol
+   (struct bfd_link_info *info,
+    bfd *abfd,
+    const char *name,
+    flagword flags,
+    asection *section,
+    bfd_vma value,
+    const char *string,
+    bool copy,
+    bool collect,
+    struct bfd_link_hash_entry **hashp);
+
 bool bfd_link_align_section (asection *, unsigned int);
 
 bool bfd_link_split_section (bfd *abfd, asection *sec);
--- a/bfd/coff-alpha.c
+++ b/bfd/coff-alpha.c
@@ -2359,7 +2359,7 @@ static const struct ecoff_backend_data a
     alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
     _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL, NULL
+    NULL, NULL, NULL,
   },
   /* Supported architecture.  */
   bfd_arch_alpha,
--- a/bfd/coff-arm.c
+++ b/bfd/coff-arm.c
@@ -1876,8 +1876,8 @@ record_arm_to_thumb_glue (struct bfd_lin
      it.  */
   bh = NULL;
   val = globals->arm_glue_size + 1;
-  bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
-				BSF_GLOBAL, s, val, NULL, true, false, &bh);
+  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
+				    BSF_GLOBAL, s, val, NULL, true, false, &bh);
 
   free (tmp_name);
 
@@ -1929,8 +1929,8 @@ record_thumb_to_arm_glue (struct bfd_lin
 
   bh = NULL;
   val = globals->thumb_glue_size + 1;
-  bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
-				BSF_GLOBAL, s, val, NULL, true, false, &bh);
+  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
+				    BSF_GLOBAL, s, val, NULL, true, false, &bh);
 
   /* If we mark it 'thumb', the disassembler will do a better job.  */
   myh = (struct coff_link_hash_entry *) bh;
@@ -1952,8 +1952,8 @@ record_thumb_to_arm_glue (struct bfd_lin
 
   bh = NULL;
   val = globals->thumb_glue_size + (globals->support_old_code ? 8 : 4);
-  bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
-				BSF_LOCAL, s, val, NULL, true, false, &bh);
+  _bfd_generic_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
+				    BSF_LOCAL, s, val, NULL, true, false, &bh);
 
   free (tmp_name);
 
--- a/bfd/coff-mips.c
+++ b/bfd/coff-mips.c
@@ -1316,7 +1316,7 @@ static const struct ecoff_backend_data m
     _bfd_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags,
     _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table,
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-    NULL, NULL, NULL
+    NULL, NULL,
   },
   /* Supported architecture.  */
   bfd_arch_mips,
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -4584,7 +4584,6 @@ static const struct xcoff_backend_data_r
       xcoff_ppc_relocate_section,
       coff_rtype_to_howto,
       NULL,			/* _bfd_coff_adjust_symndx */
-      _bfd_generic_link_add_one_symbol,
       coff_link_output_has_begun,
       coff_final_link_postscript,
       NULL			/* print_pdata.  */
@@ -4774,7 +4773,6 @@ static const struct xcoff_backend_data_r
       xcoff_ppc_relocate_section,
       coff_rtype_to_howto,
       NULL,			/* _bfd_coff_adjust_symndx */
-      _bfd_generic_link_add_one_symbol,
       coff_link_output_has_begun,
       coff_final_link_postscript,
       NULL			/* print_pdata.  */
--- a/bfd/coff-sh.c
+++ b/bfd/coff-sh.c
@@ -3108,7 +3108,7 @@ static const bfd_coff_backend_data bfd_c
   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   coff_classify_symbol, coff_compute_section_file_positions,
   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
-  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_adjust_symndx,
   coff_link_output_has_begun, coff_final_link_postscript,
   bfd_pe_print_pdata
 };
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -2495,7 +2495,6 @@ static const struct xcoff_backend_data_r
       xcoff64_ppc_relocate_section,
       coff_rtype_to_howto,
       NULL,			/* _bfd_coff_adjust_symndx */
-      _bfd_generic_link_add_one_symbol,
       coff_link_output_has_begun,
       coff_final_link_postscript,
       NULL			/* print_pdata.  */
@@ -2768,7 +2767,6 @@ static const struct xcoff_backend_data_r
       xcoff64_ppc_relocate_section,
       coff_rtype_to_howto,
       NULL,			/* _bfd_coff_adjust_symndx */
-      _bfd_generic_link_add_one_symbol,
       coff_link_output_has_begun,
       coff_final_link_postscript,
       NULL			/* print_pdata.  */
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -1516,11 +1516,6 @@ CODE_FRAGMENT
 .    (bfd *, struct bfd_link_info *, bfd *, asection *,
 .     struct internal_reloc *, bool *);
 .
-.  bool (*_bfd_coff_link_add_one_symbol)
-.    (struct bfd_link_info *, bfd *, const char *, flagword,
-.     asection *, bfd_vma, const char *, bool, bool,
-.     struct bfd_link_hash_entry **);
-.
 .  bool (*_bfd_coff_link_output_has_begun)
 .    (bfd *, struct coff_final_link_info *);
 .
@@ -1659,10 +1654,6 @@ INTERNAL
 .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
 .  ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
 .   (obfd, info, ibfd, sec, rel, adjustedp))
-.#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
-.				      value, string, cp, coll, hashp)\
-.  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
-.   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
 .
 .#define bfd_coff_link_output_has_begun(a,p) \
 .  ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
@@ -5513,10 +5504,6 @@ dummy_reloc16_extra_cases (bfd *abfd ATT
 #define coff_adjust_symndx NULL
 #endif
 
-#ifndef coff_link_add_one_symbol
-#define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
-#endif
-
 #ifndef coff_link_output_has_begun
 
 static bool
@@ -5615,7 +5602,7 @@ static const bfd_coff_backend_data bfd_c
   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   coff_classify_symbol, coff_compute_section_file_positions,
   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
-  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_adjust_symndx,
   coff_link_output_has_begun, coff_final_link_postscript,
   bfd_pe_print_pdata
 };
@@ -5656,7 +5643,7 @@ static const bfd_coff_backend_data ticof
   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   coff_classify_symbol, coff_compute_section_file_positions,
   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
-  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_adjust_symndx,
   coff_link_output_has_begun, coff_final_link_postscript,
   bfd_pe_print_pdata
 };
@@ -5698,7 +5685,7 @@ static const bfd_coff_backend_data ticof
   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   coff_classify_symbol, coff_compute_section_file_positions,
   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
-  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_adjust_symndx,
   coff_link_output_has_begun, coff_final_link_postscript,
   bfd_pe_print_pdata	/* huh */
 };
@@ -5941,7 +5928,7 @@ static const bfd_coff_backend_data bigob
   coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
   coff_classify_symbol, coff_compute_section_file_positions,
   coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
-  coff_adjust_symndx, coff_link_add_one_symbol,
+  coff_adjust_symndx,
   coff_link_output_has_begun, coff_final_link_postscript,
   bfd_pe_print_pdata	/* huh */
 };
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -451,7 +451,7 @@ coff_link_add_symbols (bfd *abfd,
 
 	  if (addit)
 	    {
-	      if (! (bfd_coff_link_add_one_symbol
+	      if (! (_bfd_generic_link_add_one_symbol
 		     (info, abfd, name, flags, section, value,
 		      (const char *) NULL, copy, false,
 		      (struct bfd_link_hash_entry **) sym_hash)))
--- a/bfd/libcoff.h
+++ b/bfd/libcoff.h
@@ -868,11 +868,6 @@ typedef struct
     (bfd *, struct bfd_link_info *, bfd *, asection *,
      struct internal_reloc *, bool *);
 
-  bool (*_bfd_coff_link_add_one_symbol)
-    (struct bfd_link_info *, bfd *, const char *, flagword,
-     asection *, bfd_vma, const char *, bool, bool,
-     struct bfd_link_hash_entry **);
-
   bool (*_bfd_coff_link_output_has_begun)
     (bfd *, struct coff_final_link_info *);
 
@@ -1009,10 +1004,6 @@ typedef struct
 #define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
   ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
    (obfd, info, ibfd, sec, rel, adjustedp))
-#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
-				     value, string, cp, coll, hashp)\
-  ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
-   (info, abfd, name, flags, section, value, string, cp, coll, hashp))
 
 #define bfd_coff_link_output_has_begun(a,p) \
   ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -645,12 +645,6 @@ extern bool _bfd_generic_link_add_archiv
 /* Forward declaration to avoid prototype errors.  */
 typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
 
-/* Generic routine to add a single symbol.  */
-extern bool _bfd_generic_link_add_one_symbol
-  (struct bfd_link_info *, bfd *, const char *name, flagword,
-   asection *, bfd_vma, const char *, bool copy,
-   bool constructor, struct bfd_link_hash_entry **) ATTRIBUTE_HIDDEN;
-
 /* Generic routine to mark section as supplying symbols only.  */
 extern void _bfd_generic_link_just_syms
   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -651,12 +651,6 @@ extern bool _bfd_generic_link_add_archiv
 /* Forward declaration to avoid prototype errors.  */
 typedef struct bfd_link_hash_entry _bfd_link_hash_entry;
 
-/* Generic routine to add a single symbol.  */
-extern bool _bfd_generic_link_add_one_symbol
-  (struct bfd_link_info *, bfd *, const char *name, flagword,
-   asection *, bfd_vma, const char *, bool copy,
-   bool constructor, struct bfd_link_hash_entry **) ATTRIBUTE_HIDDEN;
-
 /* Generic routine to mark section as supplying symbols only.  */
 extern void _bfd_generic_link_just_syms
   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -1378,7 +1378,25 @@ hash_entry_bfd (struct bfd_link_hash_ent
   /*NOTREACHED*/
 }
 
-/* Add a symbol to the global hash table.
+/*
+FUNCTION
+	_bfd_generic_link_add_one_symbol
+
+SYNOPSIS
+	bool _bfd_generic_link_add_one_symbol
+	  (struct bfd_link_info *info,
+	   bfd *abfd,
+	   const char *name,
+	   flagword flags,
+	   asection *section,
+	   bfd_vma value,
+	   const char *string,
+	   bool copy,
+	   bool collect,
+	   struct bfd_link_hash_entry **hashp);
+
+DESCRIPTION
+   Add a symbol to the global hash table.
    ABFD is the BFD the symbol comes from.
    NAME is the name of the symbol.
    FLAGS is the BSF_* bits associated with the symbol.
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -2638,9 +2638,9 @@ make_import_fixup_mark (arelent *rel, ch
   memcpy (fixup_name, buf, prefix_len);
 
   bh = NULL;
-  bfd_coff_link_add_one_symbol (&link_info, abfd, fixup_name, BSF_GLOBAL,
-				current_sec, /* sym->section, */
-				rel->address, NULL, true, false, &bh);
+  _bfd_generic_link_add_one_symbol (&link_info, abfd, fixup_name, BSF_GLOBAL,
+				    current_sec, /* sym->section, */
+				    rel->address, NULL, true, false, &bh);
 
   return bh->root.string;
 }



More information about the Binutils mailing list