diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-03-20 21:11:47 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-03-20 21:11:47 +0000 |
commit | 84b46d300c7a4f1c3ea4e452791de7733ce0d143 (patch) | |
tree | 049ccc2b88be37135422bcb4e89192216b90c96c /lib/profile/GCDAProfiling.c | |
parent | 236a098869e35b29e938cbb7bd98d8d5b656d47f (diff) |
Create a coverage initialization function.
This function replaces the call of `atexit' from being generated in the compile
units. Basically, it registers the "writeout" and "flush" functions (if
present). It will generate calls to the `atexit' function for cleanups and final
writeout functions, but only once. This is better than checking for `main',
because a library may not have a `main' function in it.
<rdar://problem/12439551>
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/GCDAProfiling.c')
-rw-r--r-- | lib/profile/GCDAProfiling.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/profile/GCDAProfiling.c b/lib/profile/GCDAProfiling.c index bca255367..86f68f58a 100644 --- a/lib/profile/GCDAProfiling.c +++ b/lib/profile/GCDAProfiling.c @@ -331,7 +331,7 @@ void llvm_register_writeout_function(writeout_fn fn) { } } -void __llvm_writeout_files() { +void llvm_writeout_files() { struct writeout_fn_node *curr = writeout_fn_head; while (curr) { @@ -381,3 +381,22 @@ void llvm_delete_flush_function_list() { flush_fn_head = flush_fn_tail = NULL; } + +void llvm_gcov_init(writeout_fn wfn, flush_fn ffn) { + static int atexit_ran = 0; + + if (wfn) + llvm_register_writeout_function(wfn); + + if (ffn) + llvm_register_flush_function(ffn); + + if (atexit_ran == 0) { + atexit_ran = 1; + + /* Make sure we write out the data and delete the data structures. */ + atexit(llvm_delete_flush_function_list); + atexit(llvm_delete_writeout_function_list); + atexit(llvm_writeout_files); + } +} |