Constify Elf_Internal_Sym in check_relocs and relocate_section

Message ID auJ4TRFxFSLjHqYU@squeak.grove.modra.org
State New
Headers
Series Constify Elf_Internal_Sym in check_relocs and relocate_section |

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:33 p.m. UTC
  At one point when looking at pr34835 I started changing check_relocs
and relocate_section to support relocs against STN_UNDEF without a
.symtab section present.  I gave up on that idea because there are
many other functions that would need changing too, but kept this part
which involves making some variable and function parameter pointers
const.
  

Patch

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index cd523be2166..c51d41c8eb4 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2381,7 +2381,7 @@  extern Elf_Internal_Sym *bfd_elf_get_elf_syms
    Elf_External_Sym_Shndx *);
 extern char * bfd_elf_get_str_section (bfd *, unsigned int);
 extern const char *bfd_elf_sym_name
-  (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
+  (bfd *, Elf_Internal_Shdr *, const Elf_Internal_Sym *, asection *);
 
 extern bool _bfd_elf_copy_private_bfd_data
   (bfd *, bfd *) ATTRIBUTE_HIDDEN;
@@ -2405,10 +2405,10 @@  extern enum elf_reloc_type_class _bfd_elf_reloc_type_class
   (const struct bfd_link_info *, const asection *,
    const Elf_Internal_Rela *) ATTRIBUTE_HIDDEN;
 extern bfd_vma _bfd_elf_rela_local_sym
-  (bfd *, Elf_Internal_Sym *, asection **, Elf_Internal_Rela *)
+  (bfd *, const Elf_Internal_Sym *, asection **, Elf_Internal_Rela *)
   ATTRIBUTE_HIDDEN;
 extern bfd_vma _bfd_elf_rel_local_sym
-  (bfd *, Elf_Internal_Sym *, asection **, bfd_vma) ATTRIBUTE_HIDDEN;
+  (bfd *, const Elf_Internal_Sym *, asection **, bfd_vma) ATTRIBUTE_HIDDEN;
 extern bfd_vma _bfd_elf_section_offset
   (bfd *, struct bfd_link_info *, asection *, bfd_vma) ATTRIBUTE_HIDDEN;
 
diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
index 6aacb0da703..22a165873c3 100644
--- a/bfd/elf-m10200.c
+++ b/bfd/elf-m10200.c
@@ -358,7 +358,7 @@  mn10200_elf_relocate_section (struct bfd_link_info *info,
       int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf.c b/bfd/elf.c
index b634ed0c472..e6699a5ffc9 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -627,7 +627,7 @@  bfd_elf_get_elf_syms (bfd *ibfd,
 static const char *
 bfd_elf_sym_name_raw (bfd *abfd,
 		      Elf_Internal_Shdr *symtab_hdr,
-		      Elf_Internal_Sym *isym)
+		      const Elf_Internal_Sym *isym)
 {
   unsigned int iname = isym->st_name;
   unsigned int shindex = symtab_hdr->sh_link;
@@ -646,7 +646,7 @@  bfd_elf_sym_name_raw (bfd *abfd,
 const char *
 bfd_elf_sym_name (bfd *abfd,
 		  Elf_Internal_Shdr *symtab_hdr,
-		  Elf_Internal_Sym *isym,
+		  const Elf_Internal_Sym *isym,
 		  asection *sym_sec)
 {
   const char *name = bfd_elf_sym_name_raw (abfd, symtab_hdr, isym);
@@ -13319,7 +13319,7 @@  _bfd_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
 
 bfd_vma
 _bfd_elf_rela_local_sym (bfd *abfd,
-			 Elf_Internal_Sym *sym,
+			 const Elf_Internal_Sym *sym,
 			 asection **psec,
 			 Elf_Internal_Rela *rel)
 {
@@ -13355,7 +13355,7 @@  _bfd_elf_rela_local_sym (bfd *abfd,
 
 bfd_vma
 _bfd_elf_rel_local_sym (bfd *abfd,
-			Elf_Internal_Sym *sym,
+			const Elf_Internal_Sym *sym,
 			asection **psec,
 			bfd_vma addend)
 {
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 29b173cf486..fc58da0efa7 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1468,7 +1468,7 @@  elf_arc_relocate_section (struct bfd_link_info *  info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h2;
       const char *msg;
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index bcba4cc3a1b..3bcf7ea26b3 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -3683,7 +3683,7 @@  elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info *info,
 
 static struct elf_dyn_relocs **
 elf32_arm_get_local_dynreloc_list (bfd *abfd, unsigned long r_symndx,
-				   Elf_Internal_Sym *isym)
+				   const Elf_Internal_Sym *isym)
 {
   if (ELF32_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
     {
@@ -13040,7 +13040,7 @@  elf32_arm_relocate_section (struct bfd_link_info * info,
       int			   r_type;
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
@@ -15241,7 +15241,7 @@  elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
     {
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       struct elf_link_hash_entry *h;
       struct elf32_arm_link_hash_entry *eh;
       unsigned int r_symndx;
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index cdb6b610baf..082b86a307d 100644
--- a/bfd/elf32-avr.c
+++ b/bfd/elf32-avr.c
@@ -1523,7 +1523,7 @@  elf32_avr_relocate_section (struct bfd_link_info *info, bfd *input_bfd,
       unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
       reloc_howto_type *howto = elf_avr_howto_table + r_type;
       struct elf_link_hash_entry *h = NULL;
-      Elf_Internal_Sym *sym = NULL;
+      const Elf_Internal_Sym *sym = NULL;
       asection *sec = NULL;
 
       if (r_symndx < symtab_hdr->sh_info)
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index c4d9389a04a..af8826a811f 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -1391,7 +1391,7 @@  bfin_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation = 0;
       bool unresolved_reloc;
diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
index 1a8a3b28180..23365147b41 100644
--- a/bfd/elf32-cr16.c
+++ b/bfd/elf32-cr16.c
@@ -1355,7 +1355,7 @@  elf32_cr16_relocate_section (struct bfd_link_info *info,
       int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c
index 938f3bc7bbb..3cf4c923050 100644
--- a/bfd/elf32-cris.c
+++ b/bfd/elf32-cris.c
@@ -1013,7 +1013,7 @@  cris_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
index 549486ccb2c..16abc3814c0 100644
--- a/bfd/elf32-crx.c
+++ b/bfd/elf32-crx.c
@@ -849,7 +849,7 @@  elf32_crx_relocate_section (struct bfd_link_info *info,
       int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
index 4069e34df5c..484135d2622 100644
--- a/bfd/elf32-csky.c
+++ b/bfd/elf32-csky.c
@@ -2493,7 +2493,7 @@  csky_elf_check_relocs (bfd * abfd,
     {
       struct elf_link_hash_entry *h;
       unsigned long r_symndx;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       int r_type;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
@@ -4303,7 +4303,7 @@  csky_elf_relocate_section (struct bfd_link_info * info,
 	= (enum elf_csky_reloc_type) ELF32_R_TYPE (rel->r_info);
       unsigned long r_symndx;
       reloc_howto_type *howto;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation;
       bfd_vma off;
diff --git a/bfd/elf32-d10v.c b/bfd/elf32-d10v.c
index 384162e23ff..e8086bb82dd 100644
--- a/bfd/elf32-d10v.c
+++ b/bfd/elf32-d10v.c
@@ -410,7 +410,7 @@  elf32_d10v_relocate_section (struct bfd_link_info *info,
       int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
index c35b4551d2c..5cb317ff155 100644
--- a/bfd/elf32-epiphany.c
+++ b/bfd/elf32-epiphany.c
@@ -491,7 +491,7 @@  epiphany_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-fr30.c b/bfd/elf32-fr30.c
index 0e158841082..2f1f3ba36b9 100644
--- a/bfd/elf32-fr30.c
+++ b/bfd/elf32-fr30.c
@@ -508,7 +508,7 @@  fr30_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
index 42efc672b34..71f40ca04f2 100644
--- a/bfd/elf32-frv.c
+++ b/bfd/elf32-frv.c
@@ -1322,7 +1322,7 @@  _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
 				       bfd *output_bfd,
 				       struct bfd_link_info *info,
 				       asection *sec,
-				       Elf_Internal_Sym *sym,
+				       const Elf_Internal_Sym *sym,
 				       bfd_vma addend)
 
 {
@@ -2703,7 +2703,7 @@  elf32_frv_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
index f2892c266e4..3e4e6f3988b 100644
--- a/bfd/elf32-ft32.c
+++ b/bfd/elf32-ft32.c
@@ -363,7 +363,7 @@  ft32_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
index d667243a387..f9550c6f694 100644
--- a/bfd/elf32-h8300.c
+++ b/bfd/elf32-h8300.c
@@ -441,7 +441,7 @@  elf32_h8_relocate_section (struct bfd_link_info *info,
     {
       unsigned int r_type;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 7b20f14751d..a9ae5f4e771 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -3560,7 +3560,7 @@  elf32_hppa_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned int r_symndx;
       struct elf32_hppa_link_hash_entry *hh;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sym_sec;
       bfd_vma relocation;
       bfd_reloc_status_type rstatus;
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index e0992ab20cd..b108a45ea72 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1064,7 +1064,7 @@  elf_i386_tls_transition (struct bfd_link_info *info, bfd *abfd,
 			 const Elf_Internal_Rela *rel,
 			 const Elf_Internal_Rela *relend,
 			 struct elf_link_hash_entry *h,
-			 Elf_Internal_Sym *sym,
+			 const Elf_Internal_Sym *sym,
 			 bool from_relocate_section)
 {
   unsigned int from_type = *r_type;
@@ -1571,7 +1571,7 @@  elf_i386_scan_relocs (bfd *abfd,
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
       struct elf_x86_link_hash_entry *eh;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       const char *name;
       bool size_reloc;
       bool no_dynreloc;
@@ -2165,7 +2165,7 @@  elf_i386_relocate_section (struct bfd_link_info *info,
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
       struct elf_x86_link_hash_entry *eh;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma off, offplt, plt_offset;
       bfd_vma relocation;
diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
index d050d679b72..40704f86163 100644
--- a/bfd/elf32-ip2k.c
+++ b/bfd/elf32-ip2k.c
@@ -1407,7 +1407,7 @@  ip2k_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-iq2000.c b/bfd/elf32-iq2000.c
index 8daeca8c1bd..e5f05313d84 100644
--- a/bfd/elf32-iq2000.c
+++ b/bfd/elf32-iq2000.c
@@ -583,7 +583,7 @@  iq2000_elf_relocate_section (struct bfd_link_info *  info,
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c
index b9768952e19..e9fbb1a131e 100644
--- a/bfd/elf32-lm32.c
+++ b/bfd/elf32-lm32.c
@@ -747,7 +747,7 @@  lm32_elf_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned int r_type;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
index 8b5bacafd31..dd8b24aa504 100644
--- a/bfd/elf32-m68hc1x.c
+++ b/bfd/elf32-m68hc1x.c
@@ -960,7 +960,7 @@  elf32_m68hc11_relocate_section (struct bfd_link_info *info,
       arelent arel;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation = 0;
       bfd_reloc_status_type r = bfd_reloc_undefined;
diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
index 1bc72c7ae42..f1027df4b48 100644
--- a/bfd/elf32-m68k.c
+++ b/bfd/elf32-m68k.c
@@ -3459,7 +3459,7 @@  elf_m68k_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation;
       bool unresolved_reloc;
diff --git a/bfd/elf32-mcore.c b/bfd/elf32-mcore.c
index 761ce7f17ce..0b0a724facf 100644
--- a/bfd/elf32-mcore.c
+++ b/bfd/elf32-mcore.c
@@ -425,7 +425,7 @@  mcore_elf_relocate_section (struct bfd_link_info * info,
       asection *		   sec = NULL;
       reloc_howto_type *	   howto;
       bfd_vma			   relocation;
-      Elf_Internal_Sym *	   sym = NULL;
+      const Elf_Internal_Sym *	   sym = NULL;
       unsigned long		   r_symndx;
       struct elf_link_hash_entry * h = NULL;
       unsigned short		   oldinst = 0;
diff --git a/bfd/elf32-mep.c b/bfd/elf32-mep.c
index 9c47a416fec..1320728549f 100644
--- a/bfd/elf32-mep.c
+++ b/bfd/elf32-mep.c
@@ -449,7 +449,7 @@  mep_elf_relocate_section
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
index d1e096e1164..0eb004057d1 100644
--- a/bfd/elf32-metag.c
+++ b/bfd/elf32-metag.c
@@ -1451,7 +1451,7 @@  elf_metag_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_metag_link_hash_entry *hh;
       bfd_vma relocation;
@@ -2061,7 +2061,7 @@  elf_metag_check_relocs (bfd *abfd,
     {
       int r_type;
       struct elf_metag_link_hash_entry *hh;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       unsigned long r_symndx;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index 027b1886e9a..e0517756aab 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -1061,7 +1061,7 @@  microblaze_elf_relocate_section (struct bfd_link_info *info,
       bfd_vma addend = rel->r_addend;
       bfd_vma offset = rel->r_offset;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       asection *sym_sec;
       const char *sym_name;
diff --git a/bfd/elf32-moxie.c b/bfd/elf32-moxie.c
index f9948d0bfd3..31ab42890b7 100644
--- a/bfd/elf32-moxie.c
+++ b/bfd/elf32-moxie.c
@@ -219,7 +219,7 @@  moxie_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
index c36e6216a04..adba0e25f1b 100644
--- a/bfd/elf32-msp430.c
+++ b/bfd/elf32-msp430.c
@@ -1395,7 +1395,7 @@  elf32_msp430_relocate_section (struct bfd_link_info * info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-mt.c b/bfd/elf32-mt.c
index ea22a420e98..f1e5d8c48ad 100644
--- a/bfd/elf32-mt.c
+++ b/bfd/elf32-mt.c
@@ -316,7 +316,7 @@  mt_elf_relocate_section
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 25dae98adb3..cde22dc2a9b 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -5114,7 +5114,7 @@  nds32_elf_relocate_section (struct bfd_link_info * info,
       reloc_howto_type *howto = NULL;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h = NULL;
-      Elf_Internal_Sym *sym = NULL;
+      const Elf_Internal_Sym *sym = NULL;
       asection *sec;
       bfd_vma relocation;
       bfd_vma relocation_sym = 0xdeadbeef;
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 49ce3ce0dad..2aaed81b894 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -1353,7 +1353,7 @@  or1k_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index b2395c1b0a6..22cdf6471e0 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -2914,7 +2914,7 @@  ppc_elf_check_relocs (bfd *abfd,
       unsigned long r_symndx;
       enum elf_ppc_reloc_type r_type;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       int tls_type;
       struct plt_entry **ifunc;
       struct plt_entry **pltent;
@@ -7029,7 +7029,7 @@  ppc_elf_relocate_section (struct bfd_link_info *info,
       enum elf_ppc_reloc_type r_type;
       bfd_vma addend;
       bfd_reloc_status_type r;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       const char *sym_name;
diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
index bc5422ce5b9..26bf2e17e80 100644
--- a/bfd/elf32-pru.c
+++ b/bfd/elf32-pru.c
@@ -708,7 +708,7 @@  pru_elf32_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
index 8ce087ef28b..37db811255e 100644
--- a/bfd/elf32-rl78.c
+++ b/bfd/elf32-rl78.c
@@ -739,7 +739,7 @@  rl78_elf_relocate_section
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
index 981a9729367..e100b3cd0ea 100644
--- a/bfd/elf32-rx.c
+++ b/bfd/elf32-rx.c
@@ -524,7 +524,7 @@  rx_elf_relocate_section
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 455b78ae620..cce9658591c 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -893,7 +893,6 @@  elf_s390_check_relocs (bfd *abfd,
   asection *sreloc;
   bfd_signed_vma *local_got_refcounts;
   int tls_type, old_tls_type;
-  Elf_Internal_Sym *isym;
 
   if (bfd_link_relocatable (info))
     return true;
@@ -913,6 +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;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
@@ -2044,7 +2044,7 @@  elf_s390_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma off;
       bfd_vma relocation;
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 1b111f3611b..a78a9c38d15 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -3441,7 +3441,7 @@  sh_elf_relocate_section (struct bfd_link_info *info,
       int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c
index f1838bf015b..297df3962df 100644
--- a/bfd/elf32-tic6x.c
+++ b/bfd/elf32-tic6x.c
@@ -2165,7 +2165,7 @@  elf32_tic6x_relocate_section (struct bfd_link_info *info,
       unsigned long r_symndx;
       arelent bfd_reloc;
       reloc_howto_type *howto;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma off, off2, relocation;
@@ -2705,7 +2705,7 @@  elf32_tic6x_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_type;
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
       r_type = ELF32_R_TYPE (rel->r_info);
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index 731f7300d2a..b759e528a29 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -2542,7 +2542,7 @@  tilepro_elf_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       tilepro_create_func create_func;
       asection *sec;
       bfd_vma relocation;
diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
index 8ffbc024156..6956fa8c499 100644
--- a/bfd/elf32-v850.c
+++ b/bfd/elf32-v850.c
@@ -2199,7 +2199,7 @@  v850_elf_relocate_section (struct bfd_link_info *info,
       unsigned int r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
index 3a302ddce9a..ddeafae92a8 100644
--- a/bfd/elf32-vax.c
+++ b/bfd/elf32-vax.c
@@ -1226,7 +1226,7 @@  elf_vax_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation;
       bfd_reloc_status_type r;
diff --git a/bfd/elf32-visium.c b/bfd/elf32-visium.c
index b862b13614e..6276c75a791 100644
--- a/bfd/elf32-visium.c
+++ b/bfd/elf32-visium.c
@@ -568,7 +568,7 @@  visium_elf_relocate_section (struct bfd_link_info *info, bfd *input_bfd,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
index e7b05058f9d..071552b9404 100644
--- a/bfd/elf32-xstormy16.c
+++ b/bfd/elf32-xstormy16.c
@@ -785,7 +785,7 @@  xstormy16_elf_relocate_section (struct bfd_link_info *	info,
     {
       reloc_howto_type *	   howto;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index 413e08a38b4..847c57bcd25 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -2631,7 +2631,7 @@  elf_xtensa_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       char sym_type;
       const char *name;
       asection *sec;
diff --git a/bfd/elf32-z80.c b/bfd/elf32-z80.c
index 4393a6130d1..a44a53351bc 100644
--- a/bfd/elf32-z80.c
+++ b/bfd/elf32-z80.c
@@ -405,7 +405,7 @@  z80_elf_relocate_section (struct bfd_link_info *info,
     {
       unsigned int r_type;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index a4f4989abb6..e542d0bc88b 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -1807,7 +1807,7 @@  elf64_alpha_sort_relocs_p (asection *sec)
 
 static bool
 elf64_alpha_ifunc_p (struct alpha_elf_link_hash_entry *h,
-		     Elf_Internal_Sym *sym)
+		     const Elf_Internal_Sym *sym)
 {
   if (h != NULL)
     return h->root.type == STT_GNU_IFUNC && h->root.def_regular;
@@ -1831,7 +1831,7 @@  elf64_alpha_ifunc_reloc_p (unsigned long r_type)
 
 static bool
 elf64_alpha_ifunc_irelplt_p (struct alpha_elf_link_hash_entry *h,
-			     Elf_Internal_Sym *sym,
+			     const Elf_Internal_Sym *sym,
 			     struct bfd_link_info *info)
 {
   if (!elf64_alpha_ifunc_p (h, sym) || bfd_link_pic (info))
@@ -2114,7 +2114,7 @@  elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       unsigned long r_symndx, r_type;
       struct alpha_elf_link_hash_entry *h;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       unsigned int gotent_flags;
       bool maybe_dynamic;
       unsigned int need;
@@ -4460,7 +4460,7 @@  elf64_alpha_relocate_section_r (struct bfd_link_info *info ATTRIBUTE_UNUSED,
 static const char *
 elf64_alpha_sym_name (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
 		      struct alpha_elf_link_hash_entry *h,
-		      Elf_Internal_Sym *sym, asection *sec)
+		      const Elf_Internal_Sym *sym, asection *sec)
 {
   if (h != NULL)
     return h->root.root.root.string;
@@ -4541,7 +4541,7 @@  elf64_alpha_relocate_section (struct bfd_link_info *info,
       bfd_reloc_status_type r;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym = NULL;
+      const Elf_Internal_Sym *sym = NULL;
       asection *sec = NULL;
       bfd_vma value;
       bfd_vma addend;
diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c
index 1e6ed7c01b1..21e76b174e6 100644
--- a/bfd/elf64-bpf.c
+++ b/bfd/elf64-bpf.c
@@ -194,7 +194,7 @@  bpf_elf_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *	   howto;
       unsigned int		   howto_index;
       unsigned long		   r_symndx;
-      Elf_Internal_Sym *	   sym;
+      const Elf_Internal_Sym *	   sym;
       asection *		   sec;
       struct elf_link_hash_entry * h;
       bfd_vma			   relocation;
diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
index 420341e91f7..6a80caf06c0 100644
--- a/bfd/elf64-ia64-vms.c
+++ b/bfd/elf64-ia64-vms.c
@@ -3414,7 +3414,7 @@  elf64_ia64_relocate_section (struct bfd_link_info *info,
       bfd_reloc_status_type r;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       unsigned int r_type;
       bfd_vma value;
       asection *sym_sec;
diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
index ca611b75012..0c21f14588b 100644
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -1374,7 +1374,7 @@  mmix_elf_relocate_section (struct bfd_link_info *info,
     {
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index 15abcd8ad8d..73a3a4715b2 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4799,7 +4799,7 @@  ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
     {
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       enum elf_ppc64_reloc_type r_type;
       int tls_type;
       struct _ppc64_elf_section_data *ppc64_sec;
@@ -15563,7 +15563,7 @@  ppc64_elf_relocate_section (struct bfd_link_info *info,
       enum elf_ppc64_reloc_type r_type;
       bfd_vma addend;
       bfd_reloc_status_type r;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h_elf;
       struct ppc_link_hash_entry *h;
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index aa377b77ffd..fdd0fcdae85 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;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
 
       r_symndx = ELF64_R_SYM (rel->r_info);
 
@@ -2334,7 +2334,7 @@  elf_s390_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma off;
       bfd_vma relocation;
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 3bce10034a3..3b200a62435 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1513,7 +1513,7 @@  elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
 			   const Elf_Internal_Rela *rel,
 			   const Elf_Internal_Rela *relend,
 			   struct elf_link_hash_entry *h,
-			   Elf_Internal_Sym *sym,
+			   const Elf_Internal_Sym *sym,
 			   bool from_relocate_section)
 {
   unsigned int from_type = *r_type;
@@ -1684,7 +1684,7 @@  elf_x86_64_need_pic (struct bfd_link_info *info,
 		     bfd *input_bfd, asection *sec,
 		     struct elf_link_hash_entry *h,
 		     Elf_Internal_Shdr *symtab_hdr,
-		     Elf_Internal_Sym *isym,
+		     const Elf_Internal_Sym *isym,
 		     reloc_howto_type *howto)
 {
   const char *v = "";
@@ -2544,7 +2544,7 @@  elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
       struct elf_x86_link_hash_entry *eh;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
       const char *name;
       bool size_reloc;
       bool converted_reloc;
@@ -3209,7 +3209,7 @@  elf_x86_64_relocate_section (struct bfd_link_info *info,
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
       struct elf_x86_link_hash_entry *eh;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma off, offplt, plt_offset;
       bfd_vma relocation;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 005f8ef50dd..0008131a08a 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5756,7 +5756,7 @@  elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
 				   bool *unresolved_reloc_p,
 				   bool save_addend,
 				   bfd_vma *saved_addend,
-				   Elf_Internal_Sym *sym)
+				   const Elf_Internal_Sym *sym)
 {
   Elf_Internal_Shdr *symtab_hdr;
   unsigned int r_type = howto->type;
@@ -7081,7 +7081,7 @@  elfNN_aarch64_relocate_section (struct bfd_link_info *info,
       bfd_reloc_code_real_type relaxed_bfd_r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
@@ -7952,11 +7952,11 @@  elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
     {
-      struct elf_link_hash_entry *h;
       unsigned int r_symndx;
       unsigned int r_type;
       bfd_reloc_code_real_type bfd_r_type;
-      Elf_Internal_Sym *isym;
+      struct elf_link_hash_entry *h;
+      const Elf_Internal_Sym *isym;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
@@ -7964,8 +7964,7 @@  elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  /* A local symbol.  */
-	  isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
-					abfd, r_symndx);
+	  isym = bfd_sym_from_r_symndx (&htab->root.sym_cache, abfd, r_symndx);
 	  if (isym == NULL)
 	    return false;
 
diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
index 4e2d27cfc3f..fa3dc62b81d 100644
--- a/bfd/elfnn-ia64.c
+++ b/bfd/elfnn-ia64.c
@@ -3805,7 +3805,7 @@  elfNN_ia64_relocate_section (struct bfd_link_info *info,
       bfd_reloc_status_type r;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       unsigned int r_type;
       bfd_vma value;
       asection *sym_sec;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 56368c206ea..831091c2129 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -1965,7 +1965,7 @@  elfNN_kvx_final_link_relocate (reloc_howto_type *howto,
 			       bool *unresolved_reloc_p,
 			       bool save_addend,
 			       bfd_vma *saved_addend,
-			       Elf_Internal_Sym *sym)
+			       const Elf_Internal_Sym *sym)
 {
   Elf_Internal_Shdr *symtab_hdr;
   unsigned int r_type = howto->type;
@@ -2454,7 +2454,7 @@  elfNN_kvx_relocate_section (struct bfd_link_info *info,
       bfd_reloc_code_real_type bfd_r_type;
       reloc_howto_type *howto;
       unsigned long r_symndx;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
       bfd_vma relocation;
@@ -3209,11 +3209,11 @@  elfNN_kvx_check_relocs (bfd *abfd, struct bfd_link_info *info,
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
     {
-      struct elf_link_hash_entry *h;
       unsigned int r_symndx;
       unsigned int r_type;
       bfd_reloc_code_real_type bfd_r_type;
-      Elf_Internal_Sym *isym;
+      struct elf_link_hash_entry *h;
+      const Elf_Internal_Sym *isym;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
@@ -3221,8 +3221,7 @@  elfNN_kvx_check_relocs (bfd *abfd, struct bfd_link_info *info,
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  /* A local symbol.  */
-	  isym = bfd_sym_from_r_symndx (&htab->sym_cache,
-					abfd, r_symndx);
+	  isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
 	  if (isym == NULL)
 	    return false;
 
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 4a2f87777b1..00b4a87147b 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -1049,7 +1049,7 @@  bad_static_reloc (struct bfd_link_info *info,
 		  bfd *abfd, const Elf_Internal_Rela *rel,
 		  asection *sec, unsigned r_type,
 		  struct elf_link_hash_entry *h,
-		  Elf_Internal_Sym *isym)
+		  const Elf_Internal_Sym *isym)
 {
   reloc_howto_type * r = loongarch_elf_rtype_to_howto (abfd, r_type);
   const char *object;
@@ -1145,8 +1145,8 @@  loongarch_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 = NULL;
       bool is_abs_symbol = false;
-      Elf_Internal_Sym *isym = NULL;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
@@ -3248,7 +3248,7 @@  static struct
   bfd_vma r_offset;
   int r_type;
   bfd_vma relocation;
-  Elf_Internal_Sym *sym;
+  const Elf_Internal_Sym *sym;
   struct elf_link_hash_entry *h;
   bfd_vma addend;
   int64_t top_then;
@@ -3258,7 +3258,7 @@  static size_t larch_reloc_queue_tail = 0;
 
 static const char *
 loongarch_sym_name (bfd *input_bfd, struct elf_link_hash_entry *h,
-		    Elf_Internal_Sym *sym)
+		    const Elf_Internal_Sym *sym)
 {
   const char *ret = NULL;
   if (sym)
@@ -3275,7 +3275,7 @@  loongarch_sym_name (bfd *input_bfd, struct elf_link_hash_entry *h,
 
 static void
 loongarch_record_one_reloc (bfd *abfd, asection *section, int r_type,
-			    bfd_vma r_offset, Elf_Internal_Sym *sym,
+			    bfd_vma r_offset, const Elf_Internal_Sym *sym,
 			    struct elf_link_hash_entry *h, bfd_vma addend)
 {
   if ((larch_reloc_queue_head == 0
@@ -3550,7 +3550,7 @@  loongarch_elf_relocate_section (struct bfd_link_info *info,
       bfd_vma pc = sec_addr (input_section) + rel->r_offset;
       reloc_howto_type *howto = NULL;
       asection *sec = NULL;
-      Elf_Internal_Sym *sym = NULL;
+      const Elf_Internal_Sym *sym = NULL;
       struct elf_link_hash_entry *h = NULL;
       const char *name;
       bfd_reloc_status_type r = bfd_reloc_ok;
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 3eac0a6e552..f5cc7505d57 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1064,6 +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;
       bool is_abs_symbol = false;
 
       r_symndx = ELFNN_R_SYM (rel->r_info);
@@ -1072,12 +1073,11 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  /* A local symbol.  */
-	  Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
-							  abfd, r_symndx);
+	  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, abfd, r_symndx);
 	  if (isym == NULL)
 	    return false;
 
-	  is_abs_symbol = isym->st_shndx == SHN_ABS ? true : false;
+	  is_abs_symbol = isym->st_shndx == SHN_ABS;
 
 	  /* Check relocation against local STT_GNU_IFUNC symbol.  */
 	  if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
@@ -1105,7 +1105,7 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
 
-	  is_abs_symbol = bfd_is_abs_symbol (&h->root) ? true : false;
+	  is_abs_symbol = bfd_is_abs_symbol (&h->root);
 	}
 
       if (h != NULL)
@@ -1328,7 +1328,6 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
 		  asection *s;
 		  void *vpp;
-		  Elf_Internal_Sym *isym;
 
 		  isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
 						abfd, r_symndx);
@@ -3077,7 +3076,7 @@  riscv_elf_relocate_section (struct bfd_link_info *info,
     {
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation;
       bfd_reloc_status_type r = bfd_reloc_ok;
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index 557a19d39dd..04c1071cc17 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -1375,7 +1375,7 @@  _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_symndx;
       struct elf_link_hash_entry *h;
       struct _bfd_sparc_elf_link_hash_entry *eh;
-      Elf_Internal_Sym *isym;
+      const Elf_Internal_Sym *isym;
 
       r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
       r_type = SPARC_ELF_R_TYPE (rel->r_info);
@@ -2813,7 +2813,7 @@  _bfd_sparc_elf_relocate_section (struct bfd_link_info *info,
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
       struct _bfd_sparc_elf_link_hash_entry *eh;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       asection *sec;
       bfd_vma relocation, off;
       bfd_reloc_status_type r;
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index a40c525ae5c..2479a4be6c7 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -2824,7 +2824,7 @@  tilegx_elf_relocate_section (struct bfd_link_info *info,
       reloc_howto_type *howto;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
-      Elf_Internal_Sym *sym;
+      const Elf_Internal_Sym *sym;
       tilegx_create_func create_func;
       asection *sec;
       bfd_vma relocation;
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 6912549446c..b9d937b0acd 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2180,7 +2180,7 @@  _bfd_elf_x86_valid_reloc_p (asection *input_section,
 			    struct elf_x86_link_hash_table *htab,
 			    const Elf_Internal_Rela *rel,
 			    struct elf_link_hash_entry *h,
-			    Elf_Internal_Sym *sym,
+			    const Elf_Internal_Sym *sym,
 			    Elf_Internal_Shdr *symtab_hdr,
 			    bool *no_dynreloc_p)
 {
@@ -3265,7 +3265,7 @@  _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info *info,
 void
 _bfd_x86_elf_link_report_relative_reloc
   (struct bfd_link_info *info, asection *asect,
-   struct elf_link_hash_entry *h, Elf_Internal_Sym *sym,
+   struct elf_link_hash_entry *h, const Elf_Internal_Sym *sym,
    const char *reloc_name, const void *reloc)
 {
   const char *name;
@@ -3303,7 +3303,7 @@  void
 _bfd_x86_elf_link_report_tls_transition_error
   (struct bfd_link_info *info, bfd *abfd, asection *asect,
    Elf_Internal_Shdr *symtab_hdr, struct elf_link_hash_entry *h,
-   Elf_Internal_Sym *sym, const Elf_Internal_Rela *rel,
+   const Elf_Internal_Sym *sym, const Elf_Internal_Rela *rel,
    const char *from_reloc_name, const char *to_reloc_name,
    enum elf_x86_tls_error_type tls_error)
 {
@@ -3387,7 +3387,7 @@  _bfd_x86_elf_link_report_tls_transition_error
 void
 _bfd_x86_elf_link_report_error
   (bfd *abfd, asection *sec, Elf_Internal_Shdr *symtab_hdr,
-   struct elf_link_hash_entry *h, Elf_Internal_Sym *sym,
+   struct elf_link_hash_entry *h, const Elf_Internal_Sym *sym,
    reloc_howto_type *howto, enum elf_x86_error_type type)
 {
   const char *name;
diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
index 48e8ab4ad73..06b65fcafc3 100644
--- a/bfd/elfxx-x86.h
+++ b/bfd/elfxx-x86.h
@@ -887,7 +887,7 @@  extern void _bfd_elf64_write_addend
 extern bool _bfd_elf_x86_valid_reloc_p
   (asection *, struct bfd_link_info *, struct elf_x86_link_hash_table *,
    const Elf_Internal_Rela *, struct elf_link_hash_entry *,
-   Elf_Internal_Sym *, Elf_Internal_Shdr *, bool *) ATTRIBUTE_HIDDEN;
+   const Elf_Internal_Sym *, Elf_Internal_Shdr *, bool *) ATTRIBUTE_HIDDEN;
 
 extern bool _bfd_x86_elf_late_size_sections
   (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
@@ -949,17 +949,17 @@  extern void _bfd_x86_elf_link_fixup_ifunc_symbol
 
 extern void _bfd_x86_elf_link_report_relative_reloc
   (struct bfd_link_info *, asection *, struct elf_link_hash_entry *,
-   Elf_Internal_Sym *, const char *, const void *) ATTRIBUTE_HIDDEN;
+   const Elf_Internal_Sym *, const char *, const void *) ATTRIBUTE_HIDDEN;
 
 extern void _bfd_x86_elf_link_report_tls_transition_error
   (struct bfd_link_info *, bfd *, asection *, Elf_Internal_Shdr *,
-   struct elf_link_hash_entry *, Elf_Internal_Sym *,
+   struct elf_link_hash_entry *, const Elf_Internal_Sym *,
    const Elf_Internal_Rela *, const char *, const char *,
    enum elf_x86_tls_error_type) ATTRIBUTE_HIDDEN;
 
 extern void _bfd_x86_elf_link_report_error
   (bfd *, asection *, Elf_Internal_Shdr *, struct elf_link_hash_entry *,
-   Elf_Internal_Sym *, reloc_howto_type *,
+   const Elf_Internal_Sym *, reloc_howto_type *,
    enum elf_x86_error_type) ATTRIBUTE_HIDDEN;
 
 extern void _bfd_x86_elf_link_report_relocation_error