aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/lib/profile/GCDAProfiling.c
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-02-16 20:13:02 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-02-16 20:13:02 +0000
commitb60736ec1405bb0a8dd40989f67ef4c93da068ab (patch)
tree5c43fbb7c9fc45f0f87e0e6795a86267dbd12f9d /compiler-rt/lib/profile/GCDAProfiling.c
parentcfca06d7963fa0909f90483b42a6d7d194d01e08 (diff)
Diffstat (limited to 'compiler-rt/lib/profile/GCDAProfiling.c')
-rw-r--r--compiler-rt/lib/profile/GCDAProfiling.c94
1 files changed, 16 insertions, 78 deletions
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index 57d8dec423cc..4293e8f7b5bf 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -128,11 +128,6 @@ struct fn_list {
struct fn_list writeout_fn_list;
/*
- * A list of flush functions that our __gcov_flush() function should call, shared between all dynamic objects.
- */
-struct fn_list flush_fn_list;
-
-/*
* A list of reset functions, shared between all dynamic objects.
*/
struct fn_list reset_fn_list;
@@ -210,22 +205,6 @@ static void write_64bit_value(uint64_t i) {
write_32bit_value(hi);
}
-static uint32_t length_of_string(const char *s) {
- return (strlen(s) / 4) + 1;
-}
-
-// Remove when we support libgcov 9 current_working_directory.
-#if !defined(_MSC_VER) && defined(__clang__)
-__attribute__((unused))
-#endif
-static void
-write_string(const char *s) {
- uint32_t len = length_of_string(s);
- write_32bit_value(len);
- write_bytes(s, strlen(s));
- write_bytes("\0\0\0\0", 4 - (strlen(s) % 4));
-}
-
static uint32_t read_32bit_value() {
uint32_t val;
@@ -324,16 +303,11 @@ static void unmap_file() {
mmap_handle = NULL;
#else
- if (msync(write_buffer, file_size, MS_SYNC) == -1) {
+ if (munmap(write_buffer, file_size) == -1) {
int errnum = errno;
- fprintf(stderr, "profiling: %s: cannot msync: %s\n", filename,
+ fprintf(stderr, "profiling: %s: cannot munmap: %s\n", filename,
strerror(errnum));
}
-
- /* We explicitly ignore errors from unmapping because at this point the data
- * is written and we don't care.
- */
- (void)munmap(write_buffer, file_size);
#endif
write_buffer = NULL;
@@ -422,32 +396,6 @@ void llvm_gcda_start_file(const char *orig_filename, uint32_t version,
#endif
}
-/* Given an array of pointers to counters (counters), increment the n-th one,
- * where we're also given a pointer to n (predecessor).
- */
-COMPILER_RT_VISIBILITY
-void llvm_gcda_increment_indirect_counter(uint32_t *predecessor,
- uint64_t **counters) {
- uint64_t *counter;
- uint32_t pred;
-
- pred = *predecessor;
- if (pred == 0xffffffff)
- return;
- counter = counters[pred];
-
- /* Don't crash if the pred# is out of sync. This can happen due to threads,
- or because of a TODO in GCOVProfiling.cpp buildEdgeLookupTable(). */
- if (counter)
- ++*counter;
-#ifdef DEBUG_GCDAPROFILING
- else
- fprintf(stderr,
- "llvmgcda: increment_indirect_counter counters=%08llx, pred=%u\n",
- *counter, *predecessor);
-#endif
-}
-
COMPILER_RT_VISIBILITY
void llvm_gcda_emit_function(uint32_t ident, uint32_t func_checksum,
uint32_t cfg_checksum) {
@@ -632,6 +580,9 @@ void llvm_writeout_files(void) {
// __attribute__((destructor)) and destructors whose priorities are greater than
// 100 run before this function and can thus be tracked. The priority is
// compatible with GCC 7 onwards.
+#if __GNUC__ >= 9
+#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
+#endif
__attribute__((destructor(100)))
#endif
static void llvm_writeout_and_clear(void) {
@@ -640,25 +591,6 @@ static void llvm_writeout_and_clear(void) {
}
COMPILER_RT_VISIBILITY
-void llvm_register_flush_function(fn_ptr fn) {
- fn_list_insert(&flush_fn_list, fn);
-}
-
-void __gcov_flush() {
- struct fn_node* curr = flush_fn_list.head;
-
- while (curr) {
- curr->fn();
- curr = curr->next;
- }
-}
-
-COMPILER_RT_VISIBILITY
-void llvm_delete_flush_function_list(void) {
- fn_list_remove(&flush_fn_list);
-}
-
-COMPILER_RT_VISIBILITY
void llvm_register_reset_function(fn_ptr fn) {
fn_list_insert(&reset_fn_list, fn);
}
@@ -698,15 +630,12 @@ pid_t __gcov_fork() {
#endif
COMPILER_RT_VISIBILITY
-void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn, fn_ptr rfn) {
+void llvm_gcov_init(fn_ptr wfn, fn_ptr rfn) {
static int atexit_ran = 0;
if (wfn)
llvm_register_writeout_function(wfn);
- if (ffn)
- llvm_register_flush_function(ffn);
-
if (rfn)
llvm_register_reset_function(rfn);
@@ -715,11 +644,20 @@ void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn, fn_ptr rfn) {
/* Make sure we write out the data and delete the data structures. */
atexit(llvm_delete_reset_function_list);
- atexit(llvm_delete_flush_function_list);
#ifdef _WIN32
atexit(llvm_writeout_and_clear);
#endif
}
}
+void __gcov_dump(void) {
+ for (struct fn_node *f = writeout_fn_list.head; f; f = f->next)
+ f->fn();
+}
+
+void __gcov_reset(void) {
+ for (struct fn_node *f = reset_fn_list.head; f; f = f->next)
+ f->fn();
+}
+
#endif