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
This commit is contained in:
Bill Wendling 2013-03-20 21:11:47 +00:00
parent fb9126578e
commit 51a6ff5799
2 changed files with 21 additions and 1 deletions

View File

@ -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 *);

View File

@ -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);
}
}