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 | 51a6ff57995ee07378b7a87c45e61d48c8363731 (patch) | |
| tree | cb7a0a823fd89938f43a96e116d1e6618dfacc20 /compiler-rt | |
| parent | fb9126578ec3b320272da281ce60aa7cd11e8a06 (diff) | |
| download | bcm5719-llvm-51a6ff57995ee07378b7a87c45e61d48c8363731.tar.gz bcm5719-llvm-51a6ff57995ee07378b7a87c45e61d48c8363731.zip | |
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>
llvm-svn: 177578
Diffstat (limited to 'compiler-rt')
| -rw-r--r-- | compiler-rt/SDKs/darwin/usr/include/stdlib.h | 1 | ||||
| -rw-r--r-- | compiler-rt/lib/profile/GCDAProfiling.c | 21 |
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler-rt/SDKs/darwin/usr/include/stdlib.h b/compiler-rt/SDKs/darwin/usr/include/stdlib.h index c18c2e49a32..7c973dcc610 100644 --- a/compiler-rt/SDKs/darwin/usr/include/stdlib.h +++ b/compiler-rt/SDKs/darwin/usr/include/stdlib.h @@ -22,6 +22,7 @@ typedef __SIZE_TYPE__ size_t; void abort(void) __attribute__((__noreturn__)); +int atexit(void (*)(void)); int atoi(const char *); void free(void *); char *getenv(const char *); diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c index bca25536755..86f68f58a9c 100644 --- a/compiler-rt/lib/profile/GCDAProfiling.c +++ b/compiler-rt/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); + } +} |

