Skip to content

Commit 1986920

Browse files
committed
Fix bug related to the personality function
1 parent 3e63da6 commit 1986920

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

gcc/expr.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13365,6 +13365,7 @@ const_vector_from_tree (tree exp)
1336513365
tree
1336613366
build_personality_function (const char *lang)
1336713367
{
13368+
// TODO: rewrite by calling build_personality_function_with_name.
1336813369
const char *unwind_and_version;
1336913370
tree decl, type;
1337013371
char *name;
@@ -13406,6 +13407,28 @@ build_personality_function (const char *lang)
1340613407
return decl;
1340713408
}
1340813409

13410+
tree
13411+
build_personality_function_with_name (const char *name)
13412+
{
13413+
tree decl, type;
13414+
13415+
type = build_function_type_list (unsigned_type_node,
13416+
integer_type_node, integer_type_node,
13417+
long_long_unsigned_type_node,
13418+
ptr_type_node, ptr_type_node, NULL_TREE);
13419+
decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
13420+
get_identifier (name), type);
13421+
DECL_ARTIFICIAL (decl) = 1;
13422+
DECL_EXTERNAL (decl) = 1;
13423+
TREE_PUBLIC (decl) = 1;
13424+
13425+
/* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
13426+
are the flags assigned by targetm.encode_section_info. */
13427+
SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
13428+
13429+
return decl;
13430+
}
13431+
1340913432
/* Extracts the personality function of DECL and returns the corresponding
1341013433
libfunc. */
1341113434

gcc/jit/dummy-frontend.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ const struct attribute_spec jit_format_attribute_table[] =
157157
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
158158
};
159159

160+
char* jit_personality_func_name = NULL;
161+
static tree personality_decl;
162+
163+
/* FIXME: This is a hack to preserve trees that we create from the
164+
garbage collector. */
165+
166+
static GTY (()) tree jit_gc_root;
167+
168+
void
169+
jit_preserve_from_gc (tree t)
170+
{
171+
jit_gc_root = tree_cons (NULL_TREE, t, jit_gc_root);
172+
}
173+
160174
/* Attribute handlers. */
161175

162176
/* Handle a "noreturn" attribute; arguments as in
@@ -589,6 +603,8 @@ jit_end_diagnostic (diagnostic_context *context,
589603
static bool
590604
jit_langhook_init (void)
591605
{
606+
jit_gc_root = NULL_TREE;
607+
personality_decl = NULL_TREE;
592608
gcc_assert (gcc::jit::active_playback_ctxt);
593609
JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
594610

@@ -920,6 +936,25 @@ jit_langhook_getdecls (void)
920936
return NULL;
921937
}
922938

939+
static tree
940+
jit_langhook_eh_personality (void)
941+
{
942+
if (personality_decl == NULL_TREE)
943+
{
944+
if (jit_personality_func_name != NULL) {
945+
personality_decl = build_personality_function_with_name (jit_personality_func_name);
946+
jit_preserve_from_gc(personality_decl);
947+
}
948+
else {
949+
return lhd_gcc_personality();
950+
}
951+
}
952+
return personality_decl;
953+
}
954+
955+
#undef LANG_HOOKS_EH_PERSONALITY
956+
#define LANG_HOOKS_EH_PERSONALITY jit_langhook_eh_personality
957+
923958
#undef LANG_HOOKS_NAME
924959
#define LANG_HOOKS_NAME "libgccjit"
925960

gcc/jit/libgccjit.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,6 +3753,13 @@ gcc_jit_function_set_personality_function (gcc_jit_function *fn,
37533753
fn->set_personality_function (personality_func);
37543754
}
37553755

3756+
extern char* jit_personality_func_name;
3757+
3758+
void
3759+
gcc_jit_set_global_personality_function_name (char* name) {
3760+
jit_personality_func_name = name;
3761+
}
3762+
37563763
/* Public entrypoint. See description in libgccjit.h.
37573764
37583765
The real work is done by the

gcc/jit/libgccjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,8 @@ void
18471847
gcc_jit_function_set_personality_function (gcc_jit_function *fn,
18481848
gcc_jit_function *personality_func);
18491849

1850+
extern void
1851+
gcc_jit_set_global_personality_function_name (char* name);
18501852

18511853
#define LIBGCCJIT_HAVE_gcc_jit_context_new_rvalue_from_vector
18521854

gcc/jit/libgccjit.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,5 @@ LIBGCCJIT_ABI_32 {
315315
gcc_jit_context_get_target_builtin_function;
316316
gcc_jit_context_new_rvalue_vector_perm;
317317
gcc_jit_context_new_vector_access;
318+
gcc_jit_set_global_personality_function_name;
318319
} LIBGCCJIT_ABI_31;

gcc/tree-eh.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,10 +4882,9 @@ pass_cleanup_eh::execute (function *fun)
48824882
/* If the function no longer needs an EH personality routine
48834883
clear it. This exposes cross-language inlining opportunities
48844884
and avoids references to a never defined personality routine. */
4885-
// TODO: uncomment and find out why this doesn't work.
4886-
/*if (DECL_FUNCTION_PERSONALITY (current_function_decl)
4885+
if (DECL_FUNCTION_PERSONALITY (current_function_decl)
48874886
&& function_needs_eh_personality (fun) != eh_personality_lang)
4888-
DECL_FUNCTION_PERSONALITY (current_function_decl) = NULL_TREE;*/
4887+
DECL_FUNCTION_PERSONALITY (current_function_decl) = NULL_TREE;
48894888

48904889
return ret;
48914890
}

gcc/tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6479,6 +6479,7 @@ extern tree get_inner_reference (tree, poly_int64_pod *, poly_int64_pod *,
64796479
tree *, machine_mode *, int *, int *, int *);
64806480

64816481
extern tree build_personality_function (const char *);
6482+
extern tree build_personality_function_with_name (const char *);
64826483

64836484
struct GTY(()) int_n_trees_t {
64846485
/* These parts are initialized at runtime */

0 commit comments

Comments
 (0)