[ARM/FDPIC v5 08/21] [ARM] FDPIC: Enforce local/global binding for function descriptors
Kyrill Tkachov
kyrylo.tkachov@foss.arm.com
Tue Jul 16 10:51:00 GMT 2019
Hi Christophe,
On 5/15/19 1:39 PM, Christophe Lyon wrote:
> Use local binding rules to decide whether we can use GOTOFFFUNCDESC to
> compute the function address.
>
> 2019-XX-XX Christophe Lyon <christophe.lyon@st.com>
>        Mickaël Guêné <mickael.guene@st.com>
>
> Â Â Â Â Â Â Â gcc/
> Â Â Â Â Â Â Â * config/arm/arm.c (arm_local_funcdesc_p): New function.
> Â Â Â Â Â Â Â (legitimize_pic_address): Enforce binding rules on function
> Â Â Â Â Â Â Â pointers in FDPIC mode.
> Â Â Â Â Â Â Â (arm_assemble_integer): Likewise.
>
> Change-Id: I3fa0b63bc0f672903f405aa72cc46052de1c0feb
>
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index dbd1671..40e3f3b 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -3790,6 +3790,42 @@ arm_options_perform_arch_sanity_checks (void)
> Â Â Â Â }
> Â }
>
> +/* Test whether a local function descriptor is canonical, i.e.,
> +Â Â whether we can use GOTOFFFUNCDESC to compute the address of the
> +  function. */
> +static bool
> +arm_fdpic_local_funcdesc_p (rtx fnx)
> +{
> +Â tree fn;
> +Â enum symbol_visibility vis;
> +Â bool ret;
> +
> +Â if (!TARGET_FDPIC)
> +Â Â Â return TRUE;
> +
> +Â if (! SYMBOL_REF_LOCAL_P (fnx))
> +Â Â Â return FALSE;
> +
Please use normal C 'true' and 'false' in this patch.
Ok with that change once the rest is approved.
Thanks,
Kyrill
> +Â fn = SYMBOL_REF_DECL (fnx);
> +
> +Â if (! fn)
> +Â Â Â return FALSE;
> +
> +Â vis = DECL_VISIBILITY (fn);
> +
> +Â if (vis == VISIBILITY_PROTECTED)
> +Â Â Â /* Private function descriptors for protected functions are not
> +      canonical. Temporarily change the visibility to global so that
> +      we can ensure uniqueness of funcdesc pointers. */
> +Â Â Â DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
> +
> +Â ret = default_binds_local_p_1 (fn, flag_pic);
> +
> +Â DECL_VISIBILITY (fn) = vis;
> +
> +Â return ret;
> +}
> +
> Â static void
> Â arm_add_gc_roots (void)
> Â {
> @@ -7563,7 +7599,9 @@ legitimize_pic_address (rtx orig, machine_mode
> mode, rtx reg, rtx pic_reg,
> Â Â Â Â Â Â Â Â Â Â Â || (GET_CODE (orig) == SYMBOL_REF
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && SYMBOL_REF_LOCAL_P (orig)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && (SYMBOL_REF_DECL (orig)
> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ? !DECL_WEAK (SYMBOL_REF_DECL (orig)) : 1)))
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ? !DECL_WEAK (SYMBOL_REF_DECL (orig)) : 1)
> +Â Â Â Â Â Â Â Â Â Â Â Â Â && (!SYMBOL_REF_FUNCTION_P (orig)
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â || arm_fdpic_local_funcdesc_p (orig))))
> Â Â Â Â Â Â Â Â Â Â && NEED_GOT_RELOC
> Â Â Â Â Â Â Â Â Â Â && arm_pic_data_is_text_relative)
> Â Â Â Â Â Â Â Â insn = arm_pic_static_addr (orig, reg);
> @@ -23231,7 +23269,9 @@ arm_assemble_integer (rtx x, unsigned int
> size, int aligned_p)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â || (GET_CODE (x) == SYMBOL_REF
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && (!SYMBOL_REF_LOCAL_P (x)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â || (SYMBOL_REF_DECL (x)
> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ? DECL_WEAK (SYMBOL_REF_DECL (x)) : 0))))
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ? DECL_WEAK (SYMBOL_REF_DECL (x)) : 0)
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â || (SYMBOL_REF_FUNCTION_P (x)
> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â && !arm_fdpic_local_funcdesc_p (x)))))
> Â Â Â Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x))
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â fputs ("(GOTFUNCDESC)", asm_out_file);
> --
> 2.6.3
>
More information about the Gcc-patches
mailing list