]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
filter_implib_symbols master
authorAlan Modra <amodra@gmail.com>
Sat, 6 Jun 2026 01:38:11 +0000 (11:08 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 6 Jun 2026 01:38:11 +0000 (11:08 +0930)
This tidies filter_implib_symbols implementations, which I noticed
returned unsigned int but took long symbol counts.  While unsigned int
is very likely sufficient, size_t is better.

_bfd_elf_filter_global_symbols is a linker-only function so really
should be moved to elflink.c, but I left it in elf.c as it calls
sym_is_global, a static function in elf.c.

* elf-bfd.h (struct elf_backend_data): Take size_t symcount
and return a size_t from elf_backend_filter_implib_symbols.
(_bfd_elf_filter_implib_symbols): Likewise.  Rename from
_bfd_elf_filter_global_symbols.
* elf.c (_bfd_elf_filter_implib_symbols): Likewise.  Use
size_t vars too, and avoid unnecessary casts.
* elf32-arm.c (elf32_arm_filter_cmse_symbols): Likewise.
(elf32_arm_filter_implib_symbols): Likewise.
* elflink.c (elf_output_implib): Avoid unneccesary casts.
Call elf_backend_filter_implib_symbols uncontitionally.
* elfxx-target.h (elf_backend_filter_implib_symbols): Define
fallback as _bfd_elf_filter_implib_symbols.

bfd/elf-bfd.h
bfd/elf.c
bfd/elf32-arm.c
bfd/elflink.c
bfd/elfxx-target.h

index 879dd62dbd6f83ec7daa9697b27ded3d2d11fb83..88d359259870253ea95c400741cbad7db6970452 100644 (file)
@@ -1400,8 +1400,8 @@ struct elf_backend_data
 
   /* Filter what symbols of the output file to include in the import
      library if one is created.  */
-  unsigned int (*elf_backend_filter_implib_symbols)
-    (struct bfd_link_info *, asymbol **, long);
+  size_t (*elf_backend_filter_implib_symbols)
+    (struct bfd_link_info *, asymbol **, size_t);
 
   /* Copy any information related to dynamic linking from a pre-existing
      symbol to a newly created symbol.  Also called to copy flags and
@@ -2459,8 +2459,8 @@ extern bool _bfd_elf_section_already_linked
   (bfd *, asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
 extern void bfd_elf_set_group_contents
   (bfd *, asection *, void *);
-extern unsigned int _bfd_elf_filter_global_symbols
-  (struct bfd_link_info *, asymbol **, long) ATTRIBUTE_HIDDEN;
+extern size_t _bfd_elf_filter_implib_symbols
+  (struct bfd_link_info *, asymbol **, size_t) ATTRIBUTE_HIDDEN;
 extern asection *_bfd_elf_check_kept_section
   (asection *, struct bfd_link_info *) ATTRIBUTE_HIDDEN;
 #define _bfd_elf_link_just_syms _bfd_generic_link_just_syms
index 1e1f09c8bbc881f7868182248f944bfd9c767326..c9a68404e9d146ceac55ed37b8a0c1f64124f99c 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4462,16 +4462,16 @@ sym_is_global (bfd *abfd, asymbol *sym)
 
    Returns the number of symbols to keep.  */
 
-unsigned int
-_bfd_elf_filter_global_symbols (struct bfd_link_info *info,
-                               asymbol **syms, long symcount)
+size_t
+_bfd_elf_filter_implib_symbols (struct bfd_link_info *info,
+                               asymbol **syms, size_t symcount)
 {
-  long src_count, dst_count = 0;
+  size_t src_count, dst_count = 0;
 
   for (src_count = 0; src_count < symcount; src_count++)
     {
       asymbol *sym = syms[src_count];
-      char *name = (char *) bfd_asymbol_name (sym);
+      const char *name = bfd_asymbol_name (sym);
       struct bfd_link_hash_entry *h;
 
       if (!sym_is_global (info->output_bfd, sym))
index 63b908462b1c754e743d2de1713b7b8794882ea0..e27aff48411ce8b4ebbe9bd8d6ee4395e376d8ca 100644 (file)
@@ -18250,13 +18250,13 @@ elf32_arm_output_arch_local_syms (struct bfd_link_info *info,
 
    Returns the number of symbols to keep.  */
 
-static unsigned int
+static size_t
 elf32_arm_filter_cmse_symbols (struct bfd_link_info *info,
-                              asymbol **syms, long symcount)
+                              asymbol **syms, size_t symcount)
 {
   size_t maxnamelen;
   char *cmse_name;
-  long src_count, dst_count = 0;
+  size_t src_count, dst_count = 0;
   struct elf32_arm_link_hash_table *htab;
 
   htab = elf32_arm_hash_table (info);
@@ -18264,7 +18264,7 @@ elf32_arm_filter_cmse_symbols (struct bfd_link_info *info,
     symcount = 0;
 
   maxnamelen = 128;
-  cmse_name = (char *) bfd_malloc (maxnamelen);
+  cmse_name = bfd_malloc (maxnamelen);
   BFD_ASSERT (cmse_name);
 
   for (src_count = 0; src_count < symcount; src_count++)
@@ -18272,12 +18272,12 @@ elf32_arm_filter_cmse_symbols (struct bfd_link_info *info,
       struct elf32_arm_link_hash_entry *cmse_hash;
       asymbol *sym;
       flagword flags;
-      char *name;
+      const char *name;
       size_t namelen;
 
       sym = syms[src_count];
       flags = sym->flags;
-      name = (char *) bfd_asymbol_name (sym);
+      name = bfd_asymbol_name (sym);
 
       if ((flags & BSF_FUNCTION) != BSF_FUNCTION)
        continue;
@@ -18287,8 +18287,7 @@ elf32_arm_filter_cmse_symbols (struct bfd_link_info *info,
       namelen = strlen (name) + sizeof (CMSE_PREFIX) + 1;
       if (namelen > maxnamelen)
        {
-         cmse_name = (char *)
-           bfd_realloc (cmse_name, namelen);
+         cmse_name = bfd_realloc (cmse_name, namelen);
          maxnamelen = namelen;
        }
       snprintf (cmse_name, maxnamelen, "%s%s", CMSE_PREFIX, name);
@@ -18317,9 +18316,9 @@ elf32_arm_filter_cmse_symbols (struct bfd_link_info *info,
 
    Returns the number of symbols to keep.  */
 
-static unsigned int
+static size_t
 elf32_arm_filter_implib_symbols (struct bfd_link_info *info,
-                                asymbol **syms, long symcount)
+                                asymbol **syms, size_t symcount)
 {
   struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
 
@@ -18330,7 +18329,7 @@ elf32_arm_filter_implib_symbols (struct bfd_link_info *info,
   if (globals->cmse_implib)
     return elf32_arm_filter_cmse_symbols (info, syms, symcount);
   else
-    return _bfd_elf_filter_global_symbols (info, syms, symcount);
+    return _bfd_elf_filter_implib_symbols (info, syms, symcount);
 }
 
 /* Allocate target specific section data.  */
index 502c80688476f53ec47346741ccaa922e13621a9..3c4332b549a2188d1af02f69b48a522ab5c45bb1 100644 (file)
@@ -12525,7 +12525,6 @@ elf_output_implib (bfd *obfd, struct bfd_link_info *info)
   long symcount;
   long src_count;
   elf_symbol_type *osymbuf;
-  size_t amt;
 
   implib_bfd = info->out_implib_bfd;
   obed = get_elf_backend_data (obfd);
@@ -12554,7 +12553,7 @@ elf_output_implib (bfd *obfd, struct bfd_link_info *info)
     return false;
 
   /* Read in the symbol table.  */
-  sympp = (asymbol **) bfd_malloc (symsize);
+  sympp = bfd_malloc (symsize);
   if (sympp == NULL)
     return false;
 
@@ -12568,10 +12567,7 @@ elf_output_implib (bfd *obfd, struct bfd_link_info *info)
     goto free_sym_buf;
 
   /* Filter symbols to appear in the import library.  */
-  if (obed->elf_backend_filter_implib_symbols)
-    symcount = obed->elf_backend_filter_implib_symbols (info, sympp, symcount);
-  else
-    symcount = _bfd_elf_filter_global_symbols (info, sympp, symcount);
+  symcount = obed->elf_backend_filter_implib_symbols (info, sympp, symcount);
   if (symcount == 0)
     {
       bfd_set_error (bfd_error_no_symbols);
@@ -12580,17 +12576,14 @@ elf_output_implib (bfd *obfd, struct bfd_link_info *info)
       goto free_sym_buf;
     }
 
-
   /* Make symbols absolute.  */
-  amt = symcount * sizeof (*osymbuf);
-  osymbuf = (elf_symbol_type *) bfd_alloc (implib_bfd, amt);
+  osymbuf = bfd_alloc (implib_bfd, symcount * sizeof (*osymbuf));
   if (osymbuf == NULL)
     goto free_sym_buf;
 
   for (src_count = 0; src_count < symcount; src_count++)
     {
-      memcpy (&osymbuf[src_count], (elf_symbol_type *) sympp[src_count],
-             sizeof (*osymbuf));
+      memcpy (&osymbuf[src_count], sympp[src_count], sizeof (*osymbuf));
       osymbuf[src_count].symbol.section = bfd_abs_section_ptr;
       osymbuf[src_count].internal_elf_sym.st_shndx = SHN_ABS;
       osymbuf[src_count].symbol.value += sympp[src_count]->section->vma;
index b6dfc108f27384749863f3f39e07e12abe31aca1..03689f68ea319424bef59f9f396da22143d6fa3b 100644 (file)
 #define elf_backend_output_arch_syms           NULL
 #endif
 #ifndef elf_backend_filter_implib_symbols
-#define elf_backend_filter_implib_symbols      NULL
+#define elf_backend_filter_implib_symbols      _bfd_elf_filter_implib_symbols
 #endif
 #ifndef elf_backend_copy_indirect_symbol
 #define elf_backend_copy_indirect_symbol       _bfd_elf_link_hash_copy_indirect