[compiler-rt] r336678 - Reapply "Make __gcov_flush flush counters for all shared libraries"
Evgenii Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 10 11:23:07 PDT 2018
Hi,
it looks like instrprof-shared-gcov-flush.test needs more XFAILs. See this
x86/x86_64 failure:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/13413/steps/test%20standalone%20compiler-rt/logs/stdio
On Tue, Jul 10, 2018 at 7:12 AM, Marco Castelluccio via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: marco
> Date: Tue Jul 10 07:12:03 2018
> New Revision: 336678
>
> URL: http://llvm.org/viewvc/llvm-project?rev=336678&view=rev
> Log:
> Reapply "Make __gcov_flush flush counters for all shared libraries"
>
> This reapplies r336365, after marking tests as failing on various
> configurations.
>
> Added:
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> dlopen-dlclose-main.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-dlclose-main.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> dlopen-dlclose-main_three-libs.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-func.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-func.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-func2.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-func2.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-func3.c
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-func3.c
> compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-func3.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-dlopen-func3.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-shared-lib.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-lib.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-lib_called-twice.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-lib_called-twice.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-lib_in-loop.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-lib_in-loop.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-main-gcov-flush.c
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main-gcov-flush.c
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-main-gcov-flush_no-writeout.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-main-gcov-flush_shared-call-after.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-main-gcov-flush_shared-call-before-after.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main-gcov-flush_shared-
> call-before-after.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-
> shared-main-gcov-flush_shared-call-before.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov
> compiler-rt/trunk/test/profile/Inputs/instrprof-shared-main.c.gcov
> - copied unchanged from r336473, compiler-rt/trunk/test/
> profile/Inputs/instrprof-shared-main.c.gcov
> compiler-rt/trunk/test/profile/instrprof-gcov-two-objects.test
> - copied, changed from r336473, compiler-rt/trunk/test/
> profile/instrprof-gcov-two-objects.test
> compiler-rt/trunk/test/profile/instrprof-shared-gcov-flush.test
> - copied, changed from r336473, compiler-rt/trunk/test/
> profile/instrprof-shared-gcov-flush.test
> Modified:
> compiler-rt/trunk/lib/profile/GCDAProfiling.c
> compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
> compiler-rt/trunk/test/profile/instrprof-dlopen-dlclose-gcov.test
>
> Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/
> profile/GCDAProfiling.c?rev=336678&r1=336677&r2=336678&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
> +++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Tue Jul 10 07:12:03 2018
> @@ -86,31 +86,76 @@ static uint64_t file_size = 0;
> static int new_file = 0;
> static int fd = -1;
>
> -/*
> - * A list of functions to write out the data.
> - */
> -typedef void (*writeout_fn)();
> +typedef void (*fn_ptr)();
>
> -struct writeout_fn_node {
> - writeout_fn fn;
> - struct writeout_fn_node *next;
> +typedef void* dynamic_object_id;
> +// The address of this variable identifies a given dynamic object.
> +static dynamic_object_id current_id;
> +#define CURRENT_ID (¤t_id)
> +
> +struct fn_node {
> + dynamic_object_id id;
> + fn_ptr fn;
> + struct fn_node* next;
> };
>
> -static struct writeout_fn_node *writeout_fn_head = NULL;
> -static struct writeout_fn_node *writeout_fn_tail = NULL;
> +struct fn_list {
> + struct fn_node *head, *tail;
> +};
>
> /*
> - * A list of flush functions that our __gcov_flush() function should
> call.
> + * A list of functions to write out the data, shared between all dynamic
> objects.
> */
> -typedef void (*flush_fn)();
> +struct fn_list writeout_fn_list;
>
> -struct flush_fn_node {
> - flush_fn fn;
> - struct flush_fn_node *next;
> -};
> +/*
> + * A list of flush functions that our __gcov_flush() function should
> call, shared between all dynamic objects.
> + */
> +struct fn_list flush_fn_list;
> +
> +static void fn_list_insert(struct fn_list* list, fn_ptr fn) {
> + struct fn_node* new_node = malloc(sizeof(struct fn_node));
> + new_node->fn = fn;
> + new_node->next = NULL;
> + new_node->id = CURRENT_ID;
> +
> + if (!list->head) {
> + list->head = list->tail = new_node;
> + } else {
> + list->tail->next = new_node;
> + list->tail = new_node;
> + }
> +}
> +
> +static void fn_list_remove(struct fn_list* list) {
> + struct fn_node* curr = list->head;
> + struct fn_node* prev = NULL;
> + struct fn_node* next = NULL;
> +
> + while (curr) {
> + next = curr->next;
> +
> + if (curr->id == CURRENT_ID) {
> + if (curr == list->head) {
> + list->head = next;
> + }
> +
> + if (curr == list->tail) {
> + list->tail = prev;
> + }
> +
> + if (prev) {
> + prev->next = next;
> + }
> +
> + free(curr);
> + } else {
> + prev = curr;
> + }
>
> -static struct flush_fn_node *flush_fn_head = NULL;
> -static struct flush_fn_node *flush_fn_tail = NULL;
> + curr = next;
> + }
> +}
>
> static void resize_write_buffer(uint64_t size) {
> if (!new_file) return;
> @@ -403,6 +448,7 @@ void llvm_gcda_summary_info() {
> const uint32_t obj_summary_len = 9; /* Length for gcov compatibility. */
> uint32_t i;
> uint32_t runs = 1;
> + static uint32_t run_counted = 0; // We only want to increase the run
> count once.
> uint32_t val = 0;
> uint64_t save_cur_pos = cur_pos;
>
> @@ -429,7 +475,9 @@ void llvm_gcda_summary_info() {
>
> read_32bit_value(); /* checksum, unused */
> read_32bit_value(); /* num, unused */
> - runs += read_32bit_value(); /* Add previous run count to new counter.
> */
> + uint32_t prev_runs = read_32bit_value();
> + /* Add previous run count to new counter, if not already counted
> before. */
> + runs = run_counted ? prev_runs : prev_runs + 1;
> }
>
> cur_pos = save_cur_pos;
> @@ -447,6 +495,8 @@ void llvm_gcda_summary_info() {
> write_bytes("\0\0\0\xa3", 4); /* tag indicates 1 program */
> write_32bit_value(0); /* 0 length */
>
> + run_counted = 1;
> +
> #ifdef DEBUG_GCDAPROFILING
> fprintf(stderr, "llvmgcda: %u runs\n", runs);
> #endif
> @@ -479,61 +529,34 @@ void llvm_gcda_end_file() {
> }
>
> COMPILER_RT_VISIBILITY
> -void llvm_register_writeout_function(writeout_fn fn) {
> - struct writeout_fn_node *new_node = malloc(sizeof(struct
> writeout_fn_node));
> - new_node->fn = fn;
> - new_node->next = NULL;
> -
> - if (!writeout_fn_head) {
> - writeout_fn_head = writeout_fn_tail = new_node;
> - } else {
> - writeout_fn_tail->next = new_node;
> - writeout_fn_tail = new_node;
> - }
> +void llvm_register_writeout_function(fn_ptr fn) {
> + fn_list_insert(&writeout_fn_list, fn);
> }
>
> COMPILER_RT_VISIBILITY
> void llvm_writeout_files(void) {
> - struct writeout_fn_node *curr = writeout_fn_head;
> + struct fn_node *curr = writeout_fn_list.head;
>
> while (curr) {
> - curr->fn();
> + if (curr->id == CURRENT_ID) {
> + curr->fn();
> + }
> curr = curr->next;
> }
> }
>
> COMPILER_RT_VISIBILITY
> void llvm_delete_writeout_function_list(void) {
> - while (writeout_fn_head) {
> - struct writeout_fn_node *node = writeout_fn_head;
> - writeout_fn_head = writeout_fn_head->next;
> - free(node);
> - }
> -
> - writeout_fn_head = writeout_fn_tail = NULL;
> + fn_list_remove(&writeout_fn_list);
> }
>
> COMPILER_RT_VISIBILITY
> -void llvm_register_flush_function(flush_fn fn) {
> - struct flush_fn_node *new_node = malloc(sizeof(struct flush_fn_node));
> - new_node->fn = fn;
> - new_node->next = NULL;
> -
> - if (!flush_fn_head) {
> - flush_fn_head = flush_fn_tail = new_node;
> - } else {
> - flush_fn_tail->next = new_node;
> - flush_fn_tail = new_node;
> - }
> +void llvm_register_flush_function(fn_ptr fn) {
> + fn_list_insert(&flush_fn_list, fn);
> }
>
> -// __gcov_flush is hidden. When called in a .so file,
> -// it dumps profile data of the calling .so file.
> -// If a main program needs to dump profile data of each linked
> -// .so files, it should use dlsym to find and call llvm_gcov_flush.
> -COMPILER_RT_VISIBILITY
> void __gcov_flush() {
> - struct flush_fn_node *curr = flush_fn_head;
> + struct fn_node* curr = flush_fn_list.head;
>
> while (curr) {
> curr->fn();
> @@ -541,25 +564,13 @@ void __gcov_flush() {
> }
> }
>
> -// llvm_gcov_flush is not hidden for a program to use dlsym to
> -// find and call for any linked .so file.
> -void llvm_gcov_flush() {
> - __gcov_flush();
> -}
> -
> COMPILER_RT_VISIBILITY
> void llvm_delete_flush_function_list(void) {
> - while (flush_fn_head) {
> - struct flush_fn_node *node = flush_fn_head;
> - flush_fn_head = flush_fn_head->next;
> - free(node);
> - }
> -
> - flush_fn_head = flush_fn_tail = NULL;
> + fn_list_remove(&flush_fn_list);
> }
>
> COMPILER_RT_VISIBILITY
> -void llvm_gcov_init(writeout_fn wfn, flush_fn ffn) {
> +void llvm_gcov_init(fn_ptr wfn, fn_ptr ffn) {
> static int atexit_ran = 0;
>
> if (wfn)
>
> Modified: compiler-rt/trunk/test/profile/Inputs/instrprof-
> dlopen-dlclose-main.c
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/
> test/profile/Inputs/instrprof-dlopen-dlclose-main.c?rev=
> 336678&r1=336677&r2=336678&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
> (original)
> +++ compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
> Tue Jul 10 07:12:03 2018
> @@ -10,6 +10,12 @@ int main(int argc, char *argv[]) {
> return EXIT_FAILURE;
> }
>
> + void (*func)(void) = (void (*)(void))dlsym(f1_handle, "func");
> + if (func == NULL) {
> + fprintf(stderr, "unable to lookup symbol 'func': %s\n", dlerror());
> + return EXIT_FAILURE;
> + }
> +
> dlerror();
> void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
> if (f2_handle == NULL) {
> @@ -17,31 +23,44 @@ int main(int argc, char *argv[]) {
> return EXIT_FAILURE;
> }
>
> - dlerror();
> - void (*gcov_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
> - if (gcov_flush != NULL || dlerror() == NULL) {
> - fprintf(stderr, "__gcov_flush should not be visible in
> func.shared'\n");
> + void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");
> + if (func2 == NULL) {
> + fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
> + return EXIT_FAILURE;
> + }
> + func2();
> +
> +#ifdef USE_LIB3
> + void *f3_handle = dlopen("func3.shared", RTLD_LAZY | RTLD_GLOBAL);
> + if (f3_handle == NULL) {
> + fprintf(stderr, "unable to open 'func3.shared': %s\n", dlerror());
> + return EXIT_FAILURE;
> + }
> +
> + void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");
> + if (func3 == NULL) {
> + fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());
> return EXIT_FAILURE;
> }
> + func3();
> +#endif
>
> dlerror();
> - void (*f1_flush)() = (void (*)())dlsym(f1_handle, "llvm_gcov_flush");
> - if (f1_flush == NULL) {
> - fprintf(stderr, "unable to find llvm_gcov_flush in func.shared':
> %s\n", dlerror());
> + void (*gcov_flush1)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
> + if (gcov_flush1 == NULL) {
> + fprintf(stderr, "unable to find __gcov_flush in func.shared': %s\n",
> dlerror());
> return EXIT_FAILURE;
> }
> - f1_flush();
>
> dlerror();
> - void (*f2_flush)() = (void (*)())dlsym(f2_handle, "llvm_gcov_flush");
> - if (f2_flush == NULL) {
> - fprintf(stderr, "unable to find llvm_gcov_flush in func2.shared':
> %s\n", dlerror());
> + void (*gcov_flush2)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
> + if (gcov_flush2 == NULL) {
> + fprintf(stderr, "unable to find __gcov_flush in func2.shared': %s\n",
> dlerror());
> return EXIT_FAILURE;
> }
> - f2_flush();
>
> - if (f1_flush == f2_flush) {
> - fprintf(stderr, "Same llvm_gcov_flush found in func.shared and
> func2.shared\n");
> + if (gcov_flush1 == gcov_flush2) {
> + fprintf(stderr, "Same __gcov_flush found in func.shared and
> func2.shared\n");
> return EXIT_FAILURE;
> }
>
> @@ -51,6 +70,17 @@ int main(int argc, char *argv[]) {
> return EXIT_FAILURE;
> }
>
> + func();
> +
> + int g1 = 0;
> + int g2 = 0;
> + int n = 10;
> +
> + if (n % 5 == 0)
> + g1++;
> + else
> + g2++;
> +
> return EXIT_SUCCESS;
> }
>
>
> Modified: compiler-rt/trunk/test/profile/instrprof-dlopen-
> dlclose-gcov.test
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/
> test/profile/instrprof-dlopen-dlclose-gcov.test?rev=336678&
> r1=336677&r2=336678&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/test/profile/instrprof-dlopen-dlclose-gcov.test
> (original)
> +++ compiler-rt/trunk/test/profile/instrprof-dlopen-dlclose-gcov.test Tue
> Jul 10 07:12:03 2018
> @@ -1,6 +1,33 @@
> +# This test fails on powerpc64 BE and s390x (https://bugs.llvm.org/show_
> bug.cgi?id=38121).
> +XFAIL: s390x || powerpc64-unknown-linux-gnu
> +
> RUN: mkdir -p %t.d
> -RUN: %clang --coverage -o %t.d/func.shared -fPIC -shared
> %S/Inputs/instrprof-dlopen-func.c
> -RUN: %clang --coverage -o %t.d/func2.shared -fPIC -shared
> %S/Inputs/instrprof-dlopen-func2.c
> +RUN: cd %t.d
> +
> +RUN: %clang --coverage -o func.shared -fPIC -shared
> %S/Inputs/instrprof-dlopen-func.c
> +RUN: %clang --coverage -o func2.shared -fPIC -shared
> %S/Inputs/instrprof-dlopen-func2.c
> +RUN: %clang --coverage -o func3.shared -fPIC -shared
> %S/Inputs/instrprof-dlopen-func3.c
> RUN: %clang --coverage -o %t -fPIC -rpath %t.d %S/Inputs/instrprof-dlopen-
> dlclose-main.c
>
> +# Test with two dlopened libraries.
> +RUN: %run %t
> +RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-dlclose-main.c.gcov %S/Inputs/instrprof-dlopen-
> dlclose-main.c.gcov
> +RUN: llvm-cov gcov instrprof-dlopen-func.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-func.c.gcov %S/Inputs/instrprof-dlopen-func.c.gcov
> +RUN: llvm-cov gcov instrprof-dlopen-func2.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func2.c.gcov
> +RUN: rm instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda
> instrprof-dlopen-func2.gcda
> +
> +# Test with three dlopened libraries.
> +RUN: %clang -DUSE_LIB3 --coverage -o %t -fPIC -rpath %t.d
> %S/Inputs/instrprof-dlopen-dlclose-main.c
> RUN: %run %t
> +RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-dlclose-main.c.gcov %S/Inputs/instrprof-dlopen-
> dlclose-main_three-libs.c.gcov
> +RUN: llvm-cov gcov instrprof-dlopen-func.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-func.c.gcov %S/Inputs/instrprof-dlopen-func.c.gcov
> +RUN: llvm-cov gcov instrprof-dlopen-func2.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func2.c.gcov
> +RUN: llvm-cov gcov instrprof-dlopen-func3.gcda
> +RUN: FileCheck --match-full-lines --strict-whitespace --input-file
> instrprof-dlopen-func2.c.gcov %S/Inputs/instrprof-dlopen-func3.c.gcov
> +RUN: rm instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda
> instrprof-dlopen-func2.gcda instrprof-dlopen-func3.gcda
>
> Copied: compiler-rt/trunk/test/profile/instrprof-gcov-two-objects.test
> (from r336473, compiler-rt/trunk/test/profile/instrprof-gcov-two-
> objects.test)
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/
> test/profile/instrprof-gcov-two-objects.test?p2=compiler-
> rt/trunk/test/profile/instrprof-gcov-two-objects.
> test&p1=compiler-rt/trunk/test/profile/instrprof-gcov-
> two-objects.test&r1=336473&r2=336678&rev=336678&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/test/profile/instrprof-gcov-two-objects.test
> (original)
> +++ compiler-rt/trunk/test/profile/instrprof-gcov-two-objects.test Tue
> Jul 10 07:12:03 2018
> @@ -1,3 +1,6 @@
> +# This test fails on powerpc64 BE and s390x (https://bugs.llvm.org/show_
> bug.cgi?id=38121).
> +XFAIL: s390x || powerpc64-unknown-linux-gnu
> +
> RUN: mkdir -p %t.d
> RUN: cd %t.d
>
>
> Copied: compiler-rt/trunk/test/profile/instrprof-shared-gcov-flush.test
> (from r336473, compiler-rt/trunk/test/profile/instrprof-shared-gcov-
> flush.test)
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/
> test/profile/instrprof-shared-gcov-flush.test?p2=compiler-
> rt/trunk/test/profile/instrprof-shared-gcov-flush.
> test&p1=compiler-rt/trunk/test/profile/instrprof-shared-
> gcov-flush.test&r1=336473&r2=336678&rev=336678&view=diff
> ============================================================
> ==================
> --- compiler-rt/trunk/test/profile/instrprof-shared-gcov-flush.test
> (original)
> +++ compiler-rt/trunk/test/profile/instrprof-shared-gcov-flush.test Tue
> Jul 10 07:12:03 2018
> @@ -1,3 +1,6 @@
> +# This test fails on Mac, powerpc64 BE and s390x (
> https://bugs.llvm.org/show_bug.cgi?id=38121).
> +XFAIL: darwin || s390x || powerpc64-unknown-linux-gnu
> +
> RUN: mkdir -p %t.d
> RUN: cd %t.d
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/bb691c02/attachment.html>
More information about the llvm-commits
mailing list