forked from OSchip/llvm-project
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:
parent
fb9126578e
commit
51a6ff5799
|
@ -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 *);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue