Duplicate bfd_sym_from_r_symndx lookup

Message ID auJ4bvQSeduo3CXX@squeak.grove.modra.org
State New
Headers
Series Duplicate bfd_sym_from_r_symndx lookup |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Oct. 28, 2026, 10:34 p.m. UTC
  elf32-csky.c, elf32-i386.c, elf32-s390.c, elf64-s390.c, elf64-x86-64.c,
elfnn-aarch64.c, elfnn-kvx.c and elfnn-riscv.c all repeat a local sym
lookup in their check_relocs function.  Fix that, and trim an old
comment in the other files touched here.
  

Patch

diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 3bcf7ea26b3..f8a20e49ce8 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -3696,9 +3696,7 @@  elf32_arm_get_local_dynreloc_list (bfd *abfd, unsigned long r_symndx,
     }
   else
     {
-      /* Track dynamic relocs needed for local syms too.
-	 We really need local syms available to do this
-	 easily.  Oh well.  */
+      /* Track dynamic relocs needed for local syms too.  */
       asection *s;
       void *vpp;
 
diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
index 484135d2622..239662e0748 100644
--- a/bfd/elf32-csky.c
+++ b/bfd/elf32-csky.c
@@ -2602,18 +2602,11 @@  csky_elf_check_relocs (bfd * abfd,
 		}
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  void **vpp;
 		  asection *s;
-		  Elf_Internal_Sym *loc_isym;
 
-		  loc_isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						    abfd, r_symndx);
-		  if (loc_isym == NULL)
-		    return false;
-		  s = bfd_section_from_elf_index (abfd, loc_isym->st_shndx);
+		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
 		  vpp = &elf_section_data (s)->local_dynrel;
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index a9ae5f4e771..b7c84d26481 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -1454,9 +1454,7 @@  elf32_hppa_check_relocs (bfd *abfd,
 		}
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *sr;
 		  void *vpp;
 		  Elf_Internal_Sym *isym;
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index b108a45ea72..1f7d9736bb8 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1948,17 +1948,10 @@  elf_i386_scan_relocs (bfd *abfd,
 		}
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  void **vpp;
 		  asection *s;
 
-		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						abfd, r_symndx);
-		  if (isym == NULL)
-		    goto error_return;
-
 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index e0517756aab..b67c4be414e 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -2657,10 +2657,7 @@  microblaze_elf_check_relocs (bfd * abfd,
 		  head = &h->dyn_relocs;
 		else
 		  {
-		    /* Track dynamic relocs needed for local syms too.
-		       We really need local syms available to do this
-		       easily.  Oh well.  */
-
+		    /* Track dynamic relocs needed for local syms too.  */
 		    asection *s;
 		    Elf_Internal_Sym *isym;
 		    void *vpp;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 2aaed81b894..537c1a8e9b1 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -2232,10 +2232,7 @@  or1k_elf_check_relocs (bfd *abfd,
 		  head = &h->dyn_relocs;
 		else
 		  {
-		    /* Track dynamic relocs needed for local syms too.
-		       We really need local syms available to do this
-		       easily.  Oh well.  */
-
+		    /* Track dynamic relocs needed for local syms too.  */
 		    asection *s;
 		    Elf_Internal_Sym *isym;
 		    void *vpp;
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 22cdf6471e0..0a831ab5ee7 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -3472,9 +3472,7 @@  ppc_elf_check_relocs (bfd *abfd,
 		}
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  struct ppc_dyn_relocs *p;
 		  struct ppc_dyn_relocs **rel_head;
 		  bool is_ifunc;
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index cce9658591c..1f2e94aa943 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -912,7 +912,7 @@  elf_s390_check_relocs (bfd *abfd,
       unsigned int r_type;
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
-      const Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym = NULL;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
@@ -1263,22 +1263,13 @@  elf_s390_check_relocs (bfd *abfd,
 	      /* If this is a global symbol, we count the number of
 		 relocations we need for this symbol.  */
 	      if (h != NULL)
-		{
-		  head = &h->dyn_relocs;
-		}
+		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 
-		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						abfd, r_symndx);
-		  if (isym == NULL)
-		    return false;
-
 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c
index 297df3962df..c21bc6444f6 100644
--- a/bfd/elf32-tic6x.c
+++ b/bfd/elf32-tic6x.c
@@ -2855,9 +2855,7 @@  elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		}
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  void **vpp;
 		  asection *s;
 
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index b759e528a29..dca0ea314b7 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -1711,10 +1711,7 @@  tilepro_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
-
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 		  Elf_Internal_Sym *isym;
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index fdd0fcdae85..23482e2646e 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -925,7 +925,7 @@  elf_s390_check_relocs (bfd *abfd,
       unsigned int r_type;
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
-      const Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym = NULL;
 
       r_symndx = ELF64_R_SYM (rel->r_info);
 
@@ -1328,22 +1328,13 @@  elf_s390_check_relocs (bfd *abfd,
 	      /* If this is a global symbol, we count the number of
 		 relocations we need for this symbol.  */
 	      if (h != NULL)
-		{
-		  head = &h->dyn_relocs;
-		}
+		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 
-		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						abfd, r_symndx);
-		  if (isym == NULL)
-		    return false;
-
 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 3b200a62435..948cc2d48ce 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3015,17 +3015,10 @@  need_got:
 		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void **vpp;
 
-		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						abfd, r_symndx);
-		  if (isym == NULL)
-		    goto error_return;
-
 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 0008131a08a..dbb29549df0 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -7956,7 +7956,7 @@  elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_type;
       bfd_reloc_code_real_type bfd_r_type;
       struct elf_link_hash_entry *h;
-      const Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym = NULL;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
@@ -8181,23 +8181,13 @@  elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	    /* If this is a global symbol, we count the number of
 	       relocations we need for this symbol.  */
 	    if (h != NULL)
-	      {
-		head = &h->dyn_relocs;
-	      }
+	      head = &h->dyn_relocs;
 	    else
 	      {
-		/* Track dynamic relocs needed for local syms too.
-		   We really need local syms available to do this
-		   easily.  Oh well.  */
-
+		/* Track dynamic relocs needed for local syms too.  */
 		asection *s;
 		void **vpp;
 
-		isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
-					      abfd, r_symndx);
-		if (isym == NULL)
-		  return false;
-
 		s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		if (s == NULL)
 		  s = sec;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 831091c2129..30db3234ec3 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -3213,7 +3213,7 @@  elfNN_kvx_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_type;
       bfd_reloc_code_real_type bfd_r_type;
       struct elf_link_hash_entry *h;
-      const Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym = NULL;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
@@ -3318,18 +3318,10 @@  elfNN_kvx_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	      }
 	    else
 	      {
-		/* Track dynamic relocs needed for local syms too.
-		   We really need local syms available to do this
-		   easily.  Oh well.  */
-
+		/* Track dynamic relocs needed for local syms too.  */
 		asection *s;
 		void **vpp;
 
-		isym = bfd_sym_from_r_symndx (&htab->sym_cache,
-					      abfd, r_symndx);
-		if (isym == NULL)
-		  return false;
-
 		s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		if (s == NULL)
 		  s = sec;
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 00b4a87147b..15f44420b4c 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -1529,10 +1529,7 @@  loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	    head = &h->dyn_relocs;
 	  else
 	    {
-	      /* Track dynamic relocs needed for local syms too.
-		 We really need local syms available to do this
-		 easily.  Oh well.  */
-
+	      /* Track dynamic relocs needed for local syms too.  */
 	      asection *s;
 	      void *vpp;
 
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index f5cc7505d57..880b7ce6ee8 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1064,7 +1064,7 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_type;
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
-      const Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym = NULL;
       bool is_abs_symbol = false;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
@@ -1322,18 +1322,10 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
-
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 
-		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-						abfd, r_symndx);
-		  if (isym == NULL)
-		    return false;
-
 		  s = bfd_section_from_elf_index (abfd, isym->st_shndx);
 		  if (s == NULL)
 		    s = sec;
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index 04c1071cc17..694ae638c1d 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -1761,9 +1761,7 @@  _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index 2479a4be6c7..520a24125e3 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -1958,10 +1958,7 @@  tilegx_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		head = &h->dyn_relocs;
 	      else
 		{
-		  /* Track dynamic relocs needed for local syms too.
-		     We really need local syms available to do this
-		     easily.  Oh well.  */
-
+		  /* Track dynamic relocs needed for local syms too.  */
 		  asection *s;
 		  void *vpp;
 		  Elf_Internal_Sym *isym;