aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r--gcc/cp/decl2.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 970c6381cc6..48febf714d0 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2731,6 +2731,50 @@ cxx_callgraph_analyze_expr (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
return NULL;
}
+/* Java requires that we be able to reference a local address for a
+ method, and not be confused by PLT entries. If hidden aliases are
+ supported, emit one for each java function that we've emitted. */
+
+static void
+build_java_method_aliases (void)
+{
+ struct cgraph_node *node;
+
+#ifndef HAVE_GAS_HIDDEN
+ return;
+#endif
+
+ for (node = cgraph_nodes; node ; node = node->next)
+ {
+ tree fndecl = node->decl;
+
+ if (TREE_ASM_WRITTEN (fndecl)
+ && DECL_CONTEXT (fndecl)
+ && TYPE_P (DECL_CONTEXT (fndecl))
+ && TYPE_FOR_JAVA (DECL_CONTEXT (fndecl))
+ && TARGET_USE_LOCAL_THUNK_ALIAS_P (fndecl))
+ {
+ /* Mangle the name in a predictable way; we need to reference
+ this from a java compiled object file. */
+ tree oid, nid, alias;
+ const char *oname;
+ char *nname;
+
+ oid = DECL_ASSEMBLER_NAME (fndecl);
+ oname = IDENTIFIER_POINTER (oid);
+ gcc_assert (oname[0] == '_' && oname[1] == 'Z');
+ nname = ACONCAT (("_ZGA", oname+2, NULL));
+ nid = get_identifier (nname);
+
+ alias = make_alias_for (fndecl, nid);
+ TREE_PUBLIC (alias) = 1;
+ DECL_VISIBILITY (alias) = VISIBILITY_HIDDEN;
+
+ assemble_alias (alias, oid);
+ }
+ }
+}
+
/* This routine is called from the last rule in yyparse ().
Its job is to create all the code needed to initialize and
destroy the global aggregates. We do the destruction
@@ -2922,6 +2966,10 @@ cp_finish_file (void)
finish_function doesn't clean things up, and we end
up with CURRENT_FUNCTION_DECL set. */
push_to_top_level ();
+ /* The decl's location will mark where it was first
+ needed. Save that so synthesize method can indicate
+ where it was needed from, in case of error */
+ input_location = DECL_SOURCE_LOCATION (decl);
synthesize_method (decl);
pop_from_top_level ();
reconsider = true;
@@ -3062,6 +3110,9 @@ cp_finish_file (void)
check_global_declarations (VEC_address (tree, pending_statics),
VEC_length (tree, pending_statics));
+ /* Generate hidden aliases for Java. */
+ build_java_method_aliases ();
+
finish_repo ();
/* The entire file is now complete. If requested, dump everything
@@ -3181,6 +3232,14 @@ mark_used (tree decl)
{
if (DECL_DEFERRED_FN (decl))
return;
+
+ /* Remember the current location for a function we will end up
+ synthesizing. Then we can inform the user where it was
+ required in the case of error. */
+ if (DECL_ARTIFICIAL (decl) && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
+ && !DECL_THUNK_P (decl))
+ DECL_SOURCE_LOCATION (decl) = input_location;
+
note_vague_linkage_fn (decl);
}
@@ -3198,14 +3257,6 @@ mark_used (tree decl)
pointing to the class location. */
&& current_function_decl)
{
- /* Put the function definition at the position where it is needed,
- rather than within the body of the class. That way, an error
- during the generation of the implicit body points at the place
- where the attempt to generate the function occurs, giving the
- user a hint as to why we are attempting to generate the
- function. */
- DECL_SOURCE_LOCATION (decl) = input_location;
-
synthesize_method (decl);
/* If we've already synthesized the method we don't need to
instantiate it, so we can return right away. */