[binutils-gdb] bfd/s390+sh: don't abuse BFD_RELOC_32_GOT_PCREL

Jan Beulich via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ffb01033a04cfc2b290d42d4d82c114a7164b53a

commit ffb01033a04cfc2b290d42d4d82c114a7164b53a
Author: Jan Beulich <[email protected]>
Date:   Thu Apr 9 08:36:55 2026 +0200

    bfd/s390+sh: don't abuse BFD_RELOC_32_GOT_PCREL
    
    Neither R_390_GOT32 nor R_SH_GOT32 are PC-relative relocations, so don't
    use a generic PC-relative enumerator for them. Doing so gets in the way
    of properly using that enumerator.

Diff:
---
 bfd/bfd-in2.h        |  4 ++++
 bfd/elf32-s390.c     |  2 +-
 bfd/elf32-sh.c       |  2 +-
 bfd/elf64-s390.c     |  2 +-
 bfd/libbfd.h         |  2 ++
 bfd/reloc.c          |  6 ++++++
 gas/config/tc-s390.c | 10 +++++-----
 gas/config/tc-sh.c   |  8 ++++----
 gas/config/tc-sh.h   |  2 +-
 9 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 7313dd12370..914f1b435a8 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -4339,6 +4339,7 @@ enum bfd_reloc_code_real
   BFD_RELOC_SH_RELATIVE64,
   BFD_RELOC_SH_GOT10BY4,
   BFD_RELOC_SH_GOT10BY8,
+  BFD_RELOC_SH_GOT32,
   BFD_RELOC_SH_GOTPLT10BY4,
   BFD_RELOC_SH_GOTPLT10BY8,
   BFD_RELOC_SH_GOTPLT32,
@@ -5432,6 +5433,9 @@ enum bfd_reloc_code_real
   /* 16 bit GOT offset.  */
   BFD_RELOC_390_GOT16,
 
+  /* 32 bit GOT offset.  */
+  BFD_RELOC_390_GOT32,
+
   /* PC relative 12 bit shifted by 1.  */
   BFD_RELOC_390_PC12DBL,
 
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index a47eb99b040..a520bec2780 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -199,7 +199,7 @@ elf_s390_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
       return &elf_howto_table[(int) R_390_PC32];
     case BFD_RELOC_390_GOT12:
       return &elf_howto_table[(int) R_390_GOT12];
-    case BFD_RELOC_32_GOT_PCREL:
+    case BFD_RELOC_390_GOT32:
       return &elf_howto_table[(int) R_390_GOT32];
     case BFD_RELOC_32_PLT_PCREL:
       return &elf_howto_table[(int) R_390_PLT32];
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 05f77e03816..81bf415a27e 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -353,7 +353,7 @@ static const struct elf_reloc_map sh_reloc_map[] =
   { BFD_RELOC_SH_TLS_DTPMOD32, R_SH_TLS_DTPMOD32 },
   { BFD_RELOC_SH_TLS_DTPOFF32, R_SH_TLS_DTPOFF32 },
   { BFD_RELOC_SH_TLS_TPOFF32, R_SH_TLS_TPOFF32 },
-  { BFD_RELOC_32_GOT_PCREL, R_SH_GOT32 },
+  { BFD_RELOC_SH_GOT32, R_SH_GOT32 },
   { BFD_RELOC_32_PLT_PCREL, R_SH_PLT32 },
   { BFD_RELOC_COPY, R_SH_COPY },
   { BFD_RELOC_GLOB_DAT, R_SH_GLOB_DAT },
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 4eb9f3d866e..f635cba0bfb 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -213,7 +213,7 @@ elf_s390_reloc_type_lookup (bfd *abfd,
       return &elf_howto_table[(int) R_390_PC32];
     case BFD_RELOC_390_GOT12:
       return &elf_howto_table[(int) R_390_GOT12];
-    case BFD_RELOC_32_GOT_PCREL:
+    case BFD_RELOC_390_GOT32:
       return &elf_howto_table[(int) R_390_GOT32];
     case BFD_RELOC_32_PLT_PCREL:
       return &elf_howto_table[(int) R_390_PLT32];
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index a5a7245c5fd..17df7667564 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -1827,6 +1827,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_SH_RELATIVE64",
   "BFD_RELOC_SH_GOT10BY4",
   "BFD_RELOC_SH_GOT10BY8",
+  "BFD_RELOC_SH_GOT32",
   "BFD_RELOC_SH_GOTPLT10BY4",
   "BFD_RELOC_SH_GOTPLT10BY8",
   "BFD_RELOC_SH_GOTPLT32",
@@ -2419,6 +2420,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
   "BFD_RELOC_390_GOT12",
   "BFD_RELOC_390_GOTPC",
   "BFD_RELOC_390_GOT16",
+  "BFD_RELOC_390_GOT32",
   "BFD_RELOC_390_PC12DBL",
   "BFD_RELOC_390_PLT12DBL",
   "BFD_RELOC_390_PC16DBL",
diff --git a/bfd/reloc.c b/bfd/reloc.c
index ff237b817be..bd12910a07d 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -3203,6 +3203,8 @@ ENUMX
   BFD_RELOC_SH_GOT10BY4
 ENUMX
   BFD_RELOC_SH_GOT10BY8
+ENUMX
+  BFD_RELOC_SH_GOT32
 ENUMX
   BFD_RELOC_SH_GOTPLT10BY4
 ENUMX
@@ -4918,6 +4920,10 @@ ENUM
   BFD_RELOC_390_GOT16
 ENUMDOC
   16 bit GOT offset.
+ENUM
+  BFD_RELOC_390_GOT32
+ENUMDOC
+  32 bit GOT offset.
 ENUM
   BFD_RELOC_390_PC12DBL
 ENUMDOC
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index 61ae323fe80..f378b3a4011 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -1107,7 +1107,7 @@ s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix)
       if (nbytes == 2)
 	reloc = BFD_RELOC_390_GOT16;
       else if (nbytes == 4)
-	reloc = BFD_RELOC_32_GOT_PCREL;
+	reloc = BFD_RELOC_390_GOT32;
       else if (nbytes == 8)
 	reloc = BFD_RELOC_390_GOT64;
     }
@@ -1271,7 +1271,7 @@ s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */)
 	      static bfd_reloc_code_real_type tab4[] =
 		{
 		  BFD_RELOC_UNUSED, 		/* ELF_SUFFIX_NONE  */
-		  BFD_RELOC_32_GOT_PCREL,	/* ELF_SUFFIX_GOT  */
+		  BFD_RELOC_390_GOT32,		/* ELF_SUFFIX_GOT  */
 		  BFD_RELOC_32_PLT_PCREL,	/* ELF_SUFFIX_PLT  */
 		  BFD_RELOC_UNUSED,		/* ELF_SUFFIX_GOTENT  */
 		  BFD_RELOC_32_GOTOFF,		/* ELF_SUFFIX_GOTOFF  */
@@ -2396,7 +2396,7 @@ tc_s390_fix_adjustable (fixS *fixP)
       || fixP->fx_r_type == BFD_RELOC_390_GOT12
       || fixP->fx_r_type == BFD_RELOC_390_GOT20
       || fixP->fx_r_type == BFD_RELOC_390_GOT16
-      || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
+      || fixP->fx_r_type == BFD_RELOC_390_GOT32
       || fixP->fx_r_type == BFD_RELOC_390_GOT64
       || fixP->fx_r_type == BFD_RELOC_390_GOTENT
       || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12
@@ -2443,7 +2443,7 @@ tc_s390_force_relocation (struct fix *fixp)
     {
     case BFD_RELOC_390_GOT12:
     case BFD_RELOC_390_GOT20:
-    case BFD_RELOC_32_GOT_PCREL:
+    case BFD_RELOC_390_GOT32:
     case BFD_RELOC_32_GOTOFF:
     case BFD_RELOC_64_GOTOFF:
     case BFD_RELOC_390_PLTOFF16:
@@ -2728,7 +2728,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	  if (fixP->fx_done)
 	    md_number_to_chars (where, value, 4);
 	  break;
-	case BFD_RELOC_32_GOT_PCREL:
+	case BFD_RELOC_390_GOT32:
 	case BFD_RELOC_390_PLTOFF32:
 	case BFD_RELOC_32_PLT_PCREL:
 	case BFD_RELOC_390_GOTPLT32:
diff --git a/gas/config/tc-sh.c b/gas/config/tc-sh.c
index 5221ca99406..04923915f40 100644
--- a/gas/config/tc-sh.c
+++ b/gas/config/tc-sh.c
@@ -340,7 +340,7 @@ sh_check_fixup (expressionS *main_exp, bfd_reloc_code_real_type *r_type_p)
 	case BFD_RELOC_SH_DISP20:
 	  switch (exp->X_md)
 	    {
-	    case BFD_RELOC_32_GOT_PCREL:
+	    case BFD_RELOC_SH_GOT32:
 	      *r_type_p = BFD_RELOC_SH_GOT20;
 	      break;
 
@@ -3313,7 +3313,7 @@ bool
 sh_fix_adjustable (fixS *fixP)
 {
   if (fixP->fx_r_type == BFD_RELOC_32_PLT_PCREL
-      || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL
+      || fixP->fx_r_type == BFD_RELOC_SH_GOT32
       || fixP->fx_r_type == BFD_RELOC_SH_GOT20
       || fixP->fx_r_type == BFD_RELOC_SH_GOTPC
       || fixP->fx_r_type == BFD_RELOC_SH_GOTFUNCDESC
@@ -3670,7 +3670,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_SH_TLS_IE_32:
       S_SET_THREAD_LOCAL (fixP->fx_addsy);
       /* Fallthrough */
-    case BFD_RELOC_32_GOT_PCREL:
+    case BFD_RELOC_SH_GOT32:
     case BFD_RELOC_SH_GOT20:
     case BFD_RELOC_SH_GOTPLT32:
     case BFD_RELOC_SH_GOTFUNCDESC:
@@ -3962,7 +3962,7 @@ sh_parse_name (char const *name,
   else if ((next_end = sh_end_of_match (next + 1, "GOTPLT")))
     reloc_type = BFD_RELOC_SH_GOTPLT32;
   else if ((next_end = sh_end_of_match (next + 1, "GOT")))
-    reloc_type = BFD_RELOC_32_GOT_PCREL;
+    reloc_type = BFD_RELOC_SH_GOT32;
   else if ((next_end = sh_end_of_match (next + 1, "PLT")))
     reloc_type = BFD_RELOC_32_PLT_PCREL;
   else if ((next_end = sh_end_of_match (next + 1, "TLSGD")))
diff --git a/gas/config/tc-sh.h b/gas/config/tc-sh.h
index 0c3db2cb958..404662578ed 100644
--- a/gas/config/tc-sh.h
+++ b/gas/config/tc-sh.h
@@ -202,7 +202,7 @@ extern bool sh_fix_adjustable (struct fix *);
 #define TC_FORCE_RELOCATION_LOCAL(FIX)			\
   (GENERIC_FORCE_RELOCATION_LOCAL (FIX)			\
    || (FIX)->fx_r_type == BFD_RELOC_32_PLT_PCREL	\
-   || (FIX)->fx_r_type == BFD_RELOC_32_GOT_PCREL	\
+   || (FIX)->fx_r_type == BFD_RELOC_SH_GOT32		\
    || (FIX)->fx_r_type == BFD_RELOC_SH_GOTPC)
 
 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG)		\
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.