Skip to content

Commit

Permalink
[ARM/FDPIC v6 08/24] [ARM] FDPIC: Enforce local/global binding for fu…
Browse files Browse the repository at this point in the history
…nction descriptors

Use local binding rules to decide whether we can use GOTOFFFUNCDESC to
compute the function address.

2019-09-10  Christophe Lyon  <christophe.lyon@st.com>
	Mickaël Guêné <mickael.guene@st.com>

	gcc/
	* config/arm/arm.c (arm_fdpic_local_funcdesc_p): New function.
	(legitimize_pic_address): Enforce binding rules on function
	pointers in FDPIC mode.
	(arm_assemble_integer): Likewise.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@275570 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
clyon committed Sep 10, 2019
1 parent 947d905 commit 2ec82e4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2019-09-10 Christophe Lyon <christophe.lyon@st.com>
Mickaël Guêné <mickael.guene@st.com>

* config/arm/arm.c (arm_fdpic_local_funcdesc_p): New function.
(legitimize_pic_address): Enforce binding rules on function
pointers in FDPIC mode.
(arm_assemble_integer): Likewise.

2019-09-10 Christophe Lyon <christophe.lyon@st.com>
Mickaël Guêné <mickael.guene@st.com>

Expand Down
44 changes: 42 additions & 2 deletions gcc/config/arm/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,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;

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)
{
Expand Down Expand Up @@ -7534,7 +7570,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);
Expand Down Expand Up @@ -23160,7 +23198,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);
Expand Down

0 comments on commit 2ec82e4

Please sign in to comment.