diff mbox series

[ARM/FDPIC,v3,08/21,ARM] FDPIC: Ensure local/global binding for function descriptors

Message ID 20181011133518.17258-9-christophe.lyon@st.com
State Superseded
Headers show
Series FDPIC ABI for ARM | expand

Commit Message

Christophe Lyon Oct. 11, 2018, 1:34 p.m. UTC
Use local binding rules to decide whether we can use GOTOFFFUNCDESC to
compute the function address.

2018-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): Ensure binding rules on function
	pointers in FDPIC mode.
	(arm_assemble_integer): Likewise.

Change-Id: I3fa0b63bc0f672903f405aa72cc46052de1c0feb

-- 
2.6.3

Comments

Richard Earnshaw (lists) Oct. 12, 2018, 11:54 a.m. UTC | #1
On 11/10/18 14:34, Christophe Lyon wrote:
> Use local binding rules to decide whether we can use GOTOFFFUNCDESC to

> compute the function address.

> 

> 2018-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): Ensure binding rules on function


Enforce?

> 	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 a6dce36..d0144fd 100644

> --- a/gcc/config/arm/arm.c

> +++ b/gcc/config/arm/arm.c

> @@ -3768,6 +3768,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_local_funcdesc_p (rtx fnx)


Given that this function doesn't return what it's name implies when not
FDPIC, I think the name should reflect that.  Please rename to
arm_fdpic_local...

> +{

> +  tree fn;

> +  enum symbol_visibility vis;

> +  bool ret;

> +

> +  if (!TARGET_FDPIC)

> +    return TRUE;

> +

> +  if (! SYMBOL_REF_LOCAL_P (fnx))

> +    return FALSE;

> +

> +  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 unicity of funcdesc pointers.  */


s/unicity/uniqueness/

> +    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)

>  {

> @@ -7485,7 +7521,9 @@ legitimize_pic_address (rtx orig, machine_mode mode, rtx 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)


space before parenthesis

> +		   || arm_local_funcdesc_p (orig))))

>  	  && NEED_GOT_RELOC

>  	  && arm_pic_data_is_text_relative)

>  	insn = arm_pic_static_addr (orig, reg);

> @@ -23053,7 +23091,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_local_funcdesc_p (x)))))

>  	    {

>  	      if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x))

>  		fputs ("(GOTFUNCDESC)", asm_out_file);

> 


OK with those changes.

R.

[gonna have to stop now and I'm OoO next week]
diff mbox series

Patch

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index a6dce36..d0144fd 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3768,6 +3768,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_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;
+
+  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 unicity 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)
 {
@@ -7485,7 +7521,9 @@  legitimize_pic_address (rtx orig, machine_mode mode, rtx 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_local_funcdesc_p (orig))))
 	  && NEED_GOT_RELOC
 	  && arm_pic_data_is_text_relative)
 	insn = arm_pic_static_addr (orig, reg);
@@ -23053,7 +23091,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_local_funcdesc_p (x)))))
 	    {
 	      if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (x))
 		fputs ("(GOTFUNCDESC)", asm_out_file);