Hi Jeevitha,

on 2023/8/21 18:32, jeevitha wrote:
> Hi All,
> 
> The following patch has been bootstrapped and regtested on powerpc64-linux.

I think we should test this on powerpc64le-linux P8 or P9 (no P10) as well.

> 
> It is currently possible to incorrectly enable PCREL for targets that do not
> officially support it. Disable PCREL for targets that do not support it.
> 
> 2023-08-21  Jeevitha Palanisamy  <jeevi...@linux.ibm.com>
> 
> gcc/
>       PR target/111045
>       * config/rs6000/rs6000.cc (rs6000_option_override_internal): Disable 
> PCREL
>       for unsupported targets.
> 
> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> index efe9adc..4838f8c 100644
> --- a/gcc/config/rs6000/rs6000.cc
> +++ b/gcc/config/rs6000/rs6000.cc
> @@ -4232,6 +4232,9 @@ rs6000_option_override_internal (bool global_init_p)
>        rs6000_isa_flags &= ~OPTION_MASK_FLOAT128_HW;
>      }
>  
> +  if (!rs6000_pcrel_p())

Nit: Only do this check when TARGET_PCREL, one space before "()",
that is "...pcrel_p ()".

I think this should be moved to be with the hunk on PCREL:

  /* If the ABI has support for PC-relative relocations, enable it by default.
     This test depends on the sub-target tests above setting the code model to
     medium for ELF v2 systems.  */
  if (PCREL_SUPPORTED_BY_OS
      && (rs6000_isa_flags_explicit & OPTION_MASK_PCREL) == 0)
    rs6000_isa_flags |= OPTION_MASK_PCREL;

  /* -mpcrel requires -mcmodel=medium, but we can't check TARGET_CMODEL until
      after the subtarget override options are done.  */
  else if (TARGET_PCREL && TARGET_CMODEL != CMODEL_MEDIUM)
    {
      if ((rs6000_isa_flags_explicit & OPTION_MASK_PCREL) != 0)
        error ("%qs requires %qs", "-mpcrel", "-mcmodel=medium");

      rs6000_isa_flags &= ~OPTION_MASK_PCREL;
    }

==>

   else if (TARGET_PCREL && !rs6000_pcrel_p ())
      rs6000_isa_flags &= ~OPTION_MASK_PCREL;

Use DEFAULT_ABI != ABI_ELFv2 seems more straightforward, but I guessed the
reason why you used rs6000_pcrel_p is to avoid scattered conditions, it's
fine to me.  Besides, I think we want one error for explicit -mpcrel on
unsupported targets just similar to the above cmodel?

BR,
Kewen

> +    rs6000_isa_flags &= ~OPTION_MASK_PCREL;
> +
>    /* Enable -mprefixed by default on power10 systems.  */
>    if (TARGET_POWER10 && (rs6000_isa_flags_explicit & OPTION_MASK_PREFIXED) 
> == 0)
>      rs6000_isa_flags |= OPTION_MASK_PREFIXED;
> 

Reply via email to