[v2,2/6] bfd/s390+sh: don't abuse BFD_RELOC_32_GOT_PCREL

Message ID 38e100ce-872d-4cab-913c-1f3c14752a6e@suse.com
State New
Headers
Series bfd: another little bit of reloc enum cleanup |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich March 27, 2026, 9:52 a.m. UTC
  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.
---
v2: Move BFD_RELOC_390_GOT32 down a little.
  

Comments

Jens Remus March 30, 2026, 4:11 p.m. UTC | #1
On 3/27/2026 10:52 AM, Jan Beulich wrote:
> 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.

Thank you, Jan!  The s390 64-bit (s390x) changes look good to me.

> ---
> v2: Move BFD_RELOC_390_GOT32 down a little.

Thanks!

> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h

> @@ -5379,6 +5380,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,
>  

> --- a/bfd/elf32-s390.c
> +++ b/bfd/elf32-s390.c
> @@ -199,7 +199,7 @@ elf_s390_reloc_type_lookup (bfd *abfd AT
>        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];

> --- 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];

> --- a/bfd/libbfd.h
> +++ b/bfd/libbfd.h

> @@ -2383,6 +2384,7 @@ static const char *const bfd_reloc_code_
>    "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",

> --- a/bfd/reloc.c
> +++ b/bfd/reloc.c

> @@ -4915,6 +4917,10 @@ ENUM
>  ENUMDOC
>    16 bit GOT offset.
>  ENUM
> +  BFD_RELOC_390_GOT32
> +ENUMDOC
> +  32 bit GOT offset.
> +ENUM
>    BFD_RELOC_390_PC12DBL
>  ENUMDOC
>    PC relative 12 bit shifted by 1.

> --- a/gas/config/tc-s390.c
> +++ b/gas/config/tc-s390.c
> @@ -1107,7 +1107,7 @@ s390_lit_suffix (char **str_p, expressio
>        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=
>  	      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 *fi
>      {
>      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,
>  	  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:

Regards,
Jens
  

Patch

--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -4286,6 +4286,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,
@@ -5379,6 +5380,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,
 
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -199,7 +199,7 @@  elf_s390_reloc_type_lookup (bfd *abfd AT
       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];
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -353,7 +353,7 @@  static const struct elf_reloc_map sh_rel
   { 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 },
--- 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];
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -1791,6 +1791,7 @@  static const char *const bfd_reloc_code_
   "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",
@@ -2383,6 +2384,7 @@  static const char *const bfd_reloc_code_
   "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",
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -3200,6 +3200,8 @@  ENUMX
 ENUMX
   BFD_RELOC_SH_GOT10BY8
 ENUMX
+  BFD_RELOC_SH_GOT32
+ENUMX
   BFD_RELOC_SH_GOTPLT10BY4
 ENUMX
   BFD_RELOC_SH_GOTPLT10BY8
@@ -4915,6 +4917,10 @@  ENUM
 ENUMDOC
   16 bit GOT offset.
 ENUM
+  BFD_RELOC_390_GOT32
+ENUMDOC
+  32 bit GOT offset.
+ENUM
   BFD_RELOC_390_PC12DBL
 ENUMDOC
   PC relative 12 bit shifted by 1.
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -1107,7 +1107,7 @@  s390_lit_suffix (char **str_p, expressio
       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=
 	      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 *fi
     {
     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,
 	  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:
--- a/gas/config/tc-sh.c
+++ b/gas/config/tc-sh.c
@@ -340,7 +340,7 @@  sh_check_fixup (expressionS *main_exp, b
 	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,
     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")))
--- a/gas/config/tc-sh.h
+++ b/gas/config/tc-sh.h
@@ -202,7 +202,7 @@  extern bool sh_fix_adjustable (struct fi
 #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)		\