chh created this revision.
chh added reviewers: sylvestre.ledru, davidxl, rnk, void.

__gcov_flush is not called from other functions in GCDAProfiling.c,
but have been used by Android, which needs an interface function
to flush profile data of multiple .so files.

See https://bugs.llvm.org/show_bug.cgi?id=27224#c5


https://reviews.llvm.org/D45454

Files:
  lib/profile/GCDAProfiling.c
  test/profile/Inputs/instrprof-dlopen-dlclose-main.c


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===================================================================
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,25 @@
     return EXIT_FAILURE;
   }
 
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+    fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+    return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+    fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+    return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+    fprintf(stderr, "Same __gcov_flush found in func.shared and 
func2.shared\n");
+    return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
     fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
     return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===================================================================
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,7 +527,7 @@
   }
 }
 
-COMPILER_RT_VISIBILITY
+// Keep __gcov_flush visible for special use cases.
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 


Index: test/profile/Inputs/instrprof-dlopen-dlclose-main.c
===================================================================
--- test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -16,6 +16,25 @@
     return EXIT_FAILURE;
   }
 
+  void (*f1_flush)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
+  if (f1_flush == NULL) {
+    fprintf(stderr, "unable to find __gcov_flush in func.shared'\n");
+    return EXIT_FAILURE;
+  }
+  f1_flush();
+
+  void (*f2_flush)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
+  if (f2_flush == NULL) {
+    fprintf(stderr, "unable to find __gcov_flush in func2.shared'\n");
+    return EXIT_FAILURE;
+  }
+  f2_flush();
+
+  if (f1_flush == f2_flush) {
+    fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
+    return EXIT_FAILURE;
+  }
+
   if (dlclose(f2_handle) != 0) {
     fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
     return EXIT_FAILURE;
Index: lib/profile/GCDAProfiling.c
===================================================================
--- lib/profile/GCDAProfiling.c
+++ lib/profile/GCDAProfiling.c
@@ -527,7 +527,7 @@
   }
 }
 
-COMPILER_RT_VISIBILITY
+// Keep __gcov_flush visible for special use cases.
 void __gcov_flush() {
   struct flush_fn_node *curr = flush_fn_head;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to