[compiler-rt] r177578 - Create a coverage initialization function.
Bill Wendling
isanbard at gmail.com
Wed Mar 20 14:11:48 PDT 2013
Author: void
Date: Wed Mar 20 16:11:47 2013
New Revision: 177578
URL: http://llvm.org/viewvc/llvm-project?rev=177578&view=rev
Log:
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>
Modified:
compiler-rt/trunk/SDKs/darwin/usr/include/stdlib.h
compiler-rt/trunk/lib/profile/GCDAProfiling.c
Modified: compiler-rt/trunk/SDKs/darwin/usr/include/stdlib.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/SDKs/darwin/usr/include/stdlib.h?rev=177578&r1=177577&r2=177578&view=diff
==============================================================================
--- compiler-rt/trunk/SDKs/darwin/usr/include/stdlib.h (original)
+++ compiler-rt/trunk/SDKs/darwin/usr/include/stdlib.h Wed Mar 20 16:11:47 2013
@@ -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 *);
Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=177578&r1=177577&r2=177578&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Wed Mar 20 16:11:47 2013
@@ -331,7 +331,7 @@ void llvm_register_writeout_function(wri
}
}
-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);
+ }
+}
More information about the llvm-commits
mailing list