[compiler-rt] r336019 - [profile] Add llvm_gcov_flush to be called outside a shared library
Chih-Hung Hsieh via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 14:45:55 PDT 2018
Author: chh
Date: Fri Jun 29 14:45:55 2018
New Revision: 336019
URL: http://llvm.org/viewvc/llvm-project?rev=336019&view=rev
Log:
[profile] Add llvm_gcov_flush to be called outside a shared library
__gcov_flush is hidden.
For applications to dump profiling data of selected .so files,
they can use dlsym to find and call llvm_gcov_flush in each .so file.
Differential Revision: https://reviews.llvm.org/D45454
Modified:
compiler-rt/trunk/lib/profile/GCDAProfiling.c
compiler-rt/trunk/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=336019&r1=336018&r2=336019&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Fri Jun 29 14:45:55 2018
@@ -527,6 +527,10 @@ void llvm_register_flush_function(flush_
}
}
+// __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;
@@ -537,6 +541,12 @@ 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) {
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=336019&r1=336018&r2=336019&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 Fri Jun 29 14:45:55 2018
@@ -10,12 +10,42 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
+ dlerror();
void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
if (f2_handle == NULL) {
fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
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");
+ return EXIT_FAILURE;
+ }
+
+ 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());
+ 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());
+ return EXIT_FAILURE;
+ }
+ f2_flush();
+
+ if (f1_flush == f2_flush) {
+ fprintf(stderr, "Same llvm_gcov_flush found in func.shared and func2.shared\n");
+ return EXIT_FAILURE;
+ }
+
+ dlerror();
if (dlclose(f2_handle) != 0) {
fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
return EXIT_FAILURE;
More information about the llvm-commits
mailing list