[ARM/FDPIC v5 12/21] [ARM] FDPIC: Restore r9 after we call __aeabi_read_tp
Kyrill Tkachov
kyrylo.tkachov@foss.arm.com
Thu Aug 29 15:44:00 GMT 2019
Hi Christophe,
On 5/15/19 1:39 PM, Christophe Lyon wrote:
> We call __aeabi_read_tp() to get the thread pointer. Since this is a
> function call, we have to restore the FDPIC register afterwards.
>
> 2019-XX-XX Christophe Lyon <christophe.lyon@st.com>
>        Mickaël Guêné <mickael.guene@st.com>
>
> Â Â Â Â Â Â Â gcc/
> Â Â Â Â Â Â Â * config/arm/arm.c (arm_load_tp): Add FDPIC support.
> Â Â Â Â Â Â Â * config/arm/arm.md (load_tp_soft_fdpic): New pattern.
> Â Â Â Â Â Â Â (load_tp_soft): Disable in FDPIC mode.
>
> Change-Id: I1f6dfaee6260ecb453270f4971b3c5124317a186
>
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index 5fc7a20..26f29c7 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -8732,7 +8732,25 @@ arm_load_tp (rtx target)
>
> Â Â Â Â Â Â rtx tmp;
>
> -Â Â Â Â Â emit_insn (gen_load_tp_soft ());
> +Â Â Â Â Â if (TARGET_FDPIC)
> +Â Â Â Â Â Â {
> +Â Â Â Â Â Â Â Â rtx par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (3));
> +Â Â Â Â Â Â Â Â rtx fdpic_reg = gen_rtx_REG (Pmode, FDPIC_REGNUM);
> +Â Â Â Â Â Â Â Â rtx initial_fdpic_reg = get_hard_reg_initial_val (Pmode,
> FDPIC_REGNUM);
> +
> +Â Â Â Â Â Â Â Â emit_insn (gen_load_tp_soft_fdpic ());
> +
> +        /* Restore r9. */
> +Â Â Â Â Â Â Â Â XVECEXP (par, 0, 0) = gen_rtx_UNSPEC (VOIDmode,
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gen_rtvec (2, fdpic_reg,
> + initial_fdpic_reg),
> + UNSPEC_PIC_RESTORE);
> +Â Â Â Â Â Â Â Â XVECEXP (par, 0, 1) = gen_rtx_USE (VOIDmode, initial_fdpic_reg);
> +Â Â Â Â Â Â Â Â XVECEXP (par, 0, 2) = gen_rtx_CLOBBER (VOIDmode, fdpic_reg);
> +Â Â Â Â Â Â Â Â emit_insn (par);
> +Â Â Â Â Â Â }
> +Â Â Â Â Â else
> +Â Â Â Â Â Â emit_insn (gen_load_tp_soft ());
>
> Â Â Â Â Â Â tmp = gen_rtx_REG (SImode, R0_REGNUM);
> Â Â Â Â Â Â emit_move_insn (target, tmp);
> diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
> index 9036255..0edcb1d 100644
> --- a/gcc/config/arm/arm.md
> +++ b/gcc/config/arm/arm.md
> @@ -11759,12 +11759,25 @@
> Â )
>
>  ;; Doesn't clobber R1-R3. Must use r0 for the first operand.
> +(define_insn "load_tp_soft_fdpic"
> +Â [(set (reg:SI 0) (unspec:SI [(const_int 0)] UNSPEC_TLS))
> +Â Â (clobber (reg:SI 9))
Use FDPIC_REGNUM here (does it need to be declared at the top of arm.md
for it to work?)
Otherwise this is ok.
Thanks,
Kyrill
> +Â Â (clobber (reg:SI LR_REGNUM))
> +Â Â (clobber (reg:SI IP_REGNUM))
> +Â Â (clobber (reg:CC CC_REGNUM))]
> +Â "TARGET_SOFT_TP && TARGET_FDPIC"
> +Â "bl\\t__aeabi_read_tp\\t@ load_tp_soft"
> +Â [(set_attr "conds" "clob")
> +Â Â (set_attr "type" "branch")]
> +)
> +
> +;; Doesn't clobber R1-R3. Must use r0 for the first operand.
> Â (define_insn "load_tp_soft"
> Â Â [(set (reg:SI 0) (unspec:SI [(const_int 0)] UNSPEC_TLS))
> Â Â Â (clobber (reg:SI LR_REGNUM))
> Â Â Â (clobber (reg:SI IP_REGNUM))
> Â Â Â (clobber (reg:CC CC_REGNUM))]
> -Â "TARGET_SOFT_TP"
> +Â "TARGET_SOFT_TP && !TARGET_FDPIC"
> Â Â "bl\\t__aeabi_read_tp\\t@ load_tp_soft"
> Â Â [(set_attr "conds" "clob")
> Â Â Â (set_attr "type" "branch")]
> --
> 2.6.3
>
More information about the Gcc-patches
mailing list