summaryrefslogtreecommitdiff
path: root/gcc/coverage.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/coverage.c')
-rw-r--r--gcc/coverage.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/gcc/coverage.c b/gcc/coverage.c
index 30cdc69e187..0b8c0b37843 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -1055,8 +1055,30 @@ build_init_ctor (tree gcov_info_type)
stmt = build_call_expr (init_fn, 1, stmt);
append_to_statement_list (stmt, &ctor);
- /* Generate a constructor to run it. */
- cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY);
+ /* Generate a constructor to run it (with priority 99). */
+ cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY - 1);
+}
+
+/* Generate the destructor function to call __gcov_exit. */
+
+static void
+build_gcov_exit_decl (void)
+{
+ tree init_fn = build_function_type_list (void_type_node, void_type_node,
+ NULL);
+ init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
+ get_identifier ("__gcov_exit"), init_fn);
+ TREE_PUBLIC (init_fn) = 1;
+ DECL_EXTERNAL (init_fn) = 1;
+ DECL_ASSEMBLER_NAME (init_fn);
+
+ /* Generate a call to __gcov_exit (). */
+ tree dtor = NULL;
+ tree stmt = build_call_expr (init_fn, 0);
+ append_to_statement_list (stmt, &dtor);
+
+ /* Generate a destructor to run it (with priority 99). */
+ cgraph_build_static_cdtor ('D', dtor, DEFAULT_INIT_PRIORITY - 1);
}
/* Create the gcov_info types and object. Generate the constructor
@@ -1114,6 +1136,7 @@ coverage_obj_init (void)
DECL_NAME (gcov_info_var) = get_identifier (name_buf);
build_init_ctor (gcov_info_type);
+ build_gcov_exit_decl ();
return true;
}