Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-29 Thread Christophe Lyon
On Fri, 26 Oct 2018 at 17:42, Richard Earnshaw (lists)
 wrote:
>
> On 26/10/2018 16:25, Christophe Lyon wrote:
> > On Tue, 23 Oct 2018 at 16:07, Richard Earnshaw (lists)
> >  wrote:
> >>
> >> On 19/10/2018 14:40, Christophe Lyon wrote:
> >>> On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:
>  On 11/10/18 14:34, Christophe Lyon wrote:
> > The FDPIC register is hard-coded to r9, as defined in the ABI.
> >
> > We have to disable tailcall optimizations if we don't know if the
> > target function is in the same module. If not, we have to set r9 to
> > the value associated with the target module.
> >
> > When generating a symbol address, we have to take into account whether
> > it is a pointer to data or to a function, because different
> > relocations are needed.
> >
> > 2018-XX-XX  Christophe Lyon  
> > Mickaël Guêné 
> >
> > * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
> > in FDPIC mode.
> > * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
> > new function.
> > * config/arm/arm.c (arm_option_override): Define pic register to
> > FDPIC_REGNUM.
> > (arm_function_ok_for_sibcall) Disable sibcall optimization if we
> 
>  Missing colon.
> 
> > have no decl or go through PLT.
> > (arm_load_pic_register): Handle TARGET_FDPIC.
> > (arm_is_segment_info_known): New function.
> > (arm_pic_static_addr): Add support for FDPIC.
> > (arm_load_function_descriptor): New function.
> > (arm_assemble_integer): Add support for FDPIC.
> > * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
> > Define. (FDPIC_REGNUM): New define.
> > * config/arm/arm.md (call): Add support for FDPIC.
> > (call_value): Likewise.
> > (*restore_pic_register_after_call): New pattern.
> > (untyped_call): Disable if FDPIC.
> > (untyped_return): Likewise.
> > * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
> >
> 
>  Other comments inline.
> 
> > diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
> > index 4471f79..90733cc 100644
> > --- a/gcc/config/arm/arm-c.c
> > +++ b/gcc/config/arm/arm-c.c
> > @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
> > builtin_define ("__ARM_EABI__");
> >   }
> >   +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
> > +
> > def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
> > def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
> >   diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> > index 0dfb3ac..28cafa8 100644
> > --- a/gcc/config/arm/arm-protos.h
> > +++ b/gcc/config/arm/arm-protos.h
> > @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
> >   extern int arm_const_double_inline_cost (rtx);
> >   extern bool arm_const_double_by_parts (rtx);
> >   extern bool arm_const_double_by_immediates (rtx);
> > +extern rtx arm_load_function_descriptor (rtx funcdesc);
> >   extern void arm_emit_call_insn (rtx, rtx, bool);
> >   bool detect_cmse_nonsecure_call (tree);
> >   extern const char *output_call (rtx *);
> > diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> > index 8810df5..92ae24b 100644
> > --- a/gcc/config/arm/arm.c
> > +++ b/gcc/config/arm/arm.c
> > @@ -3470,6 +3470,14 @@ arm_option_override (void)
> > if (flag_pic && TARGET_VXWORKS_RTP)
> >   arm_pic_register = 9;
> >   +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
> > +  if (TARGET_FDPIC)
> > +{
> > +  arm_pic_register = FDPIC_REGNUM;
> > +  if (TARGET_ARM_ARCH < 7)
> > +error ("FDPIC mode is not supported on architectures older than
> > Armv7");
> 
>  What properties of FDPIC impose this requirement?  Does it also apply to
>  Armv8-m.baseline?
> 
> >>> In fact, there was miscommunication on my side, resulting in a
> >>> misunderstanding between Kyrill and myself, which I badly translated
> >>> into this condition.
> >>>
> >>> My initial plan was to submit a patch series tested on v7, and send the
> >>> patches needed to support older architectures as a follow-up. The proper
> >>> restriction is actually "CPUs that do not support ARM or Thumb2". As you
> >>> may have noticed during the iterations of this patch series, I had
> >>> failed to remove partial Thumb1 support hunks.
> >>>
> >>> So really this should be rephrased, and rewritten as "FDPIC mode is
> >>> supported on architecture versions that support ARM or Thumb-2", if that
> >>> suits you. And the condition should thus be:
> >>> if (! TARGET_ARM && ! TARGET_THUMB2)
> >>>   error ("...")
> >>>
> >>> This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.
> >>

Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-26 Thread Richard Earnshaw (lists)
On 26/10/2018 16:25, Christophe Lyon wrote:
> On Tue, 23 Oct 2018 at 16:07, Richard Earnshaw (lists)
>  wrote:
>>
>> On 19/10/2018 14:40, Christophe Lyon wrote:
>>> On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:
 On 11/10/18 14:34, Christophe Lyon wrote:
> The FDPIC register is hard-coded to r9, as defined in the ABI.
>
> We have to disable tailcall optimizations if we don't know if the
> target function is in the same module. If not, we have to set r9 to
> the value associated with the target module.
>
> When generating a symbol address, we have to take into account whether
> it is a pointer to data or to a function, because different
> relocations are needed.
>
> 2018-XX-XX  Christophe Lyon  
> Mickaël Guêné 
>
> * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
> in FDPIC mode.
> * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
> new function.
> * config/arm/arm.c (arm_option_override): Define pic register to
> FDPIC_REGNUM.
> (arm_function_ok_for_sibcall) Disable sibcall optimization if we

 Missing colon.

> have no decl or go through PLT.
> (arm_load_pic_register): Handle TARGET_FDPIC.
> (arm_is_segment_info_known): New function.
> (arm_pic_static_addr): Add support for FDPIC.
> (arm_load_function_descriptor): New function.
> (arm_assemble_integer): Add support for FDPIC.
> * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
> Define. (FDPIC_REGNUM): New define.
> * config/arm/arm.md (call): Add support for FDPIC.
> (call_value): Likewise.
> (*restore_pic_register_after_call): New pattern.
> (untyped_call): Disable if FDPIC.
> (untyped_return): Likewise.
> * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
>

 Other comments inline.

> diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
> index 4471f79..90733cc 100644
> --- a/gcc/config/arm/arm-c.c
> +++ b/gcc/config/arm/arm-c.c
> @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
> builtin_define ("__ARM_EABI__");
>   }
>   +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
> +
> def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
> def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
>   diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> index 0dfb3ac..28cafa8 100644
> --- a/gcc/config/arm/arm-protos.h
> +++ b/gcc/config/arm/arm-protos.h
> @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
>   extern int arm_const_double_inline_cost (rtx);
>   extern bool arm_const_double_by_parts (rtx);
>   extern bool arm_const_double_by_immediates (rtx);
> +extern rtx arm_load_function_descriptor (rtx funcdesc);
>   extern void arm_emit_call_insn (rtx, rtx, bool);
>   bool detect_cmse_nonsecure_call (tree);
>   extern const char *output_call (rtx *);
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index 8810df5..92ae24b 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -3470,6 +3470,14 @@ arm_option_override (void)
> if (flag_pic && TARGET_VXWORKS_RTP)
>   arm_pic_register = 9;
>   +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
> +  if (TARGET_FDPIC)
> +{
> +  arm_pic_register = FDPIC_REGNUM;
> +  if (TARGET_ARM_ARCH < 7)
> +error ("FDPIC mode is not supported on architectures older than
> Armv7");

 What properties of FDPIC impose this requirement?  Does it also apply to
 Armv8-m.baseline?

>>> In fact, there was miscommunication on my side, resulting in a
>>> misunderstanding between Kyrill and myself, which I badly translated
>>> into this condition.
>>>
>>> My initial plan was to submit a patch series tested on v7, and send the
>>> patches needed to support older architectures as a follow-up. The proper
>>> restriction is actually "CPUs that do not support ARM or Thumb2". As you
>>> may have noticed during the iterations of this patch series, I had
>>> failed to remove partial Thumb1 support hunks.
>>>
>>> So really this should be rephrased, and rewritten as "FDPIC mode is
>>> supported on architecture versions that support ARM or Thumb-2", if that
>>> suits you. And the condition should thus be:
>>> if (! TARGET_ARM && ! TARGET_THUMB2)
>>>   error ("...")
>>>
>>> This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.
>>
>> When we get to v8-m.baseline the thumb1/2 distinction starts to become a
>> lot more blurred.  A lot of thumb2 features needed for stand-alone
>> systems are then available.  So what feature is it that you require in
>> order to make fdpic work in (traditional) thumb2 that 

Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-26 Thread Christophe Lyon
On Tue, 23 Oct 2018 at 16:07, Richard Earnshaw (lists)
 wrote:
>
> On 19/10/2018 14:40, Christophe Lyon wrote:
> > On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:
> >> On 11/10/18 14:34, Christophe Lyon wrote:
> >>> The FDPIC register is hard-coded to r9, as defined in the ABI.
> >>>
> >>> We have to disable tailcall optimizations if we don't know if the
> >>> target function is in the same module. If not, we have to set r9 to
> >>> the value associated with the target module.
> >>>
> >>> When generating a symbol address, we have to take into account whether
> >>> it is a pointer to data or to a function, because different
> >>> relocations are needed.
> >>>
> >>> 2018-XX-XX  Christophe Lyon  
> >>> Mickaël Guêné 
> >>>
> >>> * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
> >>> in FDPIC mode.
> >>> * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
> >>> new function.
> >>> * config/arm/arm.c (arm_option_override): Define pic register to
> >>> FDPIC_REGNUM.
> >>> (arm_function_ok_for_sibcall) Disable sibcall optimization if we
> >>
> >> Missing colon.
> >>
> >>> have no decl or go through PLT.
> >>> (arm_load_pic_register): Handle TARGET_FDPIC.
> >>> (arm_is_segment_info_known): New function.
> >>> (arm_pic_static_addr): Add support for FDPIC.
> >>> (arm_load_function_descriptor): New function.
> >>> (arm_assemble_integer): Add support for FDPIC.
> >>> * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
> >>> Define. (FDPIC_REGNUM): New define.
> >>> * config/arm/arm.md (call): Add support for FDPIC.
> >>> (call_value): Likewise.
> >>> (*restore_pic_register_after_call): New pattern.
> >>> (untyped_call): Disable if FDPIC.
> >>> (untyped_return): Likewise.
> >>> * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
> >>>
> >>
> >> Other comments inline.
> >>
> >>> diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
> >>> index 4471f79..90733cc 100644
> >>> --- a/gcc/config/arm/arm-c.c
> >>> +++ b/gcc/config/arm/arm-c.c
> >>> @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
> >>> builtin_define ("__ARM_EABI__");
> >>>   }
> >>>   +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
> >>> +
> >>> def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
> >>> def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
> >>>   diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> >>> index 0dfb3ac..28cafa8 100644
> >>> --- a/gcc/config/arm/arm-protos.h
> >>> +++ b/gcc/config/arm/arm-protos.h
> >>> @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
> >>>   extern int arm_const_double_inline_cost (rtx);
> >>>   extern bool arm_const_double_by_parts (rtx);
> >>>   extern bool arm_const_double_by_immediates (rtx);
> >>> +extern rtx arm_load_function_descriptor (rtx funcdesc);
> >>>   extern void arm_emit_call_insn (rtx, rtx, bool);
> >>>   bool detect_cmse_nonsecure_call (tree);
> >>>   extern const char *output_call (rtx *);
> >>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> >>> index 8810df5..92ae24b 100644
> >>> --- a/gcc/config/arm/arm.c
> >>> +++ b/gcc/config/arm/arm.c
> >>> @@ -3470,6 +3470,14 @@ arm_option_override (void)
> >>> if (flag_pic && TARGET_VXWORKS_RTP)
> >>>   arm_pic_register = 9;
> >>>   +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
> >>> +  if (TARGET_FDPIC)
> >>> +{
> >>> +  arm_pic_register = FDPIC_REGNUM;
> >>> +  if (TARGET_ARM_ARCH < 7)
> >>> +error ("FDPIC mode is not supported on architectures older than
> >>> Armv7");
> >>
> >> What properties of FDPIC impose this requirement?  Does it also apply to
> >> Armv8-m.baseline?
> >>
> > In fact, there was miscommunication on my side, resulting in a
> > misunderstanding between Kyrill and myself, which I badly translated
> > into this condition.
> >
> > My initial plan was to submit a patch series tested on v7, and send the
> > patches needed to support older architectures as a follow-up. The proper
> > restriction is actually "CPUs that do not support ARM or Thumb2". As you
> > may have noticed during the iterations of this patch series, I had
> > failed to remove partial Thumb1 support hunks.
> >
> > So really this should be rephrased, and rewritten as "FDPIC mode is
> > supported on architecture versions that support ARM or Thumb-2", if that
> > suits you. And the condition should thus be:
> > if (! TARGET_ARM && ! TARGET_THUMB2)
> >   error ("...")
> >
> > This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.
>
> When we get to v8-m.baseline the thumb1/2 distinction starts to become a
> lot more blurred.  A lot of thumb2 features needed for stand-alone
> systems are then available.  So what feature is it that you require in
> order to make fdpic work in (traditional) thumb2 that isn't in
> (traditional) thumb1?
>
At the moment I'm not 

Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-23 Thread Richard Earnshaw (lists)
On 19/10/2018 14:40, Christophe Lyon wrote:
> On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:
>> On 11/10/18 14:34, Christophe Lyon wrote:
>>> The FDPIC register is hard-coded to r9, as defined in the ABI.
>>>
>>> We have to disable tailcall optimizations if we don't know if the
>>> target function is in the same module. If not, we have to set r9 to
>>> the value associated with the target module.
>>>
>>> When generating a symbol address, we have to take into account whether
>>> it is a pointer to data or to a function, because different
>>> relocations are needed.
>>>
>>> 2018-XX-XX  Christophe Lyon  
>>> Mickaël Guêné 
>>>
>>> * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
>>> in FDPIC mode.
>>> * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
>>> new function.
>>> * config/arm/arm.c (arm_option_override): Define pic register to
>>> FDPIC_REGNUM.
>>> (arm_function_ok_for_sibcall) Disable sibcall optimization if we
>>
>> Missing colon.
>>
>>> have no decl or go through PLT.
>>> (arm_load_pic_register): Handle TARGET_FDPIC.
>>> (arm_is_segment_info_known): New function.
>>> (arm_pic_static_addr): Add support for FDPIC.
>>> (arm_load_function_descriptor): New function.
>>> (arm_assemble_integer): Add support for FDPIC.
>>> * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
>>> Define. (FDPIC_REGNUM): New define.
>>> * config/arm/arm.md (call): Add support for FDPIC.
>>> (call_value): Likewise.
>>> (*restore_pic_register_after_call): New pattern.
>>> (untyped_call): Disable if FDPIC.
>>> (untyped_return): Likewise.
>>> * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
>>>
>>
>> Other comments inline.
>>
>>> diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
>>> index 4471f79..90733cc 100644
>>> --- a/gcc/config/arm/arm-c.c
>>> +++ b/gcc/config/arm/arm-c.c
>>> @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
>>>     builtin_define ("__ARM_EABI__");
>>>   }
>>>   +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
>>> +
>>>     def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
>>>     def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
>>>   diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
>>> index 0dfb3ac..28cafa8 100644
>>> --- a/gcc/config/arm/arm-protos.h
>>> +++ b/gcc/config/arm/arm-protos.h
>>> @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
>>>   extern int arm_const_double_inline_cost (rtx);
>>>   extern bool arm_const_double_by_parts (rtx);
>>>   extern bool arm_const_double_by_immediates (rtx);
>>> +extern rtx arm_load_function_descriptor (rtx funcdesc);
>>>   extern void arm_emit_call_insn (rtx, rtx, bool);
>>>   bool detect_cmse_nonsecure_call (tree);
>>>   extern const char *output_call (rtx *);
>>> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
>>> index 8810df5..92ae24b 100644
>>> --- a/gcc/config/arm/arm.c
>>> +++ b/gcc/config/arm/arm.c
>>> @@ -3470,6 +3470,14 @@ arm_option_override (void)
>>>     if (flag_pic && TARGET_VXWORKS_RTP)
>>>   arm_pic_register = 9;
>>>   +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
>>> +  if (TARGET_FDPIC)
>>> +    {
>>> +  arm_pic_register = FDPIC_REGNUM;
>>> +  if (TARGET_ARM_ARCH < 7)
>>> +    error ("FDPIC mode is not supported on architectures older than
>>> Armv7");
>>
>> What properties of FDPIC impose this requirement?  Does it also apply to
>> Armv8-m.baseline?
>>
> In fact, there was miscommunication on my side, resulting in a
> misunderstanding between Kyrill and myself, which I badly translated
> into this condition.
> 
> My initial plan was to submit a patch series tested on v7, and send the
> patches needed to support older architectures as a follow-up. The proper
> restriction is actually "CPUs that do not support ARM or Thumb2". As you
> may have noticed during the iterations of this patch series, I had
> failed to remove partial Thumb1 support hunks.
> 
> So really this should be rephrased, and rewritten as "FDPIC mode is
> supported on architecture versions that support ARM or Thumb-2", if that
> suits you. And the condition should thus be:
> if (! TARGET_ARM && ! TARGET_THUMB2)
>   error ("...")
> 
> This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.

When we get to v8-m.baseline the thumb1/2 distinction starts to become a
lot more blurred.  A lot of thumb2 features needed for stand-alone
systems are then available.  So what feature is it that you require in
order to make fdpic work in (traditional) thumb2 that isn't in
(traditional) thumb1?



> As a side note, I tried to build GCC master (without my patches)
> --with-cpu=cortex-m23, and both targets arm-eabi and arm-linux-gnueabi
> failed to buid.
> 
> For arm-eabi, there are problems in newlib:
> newlib/libc/sys/arm/crt0.S:145: Error: lo register required -- `add
> sl,r2,#256'
> 

Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-19 Thread Christophe Lyon

On 12/10/2018 12:45, Richard Earnshaw (lists) wrote:

On 11/10/18 14:34, Christophe Lyon wrote:

The FDPIC register is hard-coded to r9, as defined in the ABI.

We have to disable tailcall optimizations if we don't know if the
target function is in the same module. If not, we have to set r9 to
the value associated with the target module.

When generating a symbol address, we have to take into account whether
it is a pointer to data or to a function, because different
relocations are needed.

2018-XX-XX  Christophe Lyon  
Mickaël Guêné 

* config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
in FDPIC mode.
* config/arm/arm-protos.h (arm_load_function_descriptor): Declare
new function.
* config/arm/arm.c (arm_option_override): Define pic register to
FDPIC_REGNUM.
(arm_function_ok_for_sibcall) Disable sibcall optimization if we


Missing colon.


have no decl or go through PLT.
(arm_load_pic_register): Handle TARGET_FDPIC.
(arm_is_segment_info_known): New function.
(arm_pic_static_addr): Add support for FDPIC.
(arm_load_function_descriptor): New function.
(arm_assemble_integer): Add support for FDPIC.
* config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
Define. (FDPIC_REGNUM): New define.
* config/arm/arm.md (call): Add support for FDPIC.
(call_value): Likewise.
(*restore_pic_register_after_call): New pattern.
(untyped_call): Disable if FDPIC.
(untyped_return): Likewise.
* config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.



Other comments inline.


diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
index 4471f79..90733cc 100644
--- a/gcc/config/arm/arm-c.c
+++ b/gcc/config/arm/arm-c.c
@@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
builtin_define ("__ARM_EABI__");
  }
  
+  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);

+
def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
  
diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h

index 0dfb3ac..28cafa8 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
  extern int arm_const_double_inline_cost (rtx);
  extern bool arm_const_double_by_parts (rtx);
  extern bool arm_const_double_by_immediates (rtx);
+extern rtx arm_load_function_descriptor (rtx funcdesc);
  extern void arm_emit_call_insn (rtx, rtx, bool);
  bool detect_cmse_nonsecure_call (tree);
  extern const char *output_call (rtx *);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 8810df5..92ae24b 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3470,6 +3470,14 @@ arm_option_override (void)
if (flag_pic && TARGET_VXWORKS_RTP)
  arm_pic_register = 9;
  
+  /* If in FDPIC mode then force arm_pic_register to be r9.  */

+  if (TARGET_FDPIC)
+{
+  arm_pic_register = FDPIC_REGNUM;
+  if (TARGET_ARM_ARCH < 7)
+   error ("FDPIC mode is not supported on architectures older than Armv7");


What properties of FDPIC impose this requirement?  Does it also apply to
Armv8-m.baseline?


In fact, there was miscommunication on my side, resulting in a misunderstanding 
between Kyrill and myself, which I badly translated into this condition.

My initial plan was to submit a patch series tested on v7, and send the patches needed to 
support older architectures as a follow-up. The proper restriction is actually "CPUs 
that do not support ARM or Thumb2". As you may have noticed during the iterations of 
this patch series, I had failed to remove partial Thumb1 support hunks.

So really this should be rephrased, and rewritten as "FDPIC mode is supported on 
architecture versions that support ARM or Thumb-2", if that suits you. And the 
condition should thus be:
if (! TARGET_ARM && ! TARGET_THUMB2)
  error ("...")

This would also exclude Armv8-m.baseline, since it doesn't support Thumb2.
As a side note, I tried to build GCC master (without my patches) 
--with-cpu=cortex-m23, and both targets arm-eabi and arm-linux-gnueabi failed 
to buid.

For arm-eabi, there are problems in newlib:
newlib/libc/sys/arm/crt0.S:145: Error: lo register required -- `add sl,r2,#256'
newlib/libc/sys/arm/trap.S:88: Error: lo register required -- `sub ip,sp,ip'

For arm-linux-gnueabi, the failure happens while building libgcc:
/home/christophe.lyon/src/GCC/sources/newlib/newlib/libc/machine/arm/setjmp.S:169:
 Error: selected processor does not support ARM opcodes
/newlib/newlib/libc/machine/arm/setjmp.S:176: Error: attempt to use an ARM 
instruction on a Thumb-only processor -- `stmea a1!,{ v1-v7,fp,ip,sp,lr }'
/newlib/newlib/libc/machine/arm/setjmp.S:186: Error: attempt to use an ARM 
instruction on a Thumb-only processor -- `mov a1,#0'

Re: [ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-12 Thread Richard Earnshaw (lists)
On 11/10/18 14:34, Christophe Lyon wrote:
> The FDPIC register is hard-coded to r9, as defined in the ABI.
> 
> We have to disable tailcall optimizations if we don't know if the
> target function is in the same module. If not, we have to set r9 to
> the value associated with the target module.
> 
> When generating a symbol address, we have to take into account whether
> it is a pointer to data or to a function, because different
> relocations are needed.
> 
> 2018-XX-XX  Christophe Lyon  
>   Mickaël Guêné 
> 
>   * config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
>   in FDPIC mode.
>   * config/arm/arm-protos.h (arm_load_function_descriptor): Declare
>   new function.
>   * config/arm/arm.c (arm_option_override): Define pic register to
>   FDPIC_REGNUM.
>   (arm_function_ok_for_sibcall) Disable sibcall optimization if we

Missing colon.

>   have no decl or go through PLT.
>   (arm_load_pic_register): Handle TARGET_FDPIC.
>   (arm_is_segment_info_known): New function.
>   (arm_pic_static_addr): Add support for FDPIC.
>   (arm_load_function_descriptor): New function.
>   (arm_assemble_integer): Add support for FDPIC.
>   * config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
>   Define. (FDPIC_REGNUM): New define.
>   * config/arm/arm.md (call): Add support for FDPIC.
>   (call_value): Likewise.
>   (*restore_pic_register_after_call): New pattern.
>   (untyped_call): Disable if FDPIC.
>   (untyped_return): Likewise.
>   * config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.
> 

Other comments inline.

> diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
> index 4471f79..90733cc 100644
> --- a/gcc/config/arm/arm-c.c
> +++ b/gcc/config/arm/arm-c.c
> @@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
>builtin_define ("__ARM_EABI__");
>  }
>  
> +  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
> +
>def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
>def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
>  
> diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> index 0dfb3ac..28cafa8 100644
> --- a/gcc/config/arm/arm-protos.h
> +++ b/gcc/config/arm/arm-protos.h
> @@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
>  extern int arm_const_double_inline_cost (rtx);
>  extern bool arm_const_double_by_parts (rtx);
>  extern bool arm_const_double_by_immediates (rtx);
> +extern rtx arm_load_function_descriptor (rtx funcdesc);
>  extern void arm_emit_call_insn (rtx, rtx, bool);
>  bool detect_cmse_nonsecure_call (tree);
>  extern const char *output_call (rtx *);
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index 8810df5..92ae24b 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -3470,6 +3470,14 @@ arm_option_override (void)
>if (flag_pic && TARGET_VXWORKS_RTP)
>  arm_pic_register = 9;
>  
> +  /* If in FDPIC mode then force arm_pic_register to be r9.  */
> +  if (TARGET_FDPIC)
> +{
> +  arm_pic_register = FDPIC_REGNUM;
> +  if (TARGET_ARM_ARCH < 7)
> + error ("FDPIC mode is not supported on architectures older than Armv7");

What properties of FDPIC impose this requirement?  Does it also apply to
Armv8-m.baseline?

> +}
> +
>if (arm_pic_register_string != NULL)
>  {
>int pic_register = decode_reg_name (arm_pic_register_string);
> @@ -7251,6 +7259,21 @@ arm_function_ok_for_sibcall (tree decl, tree exp)
>if (cfun->machine->sibcall_blocked)
>  return false;
>  
> +  if (TARGET_FDPIC)
> +{
> +  /* In FDPIC, never tailcall something for which we have no decl:
> +  the target function could be in a different module, requiring
> +  a different FDPIC register value.  */
> +  if (decl == NULL)
> + return false;
> +
> +  /* Don't tailcall if we go through the PLT since the FDPIC
> +  register is then corrupted and we don't restore it after
> +  static function calls.  */
> +  if (!targetm.binds_local_p (decl))
> + return false;
> +}
> +
>/* Never tailcall something if we are generating code for Thumb-1.  */
>if (TARGET_THUMB1)
>  return false;
> @@ -7629,7 +7652,9 @@ arm_load_pic_register (unsigned long saved_regs 
> ATTRIBUTE_UNUSED)
>  {
>rtx l1, labelno, pic_tmp, pic_rtx, pic_reg;
>  
> -  if (crtl->uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
> +  if (crtl->uses_pic_offset_table == 0
> +  || TARGET_SINGLE_PIC_BASE
> +  || TARGET_FDPIC)
>  return;
>  
>gcc_assert (flag_pic);
> @@ -7697,28 +7722,140 @@ arm_load_pic_register (unsigned long saved_regs 
> ATTRIBUTE_UNUSED)
>emit_use (pic_reg);
>  }
>  
> +/* Try to know if the object will go in text or data segment. This is

"Try to determine whether an object, referenced via ORIG, will be placed
in the text or data segment."
> +   used in FDPIC mode, to decide which relocations to use 

[ARM/FDPIC v3 04/21] [ARM] FDPIC: Add support for FDPIC for arm architecture

2018-10-11 Thread Christophe Lyon
The FDPIC register is hard-coded to r9, as defined in the ABI.

We have to disable tailcall optimizations if we don't know if the
target function is in the same module. If not, we have to set r9 to
the value associated with the target module.

When generating a symbol address, we have to take into account whether
it is a pointer to data or to a function, because different
relocations are needed.

2018-XX-XX  Christophe Lyon  
Mickaël Guêné 

* config/arm/arm-c.c (__FDPIC__): Define new pre-processor macro
in FDPIC mode.
* config/arm/arm-protos.h (arm_load_function_descriptor): Declare
new function.
* config/arm/arm.c (arm_option_override): Define pic register to
FDPIC_REGNUM.
(arm_function_ok_for_sibcall) Disable sibcall optimization if we
have no decl or go through PLT.
(arm_load_pic_register): Handle TARGET_FDPIC.
(arm_is_segment_info_known): New function.
(arm_pic_static_addr): Add support for FDPIC.
(arm_load_function_descriptor): New function.
(arm_assemble_integer): Add support for FDPIC.
* config/arm/arm.h (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED):
Define. (FDPIC_REGNUM): New define.
* config/arm/arm.md (call): Add support for FDPIC.
(call_value): Likewise.
(*restore_pic_register_after_call): New pattern.
(untyped_call): Disable if FDPIC.
(untyped_return): Likewise.
* config/arm/unspecs.md (UNSPEC_PIC_RESTORE): New.

diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
index 4471f79..90733cc 100644
--- a/gcc/config/arm/arm-c.c
+++ b/gcc/config/arm/arm-c.c
@@ -202,6 +202,8 @@ arm_cpu_builtins (struct cpp_reader* pfile)
   builtin_define ("__ARM_EABI__");
 }
 
+  def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC);
+
   def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
   def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
 
diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index 0dfb3ac..28cafa8 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -136,6 +136,7 @@ extern int arm_max_const_double_inline_cost (void);
 extern int arm_const_double_inline_cost (rtx);
 extern bool arm_const_double_by_parts (rtx);
 extern bool arm_const_double_by_immediates (rtx);
+extern rtx arm_load_function_descriptor (rtx funcdesc);
 extern void arm_emit_call_insn (rtx, rtx, bool);
 bool detect_cmse_nonsecure_call (tree);
 extern const char *output_call (rtx *);
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 8810df5..92ae24b 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3470,6 +3470,14 @@ arm_option_override (void)
   if (flag_pic && TARGET_VXWORKS_RTP)
 arm_pic_register = 9;
 
+  /* If in FDPIC mode then force arm_pic_register to be r9.  */
+  if (TARGET_FDPIC)
+{
+  arm_pic_register = FDPIC_REGNUM;
+  if (TARGET_ARM_ARCH < 7)
+   error ("FDPIC mode is not supported on architectures older than Armv7");
+}
+
   if (arm_pic_register_string != NULL)
 {
   int pic_register = decode_reg_name (arm_pic_register_string);
@@ -7251,6 +7259,21 @@ arm_function_ok_for_sibcall (tree decl, tree exp)
   if (cfun->machine->sibcall_blocked)
 return false;
 
+  if (TARGET_FDPIC)
+{
+  /* In FDPIC, never tailcall something for which we have no decl:
+the target function could be in a different module, requiring
+a different FDPIC register value.  */
+  if (decl == NULL)
+   return false;
+
+  /* Don't tailcall if we go through the PLT since the FDPIC
+register is then corrupted and we don't restore it after
+static function calls.  */
+  if (!targetm.binds_local_p (decl))
+   return false;
+}
+
   /* Never tailcall something if we are generating code for Thumb-1.  */
   if (TARGET_THUMB1)
 return false;
@@ -7629,7 +7652,9 @@ arm_load_pic_register (unsigned long saved_regs 
ATTRIBUTE_UNUSED)
 {
   rtx l1, labelno, pic_tmp, pic_rtx, pic_reg;
 
-  if (crtl->uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE)
+  if (crtl->uses_pic_offset_table == 0
+  || TARGET_SINGLE_PIC_BASE
+  || TARGET_FDPIC)
 return;
 
   gcc_assert (flag_pic);
@@ -7697,28 +7722,140 @@ arm_load_pic_register (unsigned long saved_regs 
ATTRIBUTE_UNUSED)
   emit_use (pic_reg);
 }
 
+/* Try to know if the object will go in text or data segment. This is
+   used in FDPIC mode, to decide which relocations to use when
+   accessing ORIG. IS_READONLY is set to true if ORIG is a read-only
+   location, false otherwise.  */
+static bool
+arm_is_segment_info_known (rtx orig, bool *is_readonly)
+{
+  bool res = false;
+
+  *is_readonly = false;
+
+  if (GET_CODE (orig) == LABEL_REF)
+{
+  res = true;
+  *is_readonly = true;
+}
+  else if (SYMBOL_REF_P (orig))
+{
+  if (CONSTANT_POOL_ADDRESS_P (orig))
+   {
+ res = true;
+