[PATCH v2 3/6] bfd/ELF: fold BFD_RELOC_<arch>_GOTPC*

Jens Remus jremus@linux.ibm.com
Mon Mar 30 16:13:50 GMT 2026


On 3/27/2026 10:55 AM, Jan Beulich wrote:
> For many of the cases there's no need to have separate relocs per arch;
> just like for other more or less generic ones a single one (per purpose;
> a 64-bit generic one is being introduced) will do. C-Sky - sadly -
> continues to be an exception.

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

> ---
> v2: Re-base over changes earlier in the series. Introduce
>     BFD_RELOC_64_GOT_PCREL to correct the S/390 change (and then used
>     for x86-64 as well).

Thanks!

> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -3303,6 +3303,7 @@ enum bfd_reloc_code_real
>    BFD_RELOC_16_SECIDX,
>  
>    /* For ELF.  */
> +  BFD_RELOC_64_GOT_PCREL,
>    BFD_RELOC_32_GOT_PCREL,
>    BFD_RELOC_16_GOT_PCREL,
>    BFD_RELOC_8_GOT_PCREL,

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

> --- a/bfd/elf32-s390.c
> +++ b/bfd/elf32-s390.c
> @@ -213,7 +213,7 @@ elf_s390_reloc_type_lookup (bfd *abfd AT
>        return &elf_howto_table[(int) R_390_RELATIVE];
>      case BFD_RELOC_32_GOTOFF:
>        return &elf_howto_table[(int) R_390_GOTOFF32];
> -    case BFD_RELOC_390_GOTPC:
> +    case BFD_RELOC_32_GOT_PCREL:
>        return &elf_howto_table[(int) R_390_GOTPC];
>      case BFD_RELOC_390_GOT16:
>        return &elf_howto_table[(int) R_390_GOT16];

> --- a/bfd/elf64-s390.c
> +++ b/bfd/elf64-s390.c
> @@ -227,7 +227,7 @@ elf_s390_reloc_type_lookup (bfd *abfd,
>        return &elf_howto_table[(int) R_390_RELATIVE];
>      case BFD_RELOC_32_GOTOFF:
>        return &elf_howto_table[(int) R_390_GOTOFF32];
> -    case BFD_RELOC_390_GOTPC:
> +    case BFD_RELOC_64_GOT_PCREL:
>        return &elf_howto_table[(int) R_390_GOTPC];
>      case BFD_RELOC_390_GOT16:
>        return &elf_howto_table[(int) R_390_GOT16];

> --- a/bfd/libbfd.h
> +++ b/bfd/libbfd.h
> @@ -1078,6 +1078,7 @@ static const char *const bfd_reloc_code_
>    "BFD_RELOC_8_PCREL",
>    "BFD_RELOC_32_SECREL",
>    "BFD_RELOC_16_SECIDX",
> +  "BFD_RELOC_64_GOT_PCREL",
>    "BFD_RELOC_32_GOT_PCREL",
>    "BFD_RELOC_16_GOT_PCREL",
>    "BFD_RELOC_8_GOT_PCREL",

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

> --- a/bfd/reloc.c
> +++ b/bfd/reloc.c
> @@ -1429,6 +1429,8 @@ ENUMDOC
>    Section relative relocations.  Some targets need this for DWARF2.
>  
>  ENUM
> +  BFD_RELOC_64_GOT_PCREL
> +ENUMX
>    BFD_RELOC_32_GOT_PCREL
>  ENUMX
>    BFD_RELOC_16_GOT_PCREL

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

> --- a/gas/config/tc-s390.c
> +++ b/gas/config/tc-s390.c
> @@ -2449,7 +2449,8 @@ tc_s390_force_relocation (struct fix *fi
>      case BFD_RELOC_390_PLTOFF16:
>      case BFD_RELOC_390_PLTOFF32:
>      case BFD_RELOC_390_PLTOFF64:
> -    case BFD_RELOC_390_GOTPC:
> +    case BFD_RELOC_32_GOT_PCREL:
> +    case BFD_RELOC_64_GOT_PCREL:
>      case BFD_RELOC_390_GOT16:
>      case BFD_RELOC_390_GOTPCDBL:
>      case BFD_RELOC_390_GOT64:
> @@ -2838,10 +2839,11 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UN
>    code = fixp->fx_r_type;
>    if (GOT_symbol && fixp->fx_addsy == GOT_symbol)
>      {
> -      if (   (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
> -	  || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL))
> -	code = BFD_RELOC_390_GOTPC;
> -      if (code == BFD_RELOC_390_PC32DBL)
> +      if (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL)
> +	code = BFD_RELOC_32_GOT_PCREL;
> +      else if (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)
> +	code = BFD_RELOC_64_GOT_PCREL;
> +      else if (code == BFD_RELOC_390_PC32DBL)
>  	code = BFD_RELOC_390_GOTPCDBL;
>      }
>  
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