Skip to content

Commit

Permalink
Fix bug related to the personality function
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Apr 16, 2023
1 parent 3e63da6 commit 1986920
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
23 changes: 23 additions & 0 deletions gcc/expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13365,6 +13365,7 @@ const_vector_from_tree (tree exp)
tree
build_personality_function (const char *lang)
{
// TODO: rewrite by calling build_personality_function_with_name.
const char *unwind_and_version;
tree decl, type;
char *name;
Expand Down Expand Up @@ -13406,6 +13407,28 @@ build_personality_function (const char *lang)
return decl;
}

tree
build_personality_function_with_name (const char *name)
{
tree decl, type;

type = build_function_type_list (unsigned_type_node,
integer_type_node, integer_type_node,
long_long_unsigned_type_node,
ptr_type_node, ptr_type_node, NULL_TREE);
decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
get_identifier (name), type);
DECL_ARTIFICIAL (decl) = 1;
DECL_EXTERNAL (decl) = 1;
TREE_PUBLIC (decl) = 1;

/* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
are the flags assigned by targetm.encode_section_info. */
SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);

return decl;
}

/* Extracts the personality function of DECL and returns the corresponding
libfunc. */

Expand Down
35 changes: 35 additions & 0 deletions gcc/jit/dummy-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ const struct attribute_spec jit_format_attribute_table[] =
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};

char* jit_personality_func_name = NULL;
static tree personality_decl;

/* FIXME: This is a hack to preserve trees that we create from the
garbage collector. */

static GTY (()) tree jit_gc_root;

void
jit_preserve_from_gc (tree t)
{
jit_gc_root = tree_cons (NULL_TREE, t, jit_gc_root);
}

/* Attribute handlers. */

/* Handle a "noreturn" attribute; arguments as in
Expand Down Expand Up @@ -589,6 +603,8 @@ jit_end_diagnostic (diagnostic_context *context,
static bool
jit_langhook_init (void)
{
jit_gc_root = NULL_TREE;
personality_decl = NULL_TREE;
gcc_assert (gcc::jit::active_playback_ctxt);
JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());

Expand Down Expand Up @@ -920,6 +936,25 @@ jit_langhook_getdecls (void)
return NULL;
}

static tree
jit_langhook_eh_personality (void)
{
if (personality_decl == NULL_TREE)
{
if (jit_personality_func_name != NULL) {
personality_decl = build_personality_function_with_name (jit_personality_func_name);
jit_preserve_from_gc(personality_decl);
}
else {
return lhd_gcc_personality();
}
}
return personality_decl;
}

#undef LANG_HOOKS_EH_PERSONALITY
#define LANG_HOOKS_EH_PERSONALITY jit_langhook_eh_personality

#undef LANG_HOOKS_NAME
#define LANG_HOOKS_NAME "libgccjit"

Expand Down
7 changes: 7 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3753,6 +3753,13 @@ gcc_jit_function_set_personality_function (gcc_jit_function *fn,
fn->set_personality_function (personality_func);
}

extern char* jit_personality_func_name;

void
gcc_jit_set_global_personality_function_name (char* name) {
jit_personality_func_name = name;
}

/* Public entrypoint. See description in libgccjit.h.
The real work is done by the
Expand Down
2 changes: 2 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,8 @@ void
gcc_jit_function_set_personality_function (gcc_jit_function *fn,
gcc_jit_function *personality_func);

extern void
gcc_jit_set_global_personality_function_name (char* name);

#define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector

Expand Down
1 change: 1 addition & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,5 @@ LIBGCCJIT_ABI_32 {
gcc_jit_context_get_target_builtin_function;
gcc_jit_context_new_rvalue_vector_perm;
gcc_jit_context_new_vector_access;
gcc_jit_set_global_personality_function_name;
} LIBGCCJIT_ABI_31;
5 changes: 2 additions & 3 deletions gcc/tree-eh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4882,10 +4882,9 @@ pass_cleanup_eh::execute (function *fun)
/* If the function no longer needs an EH personality routine
clear it. This exposes cross-language inlining opportunities
and avoids references to a never defined personality routine. */
// TODO: uncomment and find out why this doesn't work.
/*if (DECL_FUNCTION_PERSONALITY (current_function_decl)
if (DECL_FUNCTION_PERSONALITY (current_function_decl)
&& function_needs_eh_personality (fun) != eh_personality_lang)
DECL_FUNCTION_PERSONALITY (current_function_decl) = NULL_TREE;*/
DECL_FUNCTION_PERSONALITY (current_function_decl) = NULL_TREE;

return ret;
}
Expand Down
1 change: 1 addition & 0 deletions gcc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6479,6 +6479,7 @@ extern tree get_inner_reference (tree, poly_int64_pod *, poly_int64_pod *,
tree *, machine_mode *, int *, int *, int *);

extern tree build_personality_function (const char *);
extern tree build_personality_function_with_name (const char *);

struct GTY(()) int_n_trees_t {
/* These parts are initialized at runtime */
Expand Down

0 comments on commit 1986920

Please sign in to comment.