aboutsummaryrefslogtreecommitdiff
path: root/gcc/coverage.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2016-09-27 13:07:11 +0200
committerMartin Liska <marxin@gcc.gnu.org>2016-09-27 11:07:11 +0000
commit8c9434c2f9358b8b8bad2c1990edf10a21645f9d (patch)
tree0dfe81cd421cbccec0f0b4ed0c7bdb2943ad2f00 /gcc/coverage.c
parent511d092e41fcea25a4367dec16ea4b44d947f699 (diff)
downloadgcc-8c9434c2f9358b8b8bad2c1990edf10a21645f9d.zip
gcc-8c9434c2f9358b8b8bad2c1990edf10a21645f9d.tar.gz
gcc-8c9434c2f9358b8b8bad2c1990edf10a21645f9d.tar.bz2
gcov: dump in a static dtor instead of in an atexit handler
PR gcov-profile/7970 PR gcov-profile/16855 PR gcov-profile/44779 * g++.dg/gcov/pr16855.C: New test. * coverage.c (build_gcov_exit_decl): New function. (coverage_obj_init): Call the function and generate __gcov_exit destructor. * doc/gcov.texi: Document when __gcov_exit function is called. * libgcov-driver.c (__gcov_init): Do not register a atexit handler. (__gcov_exit): Rename from gcov_exit. * libgcov.h (__gcov_exit): Declare. From-SVN: r240529
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 30cdc69..0b8c0b3 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;
}