[PATCH 5/8] bfd/s390+sh: don't abuse BFD_RELOC_32_GOT_PCREL

Jens Remus jremus@linux.ibm.com
Fri Mar 13 17:25:14 GMT 2026


On 3/13/2026 10:55 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.

Likewise to previous patch I am wondering whether this isn't an API-
breaking change.

Technically this looks good to me.  One minor nit below.

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

> @@ -5373,6 +5374,9 @@ enum bfd_reloc_code_real
>    /* 12 bit GOT offset.  */
>    BFD_RELOC_390_GOT12,
>  
> +  /* 32 bit GOT offset.  */
> +  BFD_RELOC_390_GOT32,
> +
>    /* 32 bit PC relative offset to GOT.  */
>    BFD_RELOC_390_GOTPC,
>  

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

> @@ -2381,6 +2382,7 @@ static const char *const bfd_reloc_code_
>    "BFD_RELOC_RX_RELAX",
>    "BFD_RELOC_390_12",
>    "BFD_RELOC_390_GOT12",
> +  "BFD_RELOC_390_GOT32",
>    "BFD_RELOC_390_GOTPC",
>    "BFD_RELOC_390_GOT16",
>    "BFD_RELOC_390_PC12DBL",

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

> @@ -4907,6 +4909,10 @@ ENUM
>  ENUMDOC
>    12 bit GOT offset.
>  ENUM
> +  BFD_RELOC_390_GOT32
> +ENUMDOC
> +  32 bit GOT offset.
> +ENUM
>    BFD_RELOC_390_GOTPC
>  ENUMDOC
>    32 bit PC relative offset to GOT.

Nit: Could you please add BFD_RELOC_390_GOT32 after BFD_RELOC_390_GOT16?
While this is not apparent in this patch, this would cause the
BFD_RELOC_390_GOTnn relocs to be in order after the next patch removes
the BFD_RELOC_390_GOTPC, so that they end up as follows after your
series is applied:

ENUM
  BFD_RELOC_390_GOT12
ENUMDOC
  12 bit GOT offset.
ENUM
  BFD_RELOC_390_GOT16
ENUMDOC
  16 bit GOT offset.
ENUM
  BFD_RELOC_390_GOT32
ENUMDOC
  32 bit GOT offset.

> --- 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
-- 
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/



More information about the Binutils mailing list