summaryrefslogtreecommitdiff
path: root/test/profile
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2018-06-29 21:45:55 +0000
committerChih-Hung Hsieh <chh@google.com>2018-06-29 21:45:55 +0000
commit46ce63aeead620efb48427fe645513a32cc48757 (patch)
tree7b030f03b0cc5e804c86c47ef448af064b6713ea /test/profile
parentfc0b277ee27cea17ebe8625d2a6428b3d5f894b2 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@336019 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/profile')
-rw-r--r--test/profile/Inputs/instrprof-dlopen-dlclose-main.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/profile/Inputs/instrprof-dlopen-dlclose-main.c b/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
index fe7eaf0b5..198e4e82f 100644
--- a/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
+++ b/test/profile/Inputs/instrprof-dlopen-dlclose-main.c
@@ -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;